@baack-software/baack-ts-crm 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +74 -2
- package/dist/account.d.ts +36 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +48 -0
- package/dist/account.js.map +1 -0
- package/dist/backend.d.ts +76 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +233 -0
- package/dist/backend.js.map +1 -0
- package/dist/crm-client.d.ts +122 -0
- package/dist/crm-client.d.ts.map +1 -0
- package/dist/crm-client.js +168 -0
- package/dist/crm-client.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices.d.ts +46 -0
- package/dist/invoices.d.ts.map +1 -0
- package/dist/invoices.js +137 -0
- package/dist/invoices.js.map +1 -0
- package/dist/leads.d.ts +29 -0
- package/dist/leads.d.ts.map +1 -0
- package/dist/leads.js +56 -0
- package/dist/leads.js.map +1 -0
- package/dist/mock/index.d.ts +43 -0
- package/dist/mock/index.d.ts.map +1 -0
- package/dist/mock/index.js +303 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/money.d.ts +29 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +82 -0
- package/dist/money.js.map +1 -0
- package/dist/period.d.ts +17 -0
- package/dist/period.d.ts.map +1 -0
- package/dist/period.js +23 -0
- package/dist/period.js.map +1 -0
- package/dist/pipeline.d.ts +30 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +40 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/react/Charts.d.ts +19 -0
- package/dist/react/Charts.d.ts.map +1 -0
- package/dist/react/Charts.js +38 -0
- package/dist/react/Charts.js.map +1 -0
- package/dist/react/CompanyAccountView.d.ts +21 -0
- package/dist/react/CompanyAccountView.d.ts.map +1 -0
- package/dist/react/CompanyAccountView.js +27 -0
- package/dist/react/CompanyAccountView.js.map +1 -0
- package/dist/react/DashboardCards.d.ts +32 -0
- package/dist/react/DashboardCards.d.ts.map +1 -0
- package/dist/react/DashboardCards.js +38 -0
- package/dist/react/DashboardCards.js.map +1 -0
- package/dist/react/DealsBoard.d.ts +30 -0
- package/dist/react/DealsBoard.d.ts.map +1 -0
- package/dist/react/DealsBoard.js +33 -0
- package/dist/react/DealsBoard.js.map +1 -0
- package/dist/react/Details.d.ts +52 -0
- package/dist/react/Details.d.ts.map +1 -0
- package/dist/react/Details.js +111 -0
- package/dist/react/Details.js.map +1 -0
- package/dist/react/Forms.d.ts +59 -0
- package/dist/react/Forms.d.ts.map +1 -0
- package/dist/react/Forms.js +204 -0
- package/dist/react/Forms.js.map +1 -0
- package/dist/react/LeadsTable.d.ts +22 -0
- package/dist/react/LeadsTable.d.ts.map +1 -0
- package/dist/react/LeadsTable.js +79 -0
- package/dist/react/LeadsTable.js.map +1 -0
- package/dist/react/Sales.d.ts +49 -0
- package/dist/react/Sales.d.ts.map +1 -0
- package/dist/react/Sales.js +186 -0
- package/dist/react/Sales.js.map +1 -0
- package/dist/react/SidePanel.d.ts +21 -0
- package/dist/react/SidePanel.d.ts.map +1 -0
- package/dist/react/SidePanel.js +37 -0
- package/dist/react/SidePanel.js.map +1 -0
- package/dist/react/format.d.ts +28 -0
- package/dist/react/format.d.ts.map +1 -0
- package/dist/react/format.js +30 -0
- package/dist/react/format.js.map +1 -0
- package/dist/react/index.d.ts +14 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +14 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/parts.d.ts +45 -0
- package/dist/react/parts.d.ts.map +1 -0
- package/dist/react/parts.js +59 -0
- package/dist/react/parts.js.map +1 -0
- package/dist/react/text.d.ts +145 -0
- package/dist/react/text.d.ts.map +1 -0
- package/dist/react/text.js +142 -0
- package/dist/react/text.js.map +1 -0
- package/dist/react/ui/alert.d.ts +11 -0
- package/dist/react/ui/alert.d.ts.map +1 -0
- package/dist/react/ui/alert.js +29 -0
- package/dist/react/ui/alert.js.map +1 -0
- package/dist/react/ui/badge.d.ts +10 -0
- package/dist/react/ui/badge.d.ts.map +1 -0
- package/dist/react/ui/badge.js +26 -0
- package/dist/react/ui/badge.js.map +1 -0
- package/dist/react/ui/button.d.ts +11 -0
- package/dist/react/ui/button.d.ts.map +1 -0
- package/dist/react/ui/button.js +37 -0
- package/dist/react/ui/button.js.map +1 -0
- package/dist/react/ui/card.d.ts +12 -0
- package/dist/react/ui/card.d.ts.map +1 -0
- package/dist/react/ui/card.js +26 -0
- package/dist/react/ui/card.js.map +1 -0
- package/dist/react/ui/chart.d.ts +45 -0
- package/dist/react/ui/chart.d.ts.map +1 -0
- package/dist/react/ui/chart.js +116 -0
- package/dist/react/ui/chart.js.map +1 -0
- package/dist/react/ui/input.d.ts +4 -0
- package/dist/react/ui/input.d.ts.map +1 -0
- package/dist/react/ui/input.js +8 -0
- package/dist/react/ui/input.js.map +1 -0
- package/dist/react/ui/label.d.ts +5 -0
- package/dist/react/ui/label.d.ts.map +1 -0
- package/dist/react/ui/label.js +10 -0
- package/dist/react/ui/label.js.map +1 -0
- package/dist/react/ui/progress.d.ts +5 -0
- package/dist/react/ui/progress.d.ts.map +1 -0
- package/dist/react/ui/progress.js +10 -0
- package/dist/react/ui/progress.js.map +1 -0
- package/dist/react/ui/select.d.ts +16 -0
- package/dist/react/ui/select.d.ts.map +1 -0
- package/dist/react/ui/select.js +37 -0
- package/dist/react/ui/select.js.map +1 -0
- package/dist/react/ui/separator.d.ts +5 -0
- package/dist/react/ui/separator.d.ts.map +1 -0
- package/dist/react/ui/separator.js +10 -0
- package/dist/react/ui/separator.js.map +1 -0
- package/dist/react/ui/sheet.d.ts +15 -0
- package/dist/react/ui/sheet.d.ts.map +1 -0
- package/dist/react/ui/sheet.js +38 -0
- package/dist/react/ui/sheet.js.map +1 -0
- package/dist/react/ui/skeleton.d.ts +3 -0
- package/dist/react/ui/skeleton.d.ts.map +1 -0
- package/dist/react/ui/skeleton.js +7 -0
- package/dist/react/ui/skeleton.js.map +1 -0
- package/dist/react/ui/table.d.ts +11 -0
- package/dist/react/ui/table.d.ts.map +1 -0
- package/dist/react/ui/table.js +29 -0
- package/dist/react/ui/table.js.map +1 -0
- package/dist/react/ui/tabs.d.ts +12 -0
- package/dist/react/ui/tabs.d.ts.map +1 -0
- package/dist/react/ui/tabs.js +31 -0
- package/dist/react/ui/tabs.js.map +1 -0
- package/dist/react/views.d.ts +60 -0
- package/dist/react/views.d.ts.map +1 -0
- package/dist/react/views.js +172 -0
- package/dist/react/views.js.map +1 -0
- package/dist/sales.d.ts +57 -0
- package/dist/sales.d.ts.map +1 -0
- package/dist/sales.js +64 -0
- package/dist/sales.js.map +1 -0
- package/dist/store.d.ts +140 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +244 -0
- package/dist/store.js.map +1 -0
- package/dist/target.d.ts +21 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +36 -0
- package/dist/target.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +100 -4
- package/src/account.ts +79 -0
- package/src/backend.ts +371 -0
- package/src/crm-client.ts +250 -0
- package/src/errors.ts +34 -0
- package/src/index.ts +12 -0
- package/src/invoices.ts +157 -0
- package/src/leads.ts +78 -0
- package/src/mock/index.ts +398 -0
- package/src/money.ts +104 -0
- package/src/period.ts +32 -0
- package/src/pipeline.ts +61 -0
- package/src/react/Charts.tsx +143 -0
- package/src/react/CompanyAccountView.tsx +198 -0
- package/src/react/DashboardCards.tsx +171 -0
- package/src/react/DealsBoard.tsx +177 -0
- package/src/react/Details.tsx +293 -0
- package/src/react/Forms.tsx +619 -0
- package/src/react/LeadsTable.tsx +234 -0
- package/src/react/Sales.tsx +539 -0
- package/src/react/SidePanel.tsx +95 -0
- package/src/react/format.ts +53 -0
- package/src/react/index.ts +13 -0
- package/src/react/parts.tsx +131 -0
- package/src/react/text.ts +144 -0
- package/src/react/ui/README.md +6 -0
- package/src/react/ui/alert.tsx +75 -0
- package/src/react/ui/badge.tsx +48 -0
- package/src/react/ui/button.tsx +66 -0
- package/src/react/ui/card.tsx +102 -0
- package/src/react/ui/chart.tsx +304 -0
- package/src/react/ui/input.tsx +18 -0
- package/src/react/ui/label.tsx +23 -0
- package/src/react/ui/progress.tsx +30 -0
- package/src/react/ui/select.tsx +189 -0
- package/src/react/ui/separator.tsx +27 -0
- package/src/react/ui/sheet.tsx +145 -0
- package/src/react/ui/skeleton.tsx +13 -0
- package/src/react/ui/table.tsx +113 -0
- package/src/react/ui/tabs.tsx +89 -0
- package/src/react/views.tsx +443 -0
- package/src/sales.ts +120 -0
- package/src/store.ts +419 -0
- package/src/target.ts +51 -0
- package/src/types.ts +202 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { useId, useState, type FormEvent, type ReactNode } from 'react';
|
|
2
|
+
import { SOURCE_LABELS, leadOutcome } from '../leads.ts';
|
|
3
|
+
import { dealOutcome, dealProbability, orderedStages, stageOf } from '../pipeline.ts';
|
|
4
|
+
import type { Deal, DealOutcome, Lead, Pipeline, PipelineStage } from '../types.ts';
|
|
5
|
+
import { StageSelect } from './DealsBoard.tsx';
|
|
6
|
+
import { companyNameOf, formatDate, formatMaybeMoney, personNameOf, type CrmNames } from './format.ts';
|
|
7
|
+
import { leadCompany } from './LeadsTable.tsx';
|
|
8
|
+
import { CrmCard, LeadStatusBadge, OutcomeBadge } from './parts.tsx';
|
|
9
|
+
import { withText, type CrmText } from './text.ts';
|
|
10
|
+
import { Button } from './ui/button.tsx';
|
|
11
|
+
import { Input } from './ui/input.tsx';
|
|
12
|
+
import { Label } from './ui/label.tsx';
|
|
13
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select.tsx';
|
|
14
|
+
|
|
15
|
+
/** Label and value pairs as a description list. */
|
|
16
|
+
export function DetailList({ items }: { items: { label: string; value: ReactNode }[] }) {
|
|
17
|
+
return (
|
|
18
|
+
<dl className="grid grid-cols-[minmax(7rem,auto)_minmax(0,1fr)] gap-x-4 gap-y-2 text-sm">
|
|
19
|
+
{items.map(({ label, value }) => (
|
|
20
|
+
<div key={label} className="contents">
|
|
21
|
+
<dt className="text-muted-foreground">{label}</dt>
|
|
22
|
+
<dd>{value}</dd>
|
|
23
|
+
</div>
|
|
24
|
+
))}
|
|
25
|
+
</dl>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What converting a lead was asked to do: the company name confirmed or corrected, when the lead had no company. */
|
|
30
|
+
export interface ConvertChoice {
|
|
31
|
+
companyName?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A lead's details. While it's open: "Convert to deal", where the new client company's name can be corrected, and
|
|
36
|
+
* "Mark unqualified" with why. Once unqualified it can be reopened.
|
|
37
|
+
*/
|
|
38
|
+
export function LeadDetail({
|
|
39
|
+
lead,
|
|
40
|
+
names,
|
|
41
|
+
onConvert,
|
|
42
|
+
onSetOutcome,
|
|
43
|
+
converting,
|
|
44
|
+
sample,
|
|
45
|
+
text,
|
|
46
|
+
}: {
|
|
47
|
+
lead: Lead;
|
|
48
|
+
names?: CrmNames | undefined;
|
|
49
|
+
/** Shown while the lead is open. */
|
|
50
|
+
onConvert?: ((lead: Lead, choice: ConvertChoice) => void) | undefined;
|
|
51
|
+
/** Unqualifies (with why) or reopens the lead. */
|
|
52
|
+
onSetOutcome?: ((lead: Lead, outcome: 'IN_PROGRESS' | 'CLOSED', closedReason?: string) => void) | undefined;
|
|
53
|
+
converting?: boolean | undefined;
|
|
54
|
+
sample?: boolean | undefined;
|
|
55
|
+
text?: Partial<CrmText> | undefined;
|
|
56
|
+
}) {
|
|
57
|
+
const words = withText(text);
|
|
58
|
+
const id = useId();
|
|
59
|
+
const [companyName, setCompanyName] = useState('');
|
|
60
|
+
const [unqualifying, setUnqualifying] = useState(false);
|
|
61
|
+
const [reason, setReason] = useState('');
|
|
62
|
+
const outcome = leadOutcome(lead);
|
|
63
|
+
const open = outcome === 'IN_PROGRESS';
|
|
64
|
+
const submit = (event: FormEvent) => {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
onConvert?.(lead, lead.contactCompany ? {} : { companyName: companyName.trim() });
|
|
67
|
+
};
|
|
68
|
+
return (
|
|
69
|
+
<CrmCard title={lead.title} sample={sample} text={text}>
|
|
70
|
+
<div className="grid gap-5">
|
|
71
|
+
<DetailList
|
|
72
|
+
items={[
|
|
73
|
+
{ label: words.status, value: <LeadStatusBadge lead={lead} /> },
|
|
74
|
+
// A lead has no close time of its own: it was last changed when it closed.
|
|
75
|
+
...(!open ? [{ label: words.closed, value: formatDate(lead.updatedTimestamp) }] : []),
|
|
76
|
+
...(lead.closedReason ? [{ label: words.unqualifiedReason, value: lead.closedReason }] : []),
|
|
77
|
+
{ label: words.contact, value: personNameOf(names, lead.contactIdentity?.urn) ?? '-' },
|
|
78
|
+
{ label: words.company, value: leadCompany(lead, names) || '-' },
|
|
79
|
+
{ label: words.source, value: SOURCE_LABELS[lead.source] },
|
|
80
|
+
{ label: words.value, value: formatMaybeMoney(lead.targetValue) },
|
|
81
|
+
{ label: words.assignee, value: personNameOf(names, lead.assignee?.urn) ?? '-' },
|
|
82
|
+
{ label: words.created, value: formatDate(lead.createdTimestamp) },
|
|
83
|
+
]}
|
|
84
|
+
/>
|
|
85
|
+
{open && onConvert && (
|
|
86
|
+
<form onSubmit={submit} className="grid gap-3" aria-labelledby={`${id}-title`}>
|
|
87
|
+
<div className="grid gap-1">
|
|
88
|
+
<h3 id={`${id}-title`} className="text-sm font-semibold">
|
|
89
|
+
{words.convert}
|
|
90
|
+
</h3>
|
|
91
|
+
<p className="text-muted-foreground text-sm">{words.convertSummary}</p>
|
|
92
|
+
</div>
|
|
93
|
+
{!lead.contactCompany && (
|
|
94
|
+
<div className="grid gap-1.5">
|
|
95
|
+
<Label htmlFor={`${id}-company`}>{words.companyName}</Label>
|
|
96
|
+
<Input
|
|
97
|
+
id={`${id}-company`}
|
|
98
|
+
value={companyName}
|
|
99
|
+
onChange={(event) => setCompanyName(event.target.value)}
|
|
100
|
+
aria-describedby={`${id}-company-hint`}
|
|
101
|
+
/>
|
|
102
|
+
<p id={`${id}-company-hint`} className="text-muted-foreground text-xs">
|
|
103
|
+
{words.companyNameHint}
|
|
104
|
+
</p>
|
|
105
|
+
</div>
|
|
106
|
+
)}
|
|
107
|
+
<div>
|
|
108
|
+
<Button type="submit" size="sm" disabled={converting ?? false}>
|
|
109
|
+
{converting ? words.converting : words.convert}
|
|
110
|
+
</Button>
|
|
111
|
+
</div>
|
|
112
|
+
</form>
|
|
113
|
+
)}
|
|
114
|
+
{open && onSetOutcome && !unqualifying && (
|
|
115
|
+
<div>
|
|
116
|
+
<Button type="button" size="sm" variant="outline" onClick={() => setUnqualifying(true)}>
|
|
117
|
+
{words.markUnqualified}
|
|
118
|
+
</Button>
|
|
119
|
+
</div>
|
|
120
|
+
)}
|
|
121
|
+
{open && onSetOutcome && unqualifying && (
|
|
122
|
+
<form
|
|
123
|
+
className="grid gap-2"
|
|
124
|
+
onSubmit={(event) => {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
setUnqualifying(false);
|
|
127
|
+
onSetOutcome(lead, 'CLOSED', reason);
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<Label htmlFor={`${id}-reason`}>{words.unqualifiedReason}</Label>
|
|
131
|
+
<Input id={`${id}-reason`} value={reason} onChange={(event) => setReason(event.target.value)} />
|
|
132
|
+
<div className="flex gap-2">
|
|
133
|
+
<Button type="submit" size="sm">
|
|
134
|
+
{words.markUnqualified}
|
|
135
|
+
</Button>
|
|
136
|
+
<Button type="button" size="sm" variant="ghost" onClick={() => setUnqualifying(false)}>
|
|
137
|
+
{words.cancel}
|
|
138
|
+
</Button>
|
|
139
|
+
</div>
|
|
140
|
+
</form>
|
|
141
|
+
)}
|
|
142
|
+
{outcome === 'CLOSED' && onSetOutcome && (
|
|
143
|
+
<div>
|
|
144
|
+
<Button type="button" size="sm" variant="outline" onClick={() => onSetOutcome(lead, 'IN_PROGRESS')}>
|
|
145
|
+
{words.reopen}
|
|
146
|
+
</Button>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
</CrmCard>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const OUTCOME_LABELS: Record<DealOutcome, keyof CrmText> = {
|
|
155
|
+
OPEN: 'outcomeOpen',
|
|
156
|
+
WON: 'outcomeWon',
|
|
157
|
+
LOST: 'outcomeLost',
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Wins, loses or reopens a deal. Its outcome is on the deal, not its stage, as workflows are only progress. Open and
|
|
162
|
+
* won apply at once; lost asks why first.
|
|
163
|
+
*/
|
|
164
|
+
export function OutcomeControl({
|
|
165
|
+
deal,
|
|
166
|
+
onSetOutcome,
|
|
167
|
+
disabled,
|
|
168
|
+
text,
|
|
169
|
+
}: {
|
|
170
|
+
deal: Deal;
|
|
171
|
+
onSetOutcome: (deal: Deal, outcome: DealOutcome, closedReason?: string) => void;
|
|
172
|
+
disabled?: boolean | undefined;
|
|
173
|
+
text?: Partial<CrmText> | undefined;
|
|
174
|
+
}) {
|
|
175
|
+
const words = withText(text);
|
|
176
|
+
const id = useId();
|
|
177
|
+
const [losing, setLosing] = useState(false);
|
|
178
|
+
const [reason, setReason] = useState(deal.lostReason ?? '');
|
|
179
|
+
const outcome = dealOutcome(deal);
|
|
180
|
+
return (
|
|
181
|
+
<div className="grid gap-2">
|
|
182
|
+
<Select
|
|
183
|
+
value={losing ? 'LOST' : outcome}
|
|
184
|
+
disabled={disabled ?? false}
|
|
185
|
+
onValueChange={(value) => {
|
|
186
|
+
if (value === 'LOST') return setLosing(true);
|
|
187
|
+
setLosing(false);
|
|
188
|
+
onSetOutcome(deal, value as DealOutcome);
|
|
189
|
+
}}
|
|
190
|
+
>
|
|
191
|
+
<SelectTrigger size="sm" aria-label={`${words.outcome}: ${deal.title}`}>
|
|
192
|
+
<SelectValue />
|
|
193
|
+
</SelectTrigger>
|
|
194
|
+
<SelectContent>
|
|
195
|
+
{(['OPEN', 'WON', 'LOST'] as const).map((value) => (
|
|
196
|
+
<SelectItem key={value} value={value}>
|
|
197
|
+
{words[OUTCOME_LABELS[value]]}
|
|
198
|
+
</SelectItem>
|
|
199
|
+
))}
|
|
200
|
+
</SelectContent>
|
|
201
|
+
</Select>
|
|
202
|
+
{losing && (
|
|
203
|
+
<form
|
|
204
|
+
className="grid gap-2"
|
|
205
|
+
onSubmit={(event) => {
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
setLosing(false);
|
|
208
|
+
onSetOutcome(deal, 'LOST', reason);
|
|
209
|
+
}}
|
|
210
|
+
>
|
|
211
|
+
<Label htmlFor={`${id}-reason`}>{words.lostReason}</Label>
|
|
212
|
+
<Input id={`${id}-reason`} value={reason} onChange={(event) => setReason(event.target.value)} />
|
|
213
|
+
<div className="flex gap-2">
|
|
214
|
+
<Button type="submit" size="sm">
|
|
215
|
+
{words.markLost}
|
|
216
|
+
</Button>
|
|
217
|
+
<Button type="button" size="sm" variant="ghost" onClick={() => setLosing(false)}>
|
|
218
|
+
{words.cancel}
|
|
219
|
+
</Button>
|
|
220
|
+
</div>
|
|
221
|
+
</form>
|
|
222
|
+
)}
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** A deal's details, with its stage picker and its outcome (open, won or lost). */
|
|
228
|
+
export function DealDetail({
|
|
229
|
+
deal,
|
|
230
|
+
pipeline,
|
|
231
|
+
names,
|
|
232
|
+
onMove,
|
|
233
|
+
onSetOutcome,
|
|
234
|
+
saving,
|
|
235
|
+
sample,
|
|
236
|
+
text,
|
|
237
|
+
}: {
|
|
238
|
+
deal: Deal;
|
|
239
|
+
pipeline: Pipeline;
|
|
240
|
+
names?: CrmNames | undefined;
|
|
241
|
+
onMove?: ((deal: Deal, stage: PipelineStage) => void) | undefined;
|
|
242
|
+
onSetOutcome?: ((deal: Deal, outcome: DealOutcome, closedReason?: string) => void) | undefined;
|
|
243
|
+
saving?: boolean | undefined;
|
|
244
|
+
sample?: boolean | undefined;
|
|
245
|
+
text?: Partial<CrmText> | undefined;
|
|
246
|
+
}) {
|
|
247
|
+
const words = withText(text);
|
|
248
|
+
const stage = stageOf(deal, pipeline) ?? orderedStages(pipeline)[0];
|
|
249
|
+
const outcome = dealOutcome(deal);
|
|
250
|
+
const probability = dealProbability(deal);
|
|
251
|
+
return (
|
|
252
|
+
<CrmCard title={deal.title} sample={sample} text={text}>
|
|
253
|
+
<DetailList
|
|
254
|
+
items={[
|
|
255
|
+
{
|
|
256
|
+
label: words.stage,
|
|
257
|
+
value: onMove ? (
|
|
258
|
+
<StageSelect deal={deal} pipeline={pipeline} onMove={onMove} disabled={saving} text={text} />
|
|
259
|
+
) : (
|
|
260
|
+
(stage?.name ?? '-')
|
|
261
|
+
),
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
label: words.outcome,
|
|
265
|
+
value: onSetOutcome ? (
|
|
266
|
+
<OutcomeControl key={deal.urn} deal={deal} onSetOutcome={onSetOutcome} disabled={saving} text={text} />
|
|
267
|
+
) : (
|
|
268
|
+
<OutcomeBadge outcome={outcome} label={words[OUTCOME_LABELS[outcome]]} />
|
|
269
|
+
),
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
label: words.company,
|
|
273
|
+
value: deal.contactCompanies.map((company) => companyNameOf(names, company.urn) ?? words.unnamed).join(', ') || '-',
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
label: words.contact,
|
|
277
|
+
value:
|
|
278
|
+
deal.contactIdentities.map((contact) => personNameOf(names, contact.urn) ?? words.unnamed).join(', ') || '-',
|
|
279
|
+
},
|
|
280
|
+
{ label: words.value, value: formatMaybeMoney(deal.targetValue) },
|
|
281
|
+
{ label: words.probability, value: probability === undefined ? '-' : `${probability}%` },
|
|
282
|
+
{
|
|
283
|
+
label: deal.closeTimestamp ? words.closed : words.expectedClose,
|
|
284
|
+
value: formatDate(deal.closeTimestamp ?? deal.targetCloseTimestamp),
|
|
285
|
+
},
|
|
286
|
+
...(deal.lostReason ? [{ label: words.lostReason, value: deal.lostReason }] : []),
|
|
287
|
+
{ label: words.assignee, value: personNameOf(names, deal.assignee?.urn) ?? '-' },
|
|
288
|
+
{ label: words.created, value: formatDate(deal.createdTimestamp) },
|
|
289
|
+
]}
|
|
290
|
+
/>
|
|
291
|
+
</CrmCard>
|
|
292
|
+
);
|
|
293
|
+
}
|