@baack-software/baack-ts-crm 0.0.2 → 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/dist/backend.d.ts +29 -1
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +95 -0
- package/dist/backend.js.map +1 -1
- package/dist/crm-client.d.ts +55 -13
- package/dist/crm-client.d.ts.map +1 -1
- package/dist/crm-client.js +99 -15
- package/dist/crm-client.js.map +1 -1
- 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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/invoices.d.ts +7 -0
- package/dist/invoices.d.ts.map +1 -1
- package/dist/invoices.js +20 -2
- package/dist/invoices.js.map +1 -1
- package/dist/period.d.ts +15 -2
- package/dist/period.d.ts.map +1 -1
- package/dist/period.js +27 -1
- package/dist/period.js.map +1 -1
- package/dist/pipeline.d.ts +6 -0
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +18 -0
- package/dist/pipeline.js.map +1 -1
- 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/DealsBoard.d.ts +22 -3
- package/dist/react/DealsBoard.d.ts.map +1 -1
- package/dist/react/DealsBoard.js +53 -4
- package/dist/react/DealsBoard.js.map +1 -1
- package/dist/react/Details.d.ts +40 -7
- package/dist/react/Details.d.ts.map +1 -1
- package/dist/react/Details.js +180 -23
- package/dist/react/Details.js.map +1 -1
- package/dist/react/Forms.d.ts +148 -17
- package/dist/react/Forms.d.ts.map +1 -1
- package/dist/react/Forms.js +365 -75
- package/dist/react/Forms.js.map +1 -1
- package/dist/react/Sales.d.ts +25 -6
- package/dist/react/Sales.d.ts.map +1 -1
- package/dist/react/Sales.js +114 -30
- package/dist/react/Sales.js.map +1 -1
- package/dist/react/SidePanel.d.ts +10 -0
- package/dist/react/SidePanel.d.ts.map +1 -1
- package/dist/react/SidePanel.js +14 -2
- package/dist/react/SidePanel.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/parts.d.ts +12 -2
- package/dist/react/parts.d.ts.map +1 -1
- package/dist/react/parts.js +25 -2
- package/dist/react/parts.js.map +1 -1
- 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 +89 -2
- package/dist/react/text.d.ts.map +1 -1
- package/dist/react/text.js +89 -2
- package/dist/react/text.js.map +1 -1
- package/dist/react/ui/badge.d.ts +1 -1
- package/dist/react/ui/button.d.ts +2 -2
- package/dist/react/views.d.ts +33 -11
- package/dist/react/views.d.ts.map +1 -1
- package/dist/react/views.js +96 -27
- package/dist/react/views.js.map +1 -1
- package/dist/sales.d.ts +28 -3
- package/dist/sales.d.ts.map +1 -1
- package/dist/sales.js +33 -10
- package/dist/sales.js.map +1 -1
- package/dist/store.d.ts +31 -12
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +82 -21
- package/dist/store.js.map +1 -1
- package/dist/target.d.ts +2 -1
- package/dist/target.d.ts.map +1 -1
- package/dist/target.js +6 -2
- package/dist/target.js.map +1 -1
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/backend.ts +131 -1
- package/src/crm-client.ts +162 -19
- package/src/deal-order.ts +116 -0
- package/src/index.ts +1 -0
- package/src/invoices.ts +22 -2
- package/src/period.ts +41 -2
- package/src/pipeline.ts +21 -0
- package/src/react/ChoiceCombobox.tsx +227 -0
- package/src/react/DealsBoard.tsx +171 -4
- package/src/react/Details.tsx +608 -31
- package/src/react/Forms.tsx +1006 -139
- package/src/react/Sales.tsx +332 -44
- package/src/react/SidePanel.tsx +19 -10
- package/src/react/index.ts +1 -0
- package/src/react/parts.tsx +56 -4
- package/src/react/pipeline-choice.ts +54 -0
- package/src/react/text.ts +90 -2
- package/src/react/views.tsx +222 -32
- package/src/sales.ts +57 -10
- package/src/store.ts +136 -27
- package/src/target.ts +5 -2
- package/src/types.ts +28 -0
package/src/pipeline.ts
CHANGED
|
@@ -13,6 +13,27 @@ export const stageOf = (deal: Deal, pipeline: Pipeline): PipelineStage | undefin
|
|
|
13
13
|
export const pipelineOf = (deal: Deal, pipelines: readonly Pipeline[]): Pipeline | undefined =>
|
|
14
14
|
pipelines.find((pipeline) => stageOf(deal, pipeline));
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The pipeline to show and to start new deals in: `chosen` while it's still one of them (the one the user last picked,
|
|
18
|
+
* as their team may work in a different workflow), else the one holding the most deals, so a company's sales workflow
|
|
19
|
+
* wins over its other workflows, else the first.
|
|
20
|
+
*/
|
|
21
|
+
export function defaultPipeline(
|
|
22
|
+
pipelines: readonly Pipeline[],
|
|
23
|
+
deals: readonly Deal[],
|
|
24
|
+
chosen?: string,
|
|
25
|
+
): Pipeline | undefined {
|
|
26
|
+
const picked = chosen === undefined ? undefined : pipelines.find((pipeline) => pipeline.urn === chosen);
|
|
27
|
+
if (picked) return picked;
|
|
28
|
+
let busiest: Pipeline | undefined;
|
|
29
|
+
let most = 0;
|
|
30
|
+
for (const pipeline of pipelines) {
|
|
31
|
+
const count = deals.filter((deal) => stageOf(deal, pipeline)).length;
|
|
32
|
+
if (count > most) [busiest, most] = [pipeline, count];
|
|
33
|
+
}
|
|
34
|
+
return busiest ?? pipelines[0];
|
|
35
|
+
}
|
|
36
|
+
|
|
16
37
|
/** How a deal stands: its own outcome, open when it has none. */
|
|
17
38
|
export const dealOutcome = (deal: Deal): DealOutcome => deal.outcome ?? 'OPEN';
|
|
18
39
|
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { cn } from 'cn';
|
|
2
|
+
import { Check, Plus, X } from 'lucide-react';
|
|
3
|
+
import { useId, useState, type KeyboardEvent } from 'react';
|
|
4
|
+
import type { CrmChoice } from './Forms.tsx';
|
|
5
|
+
import { withText, type CrmText } from './text.ts';
|
|
6
|
+
import { Input } from './ui/input.tsx';
|
|
7
|
+
|
|
8
|
+
/** At most this many matches are listed; typing more narrows them. */
|
|
9
|
+
const MAX_SHOWN = 50;
|
|
10
|
+
|
|
11
|
+
/** Whether a choice matches every word typed, in its name, its detail (such as an email) or its keywords. */
|
|
12
|
+
export function choiceMatches(choice: CrmChoice, query: string): boolean {
|
|
13
|
+
const words = query.toLocaleLowerCase('en-GB').split(/\s+/).filter(Boolean);
|
|
14
|
+
if (words.length === 0) return true;
|
|
15
|
+
const haystack = [choice.name, choice.detail ?? '', ...(choice.keywords ?? [])].join(' ').toLocaleLowerCase('en-GB');
|
|
16
|
+
// Numbers are also found by their digits alone, so "07700" finds "+44 7700 900123" (its leading 0 dropped).
|
|
17
|
+
const digits = haystack.replace(/\D/g, '');
|
|
18
|
+
const byDigits = (word: string) =>
|
|
19
|
+
/^\+?[\d()-]+$/.test(word) && digits.includes(word.replace(/\D/g, '').replace(/^0/, ''));
|
|
20
|
+
return words.every((word) => haystack.includes(word) || byDigits(word));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Records chosen by searching: the chosen ones as removable chips, then a search box (an ARIA combobox) that lists the
|
|
25
|
+
* matching choices by name, detail and keywords. Arrow keys move through the matches, Enter picks or drops one,
|
|
26
|
+
* Escape closes the list and Backspace in an empty box drops the last chip. With `single`, picking one replaces the
|
|
27
|
+
* one chosen. With `add`, the list ends with a way to make a new record; one waiting to be made (`pending`) shows as a
|
|
28
|
+
* chip marked new. The box has `id`, so a field's label names it. Chosen records missing from `choices` are named by
|
|
29
|
+
* `named`, or by the end of their URN.
|
|
30
|
+
*/
|
|
31
|
+
export function ChoiceCombobox({
|
|
32
|
+
id,
|
|
33
|
+
value,
|
|
34
|
+
onChange,
|
|
35
|
+
choices,
|
|
36
|
+
named,
|
|
37
|
+
single = false,
|
|
38
|
+
add,
|
|
39
|
+
pending,
|
|
40
|
+
placeholder,
|
|
41
|
+
disabled,
|
|
42
|
+
describedBy,
|
|
43
|
+
text,
|
|
44
|
+
}: {
|
|
45
|
+
id: string;
|
|
46
|
+
/** The chosen URNs, in order. */
|
|
47
|
+
value: readonly string[];
|
|
48
|
+
onChange: (urns: string[]) => void;
|
|
49
|
+
choices: readonly CrmChoice[];
|
|
50
|
+
named?: ((urn: string) => string | undefined) | undefined;
|
|
51
|
+
/** At most one record. */
|
|
52
|
+
single?: boolean | undefined;
|
|
53
|
+
add?: { label: string; onAdd: () => void } | undefined;
|
|
54
|
+
/** A new record to be made when the form is saved, and how to drop it. */
|
|
55
|
+
pending?: { name: string; onClear: () => void } | undefined;
|
|
56
|
+
placeholder?: string | undefined;
|
|
57
|
+
disabled?: boolean | undefined;
|
|
58
|
+
describedBy?: string | undefined;
|
|
59
|
+
text?: Partial<CrmText> | undefined;
|
|
60
|
+
}) {
|
|
61
|
+
const words = withText(text);
|
|
62
|
+
const ids = useId();
|
|
63
|
+
const [query, setQuery] = useState('');
|
|
64
|
+
const [open, setOpen] = useState(false);
|
|
65
|
+
const [active, setActive] = useState(0);
|
|
66
|
+
const matches = choices.filter((choice) => choiceMatches(choice, query)).slice(0, MAX_SHOWN);
|
|
67
|
+
// The add option, when there is one, comes after the matches.
|
|
68
|
+
const count = matches.length + (add ? 1 : 0);
|
|
69
|
+
const nameOf = (urn: string) =>
|
|
70
|
+
choices.find((choice) => choice.urn === urn)?.name ?? named?.(urn) ?? `...${urn.slice(-6)}`;
|
|
71
|
+
const pick = (index: number) => {
|
|
72
|
+
const choice = matches[index];
|
|
73
|
+
if (!choice) {
|
|
74
|
+
setOpen(false);
|
|
75
|
+
add?.onAdd();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const urn = choice.urn;
|
|
79
|
+
if (single) {
|
|
80
|
+
pending?.onClear();
|
|
81
|
+
onChange(value.includes(urn) ? [] : [urn]);
|
|
82
|
+
setOpen(false);
|
|
83
|
+
} else onChange(value.includes(urn) ? value.filter((other) => other !== urn) : [...value, urn]);
|
|
84
|
+
setQuery('');
|
|
85
|
+
};
|
|
86
|
+
const listId = `${ids}-list`;
|
|
87
|
+
const optionId = (index: number) => `${ids}-option-${index}`;
|
|
88
|
+
const shown = open && !disabled;
|
|
89
|
+
|
|
90
|
+
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
91
|
+
switch (event.key) {
|
|
92
|
+
case 'ArrowDown':
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
if (!shown) setOpen(true);
|
|
95
|
+
else setActive((at) => Math.min(at + 1, count - 1));
|
|
96
|
+
break;
|
|
97
|
+
case 'ArrowUp':
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
setActive((at) => Math.max(at - 1, 0));
|
|
100
|
+
break;
|
|
101
|
+
case 'Enter':
|
|
102
|
+
if (shown && active < count) {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
pick(active);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
case 'Escape':
|
|
108
|
+
if (shown) {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
setOpen(false);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
case 'Backspace':
|
|
114
|
+
if (query) break;
|
|
115
|
+
if (pending) pending.onClear();
|
|
116
|
+
else if (value.length > 0) onChange(value.slice(0, -1));
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const chip = (key: string, label: string, onRemove: () => void) => (
|
|
122
|
+
<li
|
|
123
|
+
key={key}
|
|
124
|
+
className="bg-secondary text-secondary-foreground inline-flex items-center gap-1 rounded-md py-0.5 ps-2 pe-0.5 text-sm"
|
|
125
|
+
>
|
|
126
|
+
{label}
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
aria-label={`${words.remove}: ${label}`}
|
|
131
|
+
className="hover:bg-background/60 focus-visible:ring-ring rounded p-0.5 outline-none focus-visible:ring-2"
|
|
132
|
+
onClick={onRemove}
|
|
133
|
+
>
|
|
134
|
+
<X aria-hidden="true" className="size-3.5" />
|
|
135
|
+
</button>
|
|
136
|
+
</li>
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div className="grid gap-2">
|
|
141
|
+
{(value.length > 0 || pending) && (
|
|
142
|
+
<ul aria-label={words.chosen} className="flex flex-wrap gap-1.5">
|
|
143
|
+
{value.map((urn) => chip(urn, nameOf(urn), () => onChange(value.filter((other) => other !== urn))))}
|
|
144
|
+
{pending && chip('pending', `${pending.name} (${words.toBeCreated})`, pending.onClear)}
|
|
145
|
+
</ul>
|
|
146
|
+
)}
|
|
147
|
+
<div className="relative">
|
|
148
|
+
<Input
|
|
149
|
+
id={id}
|
|
150
|
+
role="combobox"
|
|
151
|
+
type="text"
|
|
152
|
+
autoComplete="off"
|
|
153
|
+
aria-autocomplete="list"
|
|
154
|
+
aria-expanded={shown}
|
|
155
|
+
aria-controls={listId}
|
|
156
|
+
aria-activedescendant={shown && active < count ? optionId(active) : undefined}
|
|
157
|
+
aria-describedby={describedBy}
|
|
158
|
+
placeholder={placeholder}
|
|
159
|
+
disabled={disabled}
|
|
160
|
+
value={query}
|
|
161
|
+
onChange={(event) => {
|
|
162
|
+
setQuery(event.target.value);
|
|
163
|
+
setActive(0);
|
|
164
|
+
setOpen(true);
|
|
165
|
+
}}
|
|
166
|
+
onFocus={() => setOpen(true)}
|
|
167
|
+
onClick={() => setOpen(true)}
|
|
168
|
+
onBlur={() => setOpen(false)}
|
|
169
|
+
onKeyDown={onKeyDown}
|
|
170
|
+
/>
|
|
171
|
+
<ul
|
|
172
|
+
id={listId}
|
|
173
|
+
role="listbox"
|
|
174
|
+
aria-multiselectable={single ? undefined : 'true'}
|
|
175
|
+
aria-label={placeholder ?? words.chosen}
|
|
176
|
+
hidden={!shown}
|
|
177
|
+
className="bg-popover text-popover-foreground absolute z-50 mt-1 max-h-60 w-full overflow-y-auto rounded-md border p-1 shadow-md"
|
|
178
|
+
>
|
|
179
|
+
{matches.length === 0 && (
|
|
180
|
+
<li role="presentation" className="text-muted-foreground px-2 py-1.5 text-sm">
|
|
181
|
+
{words.noMatches}
|
|
182
|
+
</li>
|
|
183
|
+
)}
|
|
184
|
+
{[...matches, ...(add ? [undefined] : [])].map((choice, index) => {
|
|
185
|
+
const selected = choice ? value.includes(choice.urn) : false;
|
|
186
|
+
return (
|
|
187
|
+
<li
|
|
188
|
+
key={choice?.urn ?? 'add'}
|
|
189
|
+
id={optionId(index)}
|
|
190
|
+
role="option"
|
|
191
|
+
aria-selected={selected}
|
|
192
|
+
className={cn(
|
|
193
|
+
'flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',
|
|
194
|
+
index === active && 'bg-accent text-accent-foreground',
|
|
195
|
+
)}
|
|
196
|
+
// Keeps focus in the box, so the list stays open for more picks.
|
|
197
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
198
|
+
onMouseMove={() => setActive(index)}
|
|
199
|
+
onClick={() => pick(index)}
|
|
200
|
+
>
|
|
201
|
+
{choice ? (
|
|
202
|
+
<>
|
|
203
|
+
<Check aria-hidden="true" className={cn('size-4 shrink-0', !selected && 'invisible')} />
|
|
204
|
+
<span>
|
|
205
|
+
{choice.name}
|
|
206
|
+
{choice.detail && (
|
|
207
|
+
<>
|
|
208
|
+
{' '}
|
|
209
|
+
<span className="text-muted-foreground">{choice.detail}</span>
|
|
210
|
+
</>
|
|
211
|
+
)}
|
|
212
|
+
</span>
|
|
213
|
+
</>
|
|
214
|
+
) : (
|
|
215
|
+
<>
|
|
216
|
+
<Plus aria-hidden="true" className="size-4 shrink-0" />
|
|
217
|
+
{add!.label}
|
|
218
|
+
</>
|
|
219
|
+
)}
|
|
220
|
+
</li>
|
|
221
|
+
);
|
|
222
|
+
})}
|
|
223
|
+
</ul>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
);
|
|
227
|
+
}
|
package/src/react/DealsBoard.tsx
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
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';
|
|
2
5
|
import { addMoney, type MoneyTotals } from '../money.ts';
|
|
3
6
|
import { dealCompany, dealOutcome, orderedStages } from '../pipeline.ts';
|
|
4
|
-
import type { Deal, Pipeline, PipelineStage } from '../types.ts';
|
|
7
|
+
import type { Deal, DealOutcome, Pipeline, PipelineStage } from '../types.ts';
|
|
8
|
+
import type { CrmChoice } from './Forms.tsx';
|
|
5
9
|
import { companyNameOf, formatDate, formatMaybeMoney, formatTotals, type CrmNames } from './format.ts';
|
|
6
10
|
import { OutcomeBadge, SampleDataBadge } from './parts.tsx';
|
|
7
11
|
import { recordItemId } from './SidePanel.tsx';
|
|
8
12
|
import { withText, type CrmText } from './text.ts';
|
|
13
|
+
import { Button } from './ui/button.tsx';
|
|
9
14
|
import { Card, CardContent, CardHeader, CardTitle } from './ui/card.tsx';
|
|
15
|
+
import { Input } from './ui/input.tsx';
|
|
16
|
+
import { Label } from './ui/label.tsx';
|
|
10
17
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select.tsx';
|
|
11
18
|
|
|
12
19
|
/** Picks the stage a deal is at; moving it is one choice, so it works from the keyboard as well as by pointer. */
|
|
@@ -50,9 +57,163 @@ export function StageSelect({
|
|
|
50
57
|
);
|
|
51
58
|
}
|
|
52
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
|
+
|
|
53
214
|
/**
|
|
54
|
-
* Deals as a board, one column per pipeline stage with its count and value
|
|
55
|
-
* its stage picker.
|
|
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.
|
|
56
217
|
*/
|
|
57
218
|
export function DealsBoard({
|
|
58
219
|
deals,
|
|
@@ -63,10 +224,13 @@ export function DealsBoard({
|
|
|
63
224
|
selected,
|
|
64
225
|
saving,
|
|
65
226
|
sample,
|
|
227
|
+
order = 'weighted',
|
|
66
228
|
text,
|
|
67
229
|
}: {
|
|
68
230
|
deals: readonly Deal[];
|
|
69
231
|
pipeline: Pipeline;
|
|
232
|
+
/** How each column's deals are ordered. */
|
|
233
|
+
order?: DealOrder | undefined;
|
|
70
234
|
names?: CrmNames | undefined;
|
|
71
235
|
onOpen?: ((deal: Deal) => void) | undefined;
|
|
72
236
|
onMove?: ((deal: Deal, stage: PipelineStage) => void) | undefined;
|
|
@@ -88,7 +252,10 @@ export function DealsBoard({
|
|
|
88
252
|
{/* Focusable, so the columns past the edge can be scrolled to from the keyboard. */}
|
|
89
253
|
<div tabIndex={0} aria-label={pipeline.name} className="flex gap-3 overflow-x-auto rounded-xl pb-2">
|
|
90
254
|
{orderedStages(pipeline).map((stage) => {
|
|
91
|
-
const here =
|
|
255
|
+
const here = sortDeals(
|
|
256
|
+
deals.filter((deal) => deal.workflowStage?.urn === stage.urn),
|
|
257
|
+
order,
|
|
258
|
+
);
|
|
92
259
|
const value = here.reduce<MoneyTotals>((totals, deal) => addMoney(totals, deal.targetValue), {});
|
|
93
260
|
return (
|
|
94
261
|
<section
|