about summary refs log tree commit diff
path: root/src/components/ageAssurance/AgeAssuranceAppealDialog.tsx
blob: cc0d568cab6c0b0ccea22cdd7df329e3a888d5e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import React from 'react'
import {View} from 'react-native'
import {BSKY_LABELER_DID, ComAtprotoModerationDefs} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useMutation} from '@tanstack/react-query'

import {logger} from '#/state/ageAssurance/util'
import {useAgent, useSession} from '#/state/session'
import * as Toast from '#/view/com/util/Toast'
import {atoms as a, useBreakpoints, web} from '#/alf'
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog'
import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography'

export function AgeAssuranceAppealDialog({
  control,
}: {
  control: Dialog.DialogControlProps
}) {
  const {_} = useLingui()
  return (
    <Dialog.Outer control={control}>
      <Dialog.Handle />
      <Dialog.ScrollableInner
        label={_(msg`Contact our moderation team`)}
        style={[web({maxWidth: 400})]}>
        <Inner control={control} />
        <Dialog.Close />
      </Dialog.ScrollableInner>
    </Dialog.Outer>
  )
}

function Inner({control}: {control: Dialog.DialogControlProps}) {
  const {_} = useLingui()
  const {currentAccount} = useSession()
  const {gtPhone} = useBreakpoints()
  const agent = useAgent()

  const [details, setDetails] = React.useState('')
  const isInvalid = details.length > 1000

  const {mutate, isPending} = useMutation({
    mutationFn: async () => {
      logger.metric('ageAssurance:appealDialogSubmit', {})

      await agent.createModerationReport(
        {
          reasonType: ComAtprotoModerationDefs.REASONAPPEAL,
          subject: {
            $type: 'com.atproto.admin.defs#repoRef',
            did: currentAccount?.did,
          },
          reason: `AGE_ASSURANCE_INQUIRY: ` + details,
        },
        {
          encoding: 'application/json',
          headers: {
            'atproto-proxy': `${BSKY_LABELER_DID}#atproto_labeler`,
          },
        },
      )
    },
    onError: err => {
      logger.error('AgeAssuranceAppealDialog failed', {safeMessage: err})
      Toast.show(
        _(msg`Age assurance inquiry failed to send, please try again.`),
        'xmark',
      )
    },
    onSuccess: () => {
      control.close()
      Toast.show(
        _(
          msg({
            message: 'Age assurance inquiry was submitted',
            context: 'toast',
          }),
        ),
      )
    },
  })

  return (
    <View>
      <View style={[a.align_start]}>
        <AgeAssuranceBadge />
      </View>

      <Text style={[a.text_2xl, a.font_heavy, a.pt_md, a.leading_tight]}>
        <Trans>Contact us</Trans>
      </Text>

      <Text style={[a.text_sm, a.pt_sm, a.leading_snug]}>
        <Trans>
          Please provide any additional details you feel moderators may need in
          order to properly assess your Age Assurance status.
        </Trans>
      </Text>

      <View style={[a.pt_md]}>
        <Dialog.Input
          multiline
          isInvalid={isInvalid}
          value={details}
          onChangeText={details => {
            setDetails(details)
          }}
          label={_(msg`Additional details (limit 1000 characters)`)}
          numberOfLines={4}
          onSubmitEditing={() => mutate()}
        />
        <View style={[a.pt_md, a.gap_sm, gtPhone && [a.flex_row_reverse]]}>
          <Button
            label={_(msg`Submit`)}
            size="small"
            variant="solid"
            color="primary"
            onPress={() => mutate()}>
            <ButtonText>
              <Trans>Submit</Trans>
            </ButtonText>
            {isPending && <ButtonIcon icon={Loader} position="right" />}
          </Button>
          <Button
            label={_(msg`Cancel`)}
            size="small"
            variant="solid"
            color="secondary"
            onPress={() => control.close()}>
            <ButtonText>
              <Trans>Cancel</Trans>
            </ButtonText>
          </Button>
        </View>
      </View>
    </View>
  )
}