Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Fix contact show task count translation flicker

Anibal Svarcased284bf60338
diff --git a/src/components/atomic-crm/contacts/ContactShow.integration.test.tsx b/src/components/atomic-crm/contacts/ContactShow.integration.test.tsx
new file mode 100644
index 00000000..004edfb8
--- /dev/null
+++ b/src/components/atomic-crm/contacts/ContactShow.integration.test.tsx
@@ -0,0 +1,53 @@
+import { describe, expect, it, vi } from "vitest";
+import { render } from "vitest-browser-react";
+
+import {
+ buildContact,
+ createCrmDb,
+ createCrmScenario,
+ CrmTestProvider,
+ MobileContactShowHarness,
+} from "@/test/browser/atomic-crm/crmUiHarness";
+
+vi.mock("@/hooks/use-mobile", () => ({
+ useIsMobile: () => true,
+}));
+
+describe("Contact show integration", () => {
+ it("renders a safe zero-task label before nb_tasks is available", async () => {
+ const scenario = createCrmScenario({
+ db: createCrmDb({
+ contacts: [
+ buildContact({
+ first_name: "Jane",
+ id: 8,
+ last_name: "Smith",
+ nb_tasks: undefined,
+ }),
+ ] as any,
+ }),
+ });
+
+ const screen = await render(
+ <CrmTestProvider
+ initialEntries={["/contacts/8/show"]}
+ resource="contacts"
+ scenario={scenario}
+ >
+ <MobileContactShowHarness />
+ </CrmTestProvider>,
+ );
+
+ await expect
+ .element(screen.getByRole("tab", { name: "0 tasks" }))
+ .toBeVisible();
+ await expect
+ .poll(
+ () => screen.container.textContent?.includes("%{smart_count}") ?? false,
+ )
+ .toBe(false);
+ await expect
+ .poll(() => screen.container.textContent?.includes("||||") ?? false)
+ .toBe(false);
+ });
+});
diff --git a/src/components/atomic-crm/contacts/ContactShow.tsx b/src/components/atomic-crm/contacts/ContactShow.tsx
index 3422e910..0de11f7f 100644
--- a/src/components/atomic-crm/contacts/ContactShow.tsx
+++ b/src/components/atomic-crm/contacts/ContactShow.tsx
@@ -58,6 +58,8 @@ const ContactShowContentMobile = () => {
const [editOpen, setEditOpen] = useState(false);
if (isPending || !record) return null;
+ const taskCount = record.nb_tasks ?? 0;
+
return (
<>
{/* We need to repeat the note creation sheet here to support the note
@@ -135,7 +137,7 @@ const ContactShowContentMobile = () => {
</TabsTrigger>
<TabsTrigger value="tasks">
{translate("crm.common.task_count", {
- smart_count: record.nb_tasks,
+ smart_count: taskCount,
})}
</TabsTrigger>
<TabsTrigger value="details">
diff --git a/src/test/browser/atomic-crm/crmUiHarness.tsx b/src/test/browser/atomic-crm/crmUiHarness.tsx
index 82b4f9b0..4c5fd845 100644
--- a/src/test/browser/atomic-crm/crmUiHarness.tsx
+++ b/src/test/browser/atomic-crm/crmUiHarness.tsx
@@ -2,6 +2,7 @@
import { Notification } from "@/components/admin/notification";
import { ThemeProvider } from "@/components/admin/theme-provider";
import { ContactList } from "@/components/atomic-crm/contacts/ContactList";
+import { ContactShow } from "@/components/atomic-crm/contacts/ContactShow";
import {
ContactListContent,
ContactListContentMobile,
@@ -30,7 +31,7 @@ import {
type AuthProvider,
} from "ra-core";
import { useMemo, useState, type ReactNode } from "react";
-import { MemoryRouter } from "react-router";
+import { MemoryRouter, Route, Routes } from "react-router";
const listSort = { field: "last_seen", order: "DESC" } as const;
const listPerPage = 25;
@@ -60,6 +61,10 @@ const resourceDefinitions = {
configuration: {
name: "configuration",
},
+ contact_notes: {
+ hasList: true,
+ name: "contact_notes",
+ },
contacts: {
hasCreate: true,
hasList: true,
@@ -318,3 +323,9 @@ export const OpenTaskCreateSheetHarness = () => {
return <TaskCreateSheet open={open} onOpenChange={setOpen} />;
};
+
+export const MobileContactShowHarness = () => (
+ <Routes>
+ <Route path="/contacts/:id/show" element={<ContactShow />} />
+ </Routes>
+);