0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-10 22:22:45 -05:00

fix(console): admin user should be able to set email if current email is null (#3301)

This commit is contained in:
Charles Zhao 2023-03-06 19:32:54 +08:00 committed by GitHub
parent 11471c4308
commit 3d57b94e30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -163,7 +163,7 @@ const LinkAccountSection = ({ user, onUpdate }: Props) => {
<NotSet /> <NotSet />
), ),
action: { action: {
name: 'profile.change', name: user.primaryEmail ? 'profile.change' : 'profile.link',
handler: () => { handler: () => {
navigate('link-email', { navigate('link-email', {
state: { email: user.primaryEmail, action: 'changeEmail' }, state: { email: user.primaryEmail, action: 'changeEmail' },

View file

@ -1,4 +1,5 @@
import { emailRegEx } from '@logto/core-kit'; import { emailRegEx } from '@logto/core-kit';
import { conditional } from '@silverhand/essentials';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
@ -43,6 +44,8 @@ const LinkEmailModal = () => {
})(); })();
}; };
const currentEmail = conditional(checkLocationState(state) && state.email);
return ( return (
<MainFlowLikeModal <MainFlowLikeModal
title="profile.link_account.link_email" title="profile.link_account.link_email"
@ -54,7 +57,8 @@ const LinkEmailModal = () => {
required: t('profile.link_account.email_required'), required: t('profile.link_account.email_required'),
pattern: { value: emailRegEx, message: t('profile.link_account.invalid_email') }, pattern: { value: emailRegEx, message: t('profile.link_account.invalid_email') },
validate: (value) => validate: (value) =>
(checkLocationState(state) && state.email !== value) || !currentEmail ||
currentEmail !== value ||
t('profile.link_account.identical_email_address'), t('profile.link_account.identical_email_address'),
})} })}
errorMessage={errors.email?.message} errorMessage={errors.email?.message}