From c521740e5ac34f933e3911dfdf15c4eecc0a3b96 Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Mon, 29 Jul 2024 13:59:46 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"=F0=9F=90=9B=20Fix=20time=20zone=20re?= =?UTF-8?q?set=20when=20replacing=20all=20options=20(#1221)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 005451d76caac288c07bbb655ed7cafb255848c5. #1226 --- .../poll/[urlId]/edit-options/page.tsx | 4 +- apps/web/src/components/create-poll.tsx | 7 +- .../month-calendar/month-calendar.tsx | 7 ++ .../poll-options-form/poll-options-form.tsx | 73 +++++++++---------- apps/web/src/components/user-provider.tsx | 3 - 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/apps/web/src/app/[locale]/poll/[urlId]/edit-options/page.tsx b/apps/web/src/app/[locale]/poll/[urlId]/edit-options/page.tsx index 932187a3a83..d9e29e07bea 100644 --- a/apps/web/src/app/[locale]/poll/[urlId]/edit-options/page.tsx +++ b/apps/web/src/app/[locale]/poll/[urlId]/edit-options/page.tsx @@ -79,8 +79,7 @@ const Page = () => { date: start.format("YYYY-MM-DD"), }; }), - timeZone: poll.timeZone || undefined, - autoTimeZone: !!poll.timeZone, + timeZone: poll.timeZone ?? "", duration: poll.options[0]?.duration || 60, }, }); @@ -107,6 +106,7 @@ const Page = () => { updatePollMutation( { urlId: poll.adminUrlId, + timeZone: data.timeZone, optionsToDelete: optionsToDelete.map(({ id }) => id), optionsToAdd, }, diff --git a/apps/web/src/components/create-poll.tsx b/apps/web/src/components/create-poll.tsx index dc6b9e24d78..1299987e399 100644 --- a/apps/web/src/components/create-poll.tsx +++ b/apps/web/src/components/create-poll.tsx @@ -18,7 +18,6 @@ import { PollSettingsForm } from "@/components/forms/poll-settings"; import { Trans } from "@/components/trans"; import { useUser } from "@/components/user-provider"; import { setCookie } from "@/utils/cookies"; -import { getBrowserTimeZone } from "@/utils/date-time-utils"; import { usePostHog } from "@/utils/posthog"; import { trpc } from "@/utils/trpc/client"; @@ -48,8 +47,6 @@ export const CreatePoll: React.FunctionComponent = () => { description: "", location: "", view: "month", - autoTimeZone: true, - timeZone: user.timeZone || getBrowserTimeZone(), options: [], hideScores: false, hideParticipants: false, @@ -79,13 +76,13 @@ export const CreatePoll: React.FunctionComponent = () => {
{ const title = required(formData?.title); - const isFullDay = formData?.options?.[0]?.type === "date"; + await createPoll.mutateAsync( { title: title, location: formData?.location, description: formData?.description, - timeZone: !isFullDay ? formData?.timeZone : undefined, + timeZone: formData?.timeZone, hideParticipants: formData?.hideParticipants, disableComments: formData?.disableComments, hideScores: formData?.hideScores, diff --git a/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx b/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx index dbb2e1f367d..d1539f9f236 100644 --- a/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx +++ b/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx @@ -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"; @@ -48,6 +51,8 @@ const MonthCalendar: React.FunctionComponent = ({ const { t } = useTranslation(); const isTimedEvent = options.some((option) => option.type === "timeSlot"); + const form = useFormContext(); + const optionsByDay = React.useMemo(() => { const res: Record< string, @@ -220,6 +225,7 @@ const MonthCalendar: React.FunctionComponent = ({ checked={isTimedEvent} onCheckedChange={(checked) => { if (checked) { + form.setValue("timeZone", getBrowserTimeZone()); // convert dates to time slots onChange( options.map((option) => { @@ -241,6 +247,7 @@ const MonthCalendar: React.FunctionComponent = ({ }), ); } else { + form.setValue("timeZone", ""); onChange( datepicker.selection.map((date) => ({ type: "date", diff --git a/apps/web/src/components/forms/poll-options-form/poll-options-form.tsx b/apps/web/src/components/forms/poll-options-form/poll-options-form.tsx index 691a8c6b09c..9d7fa460843 100644 --- a/apps/web/src/components/forms/poll-options-form/poll-options-form.tsx +++ b/apps/web/src/components/forms/poll-options-form/poll-options-form.tsx @@ -22,6 +22,7 @@ import { useFormContext } from "react-hook-form"; import { TimeZoneCommand } from "@/components/time-zone-picker/time-zone-select"; +import { getBrowserTimeZone } from "../../../utils/date-time-utils"; import { NewEventData } from "../types"; import MonthCalendar from "./month-calendar"; import { DateTimeOption } from "./types"; @@ -31,7 +32,6 @@ export type PollOptionsData = { navigationDate: string; // used to navigate to the right part of the calendar duration: number; // duration of the event in minutes timeZone: string; - autoTimeZone: boolean; view: string; options: DateTimeOption[]; }; @@ -73,6 +73,7 @@ const PollOptionsForm = ({ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const watchOptions = watch("options", [])!; const watchDuration = watch("duration"); + const watchTimeZone = watch("timeZone"); const options = getValues("options"); const datesOnly = @@ -148,6 +149,7 @@ const PollOptionsForm = ({ "options", watchOptions.filter((option) => option.type === "date"), ); + setValue("timeZone", ""); dateOrTimeRangeDialog.dismiss(); }} > @@ -159,6 +161,9 @@ const PollOptionsForm = ({ "options", watchOptions.filter((option) => option.type === "timeSlot"), ); + if (!watchTimeZone) { + setValue("timeZone", getBrowserTimeZone()); + } dateOrTimeRangeDialog.dismiss(); }} variant="primary" @@ -210,7 +215,7 @@ const PollOptionsForm = ({ {!datesOnly ? ( (
{ if (checked) { - field.onChange(true); + field.onChange(getBrowserTimeZone()); } else { - field.onChange(false); + field.onChange(""); } }} /> -
{field.value ? ( - ( -
- - - { - field.onChange(newValue); - showTimeZoneCommandModal(false); - }} - /> - -
- )} - /> +
+ + + { + field.onChange(newValue); + showTimeZoneCommandModal(false); + }} + /> + +
) : null}
)} diff --git a/apps/web/src/components/user-provider.tsx b/apps/web/src/components/user-provider.tsx index da5cf7ad843..8a9315771f7 100644 --- a/apps/web/src/components/user-provider.tsx +++ b/apps/web/src/components/user-provider.tsx @@ -78,9 +78,6 @@ export const UserProvider = (props: { children?: React.ReactNode }) => { email: user.email || null, isGuest: !user.email, tier, - timeFormat: user.timeFormat ?? null, - timeZone: user.timeZone ?? null, - weekStart: user.weekStart ?? null, }, refresh: session.update, ownsObject: ({ userId }) => {