import React from 'react'; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { Loader2 } from "lucide-react"; import { useForum } from "@/contexts/ForumContext"; import { useAuth } from "@/contexts/AuthContext"; 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 { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; const formSchema = z.object({ title: z.string().min(3, "Title must be at least 3 characters").max(50, "Title must be less than 50 characters"), description: z.string().min(10, "Description must be at least 10 characters").max(200, "Description must be less than 200 characters"), icon: z.string().url("Please enter a valid URL for the icon"), }); export function CreateCellDialog() { const { createCell, isPostingCell } = useForum(); const { isAuthenticated } = useAuth(); const [open, setOpen] = React.useState(false); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { title: "", description: "", icon: "", }, }); const onSubmit = async (values: z.infer) => { const cell = await createCell(values.title, values.description, values.icon); if (cell) { setOpen(false); form.reset(); } }; if (!isAuthenticated) return null; return ( Create a New Cell
( Title )} /> ( Description