Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♻️ Migrate the public event page to Intl datetime formatting (#2525)
Luke Vella66d309e389cf
diff --git a/apps/web/src/app/[locale]/e/[id]/components/event-header.tsx b/apps/web/src/app/[locale]/e/[id]/components/event-header.tsxindex 91c8d97e0..21ed50432 100644--- a/apps/web/src/app/[locale]/e/[id]/components/event-header.tsx+++ b/apps/web/src/app/[locale]/e/[id]/components/event-header.tsx@@ -3,7 +3,6 @@import { cn } from "@rallly/ui";import { Badge } from "@rallly/ui/badge";import { Trans } from "@/i18n/client";-import { dayjs } from "@/lib/dayjs";export function EventHeader({children,@@ -75,32 +74,3 @@ export function EventStatus({</Badge>);}--export function EventDate({- start,- end,- allDay,- timezone,-}: {- start: Date;- end: Date;- allDay: boolean;- timezone: string | null;-}) {- const startD = timezone ? dayjs(start).tz(timezone) : dayjs(start);- const endD = timezone ? dayjs(end).tz(timezone) : dayjs(end);-- const date = startD.format("dddd, LL");- const time = allDay- ? null- : `${startD.format("LT")} – ${endD.format("LT z")}`;-- return (- <div className="mt-3">- <p className="font-medium text-base text-foreground">{date}</p>- {time ? (- <p className="mt-0.5 text-muted-foreground text-sm">{time}</p>- ) : null}- </div>- );-}diff --git a/apps/web/src/app/[locale]/e/[id]/page.tsx b/apps/web/src/app/[locale]/e/[id]/page.tsxindex 198a430cf..0084d676f 100644--- a/apps/web/src/app/[locale]/e/[id]/page.tsx+++ b/apps/web/src/app/[locale]/e/[id]/page.tsx@@ -14,6 +14,11 @@ import TruncatedLinkify from "@/components/poll/truncated-linkify";import { SessionRefresher } from "@/components/session-refresher";import { BrandingStyle } from "@/features/branding/branding-style";import { formatLocationText } from "@/features/location/utils";+import {+ EventCalendarCard,+ EventDate,+ EventTimeRange,+} from "@/features/scheduled-event/components/event-date-time";import { isScheduledEventEnabled } from "@/features/scheduled-event/constants";import {createScheduledEventDTO,@@ -25,12 +30,8 @@ import { getSpaceBranding } from "@/features/space/data";import { getUserProfile } from "@/features/user/data";import { getTranslation } from "@/i18n/server";import { getSession } from "@/lib/auth";-import { dayjs } from "@/lib/dayjs";-import {- CalendarCard,- CalendarCardDay,- CalendarCardMonth,-} from "./components/calendar-card";+import { DeviceDateTimeProvider } from "@/lib/datetime/device";+import { getDeviceDateTimeConfig } from "@/lib/datetime/server";import {EventDetail,EventDetailContent,@@ -99,142 +100,159 @@ export default async function EventPage({const session = await getSession();const { t } = await getTranslation();+ const deviceDateTimeConfig = await getDeviceDateTimeConfig();return (- <div className="page-bg-gray-50 absolute inset-0 h-dvh overflow-auto md:h-dvh md:items-center md:justify-center md:p-5 dark:bg-gray-900">- <SessionRefresher />- {brandingColor ? <BrandingStyle primaryColor={brandingColor} /> : null}- <header className="fixed top-0 right-0 left-0 z-10 flex justify-between p-4">- <Link href="/">- <LogoMarkGray className="size-8 text-muted-foreground" />- </Link>- <div className="flex items-center gap-2">- {session?.user.isGuest === false ? (- <UserDropdown- name={session.user.name}- email={session.user.email}- image={session.user.image ?? undefined}- />- ) : (- <Link- href="/login"- className={buttonVariants({ variant: "ghost", size: "sm" })}- >- {t("signIn", { defaultValue: "Sign in" })}- </Link>- )}- </div>- </header>- <main id="main-content" tabIndex={-1} className="mx-auto max-w-lg pt-16">- <div className="flex flex-col justify-between gap-6 p-4">- <EventHeader>- {isBranded && branding ? (- <SpaceBranding- className="mb-4"- name={branding.name}- image={branding.image ?? undefined}- />- ) : null}- <EventTitle>{event.title}</EventTitle>- <EventSubtitle className="flex items-center gap-2">- <OptimizedAvatarImage- name={host.name}- src={host.image ?? undefined}- size="sm"+ <DeviceDateTimeProvider+ timeZone={deviceDateTimeConfig.timeZone}+ timeFormat={deviceDateTimeConfig.timeFormat}+ >+ <div className="page-bg-gray-50 absolute inset-0 h-dvh overflow-auto md:h-dvh md:items-center md:justify-center md:p-5 dark:bg-gray-900">+ <SessionRefresher />+ {brandingColor ? <BrandingStyle primaryColor={brandingColor} /> : null}+ <header className="fixed top-0 right-0 left-0 z-10 flex justify-between p-4">+ <Link href="/">+ <LogoMarkGray className="size-8 text-muted-foreground" />+ </Link>+ <div className="flex items-center gap-2">+ {session?.user.isGuest === false ? (+ <UserDropdown+ name={session.user.name}+ email={session.user.email}+ image={session.user.image ?? undefined}/>- {t("eventPageHostedBy", {- defaultValue: "Hosted by {name}",- name: host.name,- })}- </EventSubtitle>- <div className="mt-4 grid gap-4">- <EventDetail>- <CalendarCard>- <CalendarCardMonth>- {dayjs(event.start).format("MMM")}- </CalendarCardMonth>- <CalendarCardDay>- {dayjs(event.start).format("D")}- </CalendarCardDay>- </CalendarCard>- <EventDetailContent>- <EventDetailTitle>- {dayjs(event.start).format("dddd, D MMMM")}- </EventDetailTitle>- <EventDetailDescription>- {dayjs(event.start).format("LT")} -{" "}- {dayjs(event.end).format("LT z")}- </EventDetailDescription>- </EventDetailContent>- </EventDetail>- {event.location ? (+ ) : (+ <Link+ href="/login"+ className={buttonVariants({ variant: "ghost", size: "sm" })}+ >+ {t("signIn", { defaultValue: "Sign in" })}+ </Link>+ )}+ </div>+ </header>+ <main+ id="main-content"+ tabIndex={-1}+ className="mx-auto max-w-lg pt-16"+ >+ <div className="flex flex-col justify-between gap-6 p-4">+ <EventHeader>+ {isBranded && branding ? (+ <SpaceBranding+ className="mb-4"+ name={branding.name}+ image={branding.image ?? undefined}+ />+ ) : null}+ <EventTitle>{event.title}</EventTitle>+ <EventSubtitle className="flex items-center gap-2">+ <OptimizedAvatarImage+ name={host.name}+ src={host.image ?? undefined}+ size="sm"+ />+ {t("eventPageHostedBy", {+ defaultValue: "Hosted by {name}",+ name: host.name,+ })}+ </EventSubtitle>+ <div className="mt-4 grid gap-4"><EventDetail>- <EventDetailIcon>- <MapPinIcon />- </EventDetailIcon>+ <EventCalendarCard+ start={event.start}+ allDay={event.allDay}+ timeZone={event.displayTimeZone}+ /><EventDetailContent><EventDetailTitle>- {formatLocationText(event.location)}+ <EventDate+ value={event.start}+ preset="weekdayMonthDay"+ allDay={event.allDay}+ timeZone={event.displayTimeZone}+ /></EventDetailTitle>+ <EventDetailDescription>+ <EventTimeRange+ start={event.start}+ end={event.end}+ allDay={event.allDay}+ timeZone={event.displayTimeZone}+ showTimeZone={true}+ />+ </EventDetailDescription></EventDetailContent></EventDetail>- ) : null}- </div>- </EventHeader>- <RsvpCard>- <RsvpCardTitle>- {t("rsvpCardTitle", { defaultValue: "Registration" })}- </RsvpCardTitle>- <RsvpCardContent>- <RSVPArea- eventId={event.id}- status={event.status}- start={event.start}- end={event.end}- capacity={event.capacity}- acceptedCount={acceptedCount}- />- </RsvpCardContent>- </RsvpCard>- {event.description ? (- <EventSection>- <EventSectionTitle>- {t("eventPageAbout", { defaultValue: "About" })}- </EventSectionTitle>- <p className="whitespace-pre-wrap text-pretty text-foreground text-sm leading-relaxed">- <TruncatedLinkify>{event.description}</TruncatedLinkify>- </p>- </EventSection>- ) : null}- {visibleAttendees.length > 0 ? (- <EventSection>- <EventSectionTitle>- {t("eventPageGoingCount", {- defaultValue:- "{count, plural, one {# going} other {# going}}",- count: acceptedCount,- })}- </EventSectionTitle>- <AvatarGroup>- {visibleAttendees.map((attendee) => (- <OptimizedAvatarImage- key={attendee.id}- name={attendee.name}- src={attendee.image}- size="md"- />- ))}- {acceptedCount > visibleAttendees.length ? (- <AvatarGroupCount>- +{acceptedCount - visibleAttendees.length}- </AvatarGroupCount>+ {event.location ? (+ <EventDetail>+ <EventDetailIcon>+ <MapPinIcon />+ </EventDetailIcon>+ <EventDetailContent>+ <EventDetailTitle>+ {formatLocationText(event.location)}+ </EventDetailTitle>+ </EventDetailContent>+ </EventDetail>) : null}- </AvatarGroup>- </EventSection>- ) : null}- </div>- </main>- </div>+ </div>+ </EventHeader>+ <RsvpCard>+ <RsvpCardTitle>+ {t("rsvpCardTitle", { defaultValue: "Registration" })}+ </RsvpCardTitle>+ <RsvpCardContent>+ <RSVPArea+ eventId={event.id}+ status={event.status}+ start={event.start}+ end={event.end}+ capacity={event.capacity}+ acceptedCount={acceptedCount}+ />+ </RsvpCardContent>+ </RsvpCard>+ {event.description ? (+ <EventSection>+ <EventSectionTitle>+ {t("eventPageAbout", { defaultValue: "About" })}+ </EventSectionTitle>+ <p className="whitespace-pre-wrap text-pretty text-foreground text-sm leading-relaxed">+ <TruncatedLinkify>{event.description}</TruncatedLinkify>+ </p>+ </EventSection>+ ) : null}+ {visibleAttendees.length > 0 ? (+ <EventSection>+ <EventSectionTitle>+ {t("eventPageGoingCount", {+ defaultValue:+ "{count, plural, one {# going} other {# going}}",+ count: acceptedCount,+ })}+ </EventSectionTitle>+ <AvatarGroup>+ {visibleAttendees.map((attendee) => (+ <OptimizedAvatarImage+ key={attendee.id}+ name={attendee.name}+ src={attendee.image}+ size="md"+ />+ ))}+ {acceptedCount > visibleAttendees.length ? (+ <AvatarGroupCount>+ +{acceptedCount - visibleAttendees.length}+ </AvatarGroupCount>+ ) : null}+ </AvatarGroup>+ </EventSection>+ ) : null}+ </div>+ </main>+ </div>+ </DeviceDateTimeProvider>);}diff --git a/apps/web/src/app/[locale]/e/[id]/components/calendar-card.tsx b/apps/web/src/components/calendar-card.tsxsimilarity index 100%rename from apps/web/src/app/[locale]/e/[id]/components/calendar-card.tsxrename to apps/web/src/components/calendar-card.tsxdiff --git a/apps/web/src/components/time-zone-picker/time-zone-select.tsx b/apps/web/src/components/time-zone-picker/time-zone-select.tsxindex a72b3104d..95e70162b 100644--- a/apps/web/src/components/time-zone-picker/time-zone-select.tsx+++ b/apps/web/src/components/time-zone-picker/time-zone-select.tsx@@ -94,12 +94,7 @@ export function TimeZoneSelect({{getCityFromTimezoneId(entry)}</span><span className="rounded-full px-1 py-0.5 text-center text-muted-foreground text-xs tabular-nums">- <Time- value={now}- preset="time"- timeZone={entry}- showTimeZone={false}- />+ <Time value={now} preset="time" timeZone={entry} /></span></ComboboxItem>)}diff --git a/apps/web/src/features/scheduled-event/components/event-date-time.tsx b/apps/web/src/features/scheduled-event/components/event-date-time.tsxindex cc77a3f4e..85e1c5725 100644--- a/apps/web/src/features/scheduled-event/components/event-date-time.tsx+++ b/apps/web/src/features/scheduled-event/components/event-date-time.tsx@@ -1,9 +1,17 @@"use client";+import {+ CalendarCard,+ CalendarCardDay,+ CalendarCardMonth,+} from "@/components/calendar-card";import { Trans } from "@/i18n/client";import { CalendarDate } from "@/lib/datetime/calendar-date";+import { useDateTimeConfig } from "@/lib/datetime/client";import type { DateInput, DatePreset } from "@/lib/datetime/format";+import { formatDateParts } from "@/lib/datetime/format";import { Time, TimeRange } from "@/lib/datetime/time";+import { useHydrated } from "@/lib/datetime/use-hydrated";/*** Raw scheduling fields as stored on a scheduled event. `timeZone` is@@ -36,12 +44,61 @@ export function EventDate({value={value}preset={preset}timeZone="UTC"- showTimeZone={false}className={className}/>);}- return <Time value={value} preset={preset} className={className} />;+ return (+ <Time+ value={value}+ preset={preset}+ className={className}+ showTimeZone={false}+ />+ );+}++/**+ * Month/day chip for the event's start. Resolves the display zone the same+ * way as EventDate: all-day and floating values are stored as UTC wall time+ * and read in UTC; fixed instants show in the viewer's zone.+ */+export function EventCalendarCard({+ start,+ allDay,+ timeZone,+ className,+}: SchedulingFields & {+ start: DateInput;+ className?: string;+}) {+ const hydrated = useHydrated();+ const config = useDateTimeConfig();+ const displayTimeZone = allDay || timeZone === null ? "UTC" : config.timeZone;++ // Intl output isn't stable across engines, so it can't be rendered on the+ // server; keep the chip's layout without committing to a date until+ // hydration and until the viewer's zone is known.+ if (!hydrated || !displayTimeZone) {+ return (+ <CalendarCard className={className}>+ <CalendarCardMonth> </CalendarCardMonth>+ <CalendarCardDay> </CalendarCardDay>+ </CalendarCard>+ );+ }++ const parts = formatDateParts(start, {+ locale: config.locale,+ timeZone: displayTimeZone,+ });++ return (+ <CalendarCard className={className}>+ <CalendarCardMonth>{parts.month}</CalendarCardMonth>+ <CalendarCardDay>{parts.day}</CalendarCardDay>+ </CalendarCard>+ );}export function EventTimeRange({@@ -67,13 +124,7 @@ export function EventTimeRange({}if (timeZone === null) {return (- <TimeRange- start={start}- end={end}- timeZone="UTC"- showTimeZone={false}- className={className}- />+ <TimeRange start={start} end={end} timeZone="UTC" className={className} />);}return (diff --git a/apps/web/src/lib/datetime/calendar-date.tsx b/apps/web/src/lib/datetime/calendar-date.tsxindex 408a97c22..71368f44c 100644--- a/apps/web/src/lib/datetime/calendar-date.tsx+++ b/apps/web/src/lib/datetime/calendar-date.tsx@@ -3,6 +3,7 @@import { useDateTimeConfig } from "@/lib/datetime/client";import type { DateInput, DatePreset } from "@/lib/datetime/format";import { formatDate } from "@/lib/datetime/format";+import { useHydrated } from "@/lib/datetime/use-hydrated";import { toISODate } from "./utils";export type CalendarDateProps = {@@ -17,10 +18,11 @@ export function CalendarDate({preset = "dateLong",className,}: CalendarDateProps) {+ const hydrated = useHydrated();const { locale } = useDateTimeConfig();return (<time dateTime={toISODate(value)} className={className}>- {formatDate(value, { preset, locale })}+ {hydrated ? formatDate(value, { preset, locale }) : " "}</time>);}diff --git a/apps/web/src/lib/datetime/relative-time.tsx b/apps/web/src/lib/datetime/relative-time.tsxindex e7b28132b..9ef3398d7 100644--- a/apps/web/src/lib/datetime/relative-time.tsx+++ b/apps/web/src/lib/datetime/relative-time.tsx@@ -3,6 +3,7 @@import { useDateTimeConfig } from "@/lib/datetime/client";import type { DateInput } from "@/lib/datetime/format";import { formatRelativeTime } from "@/lib/datetime/format";+import { useHydrated } from "@/lib/datetime/use-hydrated";import { toISO } from "./utils";export type RelativeTimeProps = {@@ -13,10 +14,11 @@ export type RelativeTimeProps = {};export function RelativeTime({ value, locale, className }: RelativeTimeProps) {+ const hydrated = useHydrated();const config = useDateTimeConfig();return (<time dateTime={toISO(value)} className={className}>- {formatRelativeTime(value, locale ?? config.locale)}+ {hydrated ? formatRelativeTime(value, locale ?? config.locale) : " "}</time>);}diff --git a/apps/web/src/lib/datetime/time.tsx b/apps/web/src/lib/datetime/time.tsxindex 3a80bdc7a..7a7c1b985 100644--- a/apps/web/src/lib/datetime/time.tsx+++ b/apps/web/src/lib/datetime/time.tsx@@ -3,6 +3,7 @@import { useDateTimeConfig } from "@/lib/datetime/client";import type { DateInput, DateTimePreset } from "@/lib/datetime/format";import { formatDateTime, formatDateTimeRange } from "@/lib/datetime/format";+import { useHydrated } from "@/lib/datetime/use-hydrated";import { toISO } from "./utils";export type TimeProps = {@@ -10,7 +11,7 @@ export type TimeProps = {preset?: DateTimePreset;/** Display zone (e.g. a venue's zone). Omit to show the viewer's local time. */timeZone?: string;- /** Overrides the default rule: show the zone when it isn't the viewer's. */+ /** Append the zone name (e.g. "GMT+1"). Off unless set. */showTimeZone?: boolean;className?: string;};@@ -22,13 +23,14 @@ export function Time({showTimeZone,className,}: TimeProps) {+ const hydrated = useHydrated();const config = useDateTimeConfig();const displayTimeZone = timeZone ?? config.timeZone;- // The viewer's zone isn't known until the provider detects it on the- // client; render a non-breaking space (preserves the line height) rather- // than a time that may be wrong.- if (!displayTimeZone) {+ // Intl output isn't stable across engines, so it can't be rendered on the+ // server; render a non-breaking space (preserves the line height) until+ // hydration and until the viewer's zone is known.+ if (!hydrated || !displayTimeZone) {return (<time dateTime={toISO(value)} className={className}>{" "}@@ -43,8 +45,7 @@ export function Time({locale: config.locale,timeFormat: config.timeFormat,timeZone: displayTimeZone,- showTimeZone:- showTimeZone ?? Boolean(timeZone && timeZone !== config.timeZone),+ showTimeZone,})}</time>);@@ -56,7 +57,7 @@ export type TimeRangeProps = {preset?: DateTimePreset;/** Display zone (e.g. a venue's zone). Omit to show the viewer's local time. */timeZone?: string;- /** Overrides the default rule: show the zone when it isn't the viewer's. */+ /** Append the zone name (e.g. "GMT+1"). Off unless set. */showTimeZone?: boolean;className?: string;};@@ -69,13 +70,14 @@ export function TimeRange({showTimeZone,className,}: TimeRangeProps) {+ const hydrated = useHydrated();const config = useDateTimeConfig();const displayTimeZone = timeZone ?? config.timeZone;- // The viewer's zone isn't known until the provider detects it on the- // client; render a non-breaking space (preserves the line height) rather- // than a time that may be wrong.- if (!displayTimeZone) {+ // Intl output isn't stable across engines, so it can't be rendered on the+ // server; render a non-breaking space (preserves the line height) until+ // hydration and until the viewer's zone is known.+ if (!hydrated || !displayTimeZone) {return <span className={className}>{" "}</span>;}@@ -86,8 +88,7 @@ export function TimeRange({locale: config.locale,timeFormat: config.timeFormat,timeZone: displayTimeZone,- showTimeZone:- showTimeZone ?? Boolean(timeZone && timeZone !== config.timeZone),+ showTimeZone,})}</span>);diff --git a/apps/web/src/lib/datetime/use-hydrated.ts b/apps/web/src/lib/datetime/use-hydrated.tsnew file mode 100644index 000000000..e67a6f549--- /dev/null+++ b/apps/web/src/lib/datetime/use-hydrated.ts@@ -0,0 +1,19 @@+"use client";++import React from "react";++const emptySubscribe = () => () => {};++/**+ * False on the server and during the hydration render, true afterwards.+ * Intl output isn't stable across engines (ICU/CLDR/tzdata versions differ+ * between Node and each visitor's browser), so formatted dates and times+ * must not be rendered until after hydration.+ */+export function useHydrated() {+ return React.useSyncExternalStore(+ emptySubscribe,+ () => true,+ () => false,+ );+}