Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
💄 Reframe poll time zone control as "Lock timezone" (#2751)
Luke Vella712dc683f063
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex e7626afa0..0ae4e9ae3 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -74,9 +74,6 @@"authErrorsOAuthSignInFailed": "An error occurred while signing in. Please try again or contact the system administrator.","authErrorsUserBanned": "This account has been banned. Please contact support if you believe this is an error.","authErrorsUserNotFound": "No account found with this email address. Please check the email or register for a new account.",- "autoTimeZone": "Automatic Time Zone Conversion",- "autoTimeZoneDisabledHelp": "The time zone can't be changed after votes have been cast.",- "autoTimeZoneHelp": "Enable this setting to automatically adjust event times to each participant's local time zone.","back": "Back","banned": "Banned","banUser": "Ban user",@@ -381,6 +378,10 @@"locationDisplayTextPlaceholder": "Meeting link","locationInPerson": "In person","locationPlaceholder": "Joe's Coffee Shop",+ "lockTimeZone": "Lock timezone",+ "lockTimeZoneAllDayHelp": "All-day options already show the same date to everyone.",+ "lockTimeZoneDisabledHelp": "The time zone can't be changed after votes have been cast.",+ "lockTimeZoneHelp": "Everyone sees the same time, instead of it converting to each participant's time zone.","login": "Login","loginDescription": "Login to your account to continue","loginNotConfigured": "Login is currently not configured.",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.tsxindex 8c977eb0c..01eca929a 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@@ -16,7 +16,10 @@ import {import { usePoll } from "@/features/poll/components/poll-context";import { Trans, useTranslation } from "@/i18n/client";import { dayjs } from "@/lib/dayjs";-import { encodeDateOption } from "@/lib/utils/date-time-utils";+import {+ encodeDateOption,+ getBrowserTimeZone,+} from "@/lib/utils/date-time-utils";const convertOptionToString = (option: { startTime: Date; duration: number },@@ -86,6 +89,13 @@ const Page = () => {};}),timeZone: poll.timeZone ?? "",+ // A timed poll with no stored zone was locked to a single wall-clock time.+ // All-day polls are neutral (lock doesn't apply).+ lockTimeZone:+ !poll.timeZone && poll.options.some((option) => option.duration > 0),+ allDay:+ poll.options.length > 0 &&+ poll.options.every((option) => option.duration === 0),duration: poll.options[0]?.duration || 60,},});@@ -93,26 +103,46 @@ const Page = () => {<Form {...form}><formonSubmit={form.handleSubmit((data) => {+ // The submitted timeZone frame for the options: null when locked or+ // all-day (floating), else the organizer's zone.+ const submittedTimeZone =+ !data.lockTimeZone && !data.allDay+ ? data.timeZone || getBrowserTimeZone()+ : null;+const encodedOptions = data.options.map(encodeDateOption);- const optionsToDelete = poll.options.filter((option) => {- return !encodedOptions.includes(- convertOptionToString(option, data.timeZone),- );- });- const optionsToAdd = encodedOptions.filter(- (encodedOption) =>- !poll.options.find(- (o) =>- convertOptionToString(o, data.timeZone) === encodedOption,- ),- );+ // When the timezone frame changes (e.g. the organizer toggled the+ // lock), the stored instants no longer match the frame, so re-store+ // every option from the form's wall-clock under the new frame — this+ // keeps the displayed times put (3pm stays 3pm). When the frame is+ // unchanged, diff normally so we only touch what the user edited.+ const frameChanged = submittedTimeZone !== poll.timeZone;++ const optionsToDelete = frameChanged+ ? poll.options+ : poll.options.filter(+ (option) =>+ !encodedOptions.includes(+ convertOptionToString(option, poll.timeZone),+ ),+ );++ const optionsToAdd = frameChanged+ ? encodedOptions+ : encodedOptions.filter(+ (encodedOption) =>+ !poll.options.find(+ (o) =>+ convertOptionToString(o, poll.timeZone) === encodedOption,+ ),+ );const onOk = () => {updatePollMutation({pollId: poll.id,- timeZone: data.timeZone || null,+ timeZone: submittedTimeZone,optionsToDelete: optionsToDelete.map(({ id }) => id),optionsToAdd,},diff --git a/apps/web/src/features/poll/components/create-poll.tsx b/apps/web/src/features/poll/components/create-poll.tsxindex eef806da5..b462d753c 100644--- a/apps/web/src/features/poll/components/create-poll.tsx+++ b/apps/web/src/features/poll/components/create-poll.tsx@@ -38,6 +38,7 @@ import { PollSettingsForm } from "@/features/poll/components/forms/poll-settingsimport type { NewEventData } from "@/features/poll/components/forms/types";import { useUser } from "@/features/user/client";import { Trans, useTranslation } from "@/i18n/client";+import { getBrowserTimeZone } from "@/lib/utils/date-time-utils";import { trpc } from "@/trpc/client";const required = <T,>(v: T | undefined): T => {@@ -73,6 +74,8 @@ export const CreatePoll: React.FunctionComponent = () => {hideParticipants: false,disableComments: false,duration: 60,+ lockTimeZone: false,+ allDay: false,},});@@ -95,7 +98,14 @@ export const CreatePoll: React.FunctionComponent = () => {title: title,location: formData?.location?.trim(),description: formData?.description?.trim(),- timeZone: formData?.timeZone || null,+ // Attach a time zone (times convert per viewer) unless the organizer+ // locked it to a single wall-clock time or the poll is all-day.+ // Fall back to the organizer's zone so a converting poll is always+ // anchored to a concrete zone.+ timeZone:+ !formData?.lockTimeZone && !formData?.allDay+ ? formData?.timeZone || getBrowserTimeZone()+ : null,hideParticipants: formData?.hideParticipants,disableComments: formData?.disableComments,hideScores: formData?.hideScores,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.tsxindex aa23ed7bd..ce9950f38 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@@ -33,7 +33,7 @@ const PollOptionsForm = ({const { t } = useTranslation();const form = useFormContext<NewEventData>();- const { watch, setValue, getValues, formState } = form;+ const { watch, setValue, formState } = form;const views = React.useMemo(() => {const res = [@@ -62,11 +62,6 @@ const PollOptionsForm = ({const watchDuration = watch("duration");const watchTimeZone = watch("timeZone");- const options = getValues("options");- const datesOnly =- options.length === 0 ||- options.some((option) => option.type !== "timeSlot");-const dateOrTimeRangeDialog = useDialog();React.useEffect(() => {@@ -79,6 +74,17 @@ const PollOptionsForm = ({}}, [watchOptions, dateOrTimeRangeDialog]);+ // Keep the derived allDay flag in sync: a poll is all-day when every option+ // is a whole-day date rather than a time slot. Consumed at submit to decide+ // whether a time zone is attached.+ const allDay =+ watchOptions.length > 0 &&+ watchOptions.every((option) => option.type === "date");++ React.useEffect(() => {+ setValue("allDay", allDay);+ }, [allDay, setValue]);+const watchNavigationDate = watch("navigationDate");const navigationDate = new Date(watchNavigationDate ?? Date.now());@@ -198,70 +204,79 @@ const PollOptionsForm = ({)}/></div>- {!datesOnly ? (- <FormField- control={form.control}- name="timeZone"- render={({ field }) => (+ <FormField+ control={form.control}+ name="lockTimeZone"+ render={({ field }) => {+ // Locking is inert for all-day polls (no time to convert) and after+ // votes are cast. Always render the row so the layout is stable.+ const switchDisabled = disableTimeZoneChange || allDay;+ // The zone selector matters only when times DO convert: not locked and+ // not all-day.+ const showTimeZoneSelect = !field.value && !allDay;+ return (<divclassName={cn(- "grid items-center justify-between gap-2.5 border-t p-4 md:flex",+ "grid items-center justify-between gap-2.5 border-t p-3 md:flex",)}><div className="flex h-9 items-center gap-x-2.5 p-2"><Switch- id="timeZone"- disabled={disableTimeZoneChange}+ id="lockTimeZone"+ disabled={switchDisabled}checked={!!field.value}onCheckedChange={(checked) => {- if (checked) {- field.onChange(getBrowserTimeZone());- } else {- field.onChange("");+ field.onChange(checked);+ // Unlocking turns conversion back on; seed the organizer's+ // zone so the selector has a value.+ if (!checked && !watchTimeZone) {+ setValue("timeZone", getBrowserTimeZone());}}}/><Label- htmlFor="timeZone"+ htmlFor="lockTimeZone"className={- disableTimeZoneChange ? "text-muted-foreground" : undefined+ switchDisabled ? "text-muted-foreground" : undefined}>- <Trans- i18nKey="autoTimeZone"- defaults="Automatic Time Zone Conversion"- />+ <Trans i18nKey="lockTimeZone" defaults="Lock timezone" /></Label><Tooltip>- <TooltipTrigger type="button">+ <TooltipTrigger type="button" delay={0}><InfoIcon className="size-4 text-muted-foreground" /></TooltipTrigger><TooltipContent className="w-72">{disableTimeZoneChange ? (<Trans- i18nKey="autoTimeZoneDisabledHelp"+ i18nKey="lockTimeZoneDisabledHelp"defaults="The time zone can't be changed after votes have been cast."/>+ ) : allDay ? (+ <Trans+ i18nKey="lockTimeZoneAllDayHelp"+ defaults="All-day options already show the same date to everyone."+ />) : (<Trans- i18nKey="autoTimeZoneHelp"- defaults="Enable this setting to automatically adjust event times to each participant's local time zone."+ i18nKey="lockTimeZoneHelp"+ defaults="Everyone sees the same time, instead of it converting to each participant's time zone."/>)}</TooltipContent></Tooltip></div>- {field.value ? (+ {showTimeZoneSelect ? (<TimeZoneSelectdisabled={disableTimeZoneChange}- value={field.value}- onValueChange={field.onChange}+ value={watchTimeZone || getBrowserTimeZone()}+ onValueChange={(value) => setValue("timeZone", value)}/>) : null}</div>- )}- />- ) : null}+ );+ }}+ />{children}</Card>);diff --git a/apps/web/src/features/poll/components/forms/types.ts b/apps/web/src/features/poll/components/forms/types.tsindex dab29c9d4..9cf4608f3 100644--- a/apps/web/src/features/poll/components/forms/types.ts+++ b/apps/web/src/features/poll/components/forms/types.ts@@ -10,6 +10,8 @@ export type PollOptionsData = {navigationDate: string; // used to navigate to the right part of the calendarduration: number; // duration of the event in minutestimeZone: string;+ lockTimeZone: boolean; // when true, everyone sees the same wall-clock time (no per-viewer conversion)+ allDay: boolean; // derived: options are whole-day dates rather than time slotsview: string;options: DateTimeOption[];};