🐛 Fix timezone behaviour in month calendar (#1043)

This commit is contained in:
Luke Vella 2024-03-01 17:34:48 +05:30 committed by GitHub
parent 1abc8390fa
commit fc3c0c3e35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 15 deletions

View file

@ -22,11 +22,14 @@ import {
} from "lucide-react";
import { useTranslation } from "next-i18next";
import * as React from "react";
import { useFormContext } from "react-hook-form";
import { NewEventData } from "@/components/forms";
import { Trans } from "@/components/trans";
import {
expectTimeOption,
getBrowserTimeZone,
getDateProps,
removeAllOptionsForDay,
} from "../../../../utils/date-time-utils";
@ -49,6 +52,8 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
const { t } = useTranslation();
const isTimedEvent = options.some((option) => option.type === "timeSlot");
const form = useFormContext<NewEventData>();
const optionsByDay = React.useMemo(() => {
const res: Record<
string,
@ -221,6 +226,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
checked={isTimedEvent}
onCheckedChange={(checked) => {
if (checked) {
form.setValue("timeZone", getBrowserTimeZone());
// convert dates to time slots
onChange(
options.map<DateTimeOption>((option) => {
@ -242,6 +248,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
}),
);
} else {
form.setValue("timeZone", "");
onChange(
datepicker.selection.map((date) => ({
type: "date",

View file

@ -168,21 +168,6 @@ const PollOptionsForm = ({
}}
onChange={(options) => {
field.onChange(options);
if (
length === 0 ||
options.every((option) => option.type === "date")
) {
// unset the timeZone if we only have date option
setValue("timeZone", "");
}
if (
options.length > 0 &&
!formState.touchedFields.timeZone &&
options.every((option) => option.type === "timeSlot")
) {
// set timeZone if we are adding time ranges and we haven't touched the timeZone field
setValue("timeZone", getBrowserTimeZone());
}
}}
duration={watchDuration}
onChangeDuration={(duration) => {