import { z } from 'zod' import { useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { toast } from '@/hooks/use-toast' import { Button } from '@/components/ui/button' import { Dialog, DialogClose, 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' const formSchema = z.object({ file: z .instanceof(FileList) .refine((files) => files.length > 0, { message: 'Please upload a file', }) .refine( (files) => ['text/csv'].includes(files?.[0]?.type), 'Please upload csv format.' ), }) interface Props { open: boolean onOpenChange: (open: boolean) => void } export function TasksImportDialog({ open, onOpenChange }: Props) { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { file: undefined }, }) const fileRef = form.register('file') const onSubmit = () => { const file = form.getValues('file') if (file && file[0]) { const fileDetails = { name: file[0].name, size: file[0].size, type: file[0].type, } toast({ title: 'You have imported the following file:', description: (
            
              {JSON.stringify(fileDetails, null, 2)}
            
          
), }) } onOpenChange(false) } return ( { onOpenChange(val) form.reset() }} > Import Tasks Import tasks quickly from a CSV file.
( File )} />
) }