import { zodResolver } from "@hookform/resolvers/zod"; import { t } from "@lingui/macro"; import { XIcon } from "@phosphor-icons/react"; import { defaultInterest, interestSchema } from "@reactive-resume/schema"; import { Badge, BadgeInput, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Input, } 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 { SectionDialog } from "../sections/shared/section-dialog"; const formSchema = interestSchema; type FormValues = z.infer; const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); }; export const InterestsDialog = () => { const form = useForm({ defaultValues: defaultInterest, 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); }; return ( id="interests" form={form} defaultValues={defaultInterest} pendingKeyword={pendingKeyword} >
( {t`Name`} )} /> (
{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} ))}
)} />
); };