Skip to content

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

WIP(crm): Backport companies and deals

Anthony Rimetf3483c1827ea
diff --git a/src/companies/CompanyAside.tsx b/src/companies/CompanyAside.tsx
index e3943f0e..babb1052 100644
--- a/src/companies/CompanyAside.tsx
+++ b/src/companies/CompanyAside.tsx
@@ -5,8 +5,8 @@ import { Divider, Link, Stack, Tooltip, Typography } from '@mui/material';
import {
DateField,
EditButton,
- FunctionField,
ReferenceField,
+ SelectField,
ShowButton,
TextField,
UrlField,
@@ -14,6 +14,7 @@ import {
} from 'react-admin';
import { Company } from '../types';
+import { sizes } from './sizes';
interface CompanyAsideProps {
link?: string;
@@ -37,11 +38,9 @@ export const CompanyAside = ({ link = 'edit' }: CompanyAsideProps) => {
<AddressInfo record={record} />
- <FinancialInfo record={record} />
-
- <BackgroundInfo record={record} />
-
<ContextInfo record={record} />
+
+ <AdditionalInfo record={record} />
</Stack>
);
};
@@ -102,20 +101,46 @@ const CompanyInfo = ({ record }: { record: Company }) => {
);
};
-const FinancialInfo = ({ record }: { record: Company }) => {
+const ContextInfo = ({ record }: { record: Company }) => {
if (!record.revenue && !record.identifier) {
return null;
}
return (
<Stack>
- <Typography variant="subtitle2">Financial Info</Typography>
+ <Typography variant="subtitle2">Context</Typography>
<Divider sx={{ mb: 1 }} />
+ {record.sector && (
+ <Typography
+ component="span"
+ variant="body2"
+ color="textSecondary"
+ gutterBottom
+ >
+ Sector: <TextField source="sector" color="textPrimary" />
+ </Typography>
+ )}
+ {record.size && (
+ <Typography
+ component="span"
+ variant="body2"
+ color="textSecondary"
+ gutterBottom
+ >
+ Size:{' '}
+ <SelectField
+ source="size"
+ color="textPrimary"
+ choices={sizes}
+ />
+ </Typography>
+ )}
{record.revenue && (
<Typography
component="span"
variant="body2"
color="textSecondary"
+ gutterBottom
>
Revenue: <TextField source="revenue" color="textPrimary" />
</Typography>
@@ -125,6 +150,7 @@ const FinancialInfo = ({ record }: { record: Company }) => {
component="span"
variant="body2"
color="textSecondary"
+ gutterBottom
>
Tax Identifier:{' '}
<TextField source="tax_identifier" color="textPrimary" />
@@ -157,49 +183,62 @@ const AddressInfo = ({ record }: { record: Company }) => {
);
};
-const ContextInfo = ({ record }: { record: Company }) => {
- if (!record.context_links || record.context_links.length === 0) return null;
+const AdditionalInfo = ({ record }: { record: Company }) => {
+ if (
+ !record.created_at &&
+ !record.sales_id &&
+ !record.description &&
+ !record.context_links
+ ) {
+ return null;
+ }
const getBaseURL = (url: string) => {
const urlObject = new URL(url);
return urlObject.origin;
};
- return (
- <Stack>
- <Typography variant="subtitle2">Context</Typography>
- <Divider sx={{ mb: 1 }} />
- <Stack gap={1}>
- {record.context_links.map((link, index) =>
- link ? (
- <Tooltip title={link}>
- <Typography
- key={index}
- variant="body2"
- component={Link}
- href={link}
- target="_blank"
- rel="noopener noreferrer"
- >
- {getBaseURL(link)}
- </Typography>
- </Tooltip>
- ) : null
- )}
- </Stack>
- </Stack>
- );
-};
-
-const BackgroundInfo = ({ record }: { record: Company }) => {
- if (!record.created_at && !record.sales_id) {
- return null;
- }
return (
<Stack>
- <Typography variant="subtitle2">Background</Typography>
+ <Typography variant="subtitle2">Additional Info</Typography>
<Divider sx={{ mb: 1 }} />
- {record.created_at ? (
- <Typography variant="body2" color="textSecondary">
+ {record.description && (
+ <Typography variant="body2" color="textSecondary" gutterBottom>
+ {record.description}
+ </Typography>
+ )}
+ {record.context_links && (
+ <Stack>
+ {record.context_links.map((link, index) =>
+ link ? (
+ <Tooltip title={link}>
+ <Typography
+ key={index}
+ variant="body2"
+ gutterBottom
+ component={Link}
+ href={link}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ {getBaseURL(link)}
+ </Typography>
+ </Tooltip>
+ ) : null
+ )}
+ </Stack>
+ )}
+ {record.sales_id !== null && (
+ <Typography variant="body2" color="textSecondary" gutterBottom>
+ Followed by{' '}
+ <ReferenceField
+ source="sales_id"
+ reference="sales"
+ record={record}
+ />
+ </Typography>
+ )}
+ {record.created_at && (
+ <Typography variant="body2" color="textSecondary" gutterBottom>
Added on{' '}
<DateField
source="created_at"
@@ -212,30 +251,7 @@ const BackgroundInfo = ({ record }: { record: Company }) => {
}}
/>
</Typography>
- ) : null}
-
- {record.sales_id ? (
- <Typography
- component="span"
- variant="body2"
- color="textSecondary"
- >
- Followed by{' '}
- <ReferenceField
- source="sales_id"
- reference="sales"
- record={record}
- >
- <FunctionField
- source="last_name"
- color="textPrimary"
- render={record =>
- `${record.first_name} ${record.last_name}`
- }
- />
- </ReferenceField>
- </Typography>
- ) : null}
+ )}
</Stack>
);
};
diff --git a/src/companies/CompanyCard.tsx b/src/companies/CompanyCard.tsx
index 5bef385e..30dc68a9 100644
--- a/src/companies/CompanyCard.tsx
+++ b/src/companies/CompanyCard.tsx
@@ -8,6 +8,7 @@ import {
SelectField,
useRecordContext,
Link,
+ ReferenceManyCount,
} from 'react-admin';
import { CompanyAvatar } from './CompanyAvatar';
@@ -35,7 +36,6 @@ export const CompanyCard = (props: { record?: Company }) => {
<Paper
sx={{
height: 200,
- width: 195,
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
@@ -62,27 +62,19 @@ export const CompanyCard = (props: { record?: Company }) => {
<Box display="flex" justifyContent="space-around" width="100%">
<Box display="flex" alignItems="center">
<ContactsIcon color="disabled" sx={{ mr: 1 }} />
- <div>
- <Typography variant="subtitle2" sx={{ mb: -1 }}>
- {record.nb_contacts}
- </Typography>
- <Typography variant="caption" color="textSecondary">
- {record.nb_contacts > 1
- ? 'contacts'
- : 'contact'}
- </Typography>
- </div>
+ <ReferenceManyCount
+ label="Nb contacts"
+ reference="contacts"
+ target="company_id"
+ />
</Box>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<DealIcon color="disabled" sx={{ mr: 1 }} />
- <div>
- <Typography variant="subtitle2" sx={{ mb: -1 }}>
- {record.nb_deals}
- </Typography>
- <Typography variant="caption" color="textSecondary">
- {record.nb_deals > 1 ? 'deals' : 'deal'}
- </Typography>
- </div>
+ <ReferenceManyCount
+ label="Nb deals"
+ reference="deals"
+ target="company_id"
+ />
</Box>
</Box>
</Paper>
diff --git a/src/companies/CompanyEmpty.tsx b/src/companies/CompanyEmpty.tsx
index 8ff89d40..10024d2a 100644
--- a/src/companies/CompanyEmpty.tsx
+++ b/src/companies/CompanyEmpty.tsx
@@ -24,7 +24,7 @@ export const CompanyEmpty = () => {
color="text.secondary"
gutterBottom
>
- It looks like your company list is empty.
+ It seems your company list is empty.
</Typography>
</Stack>
<Stack spacing={2} direction="row">
diff --git a/src/companies/CompanyInputs.tsx b/src/companies/CompanyInputs.tsx
index 357661e4..6b9ce980 100644
--- a/src/companies/CompanyInputs.tsx
+++ b/src/companies/CompanyInputs.tsx
@@ -38,22 +38,17 @@ export const CompanyInputs = () => {
return (
<Stack gap={4} p={1}>
<CompanyDisplayInputs />
- <Stack gap={4} flexDirection={isMobile ? 'column' : 'row'}>
- <CompanyContactInputs />
- <Divider
- orientation={isMobile ? 'horizontal' : 'vertical'}
- flexItem
- />
- <CompanyContextInputs />
- </Stack>
-
- <Stack gap={4} flexDirection={isMobile ? 'column' : 'row'}>
- <CompanyAddressInputs />
+ <Stack gap={4} direction={isMobile ? 'column' : 'row'}>
+ <Stack gap={4} flex={1}>
+ <CompanyContactInputs />
+ <CompanyContextInputs />
+ </Stack>
<Divider
orientation={isMobile ? 'horizontal' : 'vertical'}
flexItem
/>
- <Stack gap={1} flex={1}>
+ <Stack gap={4} flex={1}>
+ <CompanyAddressInputs />
<CompanyAdditionalInformationInputs />
<CompanyAccountManagerInput />
</Stack>
@@ -74,22 +69,29 @@ const CompanyDisplayInputs = () => {
emptyText={record?.name.charAt(0)}
linkPosition="bottom"
/>
- <TextInput source="name" validate={required()} helperText={false} />
+ <TextInput
+ source="name"
+ validate={required()}
+ helperText={false}
+ sx={{
+ mt: 0,
+ }}
+ />
</Stack>
);
};
const CompanyContactInputs = () => {
return (
- <Stack gap={1} flex={1}>
+ <Stack>
<Typography variant="h6">Contact</Typography>
- <TextInput source="phone_number" helperText={false} />
<TextInput source="website" helperText={false} validate={isUrl} />
<TextInput
source="linkedin_url"
helperText={false}
validate={isLinkedinUrl}
/>
+ <TextInput source="phone_number" helperText={false} />
</Stack>
);
};
@@ -97,7 +99,7 @@ const CompanyContactInputs = () => {
const CompanyContextInputs = () => {
const { companySectors } = useConfigurationContext();
return (
- <Stack gap={1} flex={1}>
+ <Stack>
<Typography variant="h6">Context</Typography>
<SelectInput
source="sector"
@@ -116,7 +118,7 @@ const CompanyContextInputs = () => {
const CompanyAddressInputs = () => {
return (
- <Stack gap={1} flex={1}>
+ <Stack>
<Typography variant="h6">Address</Typography>
<TextInput source="address" helperText={false} />
<TextInput source="city" helperText={false} />
@@ -129,7 +131,7 @@ const CompanyAddressInputs = () => {
const CompanyAdditionalInformationInputs = () => {
return (
- <Stack gap={1} flex={1}>
+ <Stack>
<Typography variant="h6">Additional information</Typography>
<TextInput source="description" multiline helperText={false} />
<ArrayInput source="context_links" helperText={false}>
@@ -155,9 +157,15 @@ const CompanyAdditionalInformationInputs = () => {
const CompanyAccountManagerInput = () => {
return (
- <Stack gap={1} flex={1}>
+ <Stack>
<Typography variant="h6">Account manager</Typography>
- <ReferenceInput source="sales_id" reference="sales">
+ <ReferenceInput
+ source="sales_id"
+ reference="sales"
+ filter={{
+ 'disabled@neq': true,
+ }}
+ >
<SelectInput
label="Account manager"
helperText={false}
diff --git a/src/companies/CompanyShow.tsx b/src/companies/CompanyShow.tsx
index 579837a5..31d4c36c 100644
--- a/src/companies/CompanyShow.tsx
+++ b/src/companies/CompanyShow.tsx
@@ -4,32 +4,26 @@ import {
Button,
Card,
CardContent,
- Divider,
List,
ListItem,
ListItemAvatar,
ListItemSecondaryAction,
ListItemText,
Stack,
- Tab,
- Tabs,
Typography,
} from '@mui/material';
import { formatDistance } from 'date-fns';
-import * as React from 'react';
-import { ChangeEvent, useState } from 'react';
import {
RecordContextProvider,
ReferenceManyField,
- SelectField,
ShowBase,
SortButton,
- TextField,
+ TabbedShowLayout,
useListContext,
useRecordContext,
useShowContext,
} from 'react-admin';
-import { Link as RouterLink } from 'react-router-dom';
+import { Link as RouterLink, useLocation } from 'react-router-dom';
import { ActivityLog } from '../activity/ActivityLog';
import { Avatar } from '../contacts/Avatar';
@@ -40,7 +34,6 @@ import { useConfigurationContext } from '../root/ConfigurationContext';
import { Company, Contact, Deal } from '../types';
import { CompanyAside } from './CompanyAside';
import { CompanyAvatar } from './CompanyAvatar';
-import { sizes } from './sizes';
export const CompanyShow = () => (
<ShowBase>
@@ -50,13 +43,8 @@ export const CompanyShow = () => (
const CompanyShowContent = () => {
const { record, isPending } = useShowContext<Company>();
- const [tabValue, setTabValue] = useState(0);
- const handleTabChange = (_: ChangeEvent<{}>, newValue: number) => {
- setTabValue(newValue);
- };
- if (isPending || !record) return null;
- let tabIndex = 0;
+ if (isPending || !record) return null;
return (
<Box mt={2} display="flex">
@@ -65,62 +53,37 @@ const CompanyShowContent = () => {
<CardContent>
<Box display="flex" mb={1}>
<CompanyAvatar />
- <Box ml={2} flex="1">
- <Typography variant="h5">
- {record.name}
- </Typography>
- <Typography variant="body2">
- <TextField source="sector" />
- {record.size && ', '}
- <SelectField
- source="size"
- choices={sizes}
- />
- </Typography>
- </Box>
+ <Typography variant="h5" ml={2} flex="1">
+ {record.name}
+ </Typography>
</Box>
- <Tabs
- value={tabValue}
- indicatorColor="primary"
- textColor="primary"
- onChange={handleTabChange}
+
+ <TabbedShowLayout
+ sx={{
+ '& .RaTabbedShowLayout-content': { p: 0 },
+ }}
>
- <Tab
- label={
- !record.nb_contacts
- ? 'No Contacts'
- : record.nb_contacts === 1
- ? '1 Contact'
- : `${record.nb_contacts} Contacts`
- }
- />
- {record.nb_deals && (
- <Tab
- label={
- record.nb_deals === 1
- ? '1 deal'
- : `${record.nb_deals} Deals`
- }
+ <TabbedShowLayout.Tab label="Activity">
+ <ActivityLog
+ companyId={record.id}
+ context="company"
/>
- )}
- {record.description && <Tab label="Description" />}
- <Tab label="Activity Log" />
- </Tabs>
- <Divider />
-
- <TabPanel value={tabValue} index={tabIndex++}>
- <ReferenceManyField
- reference="contacts"
- target="company_id"
- sort={{ field: 'last_name', order: 'ASC' }}
+ </TabbedShowLayout.Tab>
+ <TabbedShowLayout.Tab
+ label="Contacts"
+ path="contacts"
>
- <Stack
- direction="row"
- justifyContent="flex-end"
- spacing={2}
- mt={1}
+ <ReferenceManyField
+ reference="contacts"
+ target="company_id"
+ sort={{ field: 'last_name', order: 'ASC' }}
>
- {!!record.nb_contacts && (
+ <Stack
+ direction="row"
+ justifyContent="flex-end"
+ spacing={2}
+ mt={1}
+ >
<SortButton
fields={[
'last_name',
@@ -128,37 +91,26 @@ const CompanyShowContent = () => {
'last_seen',
]}
/>
- )}
- <CreateRelatedContactButton />
- </Stack>
- <ContactsIterator />
- </ReferenceManyField>
- </TabPanel>
- {record.nb_deals ? (
- <TabPanel value={tabValue} index={tabIndex++}>
- <ReferenceManyField
- reference="deals"
- target="company_id"
- sort={{ field: 'name', order: 'ASC' }}
- >
- <DealsIterator />
+ <CreateRelatedContactButton />
+ </Stack>
+ <ContactsIterator />
</ReferenceManyField>
- </TabPanel>
- ) : null}
- {record.description ? (
- <TabPanel value={tabValue} index={tabIndex++}>
- <Stack
- pt={2}
- px={2}
- sx={{ whiteSpace: 'pre-line' }}
+ </TabbedShowLayout.Tab>
+ {record.nb_deals ? (
+ <TabbedShowLayout.Tab
+ label="Deals"
+ path="deals"
>
- <TextField source="description" />
- </Stack>
- </TabPanel>
- ) : null}
- <TabPanel value={tabValue} index={tabIndex++}>
- <ActivityLog companyId={record.id} />
- </TabPanel>
+ <ReferenceManyField
+ reference="deals"
+ target="company_id"
+ sort={{ field: 'name', order: 'ASC' }}
+ >
+ <DealsIterator />
+ </ReferenceManyField>
+ </TabbedShowLayout.Tab>
+ ) : null}
+ </TabbedShowLayout>
</CardContent>
</Card>
</Box>
@@ -167,30 +119,10 @@ const CompanyShowContent = () => {
);
};
-interface TabPanelProps {
- children?: React.ReactNode;
- index: any;
- value: any;
-}
-
-const TabPanel = (props: TabPanelProps) => {
- const { children, value, index, ...other } = props;
-
- return (
- <div
- role="tabpanel"
- hidden={value !== index}
- id={`wrapped-tabpanel-${index}`}
- aria-labelledby={`wrapped-tab-${index}`}
- {...other}
- >
- {children}
- </div>
- );
-};
-
const ContactsIterator = () => {
+ const location = useLocation();
const { data: contacts, error, isPending } = useListContext<Contact>();
+
if (isPending || error) return null;
const now = Date.now();
@@ -202,6 +134,7 @@ const ContactsIterator = () => {
button
component={RouterLink}
to={`/contacts/${contact.id}/show`}
+ state={{ from: location.pathname }}
>
<ListItemAvatar>
<Avatar />
diff --git a/src/companies/GridList.tsx b/src/companies/GridList.tsx
index bb57c544..5a098f19 100644
--- a/src/companies/GridList.tsx
+++ b/src/companies/GridList.tsx
@@ -31,7 +31,12 @@ const LoadedGridList = () => {
if (isPending || error) return null;
return (
- <Box display="flex" flexWrap="wrap" width="100%" gap={1}>
+ <Box
+ width="100%"
+ gap={1}
+ display="grid"
+ gridTemplateColumns="repeat(auto-fill, minmax(180px, 1fr))"
+ >
{data.map(record => (
<RecordContextProvider key={record.id} value={record}>
<CompanyCard />
diff --git a/src/deals/DealArchivedList.tsx b/src/deals/DealArchivedList.tsx
index 96bc6e2b..9dfc76dd 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: { 'archived_at@neq': null },
});
const [openDialog, setOpenDialog] = useState(false);
@@ -54,8 +54,12 @@ export const DealArchivedList = () => {
return (
<>
- <Button variant="text" onClick={() => setOpenDialog(true)}>
- View Archived List
+ <Button
+ variant="text"
+ onClick={() => setOpenDialog(true)}
+ sx={{ my: 1 }}
+ >
+ View archived deals
</Button>
<Dialog
open={openDialog}
@@ -99,7 +103,7 @@ export const DealArchivedList = () => {
);
};
-export function getRelativeTimeString(dateString: string, lang = 'en'): string {
+export function getRelativeTimeString(dateString: string): string {
const date = new Date(dateString);
date.setHours(0, 0, 0, 0);
@@ -111,13 +115,17 @@ export function getRelativeTimeString(dateString: string, lang = 'en'): string {
// Check if the date is more than one week old
if (Math.abs(unitDiff) > 7) {
- return new Intl.DateTimeFormat(lang, {
+ return new Intl.DateTimeFormat(undefined, {
day: 'numeric',
month: 'long',
}).format(date);
}
// Intl.RelativeTimeFormat for dates within the last week
- const rtf = new Intl.RelativeTimeFormat(lang, { numeric: 'auto' });
- return rtf.format(unitDiff, 'day');
+ const rtf = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
+ return ucFirst(rtf.format(unitDiff, 'day'));
+}
+
+function ucFirst(str: string): string {
+ return str.charAt(0).toUpperCase() + str.slice(1);
}
diff --git a/src/deals/DealCreate.tsx b/src/deals/DealCreate.tsx
index c337c528..b5133ebb 100644
--- a/src/deals/DealCreate.tsx
+++ b/src/deals/DealCreate.tsx
@@ -73,7 +73,7 @@ export const DealCreate = ({ open }: { open: boolean }) => {
const { identity } = useGetIdentity();
return (
- <Dialog open={open} onClose={handleClose} fullWidth maxWidth="lg">
+ <Dialog open={open} onClose={handleClose} fullWidth maxWidth="md">
<Create<Deal>
resource="deals"
mutationOptions={{ onSuccess }}
diff --git a/src/deals/DealEdit.tsx b/src/deals/DealEdit.tsx
index 39ad9cfb..10d7aa2d 100644
--- a/src/deals/DealEdit.tsx
+++ b/src/deals/DealEdit.tsx
@@ -6,6 +6,7 @@ import {
DeleteButton,
EditBase,
Form,
+ ReferenceField,
SaveButton,
Toolbar,
useNotify,
@@ -16,6 +17,7 @@ import { Link } from 'react-router-dom';
import { DialogCloseButton } from '../misc/DialogCloseButton';
import { Deal } from '../types';
import { DealInputs } from './DealInputs';
+import { CompanyAvatar } from '../companies/CompanyAvatar';
export const DealEdit = ({ open, id }: { open: boolean; id?: string }) => {
const redirect = useRedirect();
@@ -28,7 +30,7 @@ export const DealEdit = ({ open, id }: { open: boolean; id?: string }) => {
};
return (
- <Dialog open={open} onClose={handleClose} fullWidth maxWidth="lg">
+ <Dialog open={open} onClose={handleClose} fullWidth maxWidth="md">
{!!id ? (
<EditBase
id={id}
@@ -80,7 +82,16 @@ function EditHeader() {
justifyContent="space-between"
spacing={1}
>
- <Typography variant="h6">Edit {deal.name} deal</Typography>
+ <Stack direction="row" alignItems="center" gap={2}>
+ <ReferenceField
+ source="company_id"
+ reference="companies"
+ link="show"
+ >
+ <CompanyAvatar />
+ </ReferenceField>
+ <Typography variant="h6">Edit {deal.name} deal</Typography>
+ </Stack>
<Stack direction="row" spacing={1} sx={{ pr: 3 }}>
<Button component={Link} to={`/deals/${deal.id}/show`}>
diff --git a/src/deals/DealEmpty.tsx b/src/deals/DealEmpty.tsx
index 0b15e89a..04e6a3fe 100644
--- a/src/deals/DealEmpty.tsx
+++ b/src/deals/DealEmpty.tsx
@@ -43,7 +43,7 @@ export const DealEmpty = () => {
color="text.secondary"
gutterBottom
>
- It looks like your deal list is empty.
+ It seems your deal list is empty.
</Typography>
</Stack>
<Stack spacing={2} direction="row">
@@ -52,20 +52,24 @@ export const DealEmpty = () => {
<DealCreate open={!!matchCreate} />
</>
) : (
- <Typography
- variant="body2"
- align="center"
- color="text.secondary"
- gutterBottom
- >
- It looks like your contacts list is currently empty.
- <br />
- Please{' '}
- <Link to="/contacts/create">
- add your first contact
- </Link>{' '}
- before creating a deal.
- </Typography>
+ <Stack gap={0} alignItems="center">
+ <Typography variant="h6" fontWeight="bold">
+ No deals found
+ </Typography>
+ <Typography
+ variant="body2"
+ align="center"
+ color="text.secondary"
+ gutterBottom
+ >
+ It seems your contact list is empty.
+ <br />
+ <Link to="/contacts/create">
+ Add your first contact
+ </Link>{' '}
+ before creating a deal.
+ </Typography>
+ </Stack>
)}
</Stack>
);
diff --git a/src/deals/DealInputs.tsx b/src/deals/DealInputs.tsx
index 06401b47..29d05a38 100644
--- a/src/deals/DealInputs.tsx
+++ b/src/deals/DealInputs.tsx
@@ -1,4 +1,10 @@
-import { Divider, Stack } from '@mui/material';
+import {
+ Divider,
+ Stack,
+ Typography,
+ useMediaQuery,
+ useTheme,
+} from '@mui/material';
import {
AutocompleteArrayInput,
AutocompleteInput,
@@ -12,17 +18,51 @@ import {
useCreate,
useGetIdentity,
useNotify,
- useRecordContext,
} from 'react-admin';
-import { Avatar } from '../contacts/Avatar';
import { useConfigurationContext } from '../root/ConfigurationContext';
-import { Contact } from '../types';
+import { contactInputText, contactOptionText } from '../misc/ContactOption';
const validateRequired = required();
export const DealInputs = () => {
- const { dealStages, dealCategories } = useConfigurationContext();
+ const theme = useTheme();
+ const isMobile = useMediaQuery(theme.breakpoints.down('md'));
+ return (
+ <Stack gap={4} p={1}>
+ <DealInfoInputs />
+
+ <Stack gap={4} flexDirection={isMobile ? 'column' : 'row'}>
+ <DealLinkedToInputs />
+ <Divider
+ orientation={isMobile ? 'horizontal' : 'vertical'}
+ flexItem
+ />
+ <DealMiscInputs />
+ </Stack>
+ </Stack>
+ );
+};
+
+const DealInfoInputs = () => {
+ return (
+ <Stack gap={1} flex={1}>
+ <TextInput
+ source="name"
+ label="Deal name"
+ validate={validateRequired}
+ helperText={false}
+ />
+ <TextInput
+ source="description"
+ multiline
+ rows={3}
+ helperText={false}
+ />
+ </Stack>
+ );
+};
+const DealLinkedToInputs = () => {
const [create] = useCreate();
const notify = useNotify();
const { identity } = useGetIdentity();
@@ -49,20 +89,8 @@ export const DealInputs = () => {
}
};
return (
- <>
- <TextInput
- source="name"
- label="Deal name"
- validate={validateRequired}
- helperText={false}
- />
- <TextInput
- source="description"
- multiline
- rows={3}
- helperText={false}
- />
- <Divider sx={{ my: 2, width: '100%' }} />
+ <Stack gap={1} flex={1}>
+ <Typography variant="subtitle1">Linked to</Typography>
<ReferenceInput source="company_id" reference="companies">
<AutocompleteInput
optionText="name"
@@ -80,17 +108,16 @@ export const DealInputs = () => {
helperText={false}
/>
</ReferenceArrayInput>
- <Divider sx={{ my: 2, width: '100%' }} />
- <SelectInput
- source="stage"
- choices={dealStages.map(stage => ({
- id: stage.value,
- name: stage.label,
- }))}
- validate={validateRequired}
- defaultValue="opportunity"
- helperText={false}
- />
+ </Stack>
+ );
+};
+
+const DealMiscInputs = () => {
+ const { dealStages, dealCategories } = useConfigurationContext();
+ return (
+ <Stack gap={1} flex={1}>
+ <Typography variant="subtitle1">Misc</Typography>
+
<SelectInput
source="category"
label="Category"
@@ -106,27 +133,22 @@ export const DealInputs = () => {
validate={validateRequired}
helperText={false}
/>
- <Divider sx={{ my: 2, width: '100%' }} />
<DateInput
source="expected_closing_date"
fullWidth
validate={[validateRequired]}
helperText={false}
/>
- </>
- );
-};
-
-const ContactOptionRender = () => {
- const record: Contact | undefined = useRecordContext();
- if (!record) return null;
- return (
- <Stack direction="row" gap={1} alignItems="center">
- <Avatar record={record} />
- {record.first_name} {record.last_name}
+ <SelectInput
+ source="stage"
+ choices={dealStages.map(stage => ({
+ id: stage.value,
+ name: stage.label,
+ }))}
+ validate={validateRequired}
+ defaultValue="opportunity"
+ helperText={false}
+ />
</Stack>
);
};
-const contactOptionText = <ContactOptionRender />;
-const contactInputText = (choice: { first_name: string; last_name: string }) =>
- `${choice.first_name} ${choice.last_name}`;
diff --git a/src/deals/DealList.tsx b/src/deals/DealList.tsx
index bb935ca5..2926793d 100644
--- a/src/deals/DealList.tsx
+++ b/src/deals/DealList.tsx
@@ -36,7 +36,7 @@ const DealList = () => {
sales_id: identity?.id,
}}
filter={{
- 'archived_at@': 'is.null',
+ archived_at_eq: null,
}}
sort={{ field: 'index', order: 'DESC' }}
>
diff --git a/src/deals/DealShow.tsx b/src/deals/DealShow.tsx
index f5de4448..125483e9 100644
--- a/src/deals/DealShow.tsx
+++ b/src/deals/DealShow.tsx
@@ -1,6 +1,7 @@
import {
Box,
Button,
+ Chip,
Dialog,
DialogContent,
Divider,
@@ -16,7 +17,6 @@ import {
ReferenceField,
ReferenceManyField,
ShowBase,
- TextField,
useDataProvider,
useNotify,
useRecordContext,
@@ -42,7 +42,7 @@ export const DealShow = ({ open, id }: { open: boolean; id?: string }) => {
};
return (
- <Dialog open={open} onClose={handleClose} fullWidth maxWidth="lg">
+ <Dialog open={open} onClose={handleClose} fullWidth maxWidth="md">
<DialogContent sx={{ padding: 0 }}>
{!!id ? (
<ShowBase id={id}>
@@ -54,7 +54,7 @@ export const DealShow = ({ open, id }: { open: boolean; id?: string }) => {
);
};
-const CLOSE_TOP_WITH_ARCHIVED = 64 + 22 + 8; // 22 is initial top, 8 is padding, 64 is the height of the archived title
+const CLOSE_TOP_WITH_ARCHIVED = 14;
const DealShowContent = ({ handleClose }: { handleClose: () => void }) => {
const { dealStages } = useConfigurationContext();
const record = useRecordContext<Deal>();
@@ -63,41 +63,32 @@ const DealShowContent = ({ handleClose }: { handleClose: () => void }) => {
<>
<DialogCloseButton
onClose={handleClose}
- top={record.archived_at ? CLOSE_TOP_WITH_ARCHIVED : 22}
+ top={record.archived_at ? CLOSE_TOP_WITH_ARCHIVED : 16}
right={20}
+ color={record.archived_at ? 'white' : undefined}
/>
<Stack gap={1}>
{record.archived_at ? <ArchivedTitle /> : null}
- <Box display="flex" p={3}>
- <Box
- width={100}
- display="flex"
- flexDirection="column"
- alignItems="center"
- >
- <ReferenceField
- source="company_id"
- reference="companies"
- link="show"
- >
- <CompanyAvatar />
- </ReferenceField>
- <ReferenceField
- source="company_id"
- reference="companies"
- link="show"
- >
- <TextField
- source="name"
- align="center"
- component="div"
- />
- </ReferenceField>
- </Box>
+ <Box display="flex" p={2}>
<Box ml={2} flex="1">
<Stack direction="row" justifyContent="space-between">
- <Typography variant="h5">{record.name}</Typography>
- <Stack gap={1} direction="row" pr={4}>
+ <Stack direction="row" alignItems="center" gap={2}>
+ <ReferenceField
+ source="company_id"
+ reference="companies"
+ link="show"
+ >
+ <CompanyAvatar />
+ </ReferenceField>
+ <Typography variant="h5">
+ {record.name}
+ </Typography>
+ </Stack>
+ <Stack
+ gap={1}
+ direction="row"
+ pr={record.archived_at ? 0 : 4}
+ >
{record.archived_at ? (
<>
<UnarchiveButton record={record} />
@@ -120,9 +111,26 @@ const DealShowContent = ({ handleClose }: { handleClose: () => void }) => {
>
Expected closing date
</Typography>
- <Typography variant="body2">
- {format(record.expected_closing_date, 'PP')}
- </Typography>
+ <Stack
+ direction="row"
+ alignItems="center"
+ gap={1}
+ >
+ <Typography variant="body2">
+ {format(
+ record.expected_closing_date,
+ 'PP'
+ )}
+ </Typography>
+ {new Date(record.expected_closing_date) <
+ new Date() ? (
+ <Chip
+ label="Past"
+ color="error"
+ size="small"
+ />
+ ) : null}
+ </Stack>
</Box>
<Box display="flex" mr={5} flexDirection="column">
@@ -277,7 +285,7 @@ const ArchiveButton = ({ record }: { record: Deal }) => {
};
return (
- <Button onClick={handleClick} startIcon={<ArchiveIcon />}>
+ <Button onClick={handleClick} startIcon={<ArchiveIcon />} size="small">
Archive
</Button>
);
@@ -309,7 +317,11 @@ const UnarchiveButton = ({ record }: { record: Deal }) => {
};
return (
- <Button onClick={handleClick} startIcon={<UnarchiveIcon />}>
+ <Button
+ onClick={handleClick}
+ startIcon={<UnarchiveIcon />}
+ size="small"
+ >
Send back to the board
</Button>
);
diff --git a/src/root/defaultConfiguration.ts b/src/root/defaultConfiguration.ts
index 5c024fbe..9e6bcbe9 100644
--- a/src/root/defaultConfiguration.ts
+++ b/src/root/defaultConfiguration.ts
@@ -1,3 +1,7 @@
+import Man2Icon from '@mui/icons-material/Man2';
+import WcIcon from '@mui/icons-material/Wc';
+import Woman2Icon from '@mui/icons-material/Woman2';
+
export const defaultLogo =
'https://upload.wikimedia.org/wikipedia/commons/a/a7/React-icon.svg';
@@ -56,7 +60,7 @@ export const defaultTaskTypes = [
];
export const defaultContactGender = [
- { value: 'male', label: 'He/Him' },
- { value: 'female', label: 'She/Her' },
- { value: 'nonbinary', label: 'They/Them' },
+ { value: 'male', label: 'He/Him', icon: Man2Icon },
+ { value: 'female', label: 'She/Her', icon: Woman2Icon },
+ { value: 'nonbinary', label: 'They/Them', icon: WcIcon },
];
diff --git a/src/sales/index.ts b/src/sales/index.ts
index 0ea1f9e2..ab9bb353 100644
--- a/src/sales/index.ts
+++ b/src/sales/index.ts
@@ -1,4 +1,5 @@
/* eslint-disable import/no-anonymous-default-export */
+import { Sale } from '../types';
import { SalesCreate } from './SalesCreate';
import { SalesEdit } from './SalesEdit';
import { SalesList } from './SalesList';
@@ -7,4 +8,6 @@ export default {
list: SalesList,
create: SalesCreate,
edit: SalesEdit,
+ recordRepresentation: (record: Sale) =>
+ `${record.first_name} ${record.last_name}`,
};
diff --git a/src/types.ts b/src/types.ts
index 83f41bad..99ca56d0 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -48,8 +48,6 @@ export interface Company extends RaRecord {
zipcode: string;
city: string;
stateAbbr: string;
- nb_contacts: number;
- nb_deals: number;
sales_id: Identifier;
created_at: string;
description: string;