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