'use client' import React, { useEffect } from 'react' import { useTranslation } from 'react-i18next' import Link from 'next/link' import { useRouter } from 'next/navigation' import { useContext } from 'use-context-selector' import Toast from '../components/base/toast' import Loading from '../components/base/loading' import Button from '@/app/components/base/button' import I18n from '@/context/i18n' import { fetchSetupStatus, setup } from '@/service/common' import type { SetupStatusResponse } from '@/models/common' const validEmailReg = /^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$/ const validPassword = /^(?=.*[a-zA-Z])(?=.*\d).{8,}$/ const InstallForm = () => { const { t } = useTranslation() const { locale } = useContext(I18n) const router = useRouter() const [email, setEmail] = React.useState('') const [name, setName] = React.useState('') const [password, setPassword] = React.useState('') const [showPassword, setShowPassword] = React.useState(false) const [loading, setLoading] = React.useState(true) const showErrorMessage = (message: string) => { Toast.notify({ type: 'error', message, }) } const valid = () => { if (!email) { showErrorMessage(t('login.error.emailEmpty')) return false } if (!validEmailReg.test(email)) { showErrorMessage(t('login.error.emailInValid')) return false } if (!name.trim()) { showErrorMessage(t('login.error.nameEmpty')) return false } if (!password.trim()) { showErrorMessage(t('login.error.passwordEmpty')) return false } if (!validPassword.test(password)) showErrorMessage(t('login.error.passwordInvalid')) return true } const handleSetting = async () => { if (!valid()) return await setup({ body: { email, name, password, }, }) router.push('/signin') } useEffect(() => { fetchSetupStatus().then((res: SetupStatusResponse) => { if (res.step === 'finished') window.location.href = '/signin' else setLoading(false) }) }, []) return ( loading ? : <>

{t('login.setAdminAccount')}

{t('login.setAdminAccountDesc')}

{ }}>
setEmail(e.target.value)} placeholder={t('login.emailPlaceholder') || ''} className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder-gray-400 caret-primary-600 sm:text-sm'} />
setName(e.target.value)} placeholder={t('login.namePlaceholder') || ''} className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder-gray-400 caret-primary-600 sm:text-sm pr-10'} />
setPassword(e.target.value)} placeholder={t('login.passwordPlaceholder') || ''} className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder-gray-400 caret-primary-600 sm:text-sm pr-10'} />
{t('login.error.passwordInvalid')}
{/*
*/}
{t('login.license.tip')}   {t('login.license.link')}
) } export default InstallForm