'use client'; import { AlignInfoFillIcon as IconInfoCustomFill } from '@/components/misc/alignui-icons'; import * as React from 'react'; import { zodResolver } from '@hookform/resolvers/zod'; import * as LabelPrimitives from '@radix-ui/react-label'; import { SlidersHorizontal } from 'lucide-react'; import { useFieldArray, useForm } from 'react-hook-form'; import * as z from 'zod'; import * as Button from '@/components/ui/button'; import * as Input from '@/components/ui/input'; import * as Label from '@/components/ui/label'; import * as Modal from '@/components/ui/modal'; import * as Switch from '@/components/ui/switch'; import * as Tag from '@/components/ui/tag'; import * as Tooltip from '@/components/ui/tooltip'; const formSchema = z.object({ sections: z.array( z.object({ id: z.string(), label: z.string(), tags: z.array(z.string()), }), ), messagingEnabled: z.boolean(), matchingScoreEnabled: z.boolean(), }); type FormData = z.infer; export default function RecruitmentCustomizationModal() { const [open, setOpen] = React.useState(true); const [tempInputs, setTempInputs] = React.useState>( {}, ); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { sections: [ { id: 'experience', label: 'Experience Levels', tags: ['Entry Level', 'Internship', 'Mid-level Senior'], }, { id: 'sources', label: 'Candidate Sources', tags: ['LinkedIn', 'Indeed', 'Referral'], }, ], messagingEnabled: true, matchingScoreEnabled: false, }, }); const { fields } = useFieldArray({ name: 'sections', control: form.control, }); const handleAddTag = ( sectionIndex: number, e: React.KeyboardEvent, ) => { if (e.key === 'Enter') { e.preventDefault(); const newTag = tempInputs[sectionIndex]?.trim(); if (newTag) { const currentTags = form.getValues(`sections.${sectionIndex}.tags`); const isDuplicate = currentTags.some( (tag) => tag.toLowerCase() === newTag.toLowerCase(), ); if (!isDuplicate) { form.setValue(`sections.${sectionIndex}.tags`, [ ...currentTags, newTag, ]); setTempInputs((prev) => ({ ...prev, [sectionIndex]: '' })); } } } }; const handleRemoveTag = (sectionIndex: number, tagIndex: number) => { const currentTags = form.getValues(`sections.${sectionIndex}.tags`); form.setValue( `sections.${sectionIndex}.tags`, currentTags.filter((_, index) => index !== tagIndex), ); }; const onSubmit = (data: FormData) => { console.log(data); setOpen(false); }; return ( Open Modal
{fields.map((section, sectionIndex) => (
{section.label} (max. 4) Use relevant keywords, separated by commas. Tags should be concise and descriptive. setTempInputs((prev) => ({ ...prev, [sectionIndex]: e.target.value, })) } onKeyDown={(e) => handleAddTag(sectionIndex, e)} />
{form .watch(`sections.${sectionIndex}.tags`) .map((tag, tagIndex) => ( {tag} handleRemoveTag(sectionIndex, tagIndex) } /> ))}
))}
form.setValue('messagingEnabled', checked) } /> Messaging Settings
form.setValue('matchingScoreEnabled', checked) } /> Matching Score
Cancel Save Changes
); }