Skip to content

Commit

Permalink
fix: update date based on timezone update
Browse files Browse the repository at this point in the history
  • Loading branch information
RabahZeineddine committed Oct 13, 2023
1 parent 4601fce commit 872d9cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/inputs/TzDateInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export function TzDateInput(props: TzDateInputProps) {
}
}, [field.value])

useEffect(() => {
if (timezoneSourceInput.field.value && value) {
const tzDate = dayjs.tz(field.value, timezoneSourceInput.field.value)
setFormValue(props.source, tzDate?.toISOString(), {
shouldDirty: true,
})
}
}, [timezoneSourceInput.field.value])

return (
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale={adapterLocale}>
<DatePicker
Expand Down
9 changes: 9 additions & 0 deletions src/components/inputs/TzTimeInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ export function TzTimeInput(props: TzTimeInputProps) {
}
}, [field.value])

useEffect(() => {
if (timezoneSourceInput.field.value && value) {
const tzDate = dayjs.tz(field.value, timezoneSourceInput.field.value)
setFormValue(props.source, tzDate?.toISOString(), {
shouldDirty: true,
})
}
}, [timezoneSourceInput.field.value])

return (
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale={adapterLocale}>
<TimePicker
Expand Down

0 comments on commit 872d9cd

Please sign in to comment.