A full-featured CRM built with React, shadcn/ui, and Supabase.
WIP(crm): Update deals
Anthony Rimet35abd1745ddb
diff --git a/src/companies/CompanyShow.tsx b/src/companies/CompanyShow.tsxindex 31d4c36c..2878a623 100644--- a/src/companies/CompanyShow.tsx+++ b/src/companies/CompanyShow.tsx@@ -15,6 +15,7 @@ import {import { formatDistance } from 'date-fns';import {RecordContextProvider,+ ReferenceManyCount,ReferenceManyField,ShowBase,SortButton,@@ -96,20 +97,15 @@ const CompanyShowContent = () => {<ContactsIterator /></ReferenceManyField></TabbedShowLayout.Tab>- {record.nb_deals ? (- <TabbedShowLayout.Tab- label="Deals"- path="deals"+ <TabbedShowLayout.Tab label="Deals" path="deals">+ <ReferenceManyField+ reference="deals"+ target="company_id"+ sort={{ field: 'name', order: 'ASC' }}>- <ReferenceManyField- reference="deals"- target="company_id"- sort={{ field: 'name', order: 'ASC' }}- >- <DealsIterator />- </ReferenceManyField>- </TabbedShowLayout.Tab>- ) : null}+ <DealsIterator />+ </ReferenceManyField>+ </TabbedShowLayout.Tab></TabbedShowLayout></CardContent></Card>@@ -144,12 +140,12 @@ const ContactsIterator = () => {secondary={<>{contact.title}- {contact.nb_tasks- ? ` - ${contact.nb_tasks} task${- contact.nb_tasks > 1 ? 's' : ''- }`- : ''}- + {' '}+ <ReferenceManyCount+ reference="tasks"+ target="contact_id"+ />{' '}+ tasks<TagsList /></>}diff --git a/src/contacts/ContactListContent.tsx b/src/contacts/ContactListContent.tsxindex edc8798d..33b249dc 100644--- a/src/contacts/ContactListContent.tsx+++ b/src/contacts/ContactListContent.tsx@@ -3,6 +3,7 @@ import * as React from 'react';import {RecordContextProvider,ReferenceField,+ ReferenceManyCount,SimpleListLoading,TextField,useListContext,@@ -83,14 +84,12 @@ export const ContactListContent = () => {><TextField source="name" /></ReferenceField>- {contact.nb_tasks- ? ` - ${contact.nb_tasks} task${- contact.nb_tasks > 1- ? 's'- : ''- }`- : ''}- + {' - '}+ <ReferenceManyCount+ reference="tasks"+ target="contact_id"+ />{' '}+ tasks<TagsList /></>}diff --git a/src/dashboard/HotContacts.tsx b/src/dashboard/HotContacts.tsxindex 5661bfb0..2a078e23 100644--- a/src/dashboard/HotContacts.tsx+++ b/src/dashboard/HotContacts.tsx@@ -1,7 +1,14 @@import * as React from 'react';import { Card, Box, Stack } from '@mui/material';import ContactsIcon from '@mui/icons-material/Contacts';-import { useGetList, Link, SimpleList, useGetIdentity } from 'react-admin';+import {+ useGetList,+ Link,+ SimpleList,+ useGetIdentity,+ ReferenceField,+ TextField,+} from 'react-admin';import { Avatar } from '../contacts/Avatar';import { Contact } from '../types';@@ -49,7 +56,14 @@ export const HotContacts = () => {}secondaryText={contact => (<>- {contact.title} at {contact.company_name}+ {contact.title} at{' '}+ <ReferenceField+ source="company_id"+ reference="companies"+ link={false}+ >+ <TextField source="name" />+ </ReferenceField></>)}leftAvatar={contact => <Avatar record={contact} />}diff --git a/src/deals/ContactList.tsx b/src/deals/ContactList.tsxindex c26e9834..b8eb0dbe 100644--- a/src/deals/ContactList.tsx+++ b/src/deals/ContactList.tsx@@ -1,5 +1,5 @@import * as React from 'react';-import { useListContext } from 'react-admin';+import { ReferenceField, TextField, useListContext } from 'react-admin';import { Link, Stack, Typography } from '@mui/material';import { Link as RouterLink } from 'react-router-dom';import { Avatar } from '../contacts/Avatar';@@ -21,7 +21,14 @@ export const ContactList = () => {{contact.first_name} {contact.last_name}</Link><Typography variant="caption" color="text.secondary">- {contact.title} at {contact.company_name}+ {contact.title} at{' '}+ <ReferenceField+ source="company_id"+ reference="companies"+ link={false}+ >+ <TextField source="name" variant="caption" />+ </ReferenceField></Typography></Stack></Stack>diff --git a/src/deals/DealArchivedList.tsx b/src/deals/DealArchivedList.tsxindex 9dfc76dd..c62f652d 100644--- a/src/deals/DealArchivedList.tsx+++ b/src/deals/DealArchivedList.tsx@@ -22,7 +22,7 @@ export const DealArchivedList = () => {} = useGetList('deals', {pagination: { page: 1, perPage: 1000 },sort: { field: 'archived_at', order: 'DESC' },- filter: { 'archived_at@neq': null },+ filter: { '[email protected]': null },});const [openDialog, setOpenDialog] = useState(false);diff --git a/src/deals/DealEmpty.tsx b/src/deals/DealEmpty.tsxindex 04e6a3fe..a3e63580 100644--- a/src/deals/DealEmpty.tsx+++ b/src/deals/DealEmpty.tsx@@ -6,7 +6,7 @@ import { DealCreate } from './DealCreate';import { Contact } from '../types';import { Link } from 'react-router-dom';-export const DealEmpty = () => {+export const DealEmpty = ({ children }: { children?: React.ReactNode }) => {const location = useLocation();const matchCreate = matchPath('/deals/create', location.pathname);const appbarHeight = useAppBarHeight();@@ -50,6 +50,7 @@ export const DealEmpty = () => {<CreateButton variant="contained" label="Create deal" /></Stack><DealCreate open={!!matchCreate} />+ {children}</>) : (<Stack gap={0} alignItems="center">diff --git a/src/deals/DealList.tsx b/src/deals/DealList.tsxindex 2926793d..43b29a42 100644--- a/src/deals/DealList.tsx+++ b/src/deals/DealList.tsx@@ -36,7 +36,7 @@ const DealList = () => {sales_id: identity?.id,}}filter={{- archived_at_eq: null,+ 'archived_at@is': null,}}sort={{ field: 'index', order: 'DESC' }}>@@ -74,7 +74,14 @@ const DealLayout = () => {if (isPending) return <LinearProgress />;if (!data?.length && !hasOtherFiltersThanDefaultBoolean)- return <DealEmpty />;+ return (+ <>+ <DealEmpty>+ <DealShow open={!!matchShow} id={matchShow?.params.id} />+ <DealArchivedList />+ </DealEmpty>+ </>+ );return (<Stack component="div" sx={{ width: '100%' }}>diff --git a/src/misc/ContactOption.tsx b/src/misc/ContactOption.tsxindex ea811b79..2054b54b 100644--- a/src/misc/ContactOption.tsx+++ b/src/misc/ContactOption.tsx@@ -1,5 +1,5 @@import { Stack, Typography } from '@mui/material';-import { useRecordContext } from 'react-admin';+import { ReferenceField, TextField, useRecordContext } from 'react-admin';import { Avatar } from '../contacts/Avatar';import { Contact } from '../types';@@ -12,7 +12,14 @@ const ContactOptionRender = () => {<Stack>{record.first_name} {record.last_name}<Typography variant="caption" color="text.secondary">- {record.title} at {record.company_name}+ {record.title} at{' '}+ <ReferenceField+ source="company_id"+ reference="companies"+ link={false}+ >+ <TextField source="name" variant="caption" />+ </ReferenceField></Typography></Stack></Stack>diff --git a/src/types.ts b/src/types.tsindex 99ca56d0..74759336 100644--- a/src/types.ts+++ b/src/types.ts@@ -62,7 +62,6 @@ export interface Contact extends RaRecord {last_name: string;title: string;company_id: Identifier;- company_name: string;email: string;avatar?: Partial<RAFile>;linkedin_url?: string;@@ -72,7 +71,6 @@ export interface Contact extends RaRecord {tags: Identifier[];gender: string;sales_id: Identifier;- nb_notes: number;status: string;background: string;phone_number1: { number: string; type: 'Work' | 'Home' | 'Other' };@@ -102,7 +100,6 @@ export interface Deal extends RaRecord {expected_closing_date: string;sales_id: Identifier;index: number;- nb_notes: number;}export interface DealNote extends RaRecord {diff --git a/supabase/migrations/20240730075029_init_db.sql b/supabase/migrations/20240730075029_init_db.sqlindex 152823c3..8b549b4c 100644--- a/supabase/migrations/20240730075029_init_db.sql+++ b/supabase/migrations/20240730075029_init_db.sql@@ -15,8 +15,6 @@ create table "public"."companies" ("context_links" json,"country" text,"description" text,- "nb_contacts" integer,- "nb_deals" integer,"revenue" text,"tax_identifier" text,"logo" jsonb@@ -57,8 +55,7 @@ create table "public"."contacts" ("tags" bigint[],"company_id" bigint,"sales_id" bigint,- "linkedin_url" text,- "nb_notes" integer+ "linkedin_url" text);@@ -89,9 +86,9 @@ create table "public"."deals" ("created_at" timestamp with time zone not null default now(),"updated_at" timestamp with time zone not null default now(),"archived_at" timestamp with time zone default null,+ "expected_closing_date" timestamp with time zone default null,"sales_id" bigint,- "index" smallint,- "nb_notes" integer+ "index" smallint);