import { zodResolver } from "@hookform/resolvers/zod"; import { t } from "@lingui/macro"; import { XIcon } from "@phosphor-icons/react"; import type { CustomSection } from "@reactive-resume/schema"; import { customSectionSchema, defaultCustomSection } from "@reactive-resume/schema"; import { Badge, BadgeInput, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Input, RichInput, } from "@reactive-resume/ui"; import { AnimatePresence, motion } from "framer-motion"; import { useState } from "react"; import { useForm } from "react-hook-form"; import type { z } from "zod"; import { AiActions } from "@/client/components/ai-actions"; import { useDialog } from "@/client/stores/dialog"; import { SectionDialog } from "../sections/shared/section-dialog"; import { URLInput } from "../sections/shared/url-input"; const formSchema = customSectionSchema; type FormValues = z.infer; const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); }; export const CustomSectionDialog = () => { const { payload } = useDialog("custom"); const form = useForm({ defaultValues: defaultCustomSection, resolver: zodResolver(formSchema), }); const [pendingKeyword, setPendingKeyword] = useState(""); const [draggedIndex, setDraggedIndex] = useState(null); const handleDrop = ( e: React.DragEvent, dropIndex: number, field: { value: string[]; onChange: (value: string[]) => void }, ) => { e.preventDefault(); if (draggedIndex === null) return; const newKeywords = [...field.value]; const [draggedItem] = newKeywords.splice(draggedIndex, 1); newKeywords.splice(dropIndex, 0, draggedItem); field.onChange(newKeywords); setDraggedIndex(null); }; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!payload) return null; return ( form={form} id={payload.id} defaultValues={defaultCustomSection} pendingKeyword={pendingKeyword} >
( {t`Name`} )} /> ( {t`Description`} )} /> ( {t`Date or Date Range`} )} /> ( {t`Location`} )} /> ( {t`Website`} )} /> ( {t`Summary`} ( { editor.commands.setContent(value, true); field.onChange(value); }} /> )} onChange={(value) => { field.onChange(value); }} /> )} /> (
{t`Keywords`} {t`You can add multiple keywords by separating them with a comma or pressing enter.`}
{field.value.map((item, index) => ( { setDraggedIndex(index); }} onDragOver={handleDragOver} onDrop={(e) => { handleDrop(e, index, field); }} > { field.onChange(field.value.filter((v) => item !== v)); }} > {item} ))}
)} />
); };