Wait for success before closing, show errors
This commit is contained in:
@@ -52,9 +52,7 @@ export function Outer({
|
||||
<Dialog.ScrollableInner
|
||||
accessibilityLabelledBy={titleId}
|
||||
accessibilityDescribedBy={descriptionId}
|
||||
style={[
|
||||
gtMobile ? {width: 'auto', maxWidth: 400, minWidth: 200} : a.w_full,
|
||||
]}>
|
||||
style={[gtMobile ? {width: 400} : a.w_full]}>
|
||||
{children}
|
||||
</Dialog.ScrollableInner>
|
||||
</Context.Provider>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useCallback} from 'react'
|
||||
import {useCallback, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
@@ -7,11 +7,13 @@ import {logger} from '#/logger'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {useVerificationCreateMutation} from '#/state/queries/verification/useVerificationCreateMutation'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {atoms as a} from '#/alf'
|
||||
import {atoms as a, useBreakpoints} from '#/alf'
|
||||
import {Admonition} from '#/components/Admonition'
|
||||
import {Button, ButtonIcon,ButtonText} from '#/components/Button'
|
||||
import {type DialogControlProps} from '#/components/Dialog'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
import {VerifiedCheck} from '#/components/icons/VerifiedCheck'
|
||||
import {Loader} from '#/components/Loader'
|
||||
import * as ProfileCard from '#/components/ProfileCard'
|
||||
import * as Prompt from '#/components/Prompt'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
@@ -24,19 +26,22 @@ export function VerificationCreatePrompt({
|
||||
profile: bsky.profile.AnyProfileView
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {mutateAsync: create} = useVerificationCreateMutation()
|
||||
const {mutateAsync: create, isPending} = useVerificationCreateMutation()
|
||||
const [error, setError] = useState(``)
|
||||
const onConfirm = useCallback(async () => {
|
||||
try {
|
||||
await create({profile})
|
||||
Toast.show(_(msg`Successfully verified`))
|
||||
control.close()
|
||||
} catch (e) {
|
||||
Toast.show(_(msg`Failed to create a verification`), 'xmark')
|
||||
setError(_(msg`Verification failed, please try again.`))
|
||||
logger.error('Failed to create a verification', {
|
||||
safeMessage: e,
|
||||
})
|
||||
}
|
||||
}, [_, profile, create])
|
||||
}, [_, profile, create, control])
|
||||
|
||||
return (
|
||||
<Prompt.Outer control={control}>
|
||||
@@ -63,10 +68,24 @@ export function VerificationCreatePrompt({
|
||||
</ProfileCard.Header>
|
||||
) : null}
|
||||
|
||||
{error && (
|
||||
<View style={[a.pt_lg]}>
|
||||
<Admonition type="error">{error}</Admonition>
|
||||
</View>
|
||||
)}
|
||||
|
||||
<View style={[a.pt_xl]}>
|
||||
{profile.displayName ? (
|
||||
<Prompt.Actions>
|
||||
<Prompt.Action cta={_(msg`Verify account`)} onPress={onConfirm} />
|
||||
<Button
|
||||
variant="solid"
|
||||
color="primary"
|
||||
size={gtMobile ? 'small' : 'large'}
|
||||
label={_(msg`Verify account`)}
|
||||
onPress={onConfirm}>
|
||||
<ButtonText>{_(msg`Verify account`)}</ButtonText>
|
||||
{isPending && <ButtonIcon icon={Loader} />}
|
||||
</Button>
|
||||
<Prompt.Cancel />
|
||||
</Prompt.Actions>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user