Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Default a new poll's time zone to the user's preferred zone (#3403)

Luke Vella795dbcedb3f6
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
index 311f1c260..bdf1ee701 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
@@ -12,6 +12,7 @@ import PollOptionsForm from "@/features/poll/components/forms/poll-options-form/
import { useUpdatePollMutation } from "@/features/poll/components/mutations";
import { usePoll } from "@/features/poll/components/poll-context";
import { filterParticipantsByVote } from "@/features/poll/utils";
+import { useUser } from "@/features/user/client";
import { Trans, useTranslation } from "@/i18n/client";
import { resolveTimeZone } from "@/lib/datetime/time-zone-overrides";
import { dayjs } from "@/lib/dayjs";
@@ -47,6 +48,7 @@ const Page = () => {
const { mutate: updatePollMutation, isPending: isUpdating } =
useUpdatePollMutation();
const { t } = useTranslation();
+ const { user } = useUser();
const modalContext = useModalContext();
const router = useRouter();
const pollLink = `/poll/${poll.id}`;
@@ -99,7 +101,7 @@ const Page = () => {
// all-day (floating), else the organizer's zone.
const submittedTimeZone =
!data.lockTimeZone && !data.allDay
- ? data.timeZone || getBrowserTimeZone()
+ ? data.timeZone || user?.timeZone || getBrowserTimeZone()
: null;
const encodedOptions = data.options.map(encodeDateOption);
diff --git a/apps/web/src/features/poll/components/create-poll.tsx b/apps/web/src/features/poll/components/create-poll.tsx
index 05bcb288f..62cf18628 100644
--- a/apps/web/src/features/poll/components/create-poll.tsx
+++ b/apps/web/src/features/poll/components/create-poll.tsx
@@ -255,7 +255,7 @@ export const CreatePoll = ({
// anchored to a concrete zone.
timeZone:
!formData?.lockTimeZone && !formData?.allDay
- ? formData?.timeZone || getBrowserTimeZone()
+ ? formData?.timeZone || user?.timeZone || getBrowserTimeZone()
: null,
hideParticipants: formData?.hideParticipants,
disableComments: !formData?.enableComments,
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx b/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx
index 6a4ee0a14..05d1aea72 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx
@@ -28,6 +28,7 @@ import {
} from "@/components/empty-state";
import { useHeadlessDatePicker } from "@/components/headless-date-picker";
import type { NewEventData } from "@/features/poll/components/forms/types";
+import { useUser } from "@/features/user/client";
import { Trans, useTranslation } from "@/i18n/client";
import { useDateTimeConfig } from "@/lib/datetime/client";
import { Duration } from "@/lib/datetime/duration";
@@ -52,6 +53,8 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
}) => {
const { t } = useTranslation();
const { locale } = useDateTimeConfig();
+ const { user } = useUser();
+ const defaultTimeZone = user?.timeZone || getBrowserTimeZone();
// Time-based options are the default. With no options yet the selected
// duration drives the mode (0 = all-day) so the first selection creates the
// right kind of option; once options exist their type is the source of truth.
@@ -114,7 +117,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
const minutes = Number(value);
onChangeDuration(minutes);
if (!form.getValues("timeZone")) {
- form.setValue("timeZone", getBrowserTimeZone());
+ form.setValue("timeZone", defaultTimeZone);
}
// Normalize every option to a time slot of the chosen duration, keeping the
// existing start time (defaulting all-day options to midday).
@@ -281,7 +284,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
newOption.type === "timeSlot" &&
!form.getValues("timeZone")
) {
- form.setValue("timeZone", getBrowserTimeZone());
+ form.setValue("timeZone", defaultTimeZone);
}
onChange([...options, newOption]);
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/poll-options-form.tsx b/apps/web/src/features/poll/components/forms/poll-options-form/poll-options-form.tsx
index 0d9976a87..1e2326762 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/poll-options-form.tsx
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/poll-options-form.tsx
@@ -17,8 +17,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";
import { CalendarIcon, InfoIcon, TableIcon } from "lucide-react";
import * as React from "react";
import { useFormContext } from "react-hook-form";
-
import { TimeZoneSelect } from "@/components/time-zone-picker/time-zone-select";
+import { useUser } from "@/features/user/client";
import { Trans, useTranslation } from "@/i18n/client";
import { getBrowserTimeZone } from "@/lib/utils/date-time-utils";
@@ -34,6 +34,8 @@ const PollOptionsForm = ({
const form = useFormContext<NewEventData>();
const { watch, setValue, formState } = form;
+ const { user } = useUser();
+ const defaultTimeZone = user?.timeZone || getBrowserTimeZone();
const views = React.useMemo(() => {
const res = [
@@ -163,7 +165,7 @@ const PollOptionsForm = ({
watchOptions.filter((option) => option.type === "timeSlot"),
);
if (!watchTimeZone) {
- setValue("timeZone", getBrowserTimeZone());
+ setValue("timeZone", defaultTimeZone);
}
dateOrTimeRangeDialog.dismiss();
}}
@@ -242,7 +244,7 @@ const PollOptionsForm = ({
// Unlocking turns conversion back on; seed the organizer's
// zone so the selector has a value.
if (!checked && !watchTimeZone) {
- setValue("timeZone", getBrowserTimeZone());
+ setValue("timeZone", defaultTimeZone);
}
}}
/>
@@ -281,7 +283,7 @@ const PollOptionsForm = ({
{showTimeZoneSelect ? (
<TimeZoneSelect
disabled={disableTimeZoneChange}
- value={watchTimeZone || getBrowserTimeZone()}
+ value={watchTimeZone || defaultTimeZone}
onValueChange={(value) => setValue("timeZone", value)}
/>
) : null}