Juse use existing DateInput for now
This commit is contained in:
@@ -5,6 +5,7 @@ import {View} from 'react-native'
|
|||||||
|
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {Text} from '../Typography'
|
import {Text} from '../Typography'
|
||||||
|
import {DateInput} from '#/view/com/util/forms/DateInput'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {
|
import {
|
||||||
usePreferencesQuery,
|
usePreferencesQuery,
|
||||||
@@ -17,7 +18,6 @@ import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
|
|||||||
import {cleanError} from '#/lib/strings/errors'
|
import {cleanError} from '#/lib/strings/errors'
|
||||||
import {isIOS, isWeb} from '#/platform/detection'
|
import {isIOS, isWeb} from '#/platform/detection'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
import {DateField, utils} from '#/components/forms/DateField'
|
|
||||||
|
|
||||||
export function BirthDateSettingsDialog({
|
export function BirthDateSettingsDialog({
|
||||||
control,
|
control,
|
||||||
@@ -72,26 +72,20 @@ function BirthdayInner({
|
|||||||
preferences: UsePreferencesQueryResponse
|
preferences: UsePreferencesQueryResponse
|
||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const [date, setDate] = React.useState(
|
const [date, setDate] = React.useState(preferences.birthDate || new Date())
|
||||||
utils.toSimpleDateString(preferences.birthDate || new Date()),
|
|
||||||
)
|
|
||||||
const {
|
const {
|
||||||
isPending,
|
isPending,
|
||||||
isError,
|
isError,
|
||||||
error,
|
error,
|
||||||
mutateAsync: setBirthDate,
|
mutateAsync: setBirthDate,
|
||||||
} = usePreferencesSetBirthDateMutation()
|
} = usePreferencesSetBirthDateMutation()
|
||||||
const hasChanged = React.useMemo(
|
const hasChanged = date !== preferences.birthDate
|
||||||
() =>
|
|
||||||
date !== utils.toSimpleDateString(preferences.birthDate || new Date()),
|
|
||||||
[date, preferences.birthDate],
|
|
||||||
)
|
|
||||||
|
|
||||||
const onSave = React.useCallback(async () => {
|
const onSave = React.useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
// skip if date is the same
|
// skip if date is the same
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
await setBirthDate({birthDate: new Date(date)})
|
await setBirthDate({birthDate: date})
|
||||||
}
|
}
|
||||||
control.close()
|
control.close()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@@ -102,10 +96,17 @@ function BirthdayInner({
|
|||||||
return (
|
return (
|
||||||
<View style={a.gap_lg} testID="birthDateSettingsDialog">
|
<View style={a.gap_lg} testID="birthDateSettingsDialog">
|
||||||
<View style={isIOS && [a.w_full, a.align_center]}>
|
<View style={isIOS && [a.w_full, a.align_center]}>
|
||||||
<DateField
|
<DateInput
|
||||||
label={_(msg`Enter your birthday`)}
|
handleAsUTC
|
||||||
|
testID="birthdayInput"
|
||||||
value={date}
|
value={date}
|
||||||
onChangeDate={setDate}
|
onChange={setDate}
|
||||||
|
buttonType="default-light"
|
||||||
|
buttonStyle={[a.rounded_sm]}
|
||||||
|
buttonLabelType="lg"
|
||||||
|
accessibilityLabel={_(msg`Birthday`)}
|
||||||
|
accessibilityHint={_(msg`Enter your birth date`)}
|
||||||
|
accessibilityLabelledBy="birthDate"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|||||||
@@ -173,9 +173,12 @@ export function usePreferencesSetAdultContentMutation() {
|
|||||||
export function usePreferencesSetBirthDateMutation() {
|
export function usePreferencesSetBirthDateMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation<void, unknown, {birthDate: Date}>({
|
return useMutation<void, unknown, {birthDate: Date | string}>({
|
||||||
mutationFn: async ({birthDate}: {birthDate: Date}) => {
|
mutationFn: async ({birthDate}: {birthDate: Date | string}) => {
|
||||||
await getAgent().setPersonalDetails({birthDate: birthDate.toISOString()})
|
await getAgent().setPersonalDetails({
|
||||||
|
birthDate:
|
||||||
|
typeof birthDate === 'string' ? birthDate : birthDate.toISOString(),
|
||||||
|
})
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: preferencesQueryKey,
|
queryKey: preferencesQueryKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user