mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 01:48:32 +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";
|
} from "lucide-react";
|
||||||
import { useTranslation } from "next-i18next";
|
import { useTranslation } from "next-i18next";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import { useFormContext } from "react-hook-form";
|
||||||
|
|
||||||
|
import { NewEventData } from "@/components/forms";
|
||||||
import { Trans } from "@/components/trans";
|
import { Trans } from "@/components/trans";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
expectTimeOption,
|
expectTimeOption,
|
||||||
|
getBrowserTimeZone,
|
||||||
getDateProps,
|
getDateProps,
|
||||||
removeAllOptionsForDay,
|
removeAllOptionsForDay,
|
||||||
} from "../../../../utils/date-time-utils";
|
} from "../../../../utils/date-time-utils";
|
||||||
|
@ -49,6 +52,8 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const isTimedEvent = options.some((option) => option.type === "timeSlot");
|
const isTimedEvent = options.some((option) => option.type === "timeSlot");
|
||||||
|
|
||||||
|
const form = useFormContext<NewEventData>();
|
||||||
|
|
||||||
const optionsByDay = React.useMemo(() => {
|
const optionsByDay = React.useMemo(() => {
|
||||||
const res: Record<
|
const res: Record<
|
||||||
string,
|
string,
|
||||||
|
@ -221,6 +226,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
|
||||||
checked={isTimedEvent}
|
checked={isTimedEvent}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
form.setValue("timeZone", getBrowserTimeZone());
|
||||||
// convert dates to time slots
|
// convert dates to time slots
|
||||||
onChange(
|
onChange(
|
||||||
options.map<DateTimeOption>((option) => {
|
options.map<DateTimeOption>((option) => {
|
||||||
|
@ -242,6 +248,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
form.setValue("timeZone", "");
|
||||||
onChange(
|
onChange(
|
||||||
datepicker.selection.map((date) => ({
|
datepicker.selection.map((date) => ({
|
||||||
type: "date",
|
type: "date",
|
||||||
|
|
|
@ -168,21 +168,6 @@ const PollOptionsForm = ({
|
||||||
}}
|
}}
|
||||||
onChange={(options) => {
|
onChange={(options) => {
|
||||||
field.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}
|
duration={watchDuration}
|
||||||
onChangeDuration={(duration) => {
|
onChangeDuration={(duration) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue