diff --git a/components/core/notification-item.tsx b/components/core/notification-item.tsx index c602a71..c93ac86 100644 --- a/components/core/notification-item.tsx +++ b/components/core/notification-item.tsx @@ -1,10 +1,10 @@ "use client"; +import { Dot } from "lucide-react"; +import Link from "next/link"; import { UserAvatar } from "@/components/core/user-avatar"; import type { NotificationWithUser } from "@/drizzle/types"; import { toDateTimeString } from "@/lib/utils/date"; -import { Dot } from "lucide-react"; -import Link from "next/link"; export function NotificationItem({ notification, diff --git a/components/core/report-timezone.tsx b/components/core/report-timezone.tsx index 87bbae4..5424b00 100644 --- a/components/core/report-timezone.tsx +++ b/components/core/report-timezone.tsx @@ -1,9 +1,8 @@ "use client"; -import { useTRPC } from "@/trpc/client"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { useEffect } from "react"; -import { memo } from "react"; +import { memo, useEffect } from "react"; +import { useTRPC } from "@/trpc/client"; export const ReportTimezone = memo(function ReportTimezone() { const trpc = useTRPC(); diff --git a/trpc/routers/settings.ts b/trpc/routers/settings.ts index 28cffd9..cb69347 100644 --- a/trpc/routers/settings.ts +++ b/trpc/routers/settings.ts @@ -3,7 +3,7 @@ import { cookies } from "next/headers"; import { z } from "zod"; import { blob, user } from "@/drizzle/schema"; import type { User } from "@/drizzle/types"; -import { opsUser } from "@/ops/drizzle/schema"; +import { opsOrganization, opsUser } from "@/ops/drizzle/schema"; import { getOpsDatabase } from "@/ops/useOps"; import { createTRPCRouter, protectedProcedure } from "../init"; @@ -32,27 +32,42 @@ export const settingsRouter = createTRPCRouter({ maxAge: 60 * 60 * 24 * 365, }); - // Update main user database await ctx.db .update(user) .set({ timeZone: input, lastActiveAt: new Date() }) .where(eq(user.id, ctx.userId)) .execute(); - // Also update ops user database for email scheduling try { const opsDb = await getOpsDatabase(); + await opsDb .update(opsUser) - .set({ timeZone: input, lastActiveAt: new Date() }) + .set({ + timeZone: input, + lastActiveAt: new Date(), + markedForDeletionAt: null, + finalWarningAt: null, + }) .where(eq(opsUser.id, ctx.userId)) .execute(); + + if (ctx.orgId) { + await opsDb + .update(opsOrganization) + .set({ + lastActiveAt: new Date(), + markedForDeletionAt: null, + finalWarningAt: null, + }) + .where(eq(opsUser.id, ctx.orgId)) + .execute(); + } } catch (error) { console.error( "[Settings] Error updating timezone in ops database:", error, ); - // Don't throw error to avoid blocking the main update } }), getTimezone: protectedProcedure.output(z.string()).query(async () => {