// modules/admin/components/user_groups/AddGroupDialog.jsx import { useForm } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogClose, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; const schema = z.object({ name: z.string().min(1, "Name is required."), description: z.string().min(1, "Description is required."), }); /** * Dialog for creating a new group. * Matches context: createGroup({ name, description }) * * @param {Object} props * @param {boolean} props.open * @param {Function} props.onOpenChange * @param {Function} props.onSubmit Called with { name, description } * @param {boolean} [props.loading] */ export function AddGroupDialog({ open, onOpenChange, onSubmit, loading }) { const { register, handleSubmit, reset, formState: { errors }, } = useForm({ resolver: zodResolver(schema), defaultValues: { name: "", description: "" }, }); async function onValid(values) { await onSubmit(values); reset(); } function handleClose() { reset(); onOpenChange(false); } return ( Add group
{errors.name && (

{errors.name.message}

)}