'use client' import type { MailSendResponse } from '@/service/use-common' import { noop } from 'es-toolkit/compat' import Link from 'next/link' import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Toast from '@/app/components/base/toast' import Split from '@/app/signin/split' import { emailRegex } from '@/config' import { useGlobalPublicStore } from '@/context/global-public-context' import { useLocale } from '@/context/i18n' import { useSendMail } from '@/service/use-common' type Props = { onSuccess: (email: string, payload: string) => void } export default function Form({ onSuccess, }: Props) { const { t } = useTranslation() const [email, setEmail] = useState('') const locale = useLocale() const { systemFeatures } = useGlobalPublicStore() const { mutateAsync: submitMail, isPending } = useSendMail() const handleSubmit = useCallback(async () => { if (!email) { Toast.notify({ type: 'error', message: t('error.emailEmpty', { ns: 'login' }) }) return } if (!emailRegex.test(email)) { Toast.notify({ type: 'error', message: t('error.emailInValid', { ns: 'login' }), }) return } const res = await submitMail({ email, language: locale }) if ((res as MailSendResponse).result === 'success') onSuccess(email, (res as MailSendResponse).data) }, [email, locale, submitMail, t]) return (
setEmail(e.target.value)} id="email" type="email" autoComplete="email" placeholder={t('emailPlaceholder', { ns: 'login' }) || ''} tabIndex={1} />
{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' })}
)} ) }