diff --git a/packages/console/src/hooks/use-connector-in-use.ts b/packages/console/src/hooks/use-connector-in-use.ts index 89d30b066..46ed2df08 100644 --- a/packages/console/src/hooks/use-connector-in-use.ts +++ b/packages/console/src/hooks/use-connector-in-use.ts @@ -1,5 +1,5 @@ import type { SignInExperience } from '@logto/schemas'; -import { ConnectorType, SignInMethodState } from '@logto/schemas'; +import { SignUpIdentifier, SignInIdentifier, ConnectorType } from '@logto/schemas'; import useSWR from 'swr'; import type { RequestError } from './use-api'; @@ -12,11 +12,23 @@ const useConnectorInUse = (type?: ConnectorType, target?: string): boolean | und } if (type === ConnectorType.Email) { - return data.signInMethods.email !== SignInMethodState.Disabled; + return ( + data.signIn.methods.some( + ({ identifier, verificationCode }) => + verificationCode && identifier === SignInIdentifier.Email + ) || + (data.signUp.identifier === SignUpIdentifier.Email && data.signUp.verify) + ); } if (type === ConnectorType.Sms) { - return data.signInMethods.sms !== SignInMethodState.Disabled; + return ( + data.signIn.methods.some( + ({ identifier, verificationCode }) => + verificationCode && identifier === SignInIdentifier.Email + ) || + (data.signUp.identifier === SignUpIdentifier.Email && data.signUp.verify) + ); } if (!target) { diff --git a/packages/console/src/pages/SignInExperience/components/ConnectorSetupWarning.tsx b/packages/console/src/pages/SignInExperience/components/ConnectorSetupWarning.tsx deleted file mode 100644 index 09710d24a..000000000 --- a/packages/console/src/pages/SignInExperience/components/ConnectorSetupWarning.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import type { ConnectorResponse } from '@logto/schemas'; -import { ConnectorType, SignInMethodKey } from '@logto/schemas'; -import { useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import useSWR from 'swr'; - -import Alert from '@/components/Alert'; -import type { RequestError } from '@/hooks/use-api'; - -type Props = { - method: SignInMethodKey; -}; - -const ConnectorSetupWarning = ({ method }: Props) => { - const { data: connectors } = useSWR('/api/connectors'); - const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - - const type = useMemo(() => { - if (method === SignInMethodKey.Username) { - return; - } - - if (method === SignInMethodKey.Sms) { - return ConnectorType.Sms; - } - - if (method === SignInMethodKey.Email) { - return ConnectorType.Email; - } - - return ConnectorType.Social; - }, [method]); - - if (!type || !connectors) { - return null; - } - - if (connectors.some(({ type: connectorType, enabled }) => connectorType === type && enabled)) { - return null; - } - - return ( - - {t('sign_in_exp.setup_warning.no_connector', { context: type.toLowerCase() })} - - ); -}; - -export default ConnectorSetupWarning; diff --git a/packages/console/src/pages/SignInExperience/components/SignInMethodsForm.tsx b/packages/console/src/pages/SignInExperience/components/SignInMethodsForm.tsx deleted file mode 100644 index ed4d01d07..000000000 --- a/packages/console/src/pages/SignInExperience/components/SignInMethodsForm.tsx +++ /dev/null @@ -1,147 +0,0 @@ -import { SignInMethodKey } from '@logto/schemas'; -import { useMemo } from 'react'; -import { Controller, useFormContext } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; - -import Checkbox from '@/components/Checkbox'; -import FormField from '@/components/FormField'; -import Select from '@/components/Select'; -import Switch from '@/components/Switch'; - -import type { SignInExperienceForm } from '../types'; -import ConnectorSetupWarning from './ConnectorSetupWarning'; -import ConnectorsTransfer from './ConnectorsTransfer'; -import * as styles from './index.module.scss'; - -const signInMethods = Object.values(SignInMethodKey); - -const SignInMethodsForm = () => { - const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { register, watch, control, getValues, setValue } = useFormContext(); - const primaryMethod = watch('signInMethods.primary'); - const enableSecondary = watch('signInMethods.enableSecondary'); - const sms = watch('signInMethods.sms'); - const email = watch('signInMethods.email'); - const social = watch('signInMethods.social'); - - const postPrimaryMethodChange = ( - oldPrimaryMethod?: SignInMethodKey, - primaryMethod?: SignInMethodKey - ) => { - if (oldPrimaryMethod) { - // The secondary sign-in method should select the old primary method by default. - setValue(`signInMethods.${oldPrimaryMethod}`, true); - } - - if (primaryMethod) { - // When one of the sign-in methods has been primary, it should not be able to be secondary simultaneously. - setValue(`signInMethods.${primaryMethod}`, false); - } - }; - - const secondaryMethodsFields = useMemo( - () => - signInMethods.map((method) => { - const label = ( - <> - {t('sign_in_exp.sign_in_methods.methods', { context: method })} - {primaryMethod === method && ( - - {t('sign_in_exp.sign_in_methods.methods_primary_tag')} - - )} - - ); - - const enabled = - (method === SignInMethodKey.Email && email) || - (method === SignInMethodKey.Sms && sms) || - (method === SignInMethodKey.Social && social); - - return ( -
- ( - - )} - /> - {enabled && } -
- ); - }), - [t, primaryMethod, email, sms, social, control] - ); - - return ( - <> -
{t('sign_in_exp.sign_in_methods.title')}
- - ( -