From b41d0ad97dc8786b50196fee3d91c98f9ed15af7 Mon Sep 17 00:00:00 2001 From: DS Boyce <260543580+ds-boyce@users.noreply.github.com> Date: Wed, 13 May 2026 13:52:59 -0700 Subject: [PATCH] Improve birthdate handling (#10477) --- eslint-suppressions.json | 5 --- src/components/dialogs/BirthDateSettings.tsx | 22 +++++++----- src/lib/hooks/useCleanError.ts | 36 ++++++++------------ src/state/queries/preferences/index.ts | 2 +- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 09752b39ea..62e84ff5f5 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -264,11 +264,6 @@ "count": 1 } }, - "src/lib/hooks/useCleanError.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, "src/lib/hooks/useNonReactiveCallback.ts": { "@typescript-eslint/no-explicit-any": { "count": 1 diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx index 34d1952c70..8f637e41d5 100644 --- a/src/components/dialogs/BirthDateSettings.tsx +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -37,6 +37,14 @@ export function BirthDateSettingsDialog({ const isBirthdateUpdateAllowed = useIsBirthdateUpdateAllowed() const {currentAccount} = useSession() const isUsingAppPassword = isAppPassword(currentAccount?.accessJwt || '') + const cleanError = useCleanError() + const defaultErrorMessage = l`We were unable to load your birthdate preferences. Please try again.` + const fetchErrorMessage = useMemo(() => { + if (error) { + const {raw, clean} = cleanError(error) + return clean || raw + } + }, [error, cleanError]) return ( @@ -58,12 +66,9 @@ export function BirthDateSettingsDialog({ {isLoading ? ( - ) : error || !preferences ? ( + ) : fetchErrorMessage || !preferences ? ( ) : isUsingAppPassword ? ( @@ -123,12 +128,11 @@ function BirthdayInner({ const cleanError = useCleanError() const [date, setDate] = useState(preferences.birthDate || getDateAgo(18)) const {isPending, error, mutateAsync: setBirthDate} = useBirthdateMutation() - const hasChanged = date !== preferences.birthDate + const hasChanged = date?.getTime() !== preferences.birthDate?.getTime() const errorMessage = useMemo(() => { if (error) { - const e = error as Error - const {raw, clean} = cleanError(e) - return clean || raw || e.toString() + const {raw, clean} = cleanError(error) + return clean || raw } }, [error, cleanError]) diff --git a/src/lib/hooks/useCleanError.ts b/src/lib/hooks/useCleanError.ts index c7e085e68f..5f8dce6081 100644 --- a/src/lib/hooks/useCleanError.ts +++ b/src/lib/hooks/useCleanError.ts @@ -1,6 +1,5 @@ import {useCallback} from 'react' -import {msg} from '@lingui/core/macro' -import {useLingui} from '@lingui/react' +import {useLingui} from '@lingui/react/macro' type CleanedError = { raw: string | undefined @@ -8,9 +7,9 @@ type CleanedError = { } export function useCleanError() { - const {_} = useLingui() + const {t: l} = useLingui() - return useCallback<(error?: any) => CleanedError>( + return useCallback<(error?: unknown) => CleanedError>( error => { if (!error) return { @@ -18,14 +17,17 @@ export function useCleanError() { clean: undefined, } - let raw = error.toString() + let raw = + error instanceof Error + ? error.message + : typeof error === 'string' + ? error + : JSON.stringify(error) if (isNetworkError(raw)) { return { raw, - clean: _( - msg`Unable to connect. Please check your internet connection and try again.`, - ), + clean: l`Unable to connect. Please check your internet connection and try again.`, } } @@ -36,9 +38,7 @@ export function useCleanError() { ) { return { raw, - clean: _( - msg`The server appears to be experiencing issues. Please try again in a few moments.`, - ), + clean: l`The server appears to be experiencing issues. Please try again in a few moments.`, } } @@ -51,27 +51,21 @@ export function useCleanError() { ) { return { raw, - clean: _( - msg`You cannot update your birthdate while using an app password. Please sign in with your main password to update your birthdate.`, - ), + clean: l`You cannot update your birthdate while using an app password. Please sign in with your main password to update your birthdate.`, } } if (raw.includes('Bad token scope') || raw.includes('Bad token method')) { return { raw, - clean: _( - msg`This feature is not available while using an app password. Please sign in with your main password.`, - ), + clean: l`This feature is not available while using an app password. Please sign in with your main password.`, } } if (raw.includes('Rate Limit Exceeded')) { return { raw, - clean: _( - msg`You've reached the maximum number of requests allowed. Please try again later.`, - ), + clean: l`You've reached the maximum number of requests allowed. Please try again later.`, } } @@ -84,7 +78,7 @@ export function useCleanError() { clean: undefined, } }, - [_], + [l], ) } diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index d5c9a24acf..816683062e 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -53,7 +53,7 @@ export function usePreferencesQuery() { const res = await agent.getPreferences() // save to local storage to ensure there are labels on initial requests - saveLabelers( + void saveLabelers( agent.did, res.moderationPrefs.labelers.map(l => l.did), )