Skip to content

Commit

Permalink
Merge pull request #9581 from marmelab/fix-creating-a-resource-does-n…
Browse files Browse the repository at this point in the history
…ot-work-in-atomic-crm

Fix new deals do not appear in the crm demo
  • Loading branch information
slax57 authored Jan 12, 2024
2 parents 513a480 + 8e71823 commit d589e64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/crm/src/dataGenerator/deals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const generateDeals = (db: Db): Deal[] => {
deals
.filter(deal => deal.stage === stage)
.forEach((deal, index) => {
deals[deal.id].index = index;
deals[deal.id].index = index + 1;
});
});
return deals;
Expand Down
26 changes: 16 additions & 10 deletions examples/crm/src/deals/DealCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
required,
useRedirect,
useDataProvider,
useGetIdentity,
} from 'react-admin';
import { Dialog } from '@mui/material';

Expand Down Expand Up @@ -38,27 +39,32 @@ export const DealCreate = ({ open }: { open: boolean }) => {
})
.then(({ data: deals }) =>
Promise.all(
deals
.filter(oldDeal => oldDeal.id !== deal.id)
.map(oldDeal =>
dataProvider.update('deals', {
id: oldDeal.id,
data: { index: oldDeal.index + 1 },
previousData: oldDeal,
})
)
deals.map(oldDeal =>
dataProvider.update('deals', {
id: oldDeal.id,
data: { index: oldDeal.index + 1 },
previousData: oldDeal,
})
)
)
);
};

const { identity } = useGetIdentity();

return (
<Dialog open={open} onClose={handleClose}>
<Create<Deal>
resource="deals"
mutationOptions={{ onSuccess }}
sx={{ width: 500, '& .RaCreate-main': { mt: 0 } }}
>
<SimpleForm defaultValues={{ index: 0 }}>
<SimpleForm
defaultValues={{
index: 0,
sales_id: identity && identity?.id,
}}
>
<TextInput
source="name"
label="Deal name"
Expand Down

0 comments on commit d589e64

Please sign in to comment.