From 8984c7c1ae7ffd5a1516eaf88c49ce6aa0438c73 Mon Sep 17 00:00:00 2001 From: ngqile Date: Wed, 2 Dec 2026 11:31:01 +0800 Subject: [PATCH] fix(portal): inbox fixes from the live check - The list stayed on its skeleton under StrictMode: an unmount flag never reset. Dropped it; a late result on an unmounted list is harmless. - A message sent from the page kept its first status: the server's copy now wins, so ticks move on. - Templates and their sync use the chat's company when a super admin has no company picked. - A manual owner outside the assignee list (a super admin) shows in the Owner select. - The chat column can shrink to a 360 px screen. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs --- .../components/whatsapp/ConversationList.tsx | 7 +-- .../app/components/whatsapp/Thread.tsx | 15 ++++-- .../app/whatsapp/page.test.tsx | 47 ++++++++++++++++++- solvway-admin-portal/app/whatsapp/page.tsx | 4 +- 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/solvway-admin-portal/app/components/whatsapp/ConversationList.tsx b/solvway-admin-portal/app/components/whatsapp/ConversationList.tsx index a8ee8d0..9a2e8e6 100644 --- a/solvway-admin-portal/app/components/whatsapp/ConversationList.tsx +++ b/solvway-admin-portal/app/components/whatsapp/ConversationList.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useRef, useState } from "react"; +import { useEffect, useState } from "react"; import { MessageCircle } from "lucide-react"; import { Input } from "@/app/components/ui/input"; import { Tabs, TabsList, TabsTrigger } from "@/app/components/ui/tabs"; @@ -66,18 +66,13 @@ function Rows({ tab, query, companyId, admin, selected, onSelect }: Props & { ta const t = useT(); const [items, setItems] = useState(null); const [error, setError] = useState<"config" | "load" | null>(null); - const alive = useRef(true); - useEffect(() => () => { alive.current = false; }, []); - const load = () => listConversations(tab, query, 0, companyId).then( (p) => { - if (!alive.current) return; setItems(p.items); setError(null); }, (err: unknown) => { - if (!alive.current) return; const code = err instanceof ApiError ? (err.data as { code?: string } | undefined)?.code : undefined; setError(code === "WHATSAPP_NOT_CONFIGURED" ? "config" : "load"); }, diff --git a/solvway-admin-portal/app/components/whatsapp/Thread.tsx b/solvway-admin-portal/app/components/whatsapp/Thread.tsx index acd5be9..5220041 100644 --- a/solvway-admin-portal/app/components/whatsapp/Thread.tsx +++ b/solvway-admin-portal/app/components/whatsapp/Thread.tsx @@ -24,10 +24,14 @@ import { TemplatePicker } from "./TemplatePicker"; const HOUR = 3600_000; -/** Older pages, then the latest page, then messages sent here that the next poll has not returned yet; each uuid once. */ -function merge(...lists: WhatsAppMessage[][]) { +/** + * Older pages, then the latest page, then messages sent here that no poll has returned yet; each uuid once. + * The server's copy wins over the one kept from the send, so delivery ticks move on. + */ +function merge(older: WhatsAppMessage[], latest: WhatsAppMessage[], local: WhatsAppMessage[]) { const byUuid = new Map(); - for (const list of lists) for (const m of list) byUuid.set(m.uuid, m); + for (const m of [...older, ...latest]) byUuid.set(m.uuid, m); + for (const m of local) if (!byUuid.has(m.uuid)) byUuid.set(m.uuid, m); return [...byUuid.values()]; } @@ -177,7 +181,7 @@ export function Thread({ uuid, companyId, admin, onBack }: Props) { e.currentTarget.form?.requestSubmit(); } }} - className="min-h-9 flex-1 resize-none rounded-md border border-input bg-card px-3 py-2 text-sm shadow-sm focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none" + className="min-h-9 min-w-0 flex-1 resize-none rounded-md border border-input bg-card px-3 py-2 text-sm shadow-sm focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none" />