"use client"; import { zodResolver } from "@hookform/resolvers/zod"; import { Button } from "@rallly/ui/button"; import type { DialogProps } from "@rallly/ui/dialog"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@rallly/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@rallly/ui/form"; import { Input } from "@rallly/ui/input"; import { toast } from "@rallly/ui/sonner"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { Trans } from "@/components/trans"; import { useSafeAction } from "@/features/safe-action/client"; import { createSpaceAction } from "@/features/spaces/actions"; import { useTranslation } from "@/i18n/client"; const newSpaceFormSchema = z.object({ name: z.string().min(1).max(100), }); type NewSpaceFormValues = z.infer; export function NewSpaceDialog({ children, ...props }: DialogProps) { const { t } = useTranslation(); const form = useForm({ resolver: zodResolver(newSpaceFormSchema), defaultValues: { name: "", }, }); const createSpace = useSafeAction(createSpaceAction, { onSuccess: () => { form.reset(); }, }); return ( {children}
{ props.onOpenChange?.(false); toast.promise( createSpace.executeAsync({ name, }), { loading: t("createSpaceLoading", { defaultValue: "Creating space...", }), success: t("createSpaceSuccess", { defaultValue: "Space created successfully", }), error: t("createSpaceError", { defaultValue: "Failed to create space", }), }, ); })} > ( )} />
); }