Skip to content

Commit c521740

Browse files
committed
Revert "🐛 Fix time zone reset when replacing all options (#1221)"
This reverts commit 005451d. #1226
1 parent 737d6e7 commit c521740

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

apps/web/src/app/[locale]/poll/[urlId]/edit-options/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ const Page = () => {
7979
date: start.format("YYYY-MM-DD"),
8080
};
8181
}),
82-
timeZone: poll.timeZone || undefined,
83-
autoTimeZone: !!poll.timeZone,
82+
timeZone: poll.timeZone ?? "",
8483
duration: poll.options[0]?.duration || 60,
8584
},
8685
});
@@ -107,6 +106,7 @@ const Page = () => {
107106
updatePollMutation(
108107
{
109108
urlId: poll.adminUrlId,
109+
timeZone: data.timeZone,
110110
optionsToDelete: optionsToDelete.map(({ id }) => id),
111111
optionsToAdd,
112112
},

apps/web/src/components/create-poll.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { PollSettingsForm } from "@/components/forms/poll-settings";
1818
import { Trans } from "@/components/trans";
1919
import { useUser } from "@/components/user-provider";
2020
import { setCookie } from "@/utils/cookies";
21-
import { getBrowserTimeZone } from "@/utils/date-time-utils";
2221
import { usePostHog } from "@/utils/posthog";
2322
import { trpc } from "@/utils/trpc/client";
2423

@@ -48,8 +47,6 @@ export const CreatePoll: React.FunctionComponent = () => {
4847
description: "",
4948
location: "",
5049
view: "month",
51-
autoTimeZone: true,
52-
timeZone: user.timeZone || getBrowserTimeZone(),
5350
options: [],
5451
hideScores: false,
5552
hideParticipants: false,
@@ -79,13 +76,13 @@ export const CreatePoll: React.FunctionComponent = () => {
7976
<form
8077
onSubmit={form.handleSubmit(async (formData) => {
8178
const title = required(formData?.title);
82-
const isFullDay = formData?.options?.[0]?.type === "date";
79+
8380
await createPoll.mutateAsync(
8481
{
8582
title: title,
8683
location: formData?.location,
8784
description: formData?.description,
88-
timeZone: !isFullDay ? formData?.timeZone : undefined,
85+
timeZone: formData?.timeZone,
8986
hideParticipants: formData?.hideParticipants,
9087
disableComments: formData?.disableComments,
9188
hideScores: formData?.hideScores,

apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ import {
2222
} from "lucide-react";
2323
import { useTranslation } from "next-i18next";
2424
import * as React from "react";
25+
import { useFormContext } from "react-hook-form";
2526

27+
import { NewEventData } from "@/components/forms";
2628
import { Trans } from "@/components/trans";
2729

2830
import {
2931
expectTimeOption,
32+
getBrowserTimeZone,
3033
getDateProps,
3134
removeAllOptionsForDay,
3235
} from "../../../../utils/date-time-utils";
@@ -48,6 +51,8 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
4851
const { t } = useTranslation();
4952
const isTimedEvent = options.some((option) => option.type === "timeSlot");
5053

54+
const form = useFormContext<NewEventData>();
55+
5156
const optionsByDay = React.useMemo(() => {
5257
const res: Record<
5358
string,
@@ -220,6 +225,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
220225
checked={isTimedEvent}
221226
onCheckedChange={(checked) => {
222227
if (checked) {
228+
form.setValue("timeZone", getBrowserTimeZone());
223229
// convert dates to time slots
224230
onChange(
225231
options.map<DateTimeOption>((option) => {
@@ -241,6 +247,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
241247
}),
242248
);
243249
} else {
250+
form.setValue("timeZone", "");
244251
onChange(
245252
datepicker.selection.map((date) => ({
246253
type: "date",

apps/web/src/components/forms/poll-options-form/poll-options-form.tsx

+36-37
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useFormContext } from "react-hook-form";
2222

2323
import { TimeZoneCommand } from "@/components/time-zone-picker/time-zone-select";
2424

25+
import { getBrowserTimeZone } from "../../../utils/date-time-utils";
2526
import { NewEventData } from "../types";
2627
import MonthCalendar from "./month-calendar";
2728
import { DateTimeOption } from "./types";
@@ -31,7 +32,6 @@ export type PollOptionsData = {
3132
navigationDate: string; // used to navigate to the right part of the calendar
3233
duration: number; // duration of the event in minutes
3334
timeZone: string;
34-
autoTimeZone: boolean;
3535
view: string;
3636
options: DateTimeOption[];
3737
};
@@ -73,6 +73,7 @@ const PollOptionsForm = ({
7373
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7474
const watchOptions = watch("options", [])!;
7575
const watchDuration = watch("duration");
76+
const watchTimeZone = watch("timeZone");
7677

7778
const options = getValues("options");
7879
const datesOnly =
@@ -148,6 +149,7 @@ const PollOptionsForm = ({
148149
"options",
149150
watchOptions.filter((option) => option.type === "date"),
150151
);
152+
setValue("timeZone", "");
151153
dateOrTimeRangeDialog.dismiss();
152154
}}
153155
>
@@ -159,6 +161,9 @@ const PollOptionsForm = ({
159161
"options",
160162
watchOptions.filter((option) => option.type === "timeSlot"),
161163
);
164+
if (!watchTimeZone) {
165+
setValue("timeZone", getBrowserTimeZone());
166+
}
162167
dateOrTimeRangeDialog.dismiss();
163168
}}
164169
variant="primary"
@@ -210,7 +215,7 @@ const PollOptionsForm = ({
210215
{!datesOnly ? (
211216
<FormField
212217
control={form.control}
213-
name="autoTimeZone"
218+
name="timeZone"
214219
render={({ field }) => (
215220
<div
216221
className={cn(
@@ -219,24 +224,24 @@ const PollOptionsForm = ({
219224
>
220225
<div className="flex h-9 items-center gap-x-2.5 p-2">
221226
<Switch
222-
id="autoTimeZone"
227+
id="timeZone"
223228
disabled={disableTimeZoneChange}
224229
checked={!!field.value}
225230
onCheckedChange={(checked) => {
226231
if (checked) {
227-
field.onChange(true);
232+
field.onChange(getBrowserTimeZone());
228233
} else {
229-
field.onChange(false);
234+
field.onChange("");
230235
}
231236
}}
232237
/>
233-
<Label htmlFor="autoTimeZone">
238+
<Label htmlFor="timeZone">
234239
<Trans
235240
i18nKey="autoTimeZone"
236241
defaults="Automatic Time Zone Conversion"
237242
/>
238243
</Label>
239-
<Tooltip delayDuration={0}>
244+
<Tooltip>
240245
<TooltipTrigger type="button">
241246
<InfoIcon className="text-muted-foreground size-4" />
242247
</TooltipTrigger>
@@ -249,36 +254,30 @@ const PollOptionsForm = ({
249254
</Tooltip>
250255
</div>
251256
{field.value ? (
252-
<FormField
253-
control={form.control}
254-
name="timeZone"
255-
render={({ field }) => (
256-
<div>
257-
<Button
258-
disabled={disableTimeZoneChange}
259-
onClick={() => {
260-
showTimeZoneCommandModal(true);
261-
}}
262-
variant="ghost"
263-
>
264-
<GlobeIcon className="text-muted-foreground size-4" />
265-
{field.value}
266-
</Button>
267-
<CommandDialog
268-
open={isTimeZoneCommandModalOpen}
269-
onOpenChange={showTimeZoneCommandModal}
270-
>
271-
<TimeZoneCommand
272-
value={field.value}
273-
onSelect={(newValue) => {
274-
field.onChange(newValue);
275-
showTimeZoneCommandModal(false);
276-
}}
277-
/>
278-
</CommandDialog>
279-
</div>
280-
)}
281-
/>
257+
<div>
258+
<Button
259+
disabled={disableTimeZoneChange}
260+
onClick={() => {
261+
showTimeZoneCommandModal(true);
262+
}}
263+
variant="ghost"
264+
>
265+
<GlobeIcon className="text-muted-foreground size-4" />
266+
{field.value}
267+
</Button>
268+
<CommandDialog
269+
open={isTimeZoneCommandModalOpen}
270+
onOpenChange={showTimeZoneCommandModal}
271+
>
272+
<TimeZoneCommand
273+
value={field.value}
274+
onSelect={(newValue) => {
275+
field.onChange(newValue);
276+
showTimeZoneCommandModal(false);
277+
}}
278+
/>
279+
</CommandDialog>
280+
</div>
282281
) : null}
283282
</div>
284283
)}

apps/web/src/components/user-provider.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ export const UserProvider = (props: { children?: React.ReactNode }) => {
7878
email: user.email || null,
7979
isGuest: !user.email,
8080
tier,
81-
timeFormat: user.timeFormat ?? null,
82-
timeZone: user.timeZone ?? null,
83-
weekStart: user.weekStart ?? null,
8481
},
8582
refresh: session.update,
8683
ownsObject: ({ userId }) => {

0 commit comments

Comments
 (0)