import { DialogProps } from "@radix-ui/react-dialog"; import { LocationForm, LocationFormValues } from "./location-form"; import { useState } from "react"; import { UseFormReturn } from "react-hook-form"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "../ui/dialog"; import { Button } from "../ui/button"; import { Location } from "@/types/types"; const LocationDialog: React.FC< { onDelete?: (location: Location) => void; onUpdate?: (formValues: LocationFormValues) => void; onAdd?: (formValues: LocationFormValues) => void; location?: Location; } & DialogProps > = ({ open, onOpenChange, onDelete, onUpdate, onAdd, location }) => { const [form, setForm] = useState>(); const submitForm = (event: "add" | "update") => { const callback = event === "add" ? onAdd : onUpdate; if (callback) form?.handleSubmit(callback)(); }; if (!(onAdd || onUpdate)) return; return ( {!location ? "Nouvelle adresse" : "Modifier"} {onUpdate && ( )} {onDelete && ( )} {onAdd && !onUpdate && !onDelete && ( )} ); }; export default LocationDialog;