A full-featured CRM built with React, shadcn/ui, and Supabase.
Improve loading and error UI in mobile contact list
fzaninottoec7bce93fe1d
diff --git a/registry.json b/registry.jsonindex 6126704f..c835f053 100644--- a/registry.json+++ b/registry.json@@ -327,10 +327,18 @@"path": "src/components/atomic-crm/notes/StatusSelector.tsx","type": "registry:component"},+ {+ "path": "src/components/atomic-crm/notes/NotesIteratorMobile.tsx",+ "type": "registry:component"+ },{"path": "src/components/atomic-crm/notes/NotesIterator.tsx","type": "registry:component"},+ {+ "path": "src/components/atomic-crm/notes/NoteShowPage.tsx",+ "type": "registry:component"+ },{"path": "src/components/atomic-crm/notes/NoteInputs.tsx","type": "registry:component"diff --git a/src/components/atomic-crm/contacts/ContactList.tsx b/src/components/atomic-crm/contacts/ContactList.tsxindex 58224f94..4e9ad869 100644--- a/src/components/atomic-crm/contacts/ContactList.tsx+++ b/src/components/atomic-crm/contacts/ContactList.tsx@@ -16,23 +16,20 @@ import { Card } from "@/components/ui/card";import type { Company, Contact, Sale, Tag } from "../types";import { ContactEmpty } from "./ContactEmpty";import { ContactImportButton } from "./ContactImportButton";-import { ContactListContent } from "./ContactListContent";+import {+ ContactListContent,+ ContactListContentMobile,+} from "./ContactListContent";import {ContactListFilterSummary,ContactListFilter,} from "./ContactListFilter";import { TopToolbar } from "../layout/TopToolbar";-import { useIsMobile } from "@/hooks/use-mobile";import { InfinitePagination } from "../misc/InfinitePagination";import MobileHeader from "../layout/MobileHeader";import { MobileContent } from "../layout/MobileContent";export const ContactList = () => {- const isMobile = useIsMobile();- return isMobile ? <ContactListMobile /> : <ContactListDesktop />;-};--const ContactListDesktop = () => {const { identity } = useGetIdentity();if (!identity) return null;@@ -50,22 +47,6 @@ const ContactListDesktop = () => {);};-const ContactListMobile = () => {- const { identity } = useGetIdentity();-- if (!identity) return null;-- return (- <InfiniteListBase- perPage={25}- sort={{ field: "last_seen", order: "DESC" }}- exporter={exporter}- >- <ContactListLayoutMobile />- </InfiniteListBase>- );-};-const ContactListLayoutDesktop = () => {const { data, isPending, filterValues } = useListContext();@@ -88,14 +69,27 @@ const ContactListLayoutDesktop = () => {);};+export const ContactListMobile = () => {+ const { identity } = useGetIdentity();+ if (!identity) return null;++ return (+ <InfiniteListBase+ perPage={25}+ sort={{ field: "last_seen", order: "DESC" }}+ exporter={exporter}+ >+ <ContactListLayoutMobile />+ </InfiniteListBase>+ );+};+const ContactListLayoutMobile = () => {- const { data, isPending, filterValues } = useListContext();+ const { isPending, data, filterValues } = useListContext();const hasFilters = filterValues && Object.keys(filterValues).length > 0;- if (isPending) return null;-- if (!data?.length && !hasFilters) return <ContactEmpty />;+ if (!isPending && !data?.length && !hasFilters) return <ContactEmpty />;return (<div>@@ -104,7 +98,7 @@ const ContactListLayoutMobile = () => {</MobileHeader><MobileContent><ContactListFilterSummary />- <ContactListContent />+ <ContactListContentMobile /><div className="flex justify-center"><InfinitePagination /></div>diff --git a/src/components/atomic-crm/contacts/ContactListContent.tsx b/src/components/atomic-crm/contacts/ContactListContent.tsxindex 09b33267..599fa79c 100644--- a/src/components/atomic-crm/contacts/ContactListContent.tsx+++ b/src/components/atomic-crm/contacts/ContactListContent.tsx@@ -3,7 +3,9 @@ import { difference, union } from "lodash";import {type Identifier,RecordContextProvider,+ RecordRepresentation,useListContext,+ useTimeout,} from "ra-core";import { type MouseEvent, useCallback, useRef } from "react";import { Link } from "react-router";@@ -11,7 +13,8 @@ import { ReferenceField } from "@/components/admin/reference-field";import { TextField } from "@/components/admin/text-field";import { Checkbox } from "@/components/ui/checkbox";import { Skeleton } from "@/components/ui/skeleton";-import { useIsMobile } from "@/hooks/use-mobile";+import { Button } from "@/components/ui/button";+import { RotateCcw } from "lucide-react";import { Status } from "../misc/Status";import type { Contact } from "../types";@@ -27,7 +30,6 @@ export const ContactListContent = () => {onSelect,selectedIds,} = useListContext<Contact>();- const isSmall = useIsMobile();const lastSelected = useRef<Identifier | null>(null);// Handle shift+click to select a range of rows@@ -74,14 +76,10 @@ export const ContactListContent = () => {<div className="md:divide-y">{contacts.map((contact) => (<RecordContextProvider key={contact.id} value={contact}>- {isSmall ? (- <ContactItemContentMobile contact={contact} />- ) : (- <ContactItemContentDesktop- contact={contact}- handleToggleItem={handleToggleItem}- />- )}+ <ContactItemContent+ contact={contact}+ handleToggleItem={handleToggleItem}+ /></RecordContextProvider>))}@@ -94,7 +92,7 @@ export const ContactListContent = () => {);};-const ContactItemContentDesktop = ({+const ContactItemContent = ({contact,handleToggleItem,}: {@@ -162,45 +160,112 @@ const ContactItemContentDesktop = ({);};-const ContactItemContentMobile = ({ contact }: { contact: Contact }) => {- return (- <Link- to={`/contacts/${contact.id}/show`}- className="flex flex-row gap-4 items-center py-2 hover:bg-muted transition-colors"- >- <Avatar />- <div className="flex flex-col grow justify-between">- <div className="flex-1 min-w-0">- <div className="flex justify-between">- <div className="font-medium">- {`${contact.first_name} ${contact.last_name ?? ""}`}+export const ContactListContentMobile = () => {+ const {+ data: contacts,+ error,+ isPending,+ refetch,+ } = useListContext<Contact>();+ const oneSecondHasPassed = useTimeout(1000);++ if (isPending) {+ if (!oneSecondHasPassed) {+ return null;+ }+ return (+ <>+ {[...Array(5)].map((_, index) => (+ <div+ key={index}+ className="flex flex-row items-center py-2 hover:bg-muted transition-colors first:rounded-t-xl last:rounded-b-xl"+ >+ <div className="flex flex-row gap-4 items-center mr-4">+ <Skeleton className="w-10 h-10 rounded-full" /></div>- <Status status={contact.status} />- </div>- <div className="text-sm text-muted-foreground">- <div className="flex flex-col gap-1">- <span>- {contact.title}- {contact.title && contact.company_id != null && " at "}- {contact.company_id != null && (- <ReferenceField- source="company_id"- reference="companies"- link={false}- >- <TextField source="name" />- </ReferenceField>- )}- </span>- {contact.nb_tasks ? (- <span>- {contact.nb_tasks} task{contact.nb_tasks > 1 ? "s" : ""}- </span>- ) : null}+ <div className="flex-1 min-w-0">+ <Skeleton className="w-32 h-5 mb-2" />+ <Skeleton className="w-48 h-4" /></div></div>+ ))}+ </>+ );+ }++ if (error) {+ return (+ <div className="p-4">+ <div className="text-center text-muted-foreground mb-4">+ Error loading contacts+ </div>+ <div className="text-center mt-2">+ <Button+ onClick={() => {+ refetch();+ }}+ >+ <RotateCcw />+ Retry+ </Button></div></div>- </Link>+ );+ }++ return (+ <div className="md:divide-y">+ {contacts.map((contact) => (+ <RecordContextProvider key={contact.id} value={contact}>+ <ContactItemContentMobile contact={contact} />+ </RecordContextProvider>+ ))}+ {contacts.length === 0 && (+ <div className="p-4">+ <div className="text-muted-foreground">No contacts found</div>+ </div>+ )}+ </div>);};++const ContactItemContentMobile = ({ contact }: { contact: Contact }) => (+ <Link+ to={`/contacts/${contact.id}/show`}+ className="flex flex-row gap-4 items-center py-2 hover:bg-muted transition-colors"+ >+ <Avatar />+ <div className="flex flex-col grow justify-between">+ <div className="flex-1 min-w-0">+ <div className="flex justify-between">+ <div className="font-medium">+ <RecordRepresentation />+ </div>+ <Status status={contact.status} />+ </div>+ <div className="text-sm text-muted-foreground">+ <div className="flex flex-col gap-1">+ <span>+ {contact.title}+ {contact.title && contact.company_id != null && " at "}+ {contact.company_id != null && (+ <ReferenceField+ source="company_id"+ reference="companies"+ link={false}+ >+ <TextField source="name" />+ </ReferenceField>+ )}+ </span>+ {contact.nb_tasks ? (+ <span>+ {contact.nb_tasks} task{contact.nb_tasks > 1 ? "s" : ""}+ </span>+ ) : null}+ </div>+ </div>+ </div>+ </div>+ </Link>+);diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsxindex 5df8cee5..134ae0ac 100644--- a/src/components/atomic-crm/root/CRM.tsx+++ b/src/components/atomic-crm/root/CRM.tsx@@ -47,7 +47,7 @@ import { i18nProvider } from "./i18nProvider";import { StartPage } from "../login/StartPage.tsx";import { useIsMobile } from "@/hooks/use-mobile.ts";import { MobileTasksList } from "../tasks/MobileTasksList.tsx";-import { ContactList } from "../contacts/ContactList.tsx";+import { ContactListMobile } from "../contacts/ContactList.tsx";import { ContactShow } from "../contacts/ContactShow.tsx";import { CompanyShow } from "../companies/CompanyShow.tsx";@@ -211,7 +211,7 @@ const MobileAdmin = (props: CoreAdminProps) => {</CustomRoutes><Resourcename="contacts"- list={ContactList}+ list={ContactListMobile}show={ContactShow}recordRepresentation={contacts.recordRepresentation}/>