mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(console): validate sign-up identifier (#2446)
This commit is contained in:
parent
887befb761
commit
0af95d790b
1 changed files with 20 additions and 1 deletions
|
@ -6,6 +6,7 @@ import { snakeCase } from 'snake-case';
|
|||
import Checkbox from '@/components/Checkbox';
|
||||
import FormField from '@/components/FormField';
|
||||
import Select from '@/components/Select';
|
||||
import useEnabledConnectorTypes from '@/hooks/use-enabled-connector-types';
|
||||
|
||||
import type { SignInExperienceForm } from '../../types';
|
||||
import ConnectorSetupWarning from './components/ConnectorSetupWarning';
|
||||
|
@ -18,7 +19,13 @@ import * as styles from './index.module.scss';
|
|||
|
||||
const SignUpForm = () => {
|
||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||
const { control, setValue, watch } = useFormContext<SignInExperienceForm>();
|
||||
const {
|
||||
control,
|
||||
setValue,
|
||||
watch,
|
||||
formState: { errors },
|
||||
} = useFormContext<SignInExperienceForm>();
|
||||
const { isConnectorTypeEnabled } = useEnabledConnectorTypes();
|
||||
|
||||
const signUpIdentifier = watch('signUp.identifier');
|
||||
|
||||
|
@ -56,9 +63,21 @@ const SignUpForm = () => {
|
|||
<Controller
|
||||
name="signUp.identifier"
|
||||
control={control}
|
||||
rules={{
|
||||
validate: (value) => {
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return signUpIdentifierToRequiredConnectorMapping[value].every((connectorType) =>
|
||||
isConnectorTypeEnabled(connectorType)
|
||||
);
|
||||
},
|
||||
}}
|
||||
render={({ field: { value, onChange } }) => (
|
||||
<Select
|
||||
value={value}
|
||||
hasError={Boolean(errors.signUp?.identifier)}
|
||||
options={signUpIdentifiers.map((identifier) => ({
|
||||
value: identifier,
|
||||
title: (
|
||||
|
|
Loading…
Reference in a new issue