'use client'; import { useState } from 'react'; import { zodResolver } from '@hookform/resolvers/zod'; import { useAction } from 'next-safe-action/hooks'; import { useForm, useWatch } from 'react-hook-form'; import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert'; import { Button } from '@kit/ui/button'; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@kit/ui/form'; import { If } from '@kit/ui/if'; import { Input } from '@kit/ui/input'; import { Trans } from '@kit/ui/trans'; import { CreateTeamSchema, NON_LATIN_REGEX, } from '../schema/create-team.schema'; import { createTeamAccountAction } from '../server/actions/create-team-account-server-actions'; export function CreateTeamAccountForm(props: { onCancel?: () => void; submitLabel?: string; }) { const [error, setError] = useState<{ message?: string } | undefined>(); const { execute, isPending } = useAction(createTeamAccountAction, { onExecute: () => { setError(undefined); }, onSuccess: ({ data }) => { if (data?.error) { setError({ message: data.message }); } }, onError: () => { setError({}); }, }); const form = useForm({ defaultValues: { name: '', slug: '', }, resolver: zodResolver(CreateTeamSchema), }); const nameValue = useWatch({ control: form.control, name: 'name' }); const showSlugField = NON_LATIN_REGEX.test(nameValue ?? ''); return (
); } function CreateTeamAccountErrorAlert(props: { message?: string }) { return (