Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Oct 19, 2024
1 parent f1c5621 commit c23de51
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type { Workspace } from "@ctrlplane/db/schema";
import Link from "next/link";
import { IconTopologyComplex } from "@tabler/icons-react";

import { Button } from "@ctrlplane/ui/button";
import { Button, buttonVariants } from "@ctrlplane/ui/button";

export const TargetGettingStarted: React.FC = () => {
import { CreateTargetDialog } from "../../_components/CreateTarget";

export const TargetGettingStarted: React.FC<{ workspace: Workspace }> = ({
workspace,
}) => {
return (
<div className="h-full w-full p-20">
<div className="container m-auto max-w-xl space-y-6 p-20">
Expand All @@ -25,10 +31,17 @@ export const TargetGettingStarted: React.FC = () => {
</p>
</div>
<div className="flex items-center gap-2">
<Button size="sm">Register Target</Button>
<Button size="sm" variant="secondary">
<CreateTargetDialog workspace={workspace}>
<Button size="sm">Register Target</Button>
</CreateTargetDialog>
<Link
href="https://docs.ctrlplane.dev/core-concepts/targets"
target="_blank"
passHref
className={buttonVariants({ variant: "secondary", size: "sm" })}
>
Documentation
</Button>
</Link>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const TargetPageContent: React.FC<{
const { targetId, setTargetId } = useTargetDrawer();

if (targetsAll.isSuccess && targetsAll.data.total === 0)
return <TargetGettingStarted />;
return <TargetGettingStarted workspace={workspace} />;
return (
<div className="h-full text-sm">
<div className="flex h-[41px] items-center justify-between border-b border-neutral-800 p-1 px-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const CreateTargetDialog: React.FC<{
query.set("target_id", target.id);
router.replace(`?${query.toString()}`);
router.refresh();
setOpen(false);
onSuccess?.();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export const EnvironmentDrawer: React.FC = () => {
<Drawer open={isOpen} onOpenChange={setIsOpen}>
<DrawerContent
showBar={false}
className="left-auto right-0 top-0 mt-0 h-screen w-[1100px] overflow-auto rounded-none focus-visible:outline-none"
className="left-auto right-0 top-0 mt-0 h-screen w-[500px] overflow-auto rounded-none focus-visible:outline-none"
>
<DrawerTitle className="flex items-center gap-2 border-b p-6">
<div className="flex-shrink-0 rounded bg-green-500/20 p-1 text-green-400">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const EnvironmentPolicyDrawer: React.FC = () => {
<Drawer open={isOpen} onOpenChange={setIsOpen}>
<DrawerContent
showBar={false}
className="left-auto right-0 top-0 mt-0 h-screen w-[1200px] overflow-auto rounded-none focus-visible:outline-none"
className="left-auto right-0 top-0 mt-0 h-screen w-[1100px] overflow-auto rounded-none focus-visible:outline-none"
>
<DrawerTitle className="flex items-center gap-2 border-b p-6">
<div className="flex-shrink-0 rounded bg-purple-500/20 p-1 text-purple-400">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FormField,
FormItem,
FormLabel,
FormMessage,
useForm,
} from "@ctrlplane/ui/form";
import { Input } from "@ctrlplane/ui/input";
Expand Down Expand Up @@ -42,41 +43,43 @@ export const Overview: React.FC<{
);

return (
<Form {...form}>
<form onSubmit={onSubmit} className="space-y-6 p-2">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
</FormItem>
)}
/>

<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea placeholder="Add a description..." {...field} />
</FormControl>
</FormItem>
)}
/>

<Button
type="submit"
disabled={updatePolicy.isPending || !form.formState.isDirty}
>
Save
</Button>
</form>
</Form>
<div className="max-w-xl">
<Form {...form}>
<form onSubmit={onSubmit} className="space-y-6 p-2">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea placeholder="Add a description..." {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button
type="submit"
disabled={updatePolicy.isPending || !form.formState.isDirty}
>
Save
</Button>
</form>
</Form>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import type { Deployment } from "@ctrlplane/db/schema";
import { useRouter } from "next/navigation";
import { useParams, useRouter } from "next/navigation";
import { z } from "zod";

import { deploymentSchema } from "@ctrlplane/db/schema";
Expand Down Expand Up @@ -33,12 +33,22 @@ export const EditDeploymentSection: React.FC<{
});
const { handleSubmit, setError } = form;

const { workspaceSlug, systemSlug } = useParams<{
workspaceSlug: string;
systemSlug: string;
}>();
const router = useRouter();
const updateDeployment = api.deployment.update.useMutation();
const onSubmit = handleSubmit((data) => {
updateDeployment
.mutateAsync({ id: deployment.id, data })
.then(() => router.refresh())
.then(() => {
if (data.slug !== deployment.slug)
router.replace(
`/${workspaceSlug}/systems/${systemSlug}/deployments/${data.slug}`,
);
router.refresh();
})
.catch(() => {
setError("root", {
message: "Deployment with this slug already exists",
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/router/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export const deploymentRouter = createTRPCRouter({
eq(workspace.slug, workspaceSlug),
),
)
.then(takeFirst);
.then(takeFirstOrNull);
if (sys == null) return null;
return canUser
.perform(Permission.DeploymentGet)
.on({ type: "system", id: sys.system.id });
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type AuthorizationCheckFunc<T = any> = (opts: {
ctx: Context & { session: Session };
input: T;
canUser: PermissionChecker;
}) => boolean | Promise<boolean>;
}) => boolean | Promise<boolean | null>;
export type Meta = {
authorizationCheck?: AuthorizationCheckFunc;
};
Expand Down Expand Up @@ -115,7 +115,7 @@ const authzProcedure = authnProcedure.use(
if (authorizationCheck != null) {
const canUser = can().user(ctx.session.user.id);
const input = await getRawInput();
let check = false;
let check: boolean | null = null;
try {
check = await authorizationCheck({ ctx, input, canUser });
} catch (e: any) {
Expand All @@ -126,6 +126,8 @@ const authzProcedure = authnProcedure.use(
});
}

if (check == null) return next();

if (!check)
throw new TRPCError({
code: "FORBIDDEN",
Expand Down

0 comments on commit c23de51

Please sign in to comment.