@baack-software/baack-ts-crm 0.0.0-stage → 0.0.3
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 +104 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +328 -0
- package/dist/backend.js.map +1 -0
- package/dist/crm-client.d.ts +164 -0
- package/dist/crm-client.d.ts.map +1 -0
- package/dist/crm-client.js +252 -0
- package/dist/crm-client.js.map +1 -0
- package/dist/deal-order.d.ts +42 -0
- package/dist/deal-order.d.ts.map +1 -0
- package/dist/deal-order.js +80 -0
- package/dist/deal-order.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 +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices.d.ts +53 -0
- package/dist/invoices.d.ts.map +1 -0
- package/dist/invoices.js +155 -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 +30 -0
- package/dist/period.d.ts.map +1 -0
- package/dist/period.js +49 -0
- package/dist/period.js.map +1 -0
- package/dist/pipeline.d.ts +36 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +58 -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/ChoiceCombobox.d.ts +36 -0
- package/dist/react/ChoiceCombobox.d.ts.map +1 -0
- package/dist/react/ChoiceCombobox.js +105 -0
- package/dist/react/ChoiceCombobox.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 +49 -0
- package/dist/react/DealsBoard.d.ts.map +1 -0
- package/dist/react/DealsBoard.js +82 -0
- package/dist/react/DealsBoard.js.map +1 -0
- package/dist/react/Details.d.ts +85 -0
- package/dist/react/Details.d.ts.map +1 -0
- package/dist/react/Details.js +268 -0
- package/dist/react/Details.js.map +1 -0
- package/dist/react/Forms.d.ts +190 -0
- package/dist/react/Forms.d.ts.map +1 -0
- package/dist/react/Forms.js +494 -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 +68 -0
- package/dist/react/Sales.d.ts.map +1 -0
- package/dist/react/Sales.js +270 -0
- package/dist/react/Sales.js.map +1 -0
- package/dist/react/SidePanel.d.ts +31 -0
- package/dist/react/SidePanel.d.ts.map +1 -0
- package/dist/react/SidePanel.js +49 -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 +15 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +15 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/parts.d.ts +55 -0
- package/dist/react/parts.d.ts.map +1 -0
- package/dist/react/parts.js +82 -0
- package/dist/react/parts.js.map +1 -0
- package/dist/react/pipeline-choice.d.ts +19 -0
- package/dist/react/pipeline-choice.d.ts.map +1 -0
- package/dist/react/pipeline-choice.js +39 -0
- package/dist/react/pipeline-choice.js.map +1 -0
- package/dist/react/text.d.ts +232 -0
- package/dist/react/text.d.ts.map +1 -0
- package/dist/react/text.js +229 -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 +82 -0
- package/dist/react/views.d.ts.map +1 -0
- package/dist/react/views.js +241 -0
- package/dist/react/views.js.map +1 -0
- package/dist/sales.d.ts +82 -0
- package/dist/sales.d.ts.map +1 -0
- package/dist/sales.js +87 -0
- package/dist/sales.js.map +1 -0
- package/dist/store.d.ts +159 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +305 -0
- package/dist/store.js.map +1 -0
- package/dist/target.d.ts +22 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +40 -0
- package/dist/target.js.map +1 -0
- package/dist/types.d.ts +204 -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 +501 -0
- package/src/crm-client.ts +393 -0
- package/src/deal-order.ts +116 -0
- package/src/errors.ts +34 -0
- package/src/index.ts +13 -0
- package/src/invoices.ts +177 -0
- package/src/leads.ts +78 -0
- package/src/mock/index.ts +398 -0
- package/src/money.ts +104 -0
- package/src/period.ts +71 -0
- package/src/pipeline.ts +82 -0
- package/src/react/Charts.tsx +143 -0
- package/src/react/ChoiceCombobox.tsx +227 -0
- package/src/react/CompanyAccountView.tsx +198 -0
- package/src/react/DashboardCards.tsx +171 -0
- package/src/react/DealsBoard.tsx +344 -0
- package/src/react/Details.tsx +870 -0
- package/src/react/Forms.tsx +1486 -0
- package/src/react/LeadsTable.tsx +234 -0
- package/src/react/Sales.tsx +827 -0
- package/src/react/SidePanel.tsx +104 -0
- package/src/react/format.ts +53 -0
- package/src/react/index.ts +14 -0
- package/src/react/parts.tsx +183 -0
- package/src/react/pipeline-choice.ts +54 -0
- package/src/react/text.ts +232 -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 +633 -0
- package/src/sales.ts +167 -0
- package/src/store.ts +528 -0
- package/src/target.ts +54 -0
- package/src/types.ts +230 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { cn } from 'cn';
|
|
2
|
+
import { Search, X } from 'lucide-react';
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import { DEAL_ORDERS, sortDeals, type DealFilter, type DealOrder } from '../deal-order.ts';
|
|
5
|
+
import { addMoney, type MoneyTotals } from '../money.ts';
|
|
6
|
+
import { dealCompany, dealOutcome, orderedStages } from '../pipeline.ts';
|
|
7
|
+
import type { Deal, DealOutcome, Pipeline, PipelineStage } from '../types.ts';
|
|
8
|
+
import type { CrmChoice } from './Forms.tsx';
|
|
9
|
+
import { companyNameOf, formatDate, formatMaybeMoney, formatTotals, type CrmNames } from './format.ts';
|
|
10
|
+
import { OutcomeBadge, SampleDataBadge } from './parts.tsx';
|
|
11
|
+
import { recordItemId } from './SidePanel.tsx';
|
|
12
|
+
import { withText, type CrmText } from './text.ts';
|
|
13
|
+
import { Button } from './ui/button.tsx';
|
|
14
|
+
import { Card, CardContent, CardHeader, CardTitle } from './ui/card.tsx';
|
|
15
|
+
import { Input } from './ui/input.tsx';
|
|
16
|
+
import { Label } from './ui/label.tsx';
|
|
17
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select.tsx';
|
|
18
|
+
|
|
19
|
+
/** Picks the stage a deal is at; moving it is one choice, so it works from the keyboard as well as by pointer. */
|
|
20
|
+
export function StageSelect({
|
|
21
|
+
deal,
|
|
22
|
+
pipeline,
|
|
23
|
+
onMove,
|
|
24
|
+
disabled,
|
|
25
|
+
text,
|
|
26
|
+
className,
|
|
27
|
+
}: {
|
|
28
|
+
deal: Deal;
|
|
29
|
+
pipeline: Pipeline;
|
|
30
|
+
onMove: (deal: Deal, stage: PipelineStage) => void;
|
|
31
|
+
disabled?: boolean | undefined;
|
|
32
|
+
text?: Partial<CrmText> | undefined;
|
|
33
|
+
className?: string | undefined;
|
|
34
|
+
}) {
|
|
35
|
+
const words = withText(text);
|
|
36
|
+
const stages = orderedStages(pipeline);
|
|
37
|
+
return (
|
|
38
|
+
<Select
|
|
39
|
+
value={deal.workflowStage?.urn ?? ''}
|
|
40
|
+
disabled={disabled ?? false}
|
|
41
|
+
onValueChange={(urn) => {
|
|
42
|
+
const stage = stages.find((candidate) => candidate.urn === urn);
|
|
43
|
+
if (stage) onMove(deal, stage);
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<SelectTrigger size="sm" aria-label={`${words.moveTo}: ${deal.title}`} className={className}>
|
|
47
|
+
<SelectValue />
|
|
48
|
+
</SelectTrigger>
|
|
49
|
+
<SelectContent>
|
|
50
|
+
{stages.map((stage) => (
|
|
51
|
+
<SelectItem key={stage.urn} value={stage.urn}>
|
|
52
|
+
{stage.name}
|
|
53
|
+
</SelectItem>
|
|
54
|
+
))}
|
|
55
|
+
</SelectContent>
|
|
56
|
+
</Select>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const ANY = '__any__';
|
|
61
|
+
const NONE = '__none__';
|
|
62
|
+
|
|
63
|
+
const ORDER_WORDS: Record<DealOrder, keyof CrmText> = {
|
|
64
|
+
weighted: 'orderWeighted',
|
|
65
|
+
size: 'orderSize',
|
|
66
|
+
urgency: 'orderUrgency',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const OUTCOMES: readonly { outcome: DealOutcome; label: keyof CrmText }[] = [
|
|
70
|
+
{ outcome: 'OPEN', label: 'outcomeOpen' },
|
|
71
|
+
{ outcome: 'WON', label: 'outcomeWon' },
|
|
72
|
+
{ outcome: 'LOST', label: 'outcomeLost' },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
/** A labelled select of a filter or order, with "any" as `ANY` and "none" as `NONE`. */
|
|
76
|
+
function ToolbarSelect({
|
|
77
|
+
label,
|
|
78
|
+
value,
|
|
79
|
+
onChange,
|
|
80
|
+
options,
|
|
81
|
+
className,
|
|
82
|
+
}: {
|
|
83
|
+
label: string;
|
|
84
|
+
value: string;
|
|
85
|
+
onChange: (value: string) => void;
|
|
86
|
+
options: readonly { value: string; label: string }[];
|
|
87
|
+
className?: string;
|
|
88
|
+
}) {
|
|
89
|
+
const id = useId();
|
|
90
|
+
return (
|
|
91
|
+
<div className="grid gap-1.5">
|
|
92
|
+
<Label htmlFor={id}>{label}</Label>
|
|
93
|
+
<Select value={value} onValueChange={onChange}>
|
|
94
|
+
<SelectTrigger id={id} className={className}>
|
|
95
|
+
<SelectValue />
|
|
96
|
+
</SelectTrigger>
|
|
97
|
+
<SelectContent>
|
|
98
|
+
{options.map((option) => (
|
|
99
|
+
<SelectItem key={option.value} value={option.value}>
|
|
100
|
+
{option.label}
|
|
101
|
+
</SelectItem>
|
|
102
|
+
))}
|
|
103
|
+
</SelectContent>
|
|
104
|
+
</Select>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Filters for the deals board, as the tasks view has (words, outcome, assignee and company), and the order of each
|
|
111
|
+
* column's deals: weighted, by size or by urgency (see `sortDeals`). Controlled; apply them with `filterDeals`.
|
|
112
|
+
*/
|
|
113
|
+
export function DealFilters({
|
|
114
|
+
value,
|
|
115
|
+
onChange,
|
|
116
|
+
order,
|
|
117
|
+
onOrder,
|
|
118
|
+
team = [],
|
|
119
|
+
companies = [],
|
|
120
|
+
shown,
|
|
121
|
+
text,
|
|
122
|
+
}: {
|
|
123
|
+
value: DealFilter;
|
|
124
|
+
onChange: (filter: DealFilter) => void;
|
|
125
|
+
order: DealOrder;
|
|
126
|
+
onOrder: (order: DealOrder) => void;
|
|
127
|
+
team?: readonly CrmChoice[] | undefined;
|
|
128
|
+
companies?: readonly CrmChoice[] | undefined;
|
|
129
|
+
/** How many deals the filters leave, announced as they change. */
|
|
130
|
+
shown?: number | undefined;
|
|
131
|
+
text?: Partial<CrmText> | undefined;
|
|
132
|
+
}) {
|
|
133
|
+
const words = withText(text);
|
|
134
|
+
const set = <K extends keyof DealFilter>(key: K, next: DealFilter[K]) => {
|
|
135
|
+
const { [key]: _removed, ...rest } = value;
|
|
136
|
+
onChange(next === undefined ? rest : { ...rest, [key]: next });
|
|
137
|
+
};
|
|
138
|
+
const pick = (selected: string) => (selected === ANY ? undefined : selected === NONE ? null : selected);
|
|
139
|
+
const current = (selected: string | null | undefined) =>
|
|
140
|
+
selected === undefined ? ANY : selected === null ? NONE : selected;
|
|
141
|
+
const active = Object.values(value).some((field) => field !== undefined && field !== '');
|
|
142
|
+
return (
|
|
143
|
+
<div role="search" aria-label={words.filterDeals} className="flex flex-wrap items-end gap-3">
|
|
144
|
+
<div className="relative min-w-48 flex-1">
|
|
145
|
+
<Search
|
|
146
|
+
aria-hidden="true"
|
|
147
|
+
className="text-muted-foreground absolute top-1/2 left-2.5 size-4 -translate-y-1/2"
|
|
148
|
+
/>
|
|
149
|
+
<Input
|
|
150
|
+
type="search"
|
|
151
|
+
aria-label={words.filterDeals}
|
|
152
|
+
placeholder={words.filterDeals}
|
|
153
|
+
value={value.text ?? ''}
|
|
154
|
+
onChange={(event) => set('text', event.target.value || undefined)}
|
|
155
|
+
className="pl-8"
|
|
156
|
+
/>
|
|
157
|
+
</div>
|
|
158
|
+
<ToolbarSelect
|
|
159
|
+
label={words.outcome}
|
|
160
|
+
value={value.outcome ?? ANY}
|
|
161
|
+
onChange={(selected) => set('outcome', selected === ANY ? undefined : (selected as DealOutcome))}
|
|
162
|
+
options={[
|
|
163
|
+
{ value: ANY, label: words.allOutcomes },
|
|
164
|
+
...OUTCOMES.map(({ outcome, label }) => ({ value: outcome, label: words[label] })),
|
|
165
|
+
]}
|
|
166
|
+
className="w-36"
|
|
167
|
+
/>
|
|
168
|
+
<ToolbarSelect
|
|
169
|
+
label={words.assignee}
|
|
170
|
+
value={current(value.assignee)}
|
|
171
|
+
onChange={(selected) => set('assignee', pick(selected))}
|
|
172
|
+
options={[
|
|
173
|
+
{ value: ANY, label: words.anyone },
|
|
174
|
+
{ value: NONE, label: words.unassigned },
|
|
175
|
+
...team.map((person) => ({ value: person.urn, label: person.name })),
|
|
176
|
+
]}
|
|
177
|
+
className="w-44"
|
|
178
|
+
/>
|
|
179
|
+
{companies.length > 0 && (
|
|
180
|
+
<ToolbarSelect
|
|
181
|
+
label={words.company}
|
|
182
|
+
value={current(value.company)}
|
|
183
|
+
onChange={(selected) => set('company', pick(selected))}
|
|
184
|
+
options={[
|
|
185
|
+
{ value: ANY, label: words.allCompanies },
|
|
186
|
+
{ value: NONE, label: words.noCompany },
|
|
187
|
+
...companies.map((company) => ({ value: company.urn, label: company.name })),
|
|
188
|
+
]}
|
|
189
|
+
className="w-44"
|
|
190
|
+
/>
|
|
191
|
+
)}
|
|
192
|
+
<ToolbarSelect
|
|
193
|
+
label={words.sortBy}
|
|
194
|
+
value={order}
|
|
195
|
+
onChange={(selected) => onOrder(selected as DealOrder)}
|
|
196
|
+
options={DEAL_ORDERS.map((option) => ({ value: option, label: words[ORDER_WORDS[option]] }))}
|
|
197
|
+
className="w-36"
|
|
198
|
+
/>
|
|
199
|
+
{active && (
|
|
200
|
+
<Button variant="ghost" size="sm" onClick={() => onChange({})}>
|
|
201
|
+
<X aria-hidden="true" />
|
|
202
|
+
{words.clearFilters}
|
|
203
|
+
</Button>
|
|
204
|
+
)}
|
|
205
|
+
{shown !== undefined && (
|
|
206
|
+
<p aria-live="polite" className="sr-only">
|
|
207
|
+
{shown} {words.dealsShown}
|
|
208
|
+
</p>
|
|
209
|
+
)}
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Deals as a board, one column per pipeline stage with its count and value, each column in `order` (weighted to start
|
|
216
|
+
* with). Each deal can be opened, and moved with its stage picker.
|
|
217
|
+
*/
|
|
218
|
+
export function DealsBoard({
|
|
219
|
+
deals,
|
|
220
|
+
pipeline,
|
|
221
|
+
names,
|
|
222
|
+
onOpen,
|
|
223
|
+
onMove,
|
|
224
|
+
selected,
|
|
225
|
+
saving,
|
|
226
|
+
sample,
|
|
227
|
+
order = 'weighted',
|
|
228
|
+
text,
|
|
229
|
+
}: {
|
|
230
|
+
deals: readonly Deal[];
|
|
231
|
+
pipeline: Pipeline;
|
|
232
|
+
/** How each column's deals are ordered. */
|
|
233
|
+
order?: DealOrder | undefined;
|
|
234
|
+
names?: CrmNames | undefined;
|
|
235
|
+
onOpen?: ((deal: Deal) => void) | undefined;
|
|
236
|
+
onMove?: ((deal: Deal, stage: PipelineStage) => void) | undefined;
|
|
237
|
+
/** The open deal, highlighted. */
|
|
238
|
+
selected?: string | undefined;
|
|
239
|
+
/** URNs of deals being saved. */
|
|
240
|
+
saving?: ReadonlySet<string> | undefined;
|
|
241
|
+
sample?: boolean | undefined;
|
|
242
|
+
text?: Partial<CrmText> | undefined;
|
|
243
|
+
}) {
|
|
244
|
+
const words = withText(text);
|
|
245
|
+
return (
|
|
246
|
+
<section aria-label={`${pipeline.name}: ${words.deals}`} className="grid gap-3">
|
|
247
|
+
{sample && (
|
|
248
|
+
<div>
|
|
249
|
+
<SampleDataBadge text={text} />
|
|
250
|
+
</div>
|
|
251
|
+
)}
|
|
252
|
+
{/* Focusable, so the columns past the edge can be scrolled to from the keyboard. */}
|
|
253
|
+
<div tabIndex={0} aria-label={pipeline.name} className="flex gap-3 overflow-x-auto rounded-xl pb-2">
|
|
254
|
+
{orderedStages(pipeline).map((stage) => {
|
|
255
|
+
const here = sortDeals(
|
|
256
|
+
deals.filter((deal) => deal.workflowStage?.urn === stage.urn),
|
|
257
|
+
order,
|
|
258
|
+
);
|
|
259
|
+
const value = here.reduce<MoneyTotals>((totals, deal) => addMoney(totals, deal.targetValue), {});
|
|
260
|
+
return (
|
|
261
|
+
<section
|
|
262
|
+
key={stage.urn}
|
|
263
|
+
aria-labelledby={`stage-${stage.urn}`}
|
|
264
|
+
className="bg-muted/50 flex w-64 shrink-0 flex-col gap-2 rounded-xl p-2"
|
|
265
|
+
>
|
|
266
|
+
<header className="px-1 pt-1">
|
|
267
|
+
<h3
|
|
268
|
+
id={`stage-${stage.urn}`}
|
|
269
|
+
className="flex items-baseline justify-between gap-2 text-sm font-semibold"
|
|
270
|
+
>
|
|
271
|
+
{stage.name}
|
|
272
|
+
<span className="text-muted-foreground font-normal tabular-nums">{here.length}</span>
|
|
273
|
+
</h3>
|
|
274
|
+
<p className="text-muted-foreground text-xs tabular-nums">{formatTotals(value)}</p>
|
|
275
|
+
</header>
|
|
276
|
+
{here.length === 0 ? (
|
|
277
|
+
<p className="text-muted-foreground px-1 py-4 text-center text-xs">{words.noDeals}</p>
|
|
278
|
+
) : (
|
|
279
|
+
<ul className="grid gap-2">
|
|
280
|
+
{here.map((deal) => (
|
|
281
|
+
<li key={deal.urn}>
|
|
282
|
+
<Card
|
|
283
|
+
size="sm"
|
|
284
|
+
className={cn(
|
|
285
|
+
saving?.has(deal.urn) && 'opacity-60',
|
|
286
|
+
selected === deal.urn && 'ring-primary ring-2',
|
|
287
|
+
)}
|
|
288
|
+
>
|
|
289
|
+
<CardHeader>
|
|
290
|
+
<CardTitle className="text-sm">
|
|
291
|
+
{onOpen ? (
|
|
292
|
+
<button
|
|
293
|
+
type="button"
|
|
294
|
+
id={recordItemId(deal.urn)}
|
|
295
|
+
aria-current={selected === deal.urn ? 'true' : undefined}
|
|
296
|
+
className="text-left hover:underline"
|
|
297
|
+
onClick={() => onOpen(deal)}
|
|
298
|
+
>
|
|
299
|
+
{deal.title}
|
|
300
|
+
</button>
|
|
301
|
+
) : (
|
|
302
|
+
deal.title
|
|
303
|
+
)}
|
|
304
|
+
</CardTitle>
|
|
305
|
+
</CardHeader>
|
|
306
|
+
<CardContent className="grid gap-2 text-xs">
|
|
307
|
+
<p className="text-muted-foreground flex items-center justify-between gap-2">
|
|
308
|
+
<span>{companyNameOf(names, dealCompany(deal)?.urn) ?? words.unnamed}</span>
|
|
309
|
+
{dealOutcome(deal) !== 'OPEN' && (
|
|
310
|
+
<OutcomeBadge
|
|
311
|
+
outcome={dealOutcome(deal)}
|
|
312
|
+
label={dealOutcome(deal) === 'WON' ? words.outcomeWon : words.outcomeLost}
|
|
313
|
+
/>
|
|
314
|
+
)}
|
|
315
|
+
</p>
|
|
316
|
+
<p className="flex justify-between gap-2">
|
|
317
|
+
<span className="font-medium tabular-nums">{formatMaybeMoney(deal.targetValue)}</span>
|
|
318
|
+
<span className="text-muted-foreground">
|
|
319
|
+
{formatDate(deal.closeTimestamp ?? deal.targetCloseTimestamp)}
|
|
320
|
+
</span>
|
|
321
|
+
</p>
|
|
322
|
+
{onMove && (
|
|
323
|
+
<StageSelect
|
|
324
|
+
deal={deal}
|
|
325
|
+
pipeline={pipeline}
|
|
326
|
+
onMove={onMove}
|
|
327
|
+
disabled={saving?.has(deal.urn)}
|
|
328
|
+
text={text}
|
|
329
|
+
className="w-full"
|
|
330
|
+
/>
|
|
331
|
+
)}
|
|
332
|
+
</CardContent>
|
|
333
|
+
</Card>
|
|
334
|
+
</li>
|
|
335
|
+
))}
|
|
336
|
+
</ul>
|
|
337
|
+
)}
|
|
338
|
+
</section>
|
|
339
|
+
);
|
|
340
|
+
})}
|
|
341
|
+
</div>
|
|
342
|
+
</section>
|
|
343
|
+
);
|
|
344
|
+
}
|