From 8e718230c264bd499f4a95fa1dd1e35f7b5bd526 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 12 Jan 2024 11:26:33 +0100 Subject: [PATCH] fix: create new deal with connected user as sales_id and prevent duplicate index to order them --- examples/crm/src/dataGenerator/deals.ts | 2 +- examples/crm/src/deals/DealCreate.tsx | 26 +++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/crm/src/dataGenerator/deals.ts b/examples/crm/src/dataGenerator/deals.ts index 233553e91e0..e27d9d77a18 100644 --- a/examples/crm/src/dataGenerator/deals.ts +++ b/examples/crm/src/dataGenerator/deals.ts @@ -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; diff --git a/examples/crm/src/deals/DealCreate.tsx b/examples/crm/src/deals/DealCreate.tsx index 00eda04e88d..4a2cf8367d2 100644 --- a/examples/crm/src/deals/DealCreate.tsx +++ b/examples/crm/src/deals/DealCreate.tsx @@ -10,6 +10,7 @@ import { required, useRedirect, useDataProvider, + useGetIdentity, } from 'react-admin'; import { Dialog } from '@mui/material'; @@ -38,19 +39,19 @@ 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 ( @@ -58,7 +59,12 @@ export const DealCreate = ({ open }: { open: boolean }) => { mutationOptions={{ onSuccess }} sx={{ width: 500, '& .RaCreate-main': { mt: 0 } }} > - +