'use client' import type { MailSendResponse } from '@/service/use-common' import { Button } from '@langgenius/dify-ui/button' import { Field, FieldError, FieldLabel, FieldValidity } from '@langgenius/dify-ui/field' import { Form } from '@langgenius/dify-ui/form' import { Input } from '@langgenius/dify-ui/input' import { useSuspenseQuery } from '@tanstack/react-query' import { useTranslation } from 'react-i18next' import Split from '@/app/signin/split' import { emailRegex } from '@/config' import { useLocale } from '@/context/i18n' import { systemFeaturesQueryOptions } from '@/features/system-features/client' import Link from '@/next/link' import { useSearchParams } from '@/next/navigation' import { useSendMail } from '@/service/use-common' type Props = { onSuccess: (email: string, payload: string) => void } type SignupEmailFormValues = { email: string } export default function SignupEmailForm({ onSuccess }: Props) { const { t } = useTranslation() const locale = useLocale() const searchParams = useSearchParams() const queryString = searchParams.toString() const signinHref = queryString ? `/signin?${queryString}` : '/signin' const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions()) const { mutateAsync: submitMail, isPending } = useSendMail() const handleSubmit = async (email: string) => { if (isPending) return const res = await submitMail({ email, language: locale }) if ((res as MailSendResponse).result === 'success') onSuccess(email, (res as MailSendResponse).data) } return ( onFormSubmit={({ email }) => void handleSubmit(email)}> { const emailValue = String(value) return !emailValue || emailRegex.test(emailValue) ? null : t(($) => $['error.emailInValid'], { ns: 'login' }) }} className="mb-3" > {t(($) => $.email, { ns: 'login' })} $.emailPlaceholder, { ns: 'login' }) || ''} /> {({ validity }) => ( {t(($) => $[validity.valueMissing ? 'error.emailEmpty' : 'error.emailInValid'], { ns: 'login', })} )}
{t(($) => $['signup.haveAccount'], { ns: 'login' })} {t(($) => $['signup.signIn'], { ns: 'login' })}
{!systemFeatures.branding.enabled && ( <>
{t(($) => $.tosDesc, { ns: 'login' })}   {t(($) => $.tos, { ns: 'login' })}  &  {t(($) => $.pp, { ns: 'login' })}
)} ) }