Skip to content

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

Apply review

erwanMarmelab88dba61122ec
diff --git a/src/components/atomic-crm/deals/DealInputs.tsx b/src/components/atomic-crm/deals/DealInputs.tsx
index 128d9d4e..d64bafe2 100644
--- a/src/components/atomic-crm/deals/DealInputs.tsx
+++ b/src/components/atomic-crm/deals/DealInputs.tsx
@@ -107,6 +107,9 @@ const DealMiscInputs = () => {
);
};
+const requiredText = (value?: string | null) =>
+ value?.trim() ? undefined : "ra.validation.required";
+
const LostReasonInput = () => {
const stage = useWatch({ name: "stage" });
if (stage !== LOST_DEAL_STAGE) return null;
@@ -116,7 +119,7 @@ const LostReasonInput = () => {
multiline
rows={3}
helperText={false}
- validate={required()}
+ validate={requiredText}
/>
);
};
diff --git a/src/components/atomic-crm/deals/DealListContent.tsx b/src/components/atomic-crm/deals/DealListContent.tsx
index ed0a7d84..520f6e40 100644
--- a/src/components/atomic-crm/deals/DealListContent.tsx
+++ b/src/components/atomic-crm/deals/DealListContent.tsx
@@ -70,7 +70,12 @@ export const DealListContent = () => {
const sourceStage = source.droppableId;
const destinationStage = destination.droppableId;
- const sourceDeal = dealsByStage[sourceStage][source.index]!;
+ // resolve by id: the list may have refetched while the lost reason dialog was open
+ const sourceIndex = dealsByStage[sourceStage].findIndex(
+ (deal) => String(deal.id) === result.draggableId,
+ );
+ if (sourceIndex === -1) return;
+ const sourceDeal = dealsByStage[sourceStage][sourceIndex];
const destinationDeal = dealsByStage[destinationStage][
destination.index
] ?? {
@@ -82,7 +87,7 @@ export const DealListContent = () => {
setDealsByStage(
updateDealStageLocal(
sourceDeal,
- { stage: sourceStage, index: source.index },
+ { stage: sourceStage, index: sourceIndex },
{ stage: destinationStage, index: destination.index },
dealsByStage,
),