From 199a175658dc6177f59d3ece47978818afd16ffa Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 18 Mar 2024 13:50:47 -0500 Subject: [PATCH] Juse use existing DateInput for now --- src/components/dialogs/BirthDateSettings.tsx | 27 ++++++++++---------- src/state/queries/preferences/index.ts | 9 ++++--- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx index b7d61f1ad5..4a3e96e56d 100644 --- a/src/components/dialogs/BirthDateSettings.tsx +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -5,6 +5,7 @@ import {View} from 'react-native' import * as Dialog from '#/components/Dialog' import {Text} from '../Typography' +import {DateInput} from '#/view/com/util/forms/DateInput' import {logger} from '#/logger' import { usePreferencesQuery, @@ -17,7 +18,6 @@ import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' import {cleanError} from '#/lib/strings/errors' import {isIOS, isWeb} from '#/platform/detection' import {Loader} from '#/components/Loader' -import {DateField, utils} from '#/components/forms/DateField' export function BirthDateSettingsDialog({ control, @@ -72,26 +72,20 @@ function BirthdayInner({ preferences: UsePreferencesQueryResponse }) { const {_} = useLingui() - const [date, setDate] = React.useState( - utils.toSimpleDateString(preferences.birthDate || new Date()), - ) + const [date, setDate] = React.useState(preferences.birthDate || new Date()) const { isPending, isError, error, mutateAsync: setBirthDate, } = usePreferencesSetBirthDateMutation() - const hasChanged = React.useMemo( - () => - date !== utils.toSimpleDateString(preferences.birthDate || new Date()), - [date, preferences.birthDate], - ) + const hasChanged = date !== preferences.birthDate const onSave = React.useCallback(async () => { try { // skip if date is the same if (hasChanged) { - await setBirthDate({birthDate: new Date(date)}) + await setBirthDate({birthDate: date}) } control.close() } catch (e: any) { @@ -102,10 +96,17 @@ function BirthdayInner({ return ( - diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index cfc5c5bbe5..7738a3e47a 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -173,9 +173,12 @@ export function usePreferencesSetAdultContentMutation() { export function usePreferencesSetBirthDateMutation() { const queryClient = useQueryClient() - return useMutation({ - mutationFn: async ({birthDate}: {birthDate: Date}) => { - await getAgent().setPersonalDetails({birthDate: birthDate.toISOString()}) + return useMutation({ + mutationFn: async ({birthDate}: {birthDate: Date | string}) => { + await getAgent().setPersonalDetails({ + birthDate: + typeof birthDate === 'string' ? birthDate : birthDate.toISOString(), + }) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey,