-
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #785 from Dokploy/canary
v0.13.1
- Loading branch information
Showing
79 changed files
with
9,811 additions
and
807 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 120 additions & 40 deletions
160
apps/dokploy/components/dashboard/application/delete-application.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,143 @@ | ||
import { | ||
AlertDialog, | ||
AlertDialogAction, | ||
AlertDialogCancel, | ||
AlertDialogContent, | ||
AlertDialogDescription, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogTitle, | ||
AlertDialogTrigger, | ||
} from "@/components/ui/alert-dialog"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Input } from "@/components/ui/input"; | ||
import { api } from "@/utils/api"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { TrashIcon } from "lucide-react"; | ||
import { useRouter } from "next/router"; | ||
import { useState } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { toast } from "sonner"; | ||
import { z } from "zod"; | ||
|
||
const deleteApplicationSchema = z.object({ | ||
projectName: z.string().min(1, { | ||
message: "Application name is required", | ||
}), | ||
}); | ||
|
||
type DeleteApplication = z.infer<typeof deleteApplicationSchema>; | ||
|
||
interface Props { | ||
applicationId: string; | ||
} | ||
|
||
export const DeleteApplication = ({ applicationId }: Props) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const { mutateAsync, isLoading } = api.application.delete.useMutation(); | ||
const { data } = api.application.one.useQuery( | ||
{ applicationId }, | ||
{ enabled: !!applicationId }, | ||
); | ||
const { push } = useRouter(); | ||
const form = useForm<DeleteApplication>({ | ||
defaultValues: { | ||
projectName: "", | ||
}, | ||
resolver: zodResolver(deleteApplicationSchema), | ||
}); | ||
|
||
const onSubmit = async (formData: DeleteApplication) => { | ||
const expectedName = `${data?.name}/${data?.appName}`; | ||
if (formData.projectName === expectedName) { | ||
await mutateAsync({ | ||
applicationId, | ||
}) | ||
.then((data) => { | ||
push(`/dashboard/project/${data?.projectId}`); | ||
toast.success("Application deleted successfully"); | ||
setIsOpen(false); | ||
}) | ||
.catch(() => { | ||
toast.error("Error deleting the application"); | ||
}); | ||
} else { | ||
form.setError("projectName", { | ||
message: "Project name does not match", | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<AlertDialog> | ||
<AlertDialogTrigger asChild> | ||
<Dialog open={isOpen} onOpenChange={setIsOpen}> | ||
<DialogTrigger asChild> | ||
<Button variant="ghost" isLoading={isLoading}> | ||
<TrashIcon className="size-4 text-muted-foreground" /> | ||
</Button> | ||
</AlertDialogTrigger> | ||
<AlertDialogContent> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> | ||
<AlertDialogDescription> | ||
</DialogTrigger> | ||
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-lg"> | ||
<DialogHeader> | ||
<DialogTitle>Are you absolutely sure?</DialogTitle> | ||
<DialogDescription> | ||
This action cannot be undone. This will permanently delete the | ||
application | ||
</AlertDialogDescription> | ||
</AlertDialogHeader> | ||
<AlertDialogFooter> | ||
<AlertDialogCancel>Cancel</AlertDialogCancel> | ||
<AlertDialogAction | ||
onClick={async () => { | ||
await mutateAsync({ | ||
applicationId, | ||
}) | ||
.then((data) => { | ||
push(`/dashboard/project/${data?.projectId}`); | ||
|
||
toast.success("Application delete succesfully"); | ||
}) | ||
.catch(() => { | ||
toast.error("Error to delete Application"); | ||
}); | ||
application. If you are sure please enter the application name to | ||
delete this application. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<div className="grid gap-4"> | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
id="hook-form-delete-application" | ||
className="grid w-full gap-4" | ||
> | ||
<FormField | ||
control={form.control} | ||
name="projectName" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel> | ||
To confirm, type "{data?.name}/{data?.appName}" in the box | ||
below | ||
</FormLabel> | ||
<FormControl> | ||
<Input | ||
placeholder="Enter application name to confirm" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</form> | ||
</Form> | ||
</div> | ||
<DialogFooter> | ||
<Button | ||
variant="secondary" | ||
onClick={() => { | ||
setIsOpen(false); | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
isLoading={isLoading} | ||
form="hook-form-delete-application" | ||
type="submit" | ||
variant="destructive" | ||
> | ||
Confirm | ||
</AlertDialogAction> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.