0
Fork 0
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:
Xiao Yijun 2022-11-16 18:31:42 +08:00 committed by GitHub
parent 887befb761
commit 0af95d790b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: (