Skip to content

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

Trim the mobile header to what each page needs

François Zaninottoee6c4302bc4d
diff --git a/src/components/atomic-crm/contacts/ContactList.test.tsx b/src/components/atomic-crm/contacts/ContactList.test.tsx
index 886ac2a6..f3a92536 100644
--- a/src/components/atomic-crm/contacts/ContactList.test.tsx
+++ b/src/components/atomic-crm/contacts/ContactList.test.tsx
@@ -10,6 +10,7 @@ import {
BulkTagButton,
NonAdminAccountManagerFilter,
} from "./ContactList.stories";
+import { MobileSuccess } from "./ContactList.mobile.stories";
afterEach(() => {
vi.restoreAllMocks();
@@ -201,6 +202,28 @@ describe("ContactList", () => {
});
});
+ describe("header on mobile", () => {
+ beforeAll(() => {
+ page.viewport(375, 667);
+ });
+
+ it("leaves name search to the global search, keeping filters and refresh", async () => {
+ const screen = await render(<MobileSuccess />);
+
+ await expect.element(screen.getByText("Ada Lovelace")).toBeVisible();
+ await expect
+ .element(screen.getByRole("button", { name: "Search", exact: true }))
+ .toBeVisible();
+ await expect
+ .element(screen.getByRole("button", { name: "Add filter" }))
+ .toBeVisible();
+ await expect
+ .element(screen.getByRole("button", { name: "Refresh" }))
+ .toBeVisible();
+ await expect.element(screen.getByRole("textbox")).not.toBeInTheDocument();
+ });
+ });
+
describe("account manager filter on mobile", () => {
beforeAll(() => {
page.viewport(375, 667);
diff --git a/src/components/atomic-crm/contacts/ContactList.tsx b/src/components/atomic-crm/contacts/ContactList.tsx
index 8854e5c0..b938e31b 100644
--- a/src/components/atomic-crm/contacts/ContactList.tsx
+++ b/src/components/atomic-crm/contacts/ContactList.tsx
@@ -4,6 +4,7 @@ import {
InfiniteListBase,
useGetIdentity,
useListContext,
+ useTranslate,
type Exporter,
} from "ra-core";
import { BulkActionsToolbar } from "@/components/admin/bulk-actions-toolbar";
@@ -114,6 +115,7 @@ export const ContactListMobile = () => {
};
const ContactListLayoutMobile = () => {
+ const translate = useTranslate();
const { isPending, data, error, filterValues } = useListContext();
const hasFilters = filterValues && Object.keys(filterValues).length > 0;
@@ -122,8 +124,14 @@ const ContactListLayoutMobile = () => {
return (
<div>
- <MobileHeader>
- <ContactListFilter />
+ <MobileHeader showRefresh>
+ {/* No name search here: the header's global search finds contacts */}
+ <div className="flex flex-1 items-center justify-between">
+ <h1 className="text-xl font-semibold">
+ {translate("resources.contacts.name", { smart_count: 2 })}
+ </h1>
+ <ContactListFilter />
+ </div>
</MobileHeader>
<MobileContent>
<ContactListFilterSummary />
diff --git a/src/components/atomic-crm/contacts/ContactListFilter.tsx b/src/components/atomic-crm/contacts/ContactListFilter.tsx
index 4e2b53f8..714cf7ad 100644
--- a/src/components/atomic-crm/contacts/ContactListFilter.tsx
+++ b/src/components/atomic-crm/contacts/ContactListFilter.tsx
@@ -29,9 +29,12 @@ export const ContactListFilter = () => {
return (
<ResponsiveFilters
- searchInput={{
- placeholder: translate("resources.contacts.filters.search"),
- }}
+ // on mobile, the header's global search replaces the name search
+ searchInput={
+ isMobile
+ ? undefined
+ : { placeholder: translate("resources.contacts.filters.search") }
+ }
>
<FilterCategory
label="resources.contacts.fields.last_seen"
diff --git a/src/components/atomic-crm/contacts/ContactShow.test.tsx b/src/components/atomic-crm/contacts/ContactShow.test.tsx
index d4ec7be3..e0dafdea 100644
--- a/src/components/atomic-crm/contacts/ContactShow.test.tsx
+++ b/src/components/atomic-crm/contacts/ContactShow.test.tsx
@@ -36,6 +36,17 @@ describe("ContactShow", () => {
.toBe(false);
});
+ it("offers search but no refresh in the header of a contact page", async () => {
+ const screen = await render(<MobileSuccess />);
+
+ await expect
+ .element(screen.getByRole("button", { name: "Search", exact: true }))
+ .toBeVisible();
+ await expect
+ .element(screen.getByRole("button", { name: "Refresh" }))
+ .not.toBeInTheDocument();
+ });
+
it("opens on the tab named in the URL, as global search links to tasks", async () => {
const screen = await render(
<StoryWrapper
diff --git a/src/components/atomic-crm/dashboard/MobileDashboard.tsx b/src/components/atomic-crm/dashboard/MobileDashboard.tsx
index faf77a1a..52ab6331 100644
--- a/src/components/atomic-crm/dashboard/MobileDashboard.tsx
+++ b/src/components/atomic-crm/dashboard/MobileDashboard.tsx
@@ -13,7 +13,7 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => {
const { darkModeLogo, lightModeLogo, title } = useConfigurationContext();
return (
<>
- <MobileHeader>
+ <MobileHeader showRefresh>
<div className="flex items-center gap-2 text-secondary-foreground no-underline py-3">
<img
className="[.light_&]:hidden h-6"
diff --git a/src/components/atomic-crm/layout/MobileHeader.tsx b/src/components/atomic-crm/layout/MobileHeader.tsx
index 138cca3c..a3efd81e 100644
--- a/src/components/atomic-crm/layout/MobileHeader.tsx
+++ b/src/components/atomic-crm/layout/MobileHeader.tsx
@@ -1,16 +1,23 @@
import { GlobalSearchButton } from "../search";
import { MobileRefreshButton } from "./MobileRefreshButton";
-// Both actions live here rather than in each screen: there is no Cmd+K on a
-// phone, and the desktop refresh button is hidden on small screens, so this
-// header is the only place reachable from every mobile page.
-const MobileHeader = ({ children }: { children: React.ReactNode }) => {
+// The search lives here rather than in each screen: there is no Cmd+K on a
+// phone, so this header is the only place reachable from every mobile page.
+// Refresh only earns its space on the list pages, whose content changes under
+// the user; elsewhere it would just crowd the header.
+const MobileHeader = ({
+ children,
+ showRefresh = false,
+}: {
+ children: React.ReactNode;
+ showRefresh?: boolean;
+}) => {
return (
<header className="fixed top-0 left-0 right-0 z-10 bg-secondary h-14 px-4 w-full flex justify-between items-center">
{children}
<div className="flex items-center">
<GlobalSearchButton variant="icon" />
- <MobileRefreshButton />
+ {showRefresh ? <MobileRefreshButton /> : null}
</div>
</header>
);
diff --git a/src/components/atomic-crm/misc/ResponsiveFilters.tsx b/src/components/atomic-crm/misc/ResponsiveFilters.tsx
index 4971be23..a2c3fd64 100644
--- a/src/components/atomic-crm/misc/ResponsiveFilters.tsx
+++ b/src/components/atomic-crm/misc/ResponsiveFilters.tsx
@@ -48,14 +48,16 @@ export const ResponsiveFilters = ({
if (isMobile) {
return (
- <div className="flex flex-1 gap-2">
- <FilterLiveForm formComponent={FlexForm}>
- <SearchInput
- source={source}
- className={className}
- {...otherSearchInputProps}
- />
- </FilterLiveForm>
+ <div className={searchInput ? "flex flex-1 gap-2" : "flex"}>
+ {searchInput ? (
+ <FilterLiveForm formComponent={FlexForm}>
+ <SearchInput
+ source={source}
+ className={className}
+ {...otherSearchInputProps}
+ />
+ </FilterLiveForm>
+ ) : null}
<Sheet>
<SheetTrigger asChild>
<Button
diff --git a/src/components/atomic-crm/tasks/MobileTasksList.tsx b/src/components/atomic-crm/tasks/MobileTasksList.tsx
index 144b7b7e..6a2c1df4 100644
--- a/src/components/atomic-crm/tasks/MobileTasksList.tsx
+++ b/src/components/atomic-crm/tasks/MobileTasksList.tsx
@@ -7,7 +7,7 @@ export const MobileTasksList = () => {
const translate = useTranslate();
return (
<>
- <MobileHeader>
+ <MobileHeader showRefresh>
<h1 className="text-xl font-semibold">
{translate("resources.tasks.name", { smart_count: 2 })}
</h1>