'use client'; // File: components/review-team/ReviewTeamForm.tsx import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { X } from 'lucide-react'; import { useState } from 'react'; const reviewTeamSchema = z.object({ name: z.string().min(1, 'Name is required').max(100), description: z.string().max(255).optional(), defaultForRfaTypes: z.array(z.string()).optional(), }); type ReviewTeamFormValues = z.infer; interface ReviewTeamFormProps { projectPublicId: string; defaultValues?: Partial; onSubmit: (values: ReviewTeamFormValues & { projectPublicId: string }) => void; isLoading?: boolean; } const RFA_TYPE_OPTIONS = ['SDW', 'DDW', 'ADW', 'MS', 'MAT', 'BOQ']; export function ReviewTeamForm({ projectPublicId, defaultValues, onSubmit, isLoading, }: ReviewTeamFormProps) { const [typeInput, setTypeInput] = useState(''); const form = useForm({ resolver: zodResolver(reviewTeamSchema), defaultValues: { name: defaultValues?.name ?? '', description: defaultValues?.description ?? '', defaultForRfaTypes: defaultValues?.defaultForRfaTypes ?? [], }, }); const rfaTypes = form.watch('defaultForRfaTypes') ?? []; const addRfaType = (type: string) => { if (type && !rfaTypes.includes(type)) { form.setValue('defaultForRfaTypes', [...rfaTypes, type]); } setTypeInput(''); }; const removeRfaType = (type: string) => { form.setValue( 'defaultForRfaTypes', rfaTypes.filter((t) => t !== type), ); }; return (
onSubmit({ ...values, projectPublicId }), )} className="space-y-4" > ( Team Name )} /> ( Description