+11
-9
src/components/dialogs/BirthDateSettings.tsx
+11
-9
src/components/dialogs/BirthDateSettings.tsx
···
3
import {msg, Trans} from '@lingui/macro'
4
import {useLingui} from '@lingui/react'
5
6
-
import {cleanError} from '#/lib/strings/errors'
7
import {getAge, getDateAgo} from '#/lib/strings/time'
8
import {logger} from '#/logger'
9
import {isIOS, isWeb} from '#/platform/detection'
···
110
preferences: UsePreferencesQueryResponse
111
}) {
112
const {_} = useLingui()
113
const [date, setDate] = React.useState(
114
preferences.birthDate || getDateAgo(18),
115
)
116
-
const {
117
-
isPending,
118
-
isError,
119
-
error,
120
-
mutateAsync: setBirthDate,
121
-
} = useBirthdateMutation()
122
const hasChanged = date !== preferences.birthDate
123
124
const age = getAge(new Date(date))
125
const isUnder13 = age < 13
···
172
</Admonition>
173
)}
174
175
-
{isError ? (
176
-
<ErrorMessage message={cleanError(error)} style={[a.rounded_sm]} />
177
) : undefined}
178
179
<View style={isWeb && [a.flex_row, a.justify_end]}>
···
3
import {msg, Trans} from '@lingui/macro'
4
import {useLingui} from '@lingui/react'
5
6
+
import {useCleanError} from '#/lib/hooks/useCleanError'
7
import {getAge, getDateAgo} from '#/lib/strings/time'
8
import {logger} from '#/logger'
9
import {isIOS, isWeb} from '#/platform/detection'
···
110
preferences: UsePreferencesQueryResponse
111
}) {
112
const {_} = useLingui()
113
+
const cleanError = useCleanError()
114
const [date, setDate] = React.useState(
115
preferences.birthDate || getDateAgo(18),
116
)
117
+
const {isPending, error, mutateAsync: setBirthDate} = useBirthdateMutation()
118
const hasChanged = date !== preferences.birthDate
119
+
const errorMessage = React.useMemo(() => {
120
+
if (error) {
121
+
const {raw, clean} = cleanError(error)
122
+
return clean || raw || error.toString()
123
+
}
124
+
}, [error, cleanError])
125
126
const age = getAge(new Date(date))
127
const isUnder13 = age < 13
···
174
</Admonition>
175
)}
176
177
+
{errorMessage ? (
178
+
<ErrorMessage message={errorMessage} style={[a.rounded_sm]} />
179
) : undefined}
180
181
<View style={isWeb && [a.flex_row, a.justify_end]}>
+15
src/lib/hooks/useCleanError.ts
+15
src/lib/hooks/useCleanError.ts
···
42
}
43
}
44
45
+
/**
46
+
* @see https://github.com/bluesky-social/atproto/blob/255cfcebb54332a7129af768a93004e22c6858e3/packages/pds/src/actor-store/preference/transactor.ts#L24
47
+
*/
48
+
if (
49
+
raw.includes('Do not have authorization to set preferences') &&
50
+
raw.includes('app.bsky.actor.defs#personalDetailsPref')
51
+
) {
52
+
return {
53
+
raw,
54
+
clean: _(
55
+
msg`You cannot update your birthdate while using an app password. Please sign in with your main password to update your birthdate.`,
56
+
),
57
+
}
58
+
}
59
+
60
if (raw.includes('Bad token scope') || raw.includes('Bad token method')) {
61
return {
62
raw,
+9
src/lib/strings/errors.ts
+9
src/lib/strings/errors.ts
···
18
) {
19
return t`The server appears to be experiencing issues. Please try again in a few moments.`
20
}
21
if (str.includes('Bad token scope') || str.includes('Bad token method')) {
22
return t`This feature is not available while using an App Password. Please sign in with your main password.`
23
}
···
18
) {
19
return t`The server appears to be experiencing issues. Please try again in a few moments.`
20
}
21
+
/**
22
+
* @see https://github.com/bluesky-social/atproto/blob/255cfcebb54332a7129af768a93004e22c6858e3/packages/pds/src/actor-store/preference/transactor.ts#L24
23
+
*/
24
+
if (
25
+
str.includes('Do not have authorization to set preferences') &&
26
+
str.includes('app.bsky.actor.defs#personalDetailsPref')
27
+
) {
28
+
return t`You cannot update your birthdate while using an app password. Please sign in with your main password to update your birthdate.`
29
+
}
30
if (str.includes('Bad token scope') || str.includes('Bad token method')) {
31
return t`This feature is not available while using an App Password. Please sign in with your main password.`
32
}