use admonition instead of toast for errors when appealing labels (#9272)
* use admonition instead of toast for errors when appealing labels * address commments
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react'
|
import React, {useState} from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {type ComAtprotoLabelDefs, ComAtprotoModerationDefs} from '@atproto/api'
|
import {type ComAtprotoLabelDefs, ComAtprotoModerationDefs} from '@atproto/api'
|
||||||
|
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 {useMutation} from '@tanstack/react-query'
|
import {useMutation} from '@tanstack/react-query'
|
||||||
@@ -19,6 +20,7 @@ import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
|||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {InlineLinkText} from '#/components/Link'
|
import {InlineLinkText} from '#/components/Link'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
import {Admonition} from '../Admonition'
|
||||||
import {Divider} from '../Divider'
|
import {Divider} from '../Divider'
|
||||||
import {Loader} from '../Loader'
|
import {Loader} from '../Loader'
|
||||||
|
|
||||||
@@ -228,6 +230,7 @@ function AppealForm({
|
|||||||
const sourceName = labeler
|
const sourceName = labeler
|
||||||
? sanitizeHandle(labeler.creator.handle, '@')
|
? sanitizeHandle(labeler.creator.handle, '@')
|
||||||
: label.src
|
: label.src
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
const {mutate, isPending} = useMutation({
|
const {mutate, isPending} = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
@@ -252,8 +255,16 @@ function AppealForm({
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
onError: err => {
|
onError: err => {
|
||||||
|
if (err instanceof XRPCError && err.error === 'AlreadyAppealed') {
|
||||||
|
setError(
|
||||||
|
_(
|
||||||
|
msg`You've already appealed this label and it's being reviewed by our moderation team.`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
setError(_(msg`Failed to submit appeal, please try again.`))
|
||||||
|
}
|
||||||
logger.error('Failed to submit label appeal', {message: err})
|
logger.error('Failed to submit label appeal', {message: err})
|
||||||
Toast.show(_(msg`Failed to submit appeal, please try again.`), 'xmark')
|
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
control.close()
|
control.close()
|
||||||
@@ -285,6 +296,11 @@ function AppealForm({
|
|||||||
</Trans>
|
</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
{error && (
|
||||||
|
<Admonition type="error" style={[a.mt_sm]}>
|
||||||
|
{error}
|
||||||
|
</Admonition>
|
||||||
|
)}
|
||||||
<View style={[a.my_md]}>
|
<View style={[a.my_md]}>
|
||||||
<Dialog.Input
|
<Dialog.Input
|
||||||
label={_(msg`Text input field`)}
|
label={_(msg`Text input field`)}
|
||||||
|
|||||||
Reference in New Issue
Block a user