import type z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { Trans } from "@lingui/react/macro"; import { PencilSimpleLineIcon, PlusIcon } from "@phosphor-icons/react"; import { useForm, useFormContext } from "react-hook-form"; import type { DialogProps } from "@/dialogs/store"; import { RichInput } from "@/components/input/rich-input"; import { URLInput } from "@/components/input/url-input"; import { useResumeStore } from "@/components/resume/store/resume"; import { Button } from "@/components/ui/button"; import { DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { useDialogStore } from "@/dialogs/store"; import { useFormBlocker } from "@/hooks/use-form-blocker"; import { educationItemSchema } from "@/schema/resume/data"; import { createSectionItem, updateSectionItem } from "@/utils/resume/section-actions"; import { generateId } from "@/utils/string"; const formSchema = educationItemSchema; type FormValues = z.infer; export function CreateEducationDialog({ data }: DialogProps<"resume.sections.education.create">) { const closeDialog = useDialogStore((state) => state.closeDialog); const updateResumeData = useResumeStore((state) => state.updateResumeData); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { id: generateId(), hidden: data?.item?.hidden ?? false, options: data?.item?.options ?? { showLinkInTitle: false }, school: data?.item?.school ?? "", degree: data?.item?.degree ?? "", area: data?.item?.area ?? "", grade: data?.item?.grade ?? "", location: data?.item?.location ?? "", period: data?.item?.period ?? "", website: data?.item?.website ?? { url: "", label: "" }, description: data?.item?.description ?? "", }, }); const onSubmit = (formData: FormValues) => { updateResumeData((draft) => { createSectionItem(draft, "education", formData, data?.customSectionId); }); closeDialog(); }; const { blockEvents, requestClose } = useFormBlocker(form); return ( Create a new education
); } export function UpdateEducationDialog({ data }: DialogProps<"resume.sections.education.update">) { const closeDialog = useDialogStore((state) => state.closeDialog); const updateResumeData = useResumeStore((state) => state.updateResumeData); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { id: data.item.id, hidden: data.item.hidden, options: data.item.options ?? { showLinkInTitle: false }, school: data.item.school, degree: data.item.degree, area: data.item.area, grade: data.item.grade, location: data.item.location, period: data.item.period, website: data.item.website, description: data.item.description, }, }); const onSubmit = (formData: FormValues) => { updateResumeData((draft) => { updateSectionItem(draft, "education", formData, data?.customSectionId); }); closeDialog(); }; const { blockEvents, requestClose } = useFormBlocker(form); return ( Update an existing education
); } function EducationForm() { const form = useFormContext(); return ( <> ( School } /> )} /> ( Degree } /> )} /> ( Area of Study } /> )} /> ( Grade } /> )} /> ( Location } /> )} /> ( Period } /> )} /> ( Website )} /> ( } /> Show link in title )} /> ( Description } /> )} /> ); }