Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🐛 Fix week start not being persisted properly (#1823)
Luke Vella297355f999a2
diff --git a/apps/web/src/contexts/preferences.tsx b/apps/web/src/contexts/preferences.tsxindex 9d9236743..10c7c5690 100644--- a/apps/web/src/contexts/preferences.tsx+++ b/apps/web/src/contexts/preferences.tsx@@ -17,6 +17,12 @@ type Preferences = {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>;@@ -34,45 +40,27 @@ export const PreferencesProvider = ({initialValue: Partial<Preferences>;}) => {const { user } = useUser();- const [preferredTimezone, setPreferredTimezone] = useLocalStorage(- "rallly.preferredTimezone",- initialValue.timeZone,- );- const [preferredTimeFormat, setPreferredTimeFormat] = useLocalStorage(- "rallly.preferredTimeFormat",- initialValue.timeFormat,+ const [preferences = {}, setPreferences] = useLocalStorage(+ "rallly.preferences",+ initialValue,{raw: false,- serializer: timeFormatSchema.parse,- deserializer: timeFormatSchema.optional().catch(undefined).parse,+ serializer: JSON.stringify,+ deserializer: (value) => preferencesSchema.parse(JSON.parse(value)),},);- const [preferredWeekStart, setPreferredWeekStart] = useLocalStorage(- "rallly.preferredWeekStart",- initialValue.weekStart,- );+const updatePreferences = trpc.user.updatePreferences.useMutation();return (<PreferencesContext.Providervalue={{- preferences: {- timeZone: preferredTimezone,- timeFormat: preferredTimeFormat,- weekStart: preferredWeekStart,- },+ preferences,updatePreferences: async (newPreferences) => {- if (newPreferences.timeZone) {- setPreferredTimezone(newPreferences.timeZone);- }-- if (newPreferences.timeFormat) {- setPreferredTimeFormat(newPreferences.timeFormat);- }-- if (newPreferences.weekStart) {- setPreferredWeekStart(newPreferences.weekStart);- }+ setPreferences((prev) => ({+ ...prev,+ ...newPreferences,+ }));if (!user.isGuest) {await updatePreferences.mutateAsync({