Skip to content

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

company list mobile layout (best effort)

Jean-Baptiste Kaiserbec939dd0694
diff --git a/src/components/atomic-crm/companies/CompanyList.tsx b/src/components/atomic-crm/companies/CompanyList.tsx
index fb0d1ce9..7e2a8664 100644
--- a/src/components/atomic-crm/companies/CompanyList.tsx
+++ b/src/components/atomic-crm/companies/CompanyList.tsx
@@ -1,18 +1,29 @@
-import { useGetIdentity, useListContext } from "ra-core";
import { CreateButton } from "@/components/admin/create-button";
import { ExportButton } from "@/components/admin/export-button";
import { List } from "@/components/admin/list";
import { ListPagination } from "@/components/admin/list-pagination";
import { SortButton } from "@/components/admin/sort-button";
+import { InfiniteListBase, useGetIdentity, useListContext } from "ra-core";
+import { useIsMobile } from "@/hooks/use-mobile";
+import { MobileContent } from "../layout/MobileContent";
+import MobileHeader from "../layout/MobileHeader";
import { TopToolbar } from "../layout/TopToolbar";
+import { InfinitePagination } from "../misc/InfinitePagination";
import { CompanyEmpty } from "./CompanyEmpty";
import { CompanyListFilter } from "./CompanyListFilter";
import { ImageList } from "./GridList";
export const CompanyList = () => {
+ const isMobile = useIsMobile();
+ return isMobile ? <CompanyListMobile /> : <CompanyListDesktop />;
+};
+
+const CompanyListDesktop = () => {
const { identity } = useGetIdentity();
+
if (!identity) return null;
+
return (
<List
title={false}
@@ -21,12 +32,24 @@ export const CompanyList = () => {
actions={<CompanyListActions />}
pagination={<ListPagination rowsPerPageOptions={[10, 25, 50, 100]} />}
>
- <CompanyListLayout />
+ <DesktopCompanyListLayout />
</List>
);
};
-const CompanyListLayout = () => {
+const CompanyListMobile = () => {
+ const { identity } = useGetIdentity();
+
+ if (!identity) return null;
+
+ return (
+ <InfiniteListBase perPage={25} sort={{ field: "name", order: "ASC" }}>
+ <MobileCompanyListLayout />
+ </InfiniteListBase>
+ );
+};
+
+const DesktopCompanyListLayout = () => {
const { data, isPending, filterValues } = useListContext();
const hasFilters = filterValues && Object.keys(filterValues).length > 0;
@@ -43,6 +66,30 @@ const CompanyListLayout = () => {
);
};
+const MobileCompanyListLayout = () => {
+ const { data, isPending, filterValues } = useListContext();
+
+ const hasFilters = filterValues && Object.keys(filterValues).length > 0;
+
+ if (isPending) return null;
+
+ if (!data?.length && !hasFilters) return <CompanyEmpty />;
+
+ return (
+ <div>
+ <MobileHeader>
+ <CompanyListFilter />
+ </MobileHeader>
+ <MobileContent>
+ <ImageList />
+ <div className="flex justify-center">
+ <InfinitePagination />
+ </div>
+ </MobileContent>
+ </div>
+ );
+};
+
const CompanyListActions = () => {
return (
<TopToolbar>
diff --git a/src/components/atomic-crm/companies/CompanyListFilter.tsx b/src/components/atomic-crm/companies/CompanyListFilter.tsx
index 23f98c5c..b3140bcf 100644
--- a/src/components/atomic-crm/companies/CompanyListFilter.tsx
+++ b/src/components/atomic-crm/companies/CompanyListFilter.tsx
@@ -1,9 +1,9 @@
-import { Building, Truck, Users } from "lucide-react";
-import { FilterLiveForm, useGetIdentity } from "ra-core";
import { ToggleFilterButton } from "@/components/admin/toggle-filter-button";
-import { SearchInput } from "@/components/admin/search-input";
+import { Building, Truck, Users } from "lucide-react";
+import { useGetIdentity } from "ra-core";
import { FilterCategory } from "../filters/FilterCategory";
+import { ResponsiveFilters } from "../misc/ResponsiveFilters";
import { useConfigurationContext } from "../root/ConfigurationContext";
import { sizes } from "./sizes";
@@ -15,14 +15,11 @@ export const CompanyListFilter = () => {
name: sector,
}));
return (
- <div className="w-52 min-w-52 flex flex-col gap-8">
- <FilterLiveForm>
- <SearchInput source="q" />
- </FilterLiveForm>
-
+ <ResponsiveFilters>
<FilterCategory icon={<Building className="h-4 w-4" />} label="Size">
{sizes.map((size) => (
<ToggleFilterButton
+ key={size.id}
className="w-full justify-between"
label={size.name}
value={{ size: size.id }}
@@ -33,6 +30,7 @@ export const CompanyListFilter = () => {
<FilterCategory icon={<Truck className="h-4 w-4" />} label="Sector">
{sectors.map((sector) => (
<ToggleFilterButton
+ key={sector.id}
className="w-full justify-between"
label={sector.name}
value={{ sector: sector.id }}
@@ -50,6 +48,6 @@ export const CompanyListFilter = () => {
value={{ sales_id: identity?.id }}
/>
</FilterCategory>
- </div>
+ </ResponsiveFilters>
);
};
diff --git a/src/components/atomic-crm/contacts/ContactList.tsx b/src/components/atomic-crm/contacts/ContactList.tsx
index 7ad048ad..445c0969 100644
--- a/src/components/atomic-crm/contacts/ContactList.tsx
+++ b/src/components/atomic-crm/contacts/ContactList.tsx
@@ -65,11 +65,10 @@ const ContactListMobile = () => {
const DesktopContactListLayout = () => {
const { data, isPending, filterValues } = useListContext();
- const { identity } = useGetIdentity();
const hasFilters = filterValues && Object.keys(filterValues).length > 0;
- if (!identity || isPending) return null;
+ if (isPending) return null;
if (!data?.length && !hasFilters) return <ContactEmpty />;
@@ -88,11 +87,10 @@ const DesktopContactListLayout = () => {
const MobileContactListLayout = () => {
const { data, isPending, filterValues } = useListContext();
- const { identity } = useGetIdentity();
const hasFilters = filterValues && Object.keys(filterValues).length > 0;
- if (!identity || isPending) return null;
+ if (isPending) return null;
if (!data?.length && !hasFilters) return <ContactEmpty />;