mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-01 15:39:03 +02:00
🐛 Fix timezone behaviour in month calendar (#1043)
This commit is contained in:
parent
1abc8390fa
commit
fc3c0c3e35
2 changed files with 7 additions and 15 deletions
|
@ -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",
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue