Merge branch 'feat/email-update-frontend' into feat/change-user-email

pull/22471/head
JzoNg 10 months ago
commit 3e669e14ef

@ -39,6 +39,7 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
const [time, setTime] = useState<number>(0) const [time, setTime] = useState<number>(0)
const [stepToken, setStepToken] = useState<string>('') const [stepToken, setStepToken] = useState<string>('')
const [newEmailExited, setNewEmailExited] = useState<boolean>(false) const [newEmailExited, setNewEmailExited] = useState<boolean>(false)
const [isCheckingEmail, setIsCheckingEmail] = useState<boolean>(false)
const startCount = () => { const startCount = () => {
setTime(60) setTime(60)
@ -72,7 +73,7 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
} }
} }
const verifyEmailAddress = async (email: string, code: string, token: string, callback?: () => void) => { const verifyEmailAddress = async (email: string, code: string, token: string, callback?: (data?: any) => void) => {
try { try {
const res = await verifyEmail({ const res = await verifyEmail({
email, email,
@ -81,7 +82,7 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
}) })
if (res.is_valid) { if (res.is_valid) {
setStepToken(res.token) setStepToken(res.token)
callback?.() callback?.(res.token)
} }
else { else {
notify({ notify({
@ -117,28 +118,24 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
} }
const checkNewEmailExisted = async (email: string) => { const checkNewEmailExisted = async (email: string) => {
setIsCheckingEmail(true)
try { try {
await checkEmailExisted({ await checkEmailExisted({
email, email,
}) })
setNewEmailExited(false) setNewEmailExited(false)
} }
catch (error) { catch {
setNewEmailExited(false) setNewEmailExited(true)
if ((error as any)?.code === 'email_already_in_use') { }
setNewEmailExited(true) finally {
} setIsCheckingEmail(false)
else {
notify({
type: 'error',
message: `Error checking email existence: ${error ? (error as any).message : ''}`,
})
}
} }
} }
const handleNewEmailValueChange = (mailAddress: string) => { const handleNewEmailValueChange = (mailAddress: string) => {
setMail(mailAddress) setMail(mailAddress)
setNewEmailExited(false)
if (isValidEmail(mailAddress)) if (isValidEmail(mailAddress))
checkNewEmailExisted(mailAddress) checkNewEmailExisted(mailAddress)
} }
@ -172,11 +169,11 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
router.push('/signin') router.push('/signin')
} }
const updateEmail = async () => { const updateEmail = async (lastToken: string) => {
try { try {
await resetEmail({ await resetEmail({
new_email: mail, new_email: mail,
token: stepToken, token: lastToken,
}) })
handleLogout() handleLogout()
} }
@ -189,7 +186,7 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
} }
const submitNewEmail = async () => { const submitNewEmail = async () => {
await verifyEmailAddress(mail, code, stepToken, () => updateEmail()) await verifyEmailAddress(mail, code, stepToken, updateEmail)
} }
return ( return (
@ -302,7 +299,7 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
</div> </div>
<div className='mt-3 space-y-2'> <div className='mt-3 space-y-2'>
<Button <Button
disabled={!mail} disabled={!mail || newEmailExited || isCheckingEmail || !isValidEmail(mail)}
className='!w-full' className='!w-full'
variant='primary' variant='primary'
onClick={sendCodeToNewEmail} onClick={sendCodeToNewEmail}

@ -240,13 +240,13 @@ const translation = {
verifyNew: 'Verify your new email', verifyNew: 'Verify your new email',
authTip: 'Once your email is changed, Google or GitHub accounts linked to your old email will no longer be able to log in to this account.', authTip: 'Once your email is changed, Google or GitHub accounts linked to your old email will no longer be able to log in to this account.',
content1: 'If you continue, we\'ll send a verification code to <email>{{email}}</email> for re-authentication.', content1: 'If you continue, we\'ll send a verification code to <email>{{email}}</email> for re-authentication.',
content2: 'Your current email is <email>{{email}}</email> . Verification code has been sent to this email address.', content2: 'Your current email is <email>{{email}}</email>. Verification code has been sent to this email address.',
content3: 'Enter a new email and we will send you a verification code.', content3: 'Enter a new email and we will send you a verification code.',
content4: 'We just sent you a temporary verification code to <email>{{email}}</email>.', content4: 'We just sent you a temporary verification code to <email>{{email}}</email>.',
codeLabel: 'Verification code', codeLabel: 'Verification code',
codePlaceholder: 'Paste the 6-digit code', codePlaceholder: 'Paste the 6-digit code',
emailLabel: 'New email', emailLabel: 'New email',
emailPlaceholder: 'Enter new email', emailPlaceholder: 'Enter a new email',
existingEmail: 'A user with this email already exists.', existingEmail: 'A user with this email already exists.',
sendVerifyCode: 'Send verification code', sendVerifyCode: 'Send verification code',
continue: 'Continue', continue: 'Continue',

@ -238,10 +238,10 @@ const translation = {
title: 'メールアドレスを変更', title: 'メールアドレスを変更',
verifyEmail: '現在のメールアドレスを確認してください', verifyEmail: '現在のメールアドレスを確認してください',
newEmail: '新しいメールアドレスを設定する', newEmail: '新しいメールアドレスを設定する',
verifyNew: '新しいメールアドレスを確認する', verifyNew: '新しいメールアドレスを確認してください',
authTip: 'メールアドレスが変更されると、旧メールアドレスにリンクされている Google または GitHub アカウントは、このアカウントにログインできなくなります。', authTip: 'メールアドレスが変更されると、旧メールアドレスにリンクされている Google または GitHub アカウントは、このアカウントにログインできなくなります。',
content1: '続行すると、再認証のために確認コードが <email>{{email}></email> に送信されます。', content1: '変更を続ける場合、<email>{{email}}</email> に認証用の確認コードをお送りします。',
content2: '現在のメールアドレスは <email>{{email}}</email> です。認コードはこのメールアドレスに送信されました。', content2: '現在のメールアドレスは <email>{{email}}</email> です。コードはこのメールアドレスに送信されました。',
content3: '新しいメールアドレスを入力すると、確認コードが送信されます。', content3: '新しいメールアドレスを入力すると、確認コードが送信されます。',
content4: '一時確認コードを <email>{{email}}</email> に送信しました。', content4: '一時確認コードを <email>{{email}}</email> に送信しました。',
codeLabel: 'コード', codeLabel: 'コード',

@ -241,7 +241,7 @@ const translation = {
authTip: '一旦您的电子邮件地址更改,链接到您旧电子邮件地址的 Google 或 GitHub 帐户将无法再登录该帐户。', authTip: '一旦您的电子邮件地址更改,链接到您旧电子邮件地址的 Google 或 GitHub 帐户将无法再登录该帐户。',
content1: '如果您继续,我们将向 <email>{{email}}</email> 发送验证码以进行重新验证。', content1: '如果您继续,我们将向 <email>{{email}}</email> 发送验证码以进行重新验证。',
content2: '你的当前邮箱是 <email>{{email}}</email> 。验证码已发送至该邮箱。', content2: '你的当前邮箱是 <email>{{email}}</email> 。验证码已发送至该邮箱。',
content3: '输入新的电子邮件,我们将向您发送验证码。', content3: '输入新的邮箱,我们将向您发送验证码。',
content4: '我们已将验证码发送至 <email>{{email}}</email> 。', content4: '我们已将验证码发送至 <email>{{email}}</email> 。',
codeLabel: '验证码', codeLabel: '验证码',
codePlaceholder: '输入 6 位数字验证码', codePlaceholder: '输入 6 位数字验证码',

@ -396,4 +396,4 @@ export const resetEmail = (body: { new_email: string; token: string }) =>
post<CommonResponse>('/account/change-email/reset', { body }) post<CommonResponse>('/account/change-email/reset', { body })
export const checkEmailExisted = (body: { email: string }) => export const checkEmailExisted = (body: { email: string }) =>
post<CommonResponse>('/account/change-email/check-email-unique', { body }) post<CommonResponse>('/account/change-email/check-email-unique', { body }, { silent: true })

Loading…
Cancel
Save