From 4e8b5d0a1cbfed67e4e695780df11c6f4e4f1638 Mon Sep 17 00:00:00 2001 From: Arjun Komath Date: Mon, 27 Oct 2025 12:02:53 +1100 Subject: [PATCH] Fix missing last active update and deletion reset --- components/core/notification-item.tsx | 4 ++-- components/core/report-timezone.tsx | 5 ++--- trpc/routers/settings.ts | 25 ++++++++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/components/core/notification-item.tsx b/components/core/notification-item.tsx index c602a71d..c93ac86b 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 87bbae43..5424b000 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 28cffd97..cb693477 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 () => {