forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useCallback, useState} from 'react'
2import {View} from 'react-native'
3import {msg, Trans} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {logger} from '#/logger'
7import {useModerationOpts} from '#/state/preferences/moderation-opts'
8import {useVerificationCreateMutation} from '#/state/queries/verification/useVerificationCreateMutation'
9import * as Toast from '#/view/com/util/Toast'
10import {atoms as a, useBreakpoints} from '#/alf'
11import {Admonition} from '#/components/Admonition'
12import {Button, ButtonIcon, ButtonText} from '#/components/Button'
13import {type DialogControlProps} from '#/components/Dialog'
14import * as Dialog from '#/components/Dialog'
15import {VerifiedCheck} from '#/components/icons/VerifiedCheck'
16import {Loader} from '#/components/Loader'
17import * as ProfileCard from '#/components/ProfileCard'
18import * as Prompt from '#/components/Prompt'
19import type * as bsky from '#/types/bsky'
20
21export function VerificationCreatePrompt({
22 control,
23 profile,
24}: {
25 control: DialogControlProps
26 profile: bsky.profile.AnyProfileView
27}) {
28 const {_} = useLingui()
29 const {gtMobile} = useBreakpoints()
30 const moderationOpts = useModerationOpts()
31 const {mutateAsync: create, isPending} = useVerificationCreateMutation()
32 const [error, setError] = useState(``)
33 const onConfirm = useCallback(async () => {
34 try {
35 await create({profile})
36 Toast.show(_(msg`Successfully verified`))
37 control.close()
38 } catch (e) {
39 setError(_(msg`Verification failed, please try again.`))
40 logger.error('Failed to create a verification', {
41 safeMessage: e,
42 })
43 }
44 }, [_, profile, create, control])
45
46 return (
47 <Prompt.Outer control={control}>
48 <View style={[a.flex_row, a.align_center, a.gap_sm, a.pb_sm]}>
49 <VerifiedCheck width={18} />
50 <Prompt.TitleText style={[a.pb_0]}>
51 {_(msg`Verify this account?`)}
52 </Prompt.TitleText>
53 </View>
54 <Prompt.DescriptionText>
55 {_(msg`This action can be undone at any time.`)}
56 </Prompt.DescriptionText>
57
58 {moderationOpts ? (
59 <ProfileCard.Header>
60 <ProfileCard.Avatar
61 profile={profile}
62 moderationOpts={moderationOpts}
63 />
64 <ProfileCard.NameAndHandle
65 profile={profile}
66 moderationOpts={moderationOpts}
67 />
68 </ProfileCard.Header>
69 ) : null}
70
71 {error && (
72 <View style={[a.pt_lg]}>
73 <Admonition type="error">{error}</Admonition>
74 </View>
75 )}
76
77 <View style={[a.pt_xl]}>
78 {profile.displayName ? (
79 <Prompt.Actions>
80 <Button
81 variant="solid"
82 color="primary"
83 size={gtMobile ? 'small' : 'large'}
84 label={_(msg`Verify account`)}
85 onPress={onConfirm}>
86 <ButtonText>{_(msg`Verify account`)}</ButtonText>
87 {isPending && <ButtonIcon icon={Loader} />}
88 </Button>
89 <Prompt.Cancel />
90 </Prompt.Actions>
91 ) : (
92 <Admonition type="warning">
93 <Trans>
94 This user does not have a display name, and therefore cannot be
95 verified.
96 </Trans>
97 </Admonition>
98 )}
99 </View>
100
101 <Dialog.Close />
102 </Prompt.Outer>
103 )
104}