mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { FormEvent, ReactNode } from 'react';
|
|
import {
|
|
Dialog,
|
|
DialogClose,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@/components/ui/dialog';
|
|
import { Button } from '@/components/ui/button';
|
|
import { useForm } from '@inertiajs/react';
|
|
import { Form, FormField, FormFields } from '@/components/ui/form';
|
|
import { Label } from '@/components/ui/label';
|
|
import { Input } from '@/components/ui/input';
|
|
import InputError from '@/components/ui/input-error';
|
|
import { LoaderCircleIcon } from 'lucide-react';
|
|
import { Project } from '@/types/project';
|
|
|
|
export default function DeleteProject({ project, children }: { project: Project; children: ReactNode }) {
|
|
const form = useForm({
|
|
name: '',
|
|
});
|
|
|
|
const submit = (e: FormEvent) => {
|
|
e.preventDefault();
|
|
form.delete(route('projects.destroy', project.id));
|
|
};
|
|
|
|
return (
|
|
<Dialog>
|
|
<DialogTrigger asChild>{children}</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Delete {project.name}</DialogTitle>
|
|
<DialogDescription>Delete project and all its resources.</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<Form id="delete-project-form" onSubmit={submit}>
|
|
<FormFields>
|
|
<FormField>
|
|
<Label htmlFor="project-name">Name</Label>
|
|
<Input id="project-name" value={form.data.name} onChange={(e) => form.setData('name', e.target.value)} />
|
|
<InputError message={form.errors.name} />
|
|
</FormField>
|
|
</FormFields>
|
|
</Form>
|
|
|
|
<DialogFooter className="gap-2">
|
|
<DialogClose asChild>
|
|
<Button variant="secondary">Cancel</Button>
|
|
</DialogClose>
|
|
|
|
<Button form="delete-project-form" variant="destructive" disabled={form.processing}>
|
|
{form.processing && <LoaderCircleIcon className="size-4 animate-spin" />}
|
|
Delete Project
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|