Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🔥 Delete the legacy dayjs preference stack (#2524)
Luke Vellab798c62f15fc
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 5218843c2..0430fe259 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -100,10 +100,8 @@"react-image-crop": "^11.0.10","react-use": "^17.6.0","smoothscroll-polyfill": "^0.4.4",- "spacetime": "^7.4.7","superjson": "^2.0.0","tailwindcss": "^4.1.18",- "timezone-soft": "^1.5.2","zod": "^4.3.6","zustand": "^5.0.14","zxcvbn": "^4.4.2"diff --git a/apps/web/src/app/[locale]/(auth)/layout.tsx b/apps/web/src/app/[locale]/(auth)/layout.tsxindex fa87b8d75..c110fb57f 100644--- a/apps/web/src/app/[locale]/(auth)/layout.tsx+++ b/apps/web/src/app/[locale]/(auth)/layout.tsx@@ -3,39 +3,48 @@ import {QuickCreateButton,QuickCreateWidget,} from "@/features/quick-create";+import { DeviceDateTimeProvider } from "@/lib/datetime/device";+import { getDeviceDateTimeConfig } from "@/lib/datetime/server";export default async function Layout({children,}: {children: React.ReactNode;}) {+ const deviceDateTimeConfig = await getDeviceDateTimeConfig();+return (- <div className="relative flex min-h-dvh flex-col items-center justify-center bg-background">- <div className="z-10 flex w-full flex-1 lg:p-4">- <div className="flex flex-1 flex-col gap-4 p-6">- <div className="my-auto">- <main- id="main-content"- tabIndex={-1}- className="mx-auto w-full max-w-sm"- >- {children}- </main>+ <DeviceDateTimeProvider+ timeZone={deviceDateTimeConfig.timeZone}+ timeFormat={deviceDateTimeConfig.timeFormat}+ >+ <div className="relative flex min-h-dvh flex-col items-center justify-center bg-background">+ <div className="z-10 flex w-full flex-1 lg:p-4">+ <div className="flex flex-1 flex-col gap-4 p-6">+ <div className="my-auto">+ <main+ id="main-content"+ tabIndex={-1}+ className="mx-auto w-full max-w-sm"+ >+ {children}+ </main>+ </div>+ {isQuickCreateEnabled ? (+ <div className="flex justify-center lg:hidden">+ <QuickCreateButton />+ </div>+ ) : null}</div>{isQuickCreateEnabled ? (- <div className="flex justify-center lg:hidden">- <QuickCreateButton />+ <div className="relative hidden flex-1 flex-col justify-center rounded-lg border bg-muted/50 lg:flex lg:p-16">+ <div className="z-10 mx-auto w-full max-w-md">+ <QuickCreateWidget />+ </div></div>) : null}</div>- {isQuickCreateEnabled ? (- <div className="relative hidden flex-1 flex-col justify-center rounded-lg border bg-muted/50 lg:flex lg:p-16">- <div className="z-10 mx-auto w-full max-w-md">- <QuickCreateWidget />- </div>- </div>- ) : null}</div>- </div>+ </DeviceDateTimeProvider>);}diff --git a/apps/web/src/app/[locale]/(optional-space)/layout.tsx b/apps/web/src/app/[locale]/(optional-space)/layout.tsxindex 53c4dc898..fbdb06389 100644--- a/apps/web/src/app/[locale]/(optional-space)/layout.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/layout.tsx@@ -1,10 +1,10 @@import { dehydrate, HydrationBoundary } from "@tanstack/react-query";import { SessionRefresher } from "@/components/session-refresher";-import { PreferencesProvider } from "@/contexts/preferences";import { PayWall } from "@/features/billing/components/pay-wall";import { isQuickCreateEnabled } from "@/features/quick-create";import { DeviceDateTimeProvider } from "@/lib/datetime/device";import { getDeviceDateTimeConfig } from "@/lib/datetime/server";+import { LocaleSync } from "@/lib/locale/client";import {createPrivateSSRHelper,createPublicSSRHelper,@@ -28,20 +28,17 @@ export default async function Layout({return (<HydrationBoundary state={dehydrate(helpers.queryClient)}><SessionRefresher />- <PreferencesProvider>- <DeviceDateTimeProvider- timeZone={- deviceDateTimeConfig.timeZone ?? user?.timeZone ?? undefined- }- timeFormat={- deviceDateTimeConfig.timeFormat ?? user?.timeFormat ?? undefined- }- weekStart={user?.weekStart ?? undefined}- >- {children}- <PayWall />- </DeviceDateTimeProvider>- </PreferencesProvider>+ <LocaleSync userLocale={user?.locale ?? undefined} />+ <DeviceDateTimeProvider+ timeZone={user?.timeZone ?? deviceDateTimeConfig.timeZone ?? undefined}+ timeFormat={+ user?.timeFormat ?? deviceDateTimeConfig.timeFormat ?? undefined+ }+ weekStart={user?.weekStart ?? undefined}+ >+ {children}+ <PayWall />+ </DeviceDateTimeProvider></HydrationBoundary>);}diff --git a/apps/web/src/app/[locale]/quick-create/page.tsx b/apps/web/src/app/[locale]/quick-create/page.tsxindex 0efd870b2..44b5ee102 100644--- a/apps/web/src/app/[locale]/quick-create/page.tsx+++ b/apps/web/src/app/[locale]/quick-create/page.tsx@@ -10,6 +10,8 @@ import {QuickCreateWidget,} from "@/features/quick-create";import { getTranslation } from "@/i18n/server";+import { DeviceDateTimeProvider } from "@/lib/datetime/device";+import { getDeviceDateTimeConfig } from "@/lib/datetime/server";export default async function QuickCreatePage() {if (!isQuickCreateEnabled) {@@ -17,29 +19,36 @@ export default async function QuickCreatePage() {}const { t } = await getTranslation();+ const deviceDateTimeConfig = await getDeviceDateTimeConfig();+return (- <main id="main-content" tabIndex={-1} className="flex h-dvh p-2">- <Card className="flex flex-1 flex-col gap-6 p-6">- <div className="mx-auto w-full max-w-md flex-1">- <div className="space-y-8">- <div className="flex-1">- <QuickCreateWidget />+ <DeviceDateTimeProvider+ timeZone={deviceDateTimeConfig.timeZone}+ timeFormat={deviceDateTimeConfig.timeFormat}+ >+ <main id="main-content" tabIndex={-1} className="flex h-dvh p-2">+ <Card className="flex flex-1 flex-col gap-6 p-6">+ <div className="mx-auto w-full max-w-md flex-1">+ <div className="space-y-8">+ <div className="flex-1">+ <QuickCreateWidget />+ </div></div></div>- </div>- <div className="flex justify-center gap-4">- <Link- href="/login"- className={buttonVariants({ className: "rounded-full" })}- >- <Icon>- <LogInIcon />- </Icon>- {t("login")}- </Link>- </div>- </Card>- </main>+ <div className="flex justify-center gap-4">+ <Link+ href="/login"+ className={buttonVariants({ className: "rounded-full" })}+ >+ <Icon>+ <LogInIcon />+ </Icon>+ {t("login")}+ </Link>+ </div>+ </Card>+ </main>+ </DeviceDateTimeProvider>);}diff --git a/apps/web/src/components/forms/poll-options-form/week-calendar.tsx b/apps/web/src/components/forms/poll-options-form/week-calendar.tsxindex 7bdfeedb2..b4ba3b8f4 100644--- a/apps/web/src/components/forms/poll-options-form/week-calendar.tsx+++ b/apps/web/src/components/forms/poll-options-form/week-calendar.tsx@@ -7,7 +7,11 @@ import type { CalendarProps } from "react-big-calendar";import { Calendar } from "react-big-calendar";import { createBreakpoint } from "react-use";import { useDateTime, useDateTimeConfig } from "@/lib/datetime/client";-import { formatDateParts, formatDateTime } from "@/lib/datetime/format";+import {+ formatDateParts,+ formatDateTime,+ formatDateTimeRange,+} from "@/lib/datetime/format";import { dayjs } from "@/lib/dayjs";import DateNavigationToolbar from "./date-navigation-toolbar";@@ -35,6 +39,11 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({}) => {const { locale, timeFormat } = useDateTimeConfig();const { formatDuration } = useDateTime();++ // The form works in naive local times; format in the system zone.+ const formatTime = (time: Date) =>+ formatDateTime(time, { preset: "time", locale, timeFormat });+const scrollToTime =options.length > 0? options[0].type === "timeSlot"@@ -100,9 +109,6 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({eventWrapper: function EventWraper(props) {const start = dayjs(props.event.start);const end = dayjs(props.event.end);- // The form works in naive local times; format in the system zone.- const formatTime = (time: Date) =>- formatDateTime(time, { preset: "time", locale, timeFormat });return (// biome-ignore lint/a11y/noStaticElementInteractions: fix later<div@@ -157,6 +163,22 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({);},}}+ // Localizer strings that remain visible in the week/day views; the+ // dayjs localizer only does date math for the grid.+ formats={{+ timeGutterFormat: (date: Date) => formatTime(date),+ selectRangeFormat: ({ start, end }: { start: Date; end: Date }) =>+ formatDateTimeRange(start, end, {+ preset: "time",+ locale,+ timeFormat,+ }),+ dayRangeHeaderFormat: ({ start, end }: { start: Date; end: Date }) =>+ formatDateTimeRange(start, end, { preset: "monthDay", locale }),+ // The toolbar shows the year separately, so leave it out here.+ dayHeaderFormat: (date: Date) =>+ formatDateTime(date, { preset: "weekdayMonthDay", locale }),+ }}step={15}onSelectSlot={({ start, end, action }) => {// on select slotdiff --git a/apps/web/src/contexts/preferences.tsx b/apps/web/src/contexts/preferences.tsxdeleted file mode 100644index 11c6f4f9d..000000000--- a/apps/web/src/contexts/preferences.tsx+++ /dev/null@@ -1,105 +0,0 @@-"use client";--import type { TimeFormat } from "@rallly/database";-import React from "react";-import { useLocalStorage } from "react-use";-import * as z from "zod";-import { useRequiredContext } from "@/components/use-required-context";-import { LocaleSync, useLocale } from "@/lib/locale/client";-import { trpc } from "@/trpc/client";-import { DayjsProvider } from "@/utils/dayjs";--type Preferences = {- timeZone?: string;- timeFormat?: TimeFormat;- weekStart?: number;-};--const timeFormatSchema = z.enum(["hours12", "hours24"]);--const preferencesSchema = z.object({- timeZone: z.string().optional(),- timeFormat: timeFormatSchema.optional(),- weekStart: z.number().optional(),-});--type PreferencesContextValue = {- preferences: Preferences;- updatePreferences: (preferences: Partial<Preferences>) => Promise<void>;-};--const PreferencesContext = React.createContext<PreferencesContextValue | null>(- null,-);--export const PreferencesProvider = ({- children,-}: {- children?: React.ReactNode;-}) => {- const { data: user } = trpc.user.getMe.useQuery();- const { locale } = useLocale();- const [preferences = {}, setPreferences] = useLocalStorage(- "rallly.preferences",- {- timeZone: user?.timeZone,- timeFormat: user?.timeFormat,- weekStart: user?.weekStart,- },- {- raw: false,- serializer: JSON.stringify,- deserializer: (value) => {- try {- return preferencesSchema.parse(JSON.parse(value));- } catch {- return {};- }- },- },- );-- const updatePreferencesMutation = trpc.user.updatePreferences.useMutation();-- const updatePreferences = async (newPreferences: Partial<Preferences>) => {- setPreferences({- ...preferences,- ...newPreferences,- });-- if (user && !user.isGuest) {- await updatePreferencesMutation.mutateAsync({- timeZone: newPreferences.timeZone ?? undefined,- timeFormat: newPreferences.timeFormat ?? undefined,- weekStart: newPreferences.weekStart ?? undefined,- });- }- };-- return (- <PreferencesContext.Provider- value={{- preferences,- updatePreferences,- }}- >- <DayjsProvider- config={{- locale,- timeZone: preferences.timeZone ?? undefined,- localeOverrides: {- weekStart: preferences.weekStart ?? undefined,- timeFormat: preferences.timeFormat ?? undefined,- },- }}- >- {children}- <LocaleSync userLocale={user?.locale} />- </DayjsProvider>- </PreferencesContext.Provider>- );-};--export const usePreferences = () => {- return useRequiredContext(PreferencesContext);-};diff --git a/apps/web/src/features/quick-create/components/relative-date.tsx b/apps/web/src/features/quick-create/components/relative-date.tsxindex 9813245d1..feba22c54 100644--- a/apps/web/src/features/quick-create/components/relative-date.tsx+++ b/apps/web/src/features/quick-create/components/relative-date.tsx@@ -1,14 +1,15 @@"use client";import { Trans } from "@/i18n/client";-import { dayjs } from "@/lib/dayjs";+import { useDateTime } from "@/lib/datetime/client";export function RelativeDate({ date }: { date: Date }) {+ const { toRelativeTime } = useDateTime();return (<Transi18nKey="createdTime"defaults="Created {relativeTime}"- values={{ relativeTime: dayjs(date).fromNow() }}+ values={{ relativeTime: toRelativeTime(date) }}/>);}diff --git a/apps/web/src/lib/datetime/format.ts b/apps/web/src/lib/datetime/format.tsindex 48dbf4b94..0855d302a 100644--- a/apps/web/src/lib/datetime/format.ts+++ b/apps/web/src/lib/datetime/format.ts@@ -7,7 +7,9 @@ export type DatePreset =| "dateLong"| "dateFull"| "weekday"- | "monthYear";+ | "weekdayMonthDay"+ | "monthYear"+ | "monthDay";export type DateTimePreset = DatePreset | "time" | "datetime";@@ -81,8 +83,12 @@ function presetOptions(};case "weekday":return { weekday: "long" };+ case "weekdayMonthDay":+ return { weekday: "long", month: "long", day: "numeric" };case "monthYear":return { month: "long", year: "numeric" };+ case "monthDay":+ return { month: "long", day: "numeric" };case "datetime":return {year: "numeric",diff --git a/apps/web/src/trpc/routers/user.ts b/apps/web/src/trpc/routers/user.tsindex dc0225c99..58f849131 100644--- a/apps/web/src/trpc/routers/user.ts+++ b/apps/web/src/trpc/routers/user.ts@@ -9,7 +9,6 @@ import { defaultNotificationPreferences } from "@/features/notifications/constanimport { getNotificationPreferences } from "@/features/notifications/queries";import { activityEventTypes } from "@/features/notifications/schema";import { defineAbilityFor } from "@/features/user/ability";-import { timezoneSchema } from "@/utils/timezone-schema";import {createRateLimitMiddleware,privateProcedure,@@ -28,32 +27,6 @@ export const user = router({getAuthed: privateProcedure.query(async ({ ctx }) => {return ctx.user;}),- updatePreferences: privateProcedure- .input(- z.object({- locale: z.string().optional(),- timeZone: timezoneSchema.optional(),- weekStart: z.number().min(0).max(6).optional(),- timeFormat: z.enum(["hours12", "hours24"]).optional(),- }),- )- .mutation(async ({ input, ctx }) => {- if (ctx.user.isGuest) {- throw new TRPCError({- code: "UNAUTHORIZED",- message: "Guest users cannot update preferences",- });- }-- await prisma.user.update({- where: {- id: ctx.user.id,- },- data: input,- });-- return { success: true };- }),deleteMe: privateProcedure.mutation(async ({ ctx }) => {const userId = ctx.user.id;diff --git a/apps/web/src/utils/dayjs.tsx b/apps/web/src/utils/dayjs.tsxdeleted file mode 100644index 500719ef5..000000000--- a/apps/web/src/utils/dayjs.tsx+++ /dev/null@@ -1,216 +0,0 @@-"use client";--import type { TimeFormat } from "@rallly/database";-import type { SupportedLocale } from "@rallly/languages";-import dayjsLocaleCs from "dayjs/locale/cs";-import dayjsLocaleDa from "dayjs/locale/da";-import dayjsLocaleDe from "dayjs/locale/de";-import dayjsLocaleEn from "dayjs/locale/en";-import dayjsLocaleEnGb from "dayjs/locale/en-gb";-import dayjsLocaleEs from "dayjs/locale/es";-import dayjsLocaleFi from "dayjs/locale/fi";-import dayjsLocaleFr from "dayjs/locale/fr";-import dayjsLocaleHu from "dayjs/locale/hu";-import dayjsLocaleIt from "dayjs/locale/it";-import dayjsLocaleNb from "dayjs/locale/nb";-import dayjsLocaleNl from "dayjs/locale/nl";-import dayjsLocalePl from "dayjs/locale/pl";-import dayjsLocalePt from "dayjs/locale/pt";-import dayjsLocalePtBr from "dayjs/locale/pt-br";-import dayjsLocaleRu from "dayjs/locale/ru";-import dayjsLocaleSv from "dayjs/locale/sv";-import dayjsLocaleZh from "dayjs/locale/zh";-import * as React from "react";-import { dayjs } from "@/lib/dayjs";-import { getBrowserTimeZone } from "@/utils/date-time-utils";-import { useRequiredContext } from "../components/use-required-context";--const dayjsLocales: Record<- SupportedLocale,- {- weekStart: number;- timeFormat: TimeFormat;- locale: ILocale;- }-> = {- en: {- weekStart: 1,- timeFormat: "hours12",- locale: dayjsLocaleEn,- },- "en-GB": {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleEnGb,- },- es: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleEs,- },- da: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleDa,- },- de: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleDe,- },- fi: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleFi,- },- fr: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleFr,- },- it: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleIt,- },- sv: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleSv,- },- cs: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleCs,- },- pl: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocalePl,- },- pt: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocalePt,- },- "pt-BR": {- weekStart: 0,- timeFormat: "hours24",- locale: dayjsLocalePtBr,- },- ru: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleRu,- },- nl: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleNl,- },- no: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleNb, // Bokmål- },- hu: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleHu,- },- zh: {- weekStart: 1,- timeFormat: "hours24",- locale: dayjsLocaleZh,- },-};--const DayjsContext = React.createContext<{- adjustTimeZone: (- date: dayjs.ConfigType,- keepLocalTime: boolean,- ) => dayjs.Dayjs;- locale: {- weekStart: number;- timeFormat: TimeFormat;- };- timeZone: string;- timeFormat: TimeFormat;- weekStart: number;-} | null>(null);--DayjsContext.displayName = "DayjsContext";--export const useDayjs = () => {- return useRequiredContext(DayjsContext);-};--export const DayjsProvider: React.FunctionComponent<{- children?: React.ReactNode;- config?: {- locale?: string;- timeZone?: string;- localeOverrides?: {- weekStart?: number;- timeFormat?: TimeFormat;- };- };-}> = ({ config, children }) => {- const locale = config?.locale ?? "en";- const localeKey = (locale in dayjsLocales ? locale : "en") as SupportedLocale;- const localeConfig = dayjsLocales[localeKey];- const dayjsLocale = localeConfig.locale;-- const preferredTimeZone = React.useMemo(- () => config?.timeZone ?? getBrowserTimeZone(),- [config?.timeZone],- );-- const adjustTimeZone = React.useCallback(- (date: dayjs.ConfigType, localTime = false) => {- if (!localTime) {- return dayjs(date).tz(preferredTimeZone);- } else {- return dayjs(date).utc();- }- },- [preferredTimeZone],- );-- const localeTimeFormat = localeConfig.timeFormat;-- if (config?.localeOverrides) {- const timeFormat =- config.localeOverrides.timeFormat ?? localeConfig.timeFormat;- const weekStart =- config.localeOverrides.weekStart ?? localeConfig.weekStart;- dayjs.locale("custom", {- ...dayjsLocale,- weekStart,- formats:- localeTimeFormat === config.localeOverrides?.timeFormat- ? dayjsLocale.formats- : {- ...dayjsLocale.formats,- LT: timeFormat === "hours12" ? "h:mm A" : "HH:mm",- },- });- } else {- dayjs.locale(dayjsLocale);- }-- return (- <DayjsContext.Provider- value={{- adjustTimeZone,- locale: localeConfig, // locale defaults- timeZone: preferredTimeZone,- timeFormat:- config?.localeOverrides?.timeFormat ?? localeConfig.timeFormat,- weekStart: config?.localeOverrides?.weekStart ?? localeConfig.weekStart,- }}- >- {children}- </DayjsContext.Provider>- );-};diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0bbf5b226..d0eea5b5a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -430,18 +430,12 @@ importers:smoothscroll-polyfill:specifier: ^0.4.4version: 0.4.4- spacetime:- specifier: ^7.4.7- version: 7.12.0superjson:specifier: ^2.0.0version: 2.2.6tailwindcss:specifier: ^4.1.18version: 4.1.18- timezone-soft:- specifier: ^1.5.2- version: 1.5.2zod:specifier: ^4.3.6version: 4.3.6@@ -10592,9 +10586,6 @@ packages:resolution: {integrity: sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==}- resolution: {integrity: sha512-n7iQdr/oiTc0Yc0m5/8lpqRPMxuD9c6Yk7F8Np5+jH7tawt+dJZeCLDHNnr2kP5tUlv1H0fazdCOE9EQUv0B3g==}-resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==}engines: {node: '>= 10.x'}@@ -10862,9 +10853,6 @@ packages:resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==}- resolution: {integrity: sha512-BUr+CfBfeWXJwFAuEzPO9uF+v6sy3pL5SKLkDg4vdEhsyXgbBnpFoBCW8oEKSNTqNq9YHbVOjNb31xE7WyGmrA==}-resolution: {integrity: sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==}@@ -23653,8 +23641,6 @@ snapshots:- [email protected]: {}-@@ -23963,8 +23949,6 @@ snapshots:- [email protected]: {}-