Skip to content

Commit

Permalink
fix(SocialLogin): revise error copy
Browse files Browse the repository at this point in the history
  • Loading branch information
wlliaml committed Oct 9, 2023
1 parent 42d158b commit 1c0168a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lang/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -1835,4 +1835,4 @@
"defaultMessage": "{subscriber, plural, =1 {人} other {人}}",
"description": "src/views/Circle/Analytics/SubscriberAnalytics/index.tsx"
}
}
}
2 changes: 1 addition & 1 deletion lang/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -1835,4 +1835,4 @@
"defaultMessage": "{subscriber, plural, =1 {人} other {人}}",
"description": "src/views/Circle/Analytics/SubscriberAnalytics/index.tsx"
}
}
}
13 changes: 12 additions & 1 deletion src/components/Dialogs/SetEmailDialog/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useContext } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'

import {
ERROR_CODES,
KEYVALUE,
MAX_CHANGE_EMAIL_TIME_DAILY,
TOAST_SEND_EMAIL_VERIFICATION,
Expand Down Expand Up @@ -117,7 +118,17 @@ const SetEmailDialogContent: React.FC<FormProps> = ({ closeDialog }) => {
} catch (error) {
const [messages, codes] = parseFormSubmitErrors(error as any)
codes.forEach((code) => {
setFieldError('email', intl.formatMessage(messages[code]))
if (code.includes(ERROR_CODES.FORBIDDEN_BY_STATE)) {
setFieldError(
'email',
intl.formatMessage({
defaultMessage: 'Unavailable',
description: 'FORBIDDEN_BY_STATE',
})
)
} else {
setFieldError('email', intl.formatMessage(messages[code]))
}
})
setSubmitting(false)
}
Expand Down
18 changes: 16 additions & 2 deletions src/components/Forms/EmailLoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ export const EmailLoginForm: React.FC<FormProps> = ({
'This login code has expired, please try to resend',
})
)
} else if (code.includes(ERROR_CODES.FORBIDDEN_BY_STATE)) {
setFieldError(
'email',
intl.formatMessage({
defaultMessage: 'Unavailable',
description: 'FORBIDDEN_BY_STATE',
})
)
} else {
setFieldError('password', intl.formatMessage(messages[code]))
}
Expand Down Expand Up @@ -220,10 +228,16 @@ export const EmailLoginForm: React.FC<FormProps> = ({
passwordRef.current.focus()
}
} catch (error) {
const [messages, codes] = parseFormSubmitErrors(error as any)
const [, codes] = parseFormSubmitErrors(error as any)
codes.forEach((code) => {
if (code.includes(ERROR_CODES.FORBIDDEN_BY_STATE)) {
setFieldError('password', intl.formatMessage(messages[code]))
setFieldError(
'email',
intl.formatMessage({
defaultMessage: 'Unavailable',
description: 'FORBIDDEN_BY_STATE',
})
)
}
})
}
Expand Down
13 changes: 12 additions & 1 deletion src/components/Forms/EmailSignUpForm/Init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import _pickBy from 'lodash/pickBy'
import { useContext, useRef, useState } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'

import { ERROR_CODES } from '~/common/enums'
import {
parseFormSubmitErrors,
signupCallbackUrl,
Expand Down Expand Up @@ -122,7 +123,17 @@ const Init: React.FC<FormProps> = ({
setSubmitting(false)

const [messages, codes] = parseFormSubmitErrors(error as any)
setFieldError('email', intl.formatMessage(messages[codes[0]]))
if (codes[0].includes(ERROR_CODES.FORBIDDEN_BY_STATE)) {
setFieldError(
'email',
intl.formatMessage({
defaultMessage: 'Unavailable',
description: 'FORBIDDEN_BY_STATE',
})
)
} else {
setFieldError('email', intl.formatMessage(messages[codes[0]]))
}

refreshToken?.()
turnstileRef.current?.reset()
Expand Down
4 changes: 2 additions & 2 deletions src/views/Callback/SocialCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from '~/common/enums'
import { analytics, setCookies, storage } from '~/common/utils'
import {
ERROR_MESSAGES,
getErrorCodes,
LanguageContext,
toast,
Expand Down Expand Up @@ -113,7 +112,8 @@ const SocialCallback = ({ type }: Props) => {
toast.error({
message: (
<FormattedMessage
{...ERROR_MESSAGES[ERROR_CODES.FORBIDDEN_BY_STATE]}
defaultMessage="Unavailable"
description="FORBIDDEN_BY_STATE"
/>
),
})
Expand Down

0 comments on commit 1c0168a

Please sign in to comment.