From 577091d44d15680d0c14f7d4571d630bf558a74d Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 15 Mar 2024 15:45:58 +0000 Subject: ALF the birthday modal and remove legacy one --- src/components/dialogs/BirthdaySettings.tsx | 122 ++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/components/dialogs/BirthdaySettings.tsx (limited to 'src/components/dialogs/BirthdaySettings.tsx') diff --git a/src/components/dialogs/BirthdaySettings.tsx b/src/components/dialogs/BirthdaySettings.tsx new file mode 100644 index 000000000..00f6ff57e --- /dev/null +++ b/src/components/dialogs/BirthdaySettings.tsx @@ -0,0 +1,122 @@ +import React from 'react' +import {useLingui} from '@lingui/react' +import {Trans, msg} from '@lingui/macro' + +import * as Dialog from '#/components/Dialog' +import {Text} from '../Typography' +import {DateInput} from '#/view/com/util/forms/DateInput' +import {logger} from '#/logger' +import { + usePreferencesSetBirthDateMutation, + UsePreferencesQueryResponse, +} from '#/state/queries/preferences' +import {Button, ButtonText} from '../Button' +import {atoms as a, useBreakpoints, useTheme} from '#/alf' +import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' +import {cleanError} from '#/lib/strings/errors' +import {ActivityIndicator, View} from 'react-native' + +export function BirthdaySettingsDialog({ + control, + preferences, +}: { + control: Dialog.DialogControlProps + preferences: UsePreferencesQueryResponse | undefined +}) { + const {_} = useLingui() + const {isPending, isError, error, mutateAsync} = + usePreferencesSetBirthDateMutation() + + return ( + + + + {preferences && !isPending ? ( + + ) : ( + + )} + + + ) +} + +function BirthdayInner({ + control, + preferences, + isError, + error, + setBirthDate, +}: { + control: Dialog.DialogControlProps + preferences: UsePreferencesQueryResponse + isError: boolean + error: unknown + setBirthDate: (args: {birthDate: Date}) => Promise +}) { + const {_} = useLingui() + const [date, setDate] = React.useState(preferences.birthDate || new Date()) + const t = useTheme() + const {gtMobile} = useBreakpoints() + + const hasChanged = date !== preferences.birthDate + + const onSave = React.useCallback(async () => { + try { + // skip if date is the same + if (hasChanged) { + await setBirthDate({birthDate: date}) + } + control.close() + } catch (e) { + logger.error(`setBirthDate failed`, {message: e}) + } + }, [date, setBirthDate, control, hasChanged]) + + return ( + + + + My Birthday + + + This information is not shared with other users. + + + + {isError ? ( + + ) : undefined} + + + + + + ) +} -- cgit 1.4.1