A full-featured CRM built with React, shadcn/ui, and Supabase.
wip: contact list filters
Jean-Baptiste Kaiser9d0adb7abd20
diff --git a/registry.json b/registry.jsonindex 4493c26a..28c3fbed 100644--- a/registry.json+++ b/registry.json@@ -340,6 +340,10 @@"path": "src/components/atomic-crm/misc/Status.tsx","type": "registry:component"},+ {+ "path": "src/components/atomic-crm/misc/ResponsiveFilters.tsx",+ "type": "registry:component"+ },{"path": "src/components/atomic-crm/misc/RelativeDate.tsx","type": "registry:component"diff --git a/src/components/atomic-crm/contacts/ContactListFilter.tsx b/src/components/atomic-crm/contacts/ContactListFilter.tsxindex ce76bf1d..c1c38445 100644--- a/src/components/atomic-crm/contacts/ContactListFilter.tsx+++ b/src/components/atomic-crm/contacts/ContactListFilter.tsx@@ -1,16 +1,18 @@import { endOfYesterday, startOfMonth, startOfWeek, subMonths } from "date-fns";import { CheckSquare, Clock, Tag, TrendingUp, Users } from "lucide-react";-import { FilterLiveForm, useGetIdentity, useGetList } from "ra-core";+import { useGetIdentity, useGetList } from "ra-core";import { ToggleFilterButton } from "@/components/admin/toggle-filter-button";-import { SearchInput } from "@/components/admin/search-input";import { Badge } from "@/components/ui/badge";import { FilterCategory } from "../filters/FilterCategory";import { Status } from "../misc/Status";import { useConfigurationContext } from "../root/ConfigurationContext";+import { ResponsiveFilters } from "../misc/ResponsiveFilters";+import { useIsMobile } from "@/hooks/use-mobile";export const ContactListFilter = () => {const { noteStatuses } = useConfigurationContext();+ const isMobile = useIsMobile();const { identity } = useGetIdentity();const { data } = useGetList("tags", {pagination: { page: 1, perPage: 10 },@@ -18,46 +20,46 @@ export const ContactListFilter = () => {});return (- <div className="w-52 min-w-52 order-first pt-0.75 flex flex-col gap-4">- <FilterLiveForm>- <SearchInput source="q" placeholder="Search name, company..." />- </FilterLiveForm>-+ <ResponsiveFilters searchInput={{ placeholder: "Name, company" }}><FilterCategory label="Last activity" icon={<Clock />}><ToggleFilterButton- className="w-full justify-between"+ className="w-auto md:w-full justify-between"label="Today"value={{"last_seen@gte": endOfYesterday().toISOString(),"last_seen@lte": undefined,}}+ size={isMobile ? "lg" : undefined}/><ToggleFilterButton- className="w-full justify-between"+ className="w-auto md:w-full justify-between"label="This week"value={{"last_seen@gte": startOfWeek(new Date()).toISOString(),"last_seen@lte": undefined,}}+ size={isMobile ? "lg" : undefined}/><ToggleFilterButton- className="w-full justify-between"+ className="w-auto md:w-full justify-between"label="Before this week"value={{"last_seen@gte": undefined,"last_seen@lte": startOfWeek(new Date()).toISOString(),}}+ size={isMobile ? "lg" : undefined}/><ToggleFilterButton- className="w-full justify-between"+ className="w-auto md:w-full justify-between"label="Before this month"value={{"last_seen@gte": undefined,"last_seen@lte": startOfMonth(new Date()).toISOString(),}}+ size={isMobile ? "lg" : undefined}/><ToggleFilterButton- className="w-full justify-between"+ className="w-auto md:w-full justify-between"label="Before last month"value={{"last_seen@gte": undefined,@@ -66,6 +68,7 @@ export const ContactListFilter = () => {1,).toISOString(),}}+ size={isMobile ? "lg" : undefined}/></FilterCategory>@@ -73,13 +76,14 @@ export const ContactListFilter = () => {{noteStatuses.map((status) => (<ToggleFilterButtonkey={status.value}- className="w-full justify-between"+ className="w-auto md:w-full justify-between"label={<span>{status.label} <Status status={status.value} /></span>}value={{ status: status.value }}+ size={isMobile ? "lg" : undefined}/>))}</FilterCategory>@@ -88,7 +92,7 @@ export const ContactListFilter = () => {{data &&data.map((record) => (<ToggleFilterButton- className="w-full justify-between"+ className="w-auto md:w-full justify-between"key={record.id}label={<Badge@@ -102,6 +106,7 @@ export const ContactListFilter = () => {</Badge>}value={{ "tags@cs": `{${record.id}}` }}+ size={isMobile ? "lg" : undefined}/>))}</FilterCategory>@@ -111,6 +116,7 @@ export const ContactListFilter = () => {className="w-full justify-between"label={"With pending tasks"}value={{ "nb_tasks@gt": 0 }}+ size={isMobile ? "lg" : undefined}/></FilterCategory>@@ -119,8 +125,9 @@ export const ContactListFilter = () => {className="w-full justify-between"label={"Me"}value={{ sales_id: identity?.id }}+ size={isMobile ? "lg" : undefined}/></FilterCategory>- </div>+ </ResponsiveFilters>);};diff --git a/src/components/atomic-crm/filters/FilterCategory.tsx b/src/components/atomic-crm/filters/FilterCategory.tsxindex 64d6e54f..e958fc24 100644--- a/src/components/atomic-crm/filters/FilterCategory.tsx+++ b/src/components/atomic-crm/filters/FilterCategory.tsx@@ -15,6 +15,8 @@ export const FilterCategory = ({{icon}<Translate i18nKey={label} /></h3>- <div className="flex flex-col items-start pl-4">{children}</div>+ <div className="flex md:flex-col flex-wrap items-start pl-4">+ {children}+ </div></div>);diff --git a/src/components/atomic-crm/misc/ResponsiveFilters.tsx b/src/components/atomic-crm/misc/ResponsiveFilters.tsxnew file mode 100644index 00000000..957b4a90--- /dev/null+++ b/src/components/atomic-crm/misc/ResponsiveFilters.tsx@@ -0,0 +1,90 @@+import { useState } from "react";+import { FilterLiveForm } from "ra-core";+import { SearchInput, type SearchInputProps } from "@/components/admin";+import {+ Drawer,+ DrawerClose,+ DrawerContent,+ DrawerFooter,+ DrawerHeader,+ DrawerTitle,+ DrawerTrigger,+} from "@/components/ui/drawer";+import { useIsMobile } from "@/hooks/use-mobile";+import { Button } from "@/components/ui/button";++export const ResponsiveFilters = ({+ children,+ searchInput,+}: {+ children: React.ReactNode;+ searchInput?: Partial<SearchInputProps>;+}) => {+ const [open, setOpen] = useState(false);+ const {+ source = "q",+ className,+ ...otherSearchInputProps+ } = searchInput || {};+ const isMobile = useIsMobile();++ if (isMobile) {+ return (+ <Drawer open={open} onClose={() => setOpen(false)}>+ <DrawerTrigger asChild>+ <FilterLiveForm>+ <div className="mb-2">+ <SearchInput+ source={source}+ onClick={(event) => {+ event.preventDefault();+ setOpen(true);+ }}+ onKeyDown={(event) => {+ event.preventDefault();+ }}+ className={className}+ {...otherSearchInputProps}+ />+ </div>+ </FilterLiveForm>+ </DrawerTrigger>+ <DrawerContent className="data-[vaul-drawer-direction='bottom']:mt-0! data-[vaul-drawer-direction='bottom']:max-h-none! p-2 flex flex-col gap-4">+ <DrawerHeader className="sr-only">+ <DrawerTitle>Filters</DrawerTitle>+ </DrawerHeader>+ <FilterLiveForm>+ <div className="mb-2">+ <SearchInput+ type="search"+ source={source}+ className={className}+ {...otherSearchInputProps}+ />+ </div>+ </FilterLiveForm>+ {children}+ <DrawerFooter>+ <DrawerClose asChild>+ <Button>Apply</Button>+ </DrawerClose>+ </DrawerFooter>+ </DrawerContent>+ </Drawer>+ );+ }++ return (+ <div className="w-52 min-w-52 order-first pt-0.75 flex flex-col gap-4">+ <FilterLiveForm>+ <SearchInput+ source={source}+ onKeyDown={() => setOpen(false)}+ {...otherSearchInputProps}+ />+ </FilterLiveForm>++ {children}+ </div>+ );+};