A full-featured CRM built with React, shadcn/ui, and Supabase.
Revert "feat: lost deal reason"
erwanMarmelab0a3aafaeb673
diff --git a/doc/src/content/docs/users/import-data.mdx b/doc/src/content/docs/users/import-data.mdxindex d5a21bb6..7ab68d41 100644--- a/doc/src/content/docs/users/import-data.mdx+++ b/doc/src/content/docs/users/import-data.mdx@@ -41,13 +41,12 @@ The `name` column is required. `sector` is matched against the company sectors c### Deals```csv-name,company,category,stage,amount,expected_closing_date,description,lost_reason-New website,Acme,Website design,Opportunity,12000,2026-09-30,Redesign of the public website,-Print campaign,Globex,Print project,Proposal Sent,4500,2026-10-15,,-Logo refresh,Initech,UI Design,Lost,3000,2026-08-31,,Chose a cheaper agency+name,company,category,stage,amount,expected_closing_date,description+New website,Acme,Website design,Opportunity,12000,2026-09-30,Redesign of the public website+Print campaign,Globex,Print project,Proposal Sent,4500,2026-10-15,```-The `name` column is required. The `company` column holds a company name: an existing company is reused, an unknown one is created. `category` and `stage` are matched against the deal categories and stages configured in your CRM, by stored value or displayed label. Since a deal always belongs to a stage, an empty or unrecognized `stage` falls back to the first stage of your pipeline. `lost_reason` records why a lost deal was lost. It is optional on import, so deals coming from another CRM without a reason are still imported, but the reason becomes mandatory as soon as the deal is edited in Atomic CRM.+The `name` column is required. The `company` column holds a company name: an existing company is reused, an unknown one is created. `category` and `stage` are matched against the deal categories and stages configured in your CRM, by stored value or displayed label. Since a deal always belongs to a stage, an empty or unrecognized `stage` falls back to the first stage of your pipeline.## Export Contacts To CSVdiff --git a/doc/src/content/docs/users/settings.mdx b/doc/src/content/docs/users/settings.mdxindex b0ecdddc..c95a0dfc 100644--- a/doc/src/content/docs/users/settings.mdx+++ b/doc/src/content/docs/users/settings.mdx@@ -26,6 +26,4 @@ The Settings page lets you customize:Once you save your changes, they will be immediately reflected across the application. For example, if you update the deal stages, the new stages will be available for users to drag and drop deals in the Kanban view, and they will also be available when creating or editing a deal.-When updating the name of an existing category (e.g., a deal stage), the new name will be applied to all existing records that belong to that category. For instance, if you rename the "Prospecting" deal stage to "Lead", all deals that were previously in the "Prospecting" stage will now be in the "Lead" stage.--The deal stage with the value `lost` has a special behavior: moving a deal to it, either by dragging the card in the Kanban view or by picking it in the deal form, requires a reason explaining why the deal was lost. You can rename its label freely, but if you delete this stage, deals can no longer be marked as lost with a reason.\ No newline at end of file+When updating the name of an existing category (e.g., a deal stage), the new name will be applied to all existing records that belong to that category. For instance, if you rename the "Prospecting" deal stage to "Lead", all deals that were previously in the "Prospecting" stage will now be in the "Lead" stage.\ No newline at end of filediff --git a/registry.json b/registry.jsonindex e54c7e98..2f20432b 100644--- a/registry.json+++ b/registry.json@@ -581,10 +581,6 @@"path": "src/components/atomic-crm/deals/OnlyMineInput.tsx","type": "registry:component"},- {- "path": "src/components/atomic-crm/deals/LostReasonDialog.tsx",- "type": "registry:component"- },{"path": "src/components/atomic-crm/deals/DealShow.tsx","type": "registry:component"diff --git a/src/components/atomic-crm/dataImport/DataImportButton.test.tsx b/src/components/atomic-crm/dataImport/DataImportButton.test.tsxindex f4c6d927..fd6c967c 100644--- a/src/components/atomic-crm/dataImport/DataImportButton.test.tsx+++ b/src/components/atomic-crm/dataImport/DataImportButton.test.tsx@@ -204,11 +204,6 @@ describe("DataImportButton", () => {expected_closing_date: "2026-09-30",},{ name: "Print campaign", company: "Acme", stage: null },- {- name: "Logo refresh",- stage: "Lost",- lost_reason: "Chose a cheaper agency",- },]);await screen.getByRole("button", { name: "run import" }).click();@@ -219,7 +214,7 @@ describe("DataImportButton", () => {expect(companies[0].name).toBe("Acme");const { data: deals } = await listAll(dataProvider, "deals");- expect(deals).toHaveLength(3);+ expect(deals).toHaveLength(2);expect(deals[0]).toMatchObject({amount: 12000,category: "website-design",@@ -232,10 +227,6 @@ describe("DataImportButton", () => {expect(deals[1].company_id).toBe(companies[0].id);// stage is required, so an empty cell falls back to the first stageexpect(deals[1].stage).toBe("opportunity");- expect(deals[2]).toMatchObject({- stage: "lost",- lost_reason: "Chose a cheaper agency",- });});it("appends imported deals below the deals already in their stage", async () => {diff --git a/src/components/atomic-crm/dataImport/deals_sample.csv b/src/components/atomic-crm/dataImport/deals_sample.csvindex 569cb33b..a62dd7d7 100644--- a/src/components/atomic-crm/dataImport/deals_sample.csv+++ b/src/components/atomic-crm/dataImport/deals_sample.csv@@ -1,4 +1,3 @@-name,company,category,stage,amount,expected_closing_date,description,lost_reason-New website,Acme,Website design,Opportunity,12000,2026-09-30,Redesign of the public website,-Print campaign,Globex,Print project,Proposal Sent,4500,2026-10-15,,-Logo refresh,Initech,UI Design,Lost,3000,2026-08-31,,Chose a cheaper agency+name,company,category,stage,amount,expected_closing_date,description+New website,Acme,Website design,Opportunity,12000,2026-09-30,Redesign of the public website+Print campaign,Globex,Print project,Proposal Sent,4500,2026-10-15,diff --git a/src/components/atomic-crm/dataImport/useDealImport.ts b/src/components/atomic-crm/dataImport/useDealImport.tsindex 196f8259..3bfe7a22 100644--- a/src/components/atomic-crm/dataImport/useDealImport.ts+++ b/src/components/atomic-crm/dataImport/useDealImport.ts@@ -58,7 +58,7 @@ export function useDealImport(): ProcessImportBatch {category: toConfiguredValue(row.category, dealCategories),stage,description: toText(row.description),- lost_reason: toText(row.lost_reason),+ // amount lands in a bigint column, which rejects "4500.50"amount: toInteger(row.amount),expected_closing_date: toIsoDate(row.expected_closing_date),sales_id: identity?.id,diff --git a/src/components/atomic-crm/deals/DealInputs.tsx b/src/components/atomic-crm/deals/DealInputs.tsxindex d64bafe2..82c148fb 100644--- a/src/components/atomic-crm/deals/DealInputs.tsx+++ b/src/components/atomic-crm/deals/DealInputs.tsx@@ -1,5 +1,4 @@import { required, useTranslate } from "ra-core";-import { useWatch } from "react-hook-form";import { AutocompleteArrayInput } from "@/components/admin/autocomplete-array-input";import { ReferenceArrayInput } from "@/components/admin/reference-array-input";import { ReferenceInput } from "@/components/admin/reference-input";@@ -13,7 +12,6 @@ import { useIsMobile } from "@/hooks/use-mobile";import { contactOptionText } from "../misc/ContactOption";import { useConfigurationContext } from "../root/ConfigurationContext";import { AutocompleteCompanyInput } from "../companies/AutocompleteCompanyInput.tsx";-import { LOST_DEAL_STAGE } from "./stages";export const DealInputs = () => {const isMobile = useIsMobile();@@ -102,24 +100,6 @@ const DealMiscInputs = () => {helperText={false}validate={required()}/>- <LostReasonInput /></div>);};--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;- return (- <TextInput- source="lost_reason"- multiline- rows={3}- helperText={false}- validate={requiredText}- />- );-};diff --git a/src/components/atomic-crm/deals/DealListContent.tsx b/src/components/atomic-crm/deals/DealListContent.tsxindex b54df4d5..bbbad24a 100644--- a/src/components/atomic-crm/deals/DealListContent.tsx+++ b/src/components/atomic-crm/deals/DealListContent.tsx@@ -1,8 +1,4 @@-import {- DragDropContext,- type DropResult,- type OnDragEndResponder,-} from "@hello-pangea/dnd";+import { DragDropContext, type OnDragEndResponder } from "@hello-pangea/dnd";import isEqual from "lodash/isEqual";import { useDataProvider, useListContext, type DataProvider } from "ra-core";import { useEffect, useState } from "react";@@ -10,9 +6,8 @@ import { useEffect, useState } from "react";import { useConfigurationContext } from "../root/ConfigurationContext";import type { Deal } from "../types";import { DealColumn } from "./DealColumn";-import { LostReasonDialog } from "./LostReasonDialog";import type { DealsByStage } from "./stages";-import { getDealsByStage, LOST_DEAL_STAGE } from "./stages";+import { getDealsByStage } from "./stages";export const DealListContent = () => {const { dealStages } = useConfigurationContext();@@ -22,10 +17,6 @@ export const DealListContent = () => {const [dealsByStage, setDealsByStage] = useState<DealsByStage>(getDealsByStage([], dealStages),);- // a drop into the lost column waits for a reason before being applied- const [pendingLostDrop, setPendingLostDrop] = useState<PendingDrop | null>(- null,- );useEffect(() => {if (unorderedDeals) {@@ -53,78 +44,34 @@ export const DealListContent = () => {return;}- const drop: PendingDrop = {- result,- destinationDealId:- dealsByStage[destination.droppableId][destination.index]?.id,- };-- if (- destination.droppableId === LOST_DEAL_STAGE &&- source.droppableId !== LOST_DEAL_STAGE- ) {- setPendingLostDrop(drop);- return;- }-- moveDeal(drop);- };-- const moveDeal = (- { result, destinationDealId }: PendingDrop,- lostReason?: string,- ) => {- const { destination, source } = result;- if (!destination) return;-const sourceStage = source.droppableId;const destinationStage = destination.droppableId;- // resolve positions by id: the list may have refetched while the lost- // reason dialog was open, so the indexes captured at drop time may be stale- const sourceIndex = dealsByStage[sourceStage].findIndex(- (deal) => String(deal.id) === result.draggableId,- );- if (sourceIndex === -1) return;- const sourceDeal = dealsByStage[sourceStage][sourceIndex];- const foundDestinationIndex = dealsByStage[destinationStage].findIndex(- (deal) => deal.id === destinationDealId,- );- // dropped after the last item, or the deal at the drop position is gone- const destinationIndex =- foundDestinationIndex === -1 ? undefined : foundDestinationIndex;- const destinationDeal =- destinationIndex === undefined- ? { stage: destinationStage, index: undefined }- : dealsByStage[destinationStage][destinationIndex];+ const sourceDeal = dealsByStage[sourceStage][source.index]!;+ const destinationDeal = dealsByStage[destinationStage][+ destination.index+ ] ?? {+ stage: destinationStage,+ index: undefined, // undefined if dropped after the last item+ };// compute local state change synchronouslysetDealsByStage(updateDealStageLocal(sourceDeal,- { stage: sourceStage, index: sourceIndex },- { stage: destinationStage, index: destinationIndex },+ { stage: sourceStage, index: source.index },+ { stage: destinationStage, index: destination.index },dealsByStage,),);// persist the changes- updateDealStage(sourceDeal, destinationDeal, dataProvider, lostReason).then(- () => {- refetch();- },- );+ updateDealStage(sourceDeal, destinationDeal, dataProvider).then(() => {+ refetch();+ });};return (<DragDropContext onDragEnd={onDragEnd}>- <LostReasonDialog- open={pendingLostDrop != null}- onConfirm={(reason) => {- if (pendingLostDrop) moveDeal(pendingLostDrop, reason);- setPendingLostDrop(null);- }}- onCancel={() => setPendingLostDrop(null)}- /><div className="flex gap-4">{dealStages.map((stage) => (<DealColumn@@ -138,11 +85,6 @@ export const DealListContent = () => {);};-type PendingDrop = {- result: DropResult;- destinationDealId?: Deal["id"];-};-const updateDealStageLocal = (sourceDeal: Deal,source: { stage: string; index: number },@@ -186,7 +128,6 @@ const updateDealStage = async (index?: number; // undefined if dropped after the last item},dataProvider: DataProvider,- lostReason?: string,) => {if (source.stage === destination.stage) {// moving deal inside the same column@@ -296,7 +237,6 @@ const updateDealStage = async (data: {index: destinationIndex,stage: destination.stage,- ...(lostReason ? { lost_reason: lostReason } : {}),},previousData: source,}),diff --git a/src/components/atomic-crm/deals/DealShow.tsx b/src/components/atomic-crm/deals/DealShow.tsxindex c9b7d6a1..8e422c38 100644--- a/src/components/atomic-crm/deals/DealShow.tsx+++ b/src/components/atomic-crm/deals/DealShow.tsx@@ -28,7 +28,6 @@ import { useConfigurationContext } from "../root/ConfigurationContext";import type { Deal } from "../types";import { ContactList } from "./ContactList";import { findDealLabel, formatISODateString } from "./dealUtils";-import { LOST_DEAL_STAGE } from "./stages";export const DealShow = ({ open, id }: { open: boolean; id?: string }) => {const redirect = useRedirect();@@ -158,15 +157,6 @@ const DealShowContent = () => {</div>)}- {record.stage === LOST_DEAL_STAGE && record.lost_reason && (- <div className="m-4 whitespace-pre-line">- <span className="text-xs text-muted-foreground tracking-wide">- {translate("resources.deals.fields.lost_reason")}- </span>- <p className="text-sm leading-6">{record.lost_reason}</p>- </div>- )}-{record.description && (<div className="m-4 whitespace-pre-line"><span className="text-xs text-muted-foreground tracking-wide">diff --git a/src/components/atomic-crm/deals/LostReasonDialog.test.tsx b/src/components/atomic-crm/deals/LostReasonDialog.test.tsxdeleted file mode 100644index 10e4d095..00000000--- a/src/components/atomic-crm/deals/LostReasonDialog.test.tsx+++ /dev/null@@ -1,55 +0,0 @@-import { I18nContextProvider } from "ra-core";-import { render } from "vitest-browser-react";-import { page, userEvent } from "vitest/browser";--import { i18nProvider } from "../providers/commons/i18nProvider";-import { LostReasonDialog } from "./LostReasonDialog";--// the dialog renders in a portal, so query the whole page-const renderDialog = async () => {- const onConfirm = vi.fn();- const onCancel = vi.fn();- await i18nProvider.changeLocale("en");- await render(- <I18nContextProvider value={i18nProvider}>- <LostReasonDialog open onConfirm={onConfirm} onCancel={onCancel} />- </I18nContextProvider>,- );- return { onConfirm, onCancel };-};--describe("LostReasonDialog", () => {- it("blocks marking the deal as lost until a reason is given", async () => {- const { onConfirm } = await renderDialog();- const confirm = page.getByRole("button", { name: "Mark as lost" });-- await expect.element(confirm).toBeDisabled();- await userEvent.type(- page.getByRole("textbox", { name: "Why was this deal lost?" }),- " ",- );- await expect.element(confirm).toBeDisabled();- expect(onConfirm).not.toHaveBeenCalled();- });-- it("submits the trimmed reason", async () => {- const { onConfirm } = await renderDialog();-- await userEvent.type(- page.getByRole("textbox", { name: "Why was this deal lost?" }),- " Budget cut ",- );- await page.getByRole("button", { name: "Mark as lost" }).click();-- expect(onConfirm).toHaveBeenCalledWith("Budget cut");- });-- it("cancels without a reason", async () => {- const { onConfirm, onCancel } = await renderDialog();-- await page.getByRole("button", { name: "Cancel" }).click();-- expect(onCancel).toHaveBeenCalled();- expect(onConfirm).not.toHaveBeenCalled();- });-});diff --git a/src/components/atomic-crm/deals/LostReasonDialog.tsx b/src/components/atomic-crm/deals/LostReasonDialog.tsxdeleted file mode 100644index 73926d29..00000000--- a/src/components/atomic-crm/deals/LostReasonDialog.tsx+++ /dev/null@@ -1,71 +0,0 @@-import { useTranslate } from "ra-core";-import { useState, type FormEvent } from "react";-import { Button } from "@/components/ui/button";-import {- Dialog,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,-} from "@/components/ui/dialog";-import { Textarea } from "@/components/ui/textarea";--export const LostReasonDialog = ({- open,- onConfirm,- onCancel,-}: {- open: boolean;- onConfirm: (reason: string) => void;- onCancel: () => void;-}) => {- const translate = useTranslate();- const [reason, setReason] = useState("");- const trimmedReason = reason.trim();-- const handleSubmit = (event: FormEvent) => {- event.preventDefault();- if (!trimmedReason) return;- onConfirm(trimmedReason);- setReason("");- };-- const handleCancel = () => {- setReason("");- onCancel();- };-- return (- <Dialog open={open} onOpenChange={(isOpen) => !isOpen && handleCancel()}>- <DialogContent>- <form onSubmit={handleSubmit} className="flex flex-col gap-4">- <DialogHeader>- <DialogTitle>- {translate("resources.deals.lost_reason_dialog.title")}- </DialogTitle>- <DialogDescription>- {translate("resources.deals.lost_reason_dialog.description")}- </DialogDescription>- </DialogHeader>- <Textarea- aria-label={translate("resources.deals.fields.lost_reason")}- value={reason}- onChange={(event) => setReason(event.target.value)}- rows={4}- required- autoFocus- />- <DialogFooter>- <Button type="button" variant="outline" onClick={handleCancel}>- {translate("ra.action.cancel")}- </Button>- <Button type="submit" disabled={!trimmedReason}>- {translate("resources.deals.lost_reason_dialog.confirm")}- </Button>- </DialogFooter>- </form>- </DialogContent>- </Dialog>- );-};diff --git a/src/components/atomic-crm/deals/stages.ts b/src/components/atomic-crm/deals/stages.tsindex 72bed71b..944353e6 100644--- a/src/components/atomic-crm/deals/stages.ts+++ b/src/components/atomic-crm/deals/stages.ts@@ -1,8 +1,6 @@import type { ConfigurationContextValue } from "../root/ConfigurationContext";import type { Deal } from "../types";-export const LOST_DEAL_STAGE = "lost";-export type DealsByStage = Record<Deal["stage"], Deal[]>;export const getDealsByStage = (diff --git a/src/components/atomic-crm/providers/commons/englishCrmMessages.ts b/src/components/atomic-crm/providers/commons/englishCrmMessages.tsindex e5cbcbb6..15a8eabe 100644--- a/src/components/atomic-crm/providers/commons/englishCrmMessages.ts+++ b/src/components/atomic-crm/providers/commons/englishCrmMessages.ts@@ -186,13 +186,6 @@ export const englishCrmMessages = {amount: "Budget",expected_closing_date: "Expected closing date",stage: "Stage",- lost_reason: "Why was this deal lost?",- },- lost_reason_dialog: {- title: "Why was this deal lost?",- description:- "Give a reason so managers can understand what went wrong.",- confirm: "Mark as lost",},action: {back_to_deal: "Back to deal",diff --git a/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts b/src/components/atomic-crm/providers/commons/frenchCrmMessages.tsindex fac003ca..20448cc8 100644--- a/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts+++ b/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts@@ -190,13 +190,6 @@ export const frenchCrmMessages = {amount: "Budget",expected_closing_date: "Date de clôture prévue",stage: "Étape",- lost_reason: "Pourquoi cette affaire a-t-elle été perdue ?",- },- lost_reason_dialog: {- title: "Pourquoi cette affaire a-t-elle été perdue ?",- description:- "Indiquez une raison pour que les managers comprennent ce qui n'a pas fonctionné.",- confirm: "Marquer comme perdue",},action: {back_to_deal: "Retour à l'affaire",diff --git a/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts b/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.tsindex 2a2dd722..440592c6 100644--- a/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts+++ b/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts@@ -27,15 +27,13 @@ export const generateDeals = (db: Db): Deal[] => {.toISOString().split("T")[0];- const stage = random.arrayElement(defaultDealStages).value;return {id,name: lowercaseName[0].toUpperCase() + lowercaseName.slice(1),company_id: company.id,contact_ids: contacts.map((contact) => contact.id),category: random.arrayElement(defaultDealCategories).value,- stage,- lost_reason: stage === "lost" ? lorem.sentence() : null,+ stage: random.arrayElement(defaultDealStages).value,description: lorem.paragraphs(datatype.number({ min: 1, max: 4 })),amount: datatype.number(1000) * 100,created_at,diff --git a/src/components/atomic-crm/types.ts b/src/components/atomic-crm/types.tsindex f026a087..8c8c70d5 100644--- a/src/components/atomic-crm/types.ts+++ b/src/components/atomic-crm/types.ts@@ -128,7 +128,6 @@ export type Deal = {expected_closing_date: string;sales_id: Identifier;index: number;- lost_reason?: string | null;} & Pick<RaRecord, "id">;export type DealNote = {diff --git a/supabase/functions/_shared/db.ts b/supabase/functions/_shared/db.tsindex 34667424..ce02afa1 100644--- a/supabase/functions/_shared/db.ts+++ b/supabase/functions/_shared/db.ts@@ -72,7 +72,6 @@ interface DealsTable {expected_closing_date: Date | null;sales_id: number | null;index: number | null;- lost_reason: string | null;}interface Database {diff --git a/supabase/migrations/20260924120000_deals_lost_reason.sql b/supabase/migrations/20260924120000_deals_lost_reason.sqldeleted file mode 100644index f8698505..00000000--- a/supabase/migrations/20260924120000_deals_lost_reason.sql+++ /dev/null@@ -1 +0,0 @@-alter table "public"."deals" add column "lost_reason" text;diff --git a/supabase/schemas/01_tables.sql b/supabase/schemas/01_tables.sqlindex 8237f607..bdb383c4 100644--- a/supabase/schemas/01_tables.sql+++ b/supabase/schemas/01_tables.sql@@ -76,8 +76,7 @@ create table public.deals (archived_at timestamp with time zone,expected_closing_date date,sales_id bigint,- index smallint,- lost_reason text+ index smallint);create table public.deal_notes (