import { zodResolver } from "@hookform/resolvers/zod"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { Button } from "~/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "~/components/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel } from "~/components/ui/form"; import { Input } from "~/components/ui/input"; import RequiredIcon from "~/components/ui/required-icon"; import { useAgreementProject } from "~/services/projects/agreement"; export const signContractSchema = z.object({ id: z.string().optional(), contract: z.instanceof(File).refine((file) => file.size < 4 * 1024 * 1024, { message: "Ukuran file maksimal 4MB", }), }); interface SignContractDialogProps { id: string; disabled?: boolean; } export default function SignContractDialog({ id, disabled }: SignContractDialogProps) { const { mutateAsync } = useAgreementProject(); const [isOpen, setIsOpen] = useState(false); const [loading, setLoading] = useState(false); const form = useForm>({ resolver: zodResolver(signContractSchema), defaultValues: { id: id, contract: undefined, }, }); const onSubmit = async (data: z.infer) => { try { setLoading(true); await mutateAsync({ id: data.id, contract: data.contract }); toast.success("Tanda tangan kontrak berhasil"); } catch (error) { console.error(error); toast.error("Gagal menandatangani kontrak"); } setLoading(false); }; return ( Tanda Tangan Kontrak This action cannot be undone. This will permanently delete your account and remove your data from our servers.
( Input Tanda Tangan field.onChange(e.target.files?.[0])} onBlur={field.onBlur} name={field.name} ref={field.ref} /> )} />
); }