Skip to content

Commit

Permalink
Merge pull request marmelab#10140 from marmelab/atomic-crm-backport
Browse files Browse the repository at this point in the history
Feat(demo): Backport Atomic CRM to RA repo
  • Loading branch information
fzaninotto authored Aug 21, 2024
2 parents 19c951e + 2bb14b9 commit bec289b
Show file tree
Hide file tree
Showing 88 changed files with 2,214 additions and 863 deletions.
14 changes: 14 additions & 0 deletions examples/crm/public/logos/logo_atomic_crm.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 26 additions & 22 deletions examples/crm/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { CRM } from './root/CRM';
import {
defaultCompanySectors,
defaultContactGender,
defaultDealCategories,
defaultDealStages,
defaultLogo,
defaultNoteStatuses,
defaultTaskTypes,
defaultTitle,
} from './root/defaultConfiguration';

const App = () => (
<CRM
contactGender={defaultContactGender}
companySectors={defaultCompanySectors}
dealCategories={defaultDealCategories}
dealStages={defaultDealStages}
logo={defaultLogo}
noteStatuses={defaultNoteStatuses}
taskTypes={defaultTaskTypes}
title={defaultTitle}
/>
);
/**
* Application entry point
*
* Customize Atomic CRM by passing props to the CRM component:
* - contactGender
* - companySectors
* - darkTheme
* - dealCategories
* - dealPipelineStatuses
* - dealStages
* - lightTheme
* - logo
* - noteStatuses
* - taskTypes
* - title
* ... as well as all the props accepted by react-admin's <Admin> component.
*
* @example
* const App = () => (
* <CRM
* logo="./img/logo.png"
* title="Acme CRM"
* />
* );
*/
const App = () => <CRM />;

export default App;
4 changes: 2 additions & 2 deletions examples/crm/src/activity/ActivityLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Alert, Divider, Skeleton, Stack } from '@mui/material';
import { useQuery } from '@tanstack/react-query';
import { Identifier, useDataProvider } from 'react-admin';

import { CustomDataProvider } from '../dataProvider';
import { CrmDataProvider } from '../providers/types';
import { ActivityLogContext } from './ActivityLogContext';
import { ActivityLogIterator } from './ActivityLogIterator';

