Handle did error
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
import {useState} from 'react'
|
import {useState} from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
|
import {XRPCError} from '@atproto/xrpc'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {validate as validateEmail} from 'email-validator'
|
import {validate as validateEmail} from 'email-validator'
|
||||||
|
|
||||||
import {useCleanError} from '#/lib/hooks/useCleanError'
|
import {useCleanError} from '#/lib/hooks/useCleanError'
|
||||||
|
import {
|
||||||
|
SupportCode,
|
||||||
|
useCreateSupportLink,
|
||||||
|
} from '#/lib/hooks/useCreateSupportLink'
|
||||||
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
||||||
import {useTLDs} from '#/lib/hooks/useTLDs'
|
import {useTLDs} from '#/lib/hooks/useTLDs'
|
||||||
import {isEmailMaybeInvalid} from '#/lib/strings/email'
|
import {isEmailMaybeInvalid} from '#/lib/strings/email'
|
||||||
@@ -66,6 +71,7 @@ function Inner() {
|
|||||||
const {lastInitiatedAt} = useAgeAssuranceContext()
|
const {lastInitiatedAt} = useAgeAssuranceContext()
|
||||||
const getTimeAgo = useGetTimeAgo()
|
const getTimeAgo = useGetTimeAgo()
|
||||||
const tlds = useTLDs()
|
const tlds = useTLDs()
|
||||||
|
const createSupportLink = useCreateSupportLink()
|
||||||
|
|
||||||
const wasRecentlyInitiated =
|
const wasRecentlyInitiated =
|
||||||
lastInitiatedAt &&
|
lastInitiatedAt &&
|
||||||
@@ -79,7 +85,7 @@ function Inner() {
|
|||||||
const [language, setLanguage] = useState<string | undefined>(
|
const [language, setLanguage] = useState<string | undefined>(
|
||||||
convertToKWSSupportedLanguage(langPrefs.appLanguage),
|
convertToKWSSupportedLanguage(langPrefs.appLanguage),
|
||||||
)
|
)
|
||||||
const [error, setError] = useState<string>('')
|
const [error, setError] = useState<React.ReactNode>(null)
|
||||||
|
|
||||||
const {mutateAsync: init, isPending} = useInitAgeAssurance()
|
const {mutateAsync: init, isPending} = useInitAgeAssurance()
|
||||||
|
|
||||||
@@ -125,22 +131,32 @@ function Inner() {
|
|||||||
|
|
||||||
setSuccess(true)
|
setSuccess(true)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const {clean, raw} = cleanError(e)
|
if (e instanceof XRPCError) {
|
||||||
|
if (e.error === 'InvalidEmail') {
|
||||||
if (clean) {
|
setError(
|
||||||
setError(clean || _(msg`Something went wrong, please try again`))
|
_(
|
||||||
} else {
|
|
||||||
let message = _(msg`Something went wrong, please try again`)
|
|
||||||
|
|
||||||
if (raw) {
|
|
||||||
if (raw.startsWith('This email address is not supported')) {
|
|
||||||
message = _(
|
|
||||||
msg`Please enter a valid, non-temporary email address. You may need to access this email in the future.`,
|
msg`Please enter a valid, non-temporary email address. You may need to access this email in the future.`,
|
||||||
)
|
),
|
||||||
}
|
)
|
||||||
|
} else if (e.error === 'DidTooLong') {
|
||||||
|
setError(
|
||||||
|
<>
|
||||||
|
<Trans>
|
||||||
|
We're having issues initializing the age assurance process for
|
||||||
|
your account. Please{' '}
|
||||||
|
<InlineLinkText
|
||||||
|
to={createSupportLink({code: SupportCode.AA_DID, email})}
|
||||||
|
label={_(msg`Contact support`)}>
|
||||||
|
contact support
|
||||||
|
</InlineLinkText>{' '}
|
||||||
|
for assistance.
|
||||||
|
</Trans>
|
||||||
|
</>,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
setError(message)
|
const {clean, raw} = cleanError(e)
|
||||||
|
setError(clean || raw || _(msg`Something went wrong, please try again`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import {useCallback} from 'react'
|
||||||
|
import {msg} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {useSession} from '#/state/session'
|
||||||
|
|
||||||
|
export const ZENDESK_SUPPORT_URL =
|
||||||
|
'https://blueskyweb.zendesk.com/hc/requests/new'
|
||||||
|
|
||||||
|
export enum SupportCode {
|
||||||
|
AA_DID = 'AA_DID',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link https://support.zendesk.com/hc/en-us/articles/4408839114522-Creating-pre-filled-ticket-forms}
|
||||||
|
*/
|
||||||
|
export function useCreateSupportLink() {
|
||||||
|
const {_} = useLingui()
|
||||||
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
|
return useCallback(
|
||||||
|
({code, email}: {code: SupportCode; email?: string}) => {
|
||||||
|
const url = new URL(ZENDESK_SUPPORT_URL)
|
||||||
|
if (currentAccount) {
|
||||||
|
url.search = new URLSearchParams({
|
||||||
|
tf_anonymous_requester_email: email || currentAccount.email || '', // email will be defined
|
||||||
|
tf_description:
|
||||||
|
`[Code: ${code}] — ` + _(msg`Please write your message below:`),
|
||||||
|
/**
|
||||||
|
* Custom field specific to {@link ZENDESK_SUPPORT_URL} form
|
||||||
|
*/
|
||||||
|
tf_17205412673421: currentAccount.handle + ` (${currentAccount.did})`,
|
||||||
|
}).toString()
|
||||||
|
}
|
||||||
|
return url.toString()
|
||||||
|
},
|
||||||
|
[_, currentAccount],
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user