format: fix formatting

This commit is contained in:
djknaeckebrot 2024-12-23 08:39:11 +01:00
parent 375decebb2
commit fa710d4855
2 changed files with 700 additions and 700 deletions

View File

@ -1,21 +1,21 @@
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogDescription, DialogDescription,
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
DialogTrigger, DialogTrigger,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { import {
Form, Form,
FormControl, FormControl,
FormField, FormField,
FormItem, FormItem,
FormLabel, FormLabel,
FormMessage, FormMessage,
} from "@/components/ui/form"; } from "@/components/ui/form";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
@ -28,134 +28,134 @@ import { toast } from "sonner";
import { z } from "zod"; import { z } from "zod";
const deleteApplicationSchema = z.object({ const deleteApplicationSchema = z.object({
projectName: z.string().min(1, { projectName: z.string().min(1, {
message: "Application name is required", message: "Application name is required",
}), }),
}); });
type DeleteApplication = z.infer<typeof deleteApplicationSchema>; type DeleteApplication = z.infer<typeof deleteApplicationSchema>;
interface Props { interface Props {
applicationId: string; applicationId: string;
} }
export const DeleteApplication = ({ applicationId }: Props) => { export const DeleteApplication = ({ applicationId }: Props) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const { mutateAsync, isLoading } = api.application.delete.useMutation(); const { mutateAsync, isLoading } = api.application.delete.useMutation();
const { data } = api.application.one.useQuery( const { data } = api.application.one.useQuery(
{ applicationId }, { applicationId },
{ enabled: !!applicationId } { enabled: !!applicationId },
); );
const { push } = useRouter(); const { push } = useRouter();
const form = useForm<DeleteApplication>({ const form = useForm<DeleteApplication>({
defaultValues: { defaultValues: {
projectName: "", projectName: "",
}, },
resolver: zodResolver(deleteApplicationSchema), resolver: zodResolver(deleteApplicationSchema),
}); });
const onSubmit = async (formData: DeleteApplication) => { const onSubmit = async (formData: DeleteApplication) => {
const expectedName = `${data?.name}/${data?.appName}`; const expectedName = `${data?.name}/${data?.appName}`;
if (formData.projectName === expectedName) { if (formData.projectName === expectedName) {
await mutateAsync({ await mutateAsync({
applicationId, applicationId,
}) })
.then((data) => { .then((data) => {
push(`/dashboard/project/${data?.projectId}`); push(`/dashboard/project/${data?.projectId}`);
toast.success("Application deleted successfully"); toast.success("Application deleted successfully");
setIsOpen(false); setIsOpen(false);
}) })
.catch(() => { .catch(() => {
toast.error("Error deleting the application"); toast.error("Error deleting the application");
}); });
} else { } else {
form.setError("projectName", { form.setError("projectName", {
message: "Project name does not match", message: "Project name does not match",
}); });
} }
}; };
return ( return (
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="ghost" isLoading={isLoading}> <Button variant="ghost" isLoading={isLoading}>
<TrashIcon className="size-4 text-muted-foreground" /> <TrashIcon className="size-4 text-muted-foreground" />
</Button> </Button>
</DialogTrigger> </DialogTrigger>
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-lg"> <DialogContent className="max-h-screen overflow-y-auto sm:max-w-lg">
<DialogHeader> <DialogHeader>
<DialogTitle>Are you absolutely sure?</DialogTitle> <DialogTitle>Are you absolutely sure?</DialogTitle>
<DialogDescription> <DialogDescription>
This action cannot be undone. This will permanently delete the This action cannot be undone. This will permanently delete the
application. If you are sure please enter the application name to application. If you are sure please enter the application name to
delete this application. delete this application.
</DialogDescription> </DialogDescription>
</DialogHeader> </DialogHeader>
<div className="grid gap-4"> <div className="grid gap-4">
<Form {...form}> <Form {...form}>
<form <form
onSubmit={form.handleSubmit(onSubmit)} onSubmit={form.handleSubmit(onSubmit)}
id="hook-form-delete-application" id="hook-form-delete-application"
className="grid w-full gap-4" className="grid w-full gap-4"
> >
<FormField <FormField
control={form.control} control={form.control}
name="projectName" name="projectName"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel className="flex items-center gap-2"> <FormLabel className="flex items-center gap-2">
<span> <span>
To confirm, type{" "} To confirm, type{" "}
<Badge <Badge
className="p-2 rounded-md ml-1 mr-1 hover:border-primary hover:text-primary-foreground hover:bg-primary hover:cursor-pointer" className="p-2 rounded-md ml-1 mr-1 hover:border-primary hover:text-primary-foreground hover:bg-primary hover:cursor-pointer"
variant="outline" variant="outline"
onClick={() => { onClick={() => {
if (data?.name && data?.appName) { if (data?.name && data?.appName) {
navigator.clipboard.writeText( navigator.clipboard.writeText(
`${data.name}/${data.appName}` `${data.name}/${data.appName}`,
); );
toast.success("Copied to clipboard. Be careful!"); toast.success("Copied to clipboard. Be careful!");
} }
}} }}
> >
{data?.name}/{data?.appName}&nbsp; {data?.name}/{data?.appName}&nbsp;
<Copy className="h-4 w-4 ml-1 text-muted-foreground" /> <Copy className="h-4 w-4 ml-1 text-muted-foreground" />
</Badge>{" "} </Badge>{" "}
in the box below: in the box below:
</span> </span>
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<Input <Input
placeholder="Enter application name to confirm" placeholder="Enter application name to confirm"
{...field} {...field}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}
/> />
</form> </form>
</Form> </Form>
</div> </div>
<DialogFooter> <DialogFooter>
<Button <Button
variant="secondary" variant="secondary"
onClick={() => { onClick={() => {
setIsOpen(false); setIsOpen(false);
}} }}
> >
Cancel Cancel
</Button> </Button>
<Button <Button
isLoading={isLoading} isLoading={isLoading}
form="hook-form-delete-application" form="hook-form-delete-application"
type="submit" type="submit"
variant="destructive" variant="destructive"
> >
Confirm Confirm
</Button> </Button>
</DialogFooter> </DialogFooter>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
); );
}; };

File diff suppressed because it is too large Load Diff