Expand All @@ -17,7 +17,7 @@ export function ActivityLog({
pageSize = 20,
context = 'all',
}: ActivityLogProps) {
const dataProvider = useDataProvider<CustomDataProvider>();
const dataProvider = useDataProvider<CrmDataProvider>();
const { data, isPending, error } = useQuery({
queryKey: ['activityLog', companyId],
queryFn: () => dataProvider.getActivityLog(companyId),
Expand Down
4 changes: 2 additions & 2 deletions examples/crm/src/companies/CompanyAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const CompanyAside = ({ link = 'edit' }: CompanyAsideProps) => {
};

const CompanyInfo = ({ record }: { record: Company }) => {
if (!record.website && !record.linkedIn && !record.phone_number) {
if (!record.website && !record.linkedin_url && !record.phone_number) {
return null;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ const CompanyInfo = ({ record }: { record: Company }) => {
};

const ContextInfo = ({ record }: { record: Company }) => {
if (!record.revenue && !record.identifier) {
if (!record.revenue && !record.id) {
return null;
}

Expand Down
1 change: 1 addition & 0 deletions examples/crm/src/companies/CompanyAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const CompanyAvatar = (props: {
'& img': { objectFit: 'contain' },
width,
height,
fontSize: height !== 40 ? '0.6rem' : undefined,
}}
>
{record.name.charAt(0)}
Expand Down
12 changes: 9 additions & 3 deletions examples/crm/src/companies/CompanyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ export const CompanyCard = (props: { record?: Company }) => {
{record.nb_contacts}
</Typography>
<Typography variant="caption" color="textSecondary">
{record.nb_contacts > 1
? 'contacts'
{record.nb_contacts
? record.nb_contacts > 1
? 'contacts'
: 'contact'
: 'contact'}
</Typography>
</div>
Expand All @@ -79,7 +81,11 @@ export const CompanyCard = (props: { record?: Company }) => {
{record.nb_deals}
</Typography>
<Typography variant="caption" color="textSecondary">
{record.nb_deals > 1 ? 'deals' : 'deal'}
{record.nb_deals
? record.nb_deals > 1
? 'deals'
: 'deal'
: 'deal'}
</Typography>
</div>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion examples/crm/src/companies/CompanyInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const CompanyAccountManagerInput = () => {
source="sales_id"
reference="sales"
filter={{
disabled_neq: true,
'disabled@neq': true,
}}
>
<SelectInput
Expand Down
23 changes: 6 additions & 17 deletions examples/crm/src/companies/CompanyList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import {
TopToolbar,
ExportButton,
Expand All @@ -13,35 +12,25 @@ import {

import { ImageList } from './GridList';
import { CompanyListFilter } from './CompanyListFilter';
import { LinearProgress, Stack } from '@mui/material';
import { 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>
);
};

const CompanyListLayout = () => {
const { data, isPending, filterValues } = useListContext();
const { identity } = useGetIdentity();
const hasOtherFiltersThanDefaultBoolean = hasOtherFiltersThanDefault(
filterValues,
'sales_id',
identity?.id
);
if (isPending) return <LinearProgress />;
if (!data?.length && !hasOtherFiltersThanDefaultBoolean)
return <CompanyEmpty />;
const hasFilters = filterValues && Object.keys(filterValues).length > 0;

if (isPending) return null;
if (!data?.length && !hasFilters) return <CompanyEmpty />;

return (
<Stack direction="row" component="div">
Expand Down
2 changes: 1 addition & 1 deletion examples/crm/src/companies/CompanyListFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const CompanyListFilter = () => {
<FilterListItem
label="Me"
value={{
sales_id: identity && identity.id,
sales_id: identity?.id,
}}
/>
</FilterList>
Expand Down
4 changes: 2 additions & 2 deletions examples/crm/src/companies/CompanyShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const CompanyShowContent = () => {
path="contacts"
>
<ReferenceManyField
reference="contacts"
reference="contacts_summary"
target="company_id"
sort={{ field: 'last_name', order: 'ASC' }}
>
Expand Down Expand Up @@ -228,7 +228,7 @@ const DealsIterator = () => {
currencyDisplay: 'narrowSymbol',
minimumSignificantDigits: 3,
})}
, {deal.type}
{deal.category ? `, ${deal.category}` : ''}
</>
}
/>
Expand Down
4 changes: 2 additions & 2 deletions examples/crm/src/contacts/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const Avatar = (props: {
fontSize: props.height ? '0.6rem' : undefined,
}}
>
{record.first_name?.charAt(0)}
{record.last_name?.charAt(0)}
{record.first_name?.charAt(0).toUpperCase()}
{record.last_name?.charAt(0).toUpperCase()}
</MuiAvatar>
);
};
16 changes: 8 additions & 8 deletions examples/crm/src/contacts/ContactAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
/>
</Stack>
)}
{record.phone_number1?.number && (
{record.phone_1_number && (
<Stack direction="row" alignItems="center" gap={1}>
<PhoneIcon color="disabled" fontSize="small" />
<Box>
<TextField source="phone_number1.number" />{' '}
{record.phone_number1.type !== 'Other' && (
<TextField source="phone_1_number" />{' '}
{record.phone_1_type !== 'Other' && (
<TextField
source="phone_number1.type"
source="phone_1_type"
color="textSecondary"
/>
)}
</Box>
</Stack>
)}
{record.phone_number2?.number && (
{record.phone_2_number && (
<Stack
direction="row"
alignItems="center"
Expand All @@ -96,10 +96,10 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
>
<PhoneIcon color="disabled" fontSize="small" />
<Box>
<TextField source="phone_number2.number" />{' '}
{record.phone_number2.type !== 'Other' && (
<TextField source="phone_2_number" />{' '}
{record.phone_2_type !== 'Other' && (
<TextField
source="phone_number2.type"
source="phone_2_type"
color="textSecondary"
/>
)}
Expand Down
1 change: 1 addition & 0 deletions examples/crm/src/contacts/ContactImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export function ContactImportModal({ open, onClose }: ContactImportModalProps) {
label="Download CSV sample"
color="info"
to={SAMPLE_URL}
download={'crm_contacts_sample.csv'}
/>
}
>
Expand Down
10 changes: 5 additions & 5 deletions examples/crm/src/contacts/ContactInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ const ContactPersonalInformationInputs = () => {
<TextInput source="email" helperText={false} validate={email()} />
<Stack gap={1} flexDirection="row">
<TextInput
source="phone_number1.number"
source="phone_1_number"
label="Phone number 1"
helperText={false}
/>
<SelectInput
source="phone_number1.type"
source="phone_1_type"
label="Type"
helperText={false}
optionText={choice => choice.id}
Expand All @@ -140,12 +140,12 @@ const ContactPersonalInformationInputs = () => {
</Stack>
<Stack gap={1} flexDirection="row">
<TextInput
source="phone_number2.number"
source="phone_2_number"
label="Phone number 2"
helperText={false}
/>
<SelectInput
source="phone_number2.type"
source="phone_2_type"
label="Type"
helperText={false}
optionText={choice => choice.id}
Expand Down Expand Up @@ -179,7 +179,7 @@ const ContactMiscInputs = () => {
source="sales_id"
sort={{ field: 'last_name', order: 'ASC' }}
filter={{
disabled_neq: true,
'disabled@neq': true,
}}
>
<SelectInput
Expand Down
Loading

0 comments on commit bec289b

Please sign in to comment.