Skip to content

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

Feat(ui): Display emptys components only if no data with no filters

Anthony Rimetbd315e234313
diff --git a/src/companies/CompanyList.tsx b/src/companies/CompanyList.tsx
index 939f3a06..fac7d832 100644
--- a/src/companies/CompanyList.tsx
+++ b/src/companies/CompanyList.tsx
@@ -15,17 +15,12 @@ import { ImageList } from './GridList';
import { CompanyListFilter } from './CompanyListFilter';
import { LinearProgress, Stack } from '@mui/material';
import { CompanyEmpty } from './CompanyEmpty';
-import { hasOtherFiltersThanDefault } from '../misc/hasOtherFiltersThanDefault';
export const CompanyList = () => {
const { identity } = useGetIdentity();
if (!identity) return null;
return (
- <ListBase
- perPage={25}
- filterDefaultValues={{ sales_id: identity?.id }}
- sort={{ field: 'name', order: 'ASC' }}
- >
+ <ListBase perPage={25} sort={{ field: 'name', order: 'ASC' }}>
<CompanyListLayout />
</ListBase>
);
@@ -33,15 +28,10 @@ export const CompanyList = () => {
const CompanyListLayout = () => {
const { data, isPending, filterValues } = useListContext();
- const { identity } = useGetIdentity();
- const hasOtherFiltersThanDefaultBoolean = hasOtherFiltersThanDefault(
- filterValues,
- 'sales_id',
- identity?.id
- );
+ const hasFilters = filterValues && Object.keys(filterValues).length > 0;
+
if (isPending) return <LinearProgress />;
- if (!data?.length && !hasOtherFiltersThanDefaultBoolean)
- return <CompanyEmpty />;
+ if (!data?.length && !hasFilters) return <CompanyEmpty />;
return (
<Stack direction="row" component="div">
diff --git a/src/companies/CompanyListFilter.tsx b/src/companies/CompanyListFilter.tsx
index cd70f76d..f47465b4 100644
--- a/src/companies/CompanyListFilter.tsx
+++ b/src/companies/CompanyListFilter.tsx
@@ -24,7 +24,17 @@ export const CompanyListFilter = () => {
return (
<Box width="13em" minWidth="13em" order={-1} mr={2} mt={5}>
<FilterLiveSearch hiddenLabel />
-
+ <FilterList
+ label="Account manager"
+ icon={<SupervisorAccountIcon />}
+ >
+ <FilterListItem
+ label="Me"
+ value={{
+ sales_id: identity && identity.id,
+ }}
+ />
+ </FilterList>
<FilterList label="Size" icon={<BusinessIcon />}>
{sizes.map(size => (
<FilterListItem
@@ -44,18 +54,6 @@ export const CompanyListFilter = () => {
/>
))}
</FilterList>
-
- <FilterList
- label="Account manager"
- icon={<SupervisorAccountIcon />}
- >
- <FilterListItem
- label="Me"
- value={{
- sales_id: identity && identity.id,
- }}
- />
- </FilterList>
</Box>
);
};
diff --git a/src/contacts/ContactList.tsx b/src/contacts/ContactList.tsx
index 7dfac42c..ef45db01 100644
--- a/src/contacts/ContactList.tsx
+++ b/src/contacts/ContactList.tsx
@@ -17,7 +17,6 @@ import {
useGetIdentity,
useListContext,
} from 'react-admin';
-import { hasOtherFiltersThanDefault } from '../misc/hasOtherFiltersThanDefault';
import { Company, Contact, Sale, Tag } from '../types';
import { ContactEmpty } from './ContactEmpty';
import { ContactImportButton } from './ContactImportButton';
@@ -32,7 +31,6 @@ export const ContactList = () => {
return (
<ListBase
perPage={25}
- filterDefaultValues={{ sales_id: identity?.id }}
sort={{ field: 'last_seen', order: 'DESC' }}
exporter={exporter}
>
@@ -44,17 +42,13 @@ export const ContactList = () => {
const ContactListLayout = () => {
const { data, isPending, filterValues } = useListContext();
const { identity } = useGetIdentity();
- const hasOtherFiltersThanDefaultBoolean = hasOtherFiltersThanDefault(
- filterValues,
- 'sales_id',
- identity?.id
- );
+
+ const hasFilters = filterValues && Object.keys(filterValues).length > 0;
if (!identity) return null;
if (isPending) return <LinearProgress />;
- if (!data?.length && !hasOtherFiltersThanDefaultBoolean)
- return <ContactEmpty />;
+ if (!data?.length && !hasFilters) return <ContactEmpty />;
return (
<Stack direction="row">
diff --git a/src/contacts/ContactListFilter.tsx b/src/contacts/ContactListFilter.tsx
index 33e622bd..7e58e414 100644
--- a/src/contacts/ContactListFilter.tsx
+++ b/src/contacts/ContactListFilter.tsx
@@ -34,6 +34,15 @@ export const ContactListFilter = () => {
}}
placeholder="Search name, company, etc."
/>
+ <FilterList
+ label="Account manager"
+ icon={<SupervisorAccountIcon />}
+ >
+ <FilterListItem
+ label="Me"
+ value={{ sales_id: identity && identity.id }}
+ />
+ </FilterList>
<FilterList label="Last activity" icon={<AccessTimeIcon />}>
<FilterListItem
label="Today"
@@ -107,15 +116,6 @@ export const ContactListFilter = () => {
/>
))}
</FilterList>
- <FilterList
- label="Account manager"
- icon={<SupervisorAccountIcon />}
- >
- <FilterListItem
- label="Me"
- value={{ sales_id: identity && identity.id }}
- />
- </FilterList>
</Box>
);
};
diff --git a/src/deals/DealList.tsx b/src/deals/DealList.tsx
index 43b29a42..38ce8e60 100644
--- a/src/deals/DealList.tsx
+++ b/src/deals/DealList.tsx
@@ -15,7 +15,6 @@ import {
import { matchPath, useLocation } from 'react-router';
import { Card, LinearProgress, Stack } from '@mui/material';
-import { hasOtherFiltersThanDefault } from '../misc/hasOtherFiltersThanDefault';
import { useConfigurationContext } from '../root/ConfigurationContext';
import { DealArchivedList } from './DealArchivedList';
import { DealCreate } from './DealCreate';
@@ -32,9 +31,6 @@ const DealList = () => {
return (
<ListBase
perPage={100}
- filterDefaultValues={{
- sales_id: identity?.id,
- }}
filter={{
'archived_at@is': null,
}}
@@ -65,15 +61,10 @@ const DealLayout = () => {
];
const { data, isPending, filterValues } = useListContext();
- const { identity } = useGetIdentity();
- const hasOtherFiltersThanDefaultBoolean = hasOtherFiltersThanDefault(
- filterValues,
- 'sales_id',
- identity?.id
- );
+ const hasFilters = filterValues && Object.keys(filterValues).length > 0;
if (isPending) return <LinearProgress />;
- if (!data?.length && !hasOtherFiltersThanDefaultBoolean)
+ if (!data?.length && !hasFilters)
return (
<>
<DealEmpty>
diff --git a/src/misc/hasOtherFiltersThanDefault.ts b/src/misc/hasOtherFiltersThanDefault.ts
deleted file mode 100644
index 5b511923..00000000
--- a/src/misc/hasOtherFiltersThanDefault.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-export function hasOtherFiltersThanDefault(
- filterValues: { [key: string]: any },
- defaultFilterKey: string,
- defaultFilterValue: unknown
-): boolean {
- return Object.keys(filterValues).some(
- key =>
- key !== defaultFilterKey || filterValues[key] !== defaultFilterValue
- );
-}