import React, { useCallback, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import Link from 'next/link' import { RiContractLine, RiDoorLockLine, RiErrorWarningFill } from '@remixicon/react' import Loading from '@/app/components/base/loading' import MailAndCodeAuth from './components/mail-and-code-auth' import MailAndPasswordAuth from './components/mail-and-password-auth' import SSOAuth from './components/sso-auth' import cn from '@/utils/classnames' import { LicenseStatus } from '@/types/feature' import { IS_CE_EDITION } from '@/config' import { useGlobalPublicStore } from '@/context/global-public-context' const NormalForm = () => { const { t } = useTranslation() const [isLoading, setIsLoading] = useState(true) const { systemFeatures } = useGlobalPublicStore() const [authType, updateAuthType] = useState<'code' | 'password'>('password') const [showORLine, setShowORLine] = useState(false) const [allMethodsAreDisabled, setAllMethodsAreDisabled] = useState(false) const init = useCallback(async () => { try { setAllMethodsAreDisabled(!systemFeatures.enable_social_oauth_login && !systemFeatures.enable_email_code_login && !systemFeatures.enable_email_password_login && !systemFeatures.sso_enforced_for_signin) setShowORLine((systemFeatures.enable_social_oauth_login || systemFeatures.sso_enforced_for_signin) && (systemFeatures.enable_email_code_login || systemFeatures.enable_email_password_login)) updateAuthType(systemFeatures.enable_email_password_login ? 'password' : 'code') } catch (error) { console.error(error) setAllMethodsAreDisabled(true) } finally { setIsLoading(false) } }, [systemFeatures]) useEffect(() => { init() }, [init]) if (isLoading) { return
} if (systemFeatures.license?.status === LicenseStatus.LOST) { return

{t('login.licenseLost')}

{t('login.licenseLostTip')}

} if (systemFeatures.license?.status === LicenseStatus.EXPIRED) { return

{t('login.licenseExpired')}

{t('login.licenseExpiredTip')}

} if (systemFeatures.license?.status === LicenseStatus.INACTIVE) { return

{t('login.licenseInactive')}

{t('login.licenseInactiveTip')}

} return ( <>

{t('login.pageTitle')}

{!systemFeatures.branding.enabled &&

{t('login.welcome')}

}
{systemFeatures.sso_enforced_for_signin &&
}
{showORLine &&
{t('login.or')}
} { (systemFeatures.enable_email_code_login || systemFeatures.enable_email_password_login) && <> {systemFeatures.enable_email_code_login && authType === 'code' && <> {systemFeatures.enable_email_password_login &&
{ updateAuthType('password') }}> {t('login.usePassword')}
} } {systemFeatures.enable_email_password_login && authType === 'password' && <> {systemFeatures.enable_email_code_login &&
{ updateAuthType('code') }}> {t('login.useVerificationCode')}
} } } {allMethodsAreDisabled && <>

{t('login.noLoginMethod')}

{t('login.noLoginMethodTip')}

} {!systemFeatures.branding.enabled && <>
{t('login.tosDesc')}   {t('login.tos')}  &  {t('login.pp')}
{IS_CE_EDITION &&
{t('login.goToInit')}   {t('login.setAdminAccount')}
} }
) } export default NormalForm