@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
package/src/money.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Money } from './types.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Money in whole minor units (pence, cents), as the API writes it, so amounts add up exactly. Amounts in different
|
|
5
|
+
* currencies are never added together: totals are kept per currency. Decimal text is only for people: parse what they
|
|
6
|
+
* type with `toMinor`, and write amounts out with `toDecimal` or `formatMoney`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Totals per currency, in minor units: `{ GBP: 125000 }` is 1,250.00 GBP. */
|
|
10
|
+
export type MoneyTotals = Readonly<Record<string, number>>;
|
|
11
|
+
|
|
12
|
+
const digitsCache = new Map<string, number>();
|
|
13
|
+
|
|
14
|
+
/** How many decimal places a currency uses: 2 for GBP, 0 for JPY, 3 for KWD. */
|
|
15
|
+
export function fractionDigits(currencyCode: string): number {
|
|
16
|
+
let digits = digitsCache.get(currencyCode);
|
|
17
|
+
if (digits === undefined) {
|
|
18
|
+
try {
|
|
19
|
+
digits =
|
|
20
|
+
new Intl.NumberFormat('en', { style: 'currency', currency: currencyCode }).resolvedOptions()
|
|
21
|
+
.maximumFractionDigits ?? 2;
|
|
22
|
+
} catch {
|
|
23
|
+
digits = 2;
|
|
24
|
+
}
|
|
25
|
+
digitsCache.set(currencyCode, digits);
|
|
26
|
+
}
|
|
27
|
+
return digits;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DECIMAL = /^\s*([+-]?)(\d*)(?:\.(\d*))?\s*$/;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Decimal text, such as a person types it, in minor units, rounding half away from zero past the currency's decimal places. Throws on a value
|
|
34
|
+
* that isn't a plain decimal, such as `"1,250"` or `"abc"`.
|
|
35
|
+
*/
|
|
36
|
+
export function toMinor(amount: string, currencyCode: string): number {
|
|
37
|
+
const match = DECIMAL.exec(amount);
|
|
38
|
+
if (!match || (match[2] === '' && !match[3])) throw new RangeError(`Not a decimal amount: "${amount}"`);
|
|
39
|
+
const [, sign, whole = '', fraction = ''] = match;
|
|
40
|
+
const digits = fractionDigits(currencyCode);
|
|
41
|
+
let minor = Number(whole || '0') * 10 ** digits + Number(fraction.slice(0, digits).padEnd(digits, '0') || '0');
|
|
42
|
+
if (Number(fraction[digits] ?? '0') >= 5) minor += 1;
|
|
43
|
+
return sign === '-' ? -minor : minor;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Minor units as decimal text with the currency's decimal places: `toDecimal(125000, 'GBP')` is `"1250.00"`. */
|
|
47
|
+
export function toDecimal(minor: number, currencyCode: string): string {
|
|
48
|
+
const digits = fractionDigits(currencyCode);
|
|
49
|
+
const sign = minor < 0 ? '-' : '';
|
|
50
|
+
const units = String(Math.abs(Math.round(minor))).padStart(digits + 1, '0');
|
|
51
|
+
return sign + (digits === 0 ? units : `${units.slice(0, -digits)}.${units.slice(-digits)}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Minor units as Money, rounded to a whole unit. */
|
|
55
|
+
export const fromMinor = (minor: number, currencyCode: string): Money => ({
|
|
56
|
+
unitValue: Math.round(minor),
|
|
57
|
+
currencyCode,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
/** An amount's minor units, 0 when there's none: for the API's optional money fields (`paid`, `refunded`). */
|
|
61
|
+
export const minorOf = (money: Pick<Money, 'unitValue'> | null | undefined): number => money?.unitValue ?? 0;
|
|
62
|
+
|
|
63
|
+
/** Totals with `money` added (`times` scales it, such as -1 for a refund). Absent money adds nothing. */
|
|
64
|
+
export function addMoney(
|
|
65
|
+
totals: MoneyTotals,
|
|
66
|
+
money: Pick<Money, 'unitValue' | 'currencyCode'> | null | undefined,
|
|
67
|
+
times = 1,
|
|
68
|
+
): MoneyTotals {
|
|
69
|
+
if (!money) return totals;
|
|
70
|
+
return { ...totals, [money.currencyCode]: (totals[money.currencyCode] ?? 0) + money.unitValue * times };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The totals of a list of amounts, per currency. */
|
|
74
|
+
export function sumMoney(values: Iterable<Money | null | undefined>): MoneyTotals {
|
|
75
|
+
let totals: MoneyTotals = {};
|
|
76
|
+
for (const value of values) totals = addMoney(totals, value);
|
|
77
|
+
return totals;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Two sets of totals added together. */
|
|
81
|
+
export function addTotals(a: MoneyTotals, b: MoneyTotals): MoneyTotals {
|
|
82
|
+
const totals: Record<string, number> = { ...a };
|
|
83
|
+
for (const [currency, minor] of Object.entries(b)) totals[currency] = (totals[currency] ?? 0) + minor;
|
|
84
|
+
return totals;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Totals as Money, largest first, leaving out currencies that total zero. */
|
|
88
|
+
export function totalsToMoney(totals: MoneyTotals): Money[] {
|
|
89
|
+
return Object.entries(totals)
|
|
90
|
+
.filter(([, minor]) => minor !== 0)
|
|
91
|
+
.sort(([, a], [, b]) => b - a)
|
|
92
|
+
.map(([currency, minor]) => fromMinor(minor, currency));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The total in one currency, in minor units (0 when there's none). */
|
|
96
|
+
export const totalIn = (totals: MoneyTotals, currencyCode: string): number => totals[currencyCode] ?? 0;
|
|
97
|
+
|
|
98
|
+
/** Money for people to read, such as "GBP 1,250.00" written with its symbol. */
|
|
99
|
+
export function formatMoney(money: Money, locale = 'en-GB', options: Intl.NumberFormatOptions = {}): string {
|
|
100
|
+
const digits = fractionDigits(money.currencyCode);
|
|
101
|
+
return new Intl.NumberFormat(locale, { style: 'currency', currency: money.currencyCode, ...options }).format(
|
|
102
|
+
money.unitValue / 10 ** digits,
|
|
103
|
+
);
|
|
104
|
+
}
|
package/src/period.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parseTimestamp } from '@baack-software/baack-ts-tasks';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A span of time: from `start` (included) to `end` (excluded). `previous` is what it's compared with, when that isn't
|
|
5
|
+
* the same length of time just before it (see `previousRange`).
|
|
6
|
+
*/
|
|
7
|
+
export interface DateRange {
|
|
8
|
+
start: Date;
|
|
9
|
+
end: Date;
|
|
10
|
+
previous?: DateRange | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The `days` up to `now`, for "last 28 days" views. */
|
|
14
|
+
export function lastDays(days: number, now = new Date()): DateRange {
|
|
15
|
+
return { start: new Date(now.getTime() - days * 86_400_000), end: now };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** What `range` is compared with: its own `previous`, else the same length of time just before it. */
|
|
19
|
+
export function previousRange(range: DateRange): DateRange {
|
|
20
|
+
if (range.previous) return range.previous;
|
|
21
|
+
const length = range.end.getTime() - range.start.getTime();
|
|
22
|
+
return { start: new Date(range.start.getTime() - length), end: range.start };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Whether a Baack timestamp falls in a range. Empty or invalid timestamps don't. */
|
|
26
|
+
export function inRange(timestamp: string | null | undefined, range: DateRange): boolean {
|
|
27
|
+
const date = parseTimestamp(timestamp);
|
|
28
|
+
return date !== undefined && date >= range.start && date < range.end;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The change from `previous` to `current` as a fraction (0.1 is a 10% rise), or undefined when there was nothing
|
|
33
|
+
* before to compare with.
|
|
34
|
+
*/
|
|
35
|
+
export function periodChange(current: number, previous: number): number | undefined {
|
|
36
|
+
return previous === 0 ? undefined : (current - previous) / previous;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The reporting periods views offer: the last 30 days against the 30 before, or the calendar quarter or year so far
|
|
41
|
+
* against the same span of the one before. TODO: a company's own reporting year (most don't follow the calendar),
|
|
42
|
+
* once companies can record when theirs starts.
|
|
43
|
+
*/
|
|
44
|
+
export type ReportingPeriod = 'last30' | 'quarter' | 'year';
|
|
45
|
+
|
|
46
|
+
export const REPORTING_PERIODS: readonly ReportingPeriod[] = ['last30', 'quarter', 'year'];
|
|
47
|
+
|
|
48
|
+
/** The span so far of the period that started at `start`, against the same span from `before` (that period's start). */
|
|
49
|
+
function soFar(start: Date, before: Date, now: Date): DateRange {
|
|
50
|
+
const elapsed = now.getTime() - start.getTime();
|
|
51
|
+
return {
|
|
52
|
+
start,
|
|
53
|
+
end: now,
|
|
54
|
+
previous: { start: before, end: new Date(Math.min(before.getTime() + elapsed, start.getTime())) },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A reporting period's range at `now`, in UTC, with what it's compared with. */
|
|
59
|
+
export function periodRange(period: ReportingPeriod, now = new Date()): DateRange {
|
|
60
|
+
const year = now.getUTCFullYear();
|
|
61
|
+
switch (period) {
|
|
62
|
+
case 'last30':
|
|
63
|
+
return lastDays(30, now);
|
|
64
|
+
case 'quarter': {
|
|
65
|
+
const month = now.getUTCMonth() - (now.getUTCMonth() % 3);
|
|
66
|
+
return soFar(new Date(Date.UTC(year, month, 1)), new Date(Date.UTC(year, month - 3, 1)), now);
|
|
67
|
+
}
|
|
68
|
+
case 'year':
|
|
69
|
+
return soFar(new Date(Date.UTC(year, 0, 1)), new Date(Date.UTC(year - 1, 0, 1)), now);
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/pipeline.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { addMoney, type MoneyTotals } from './money.ts';
|
|
2
|
+
import type { Deal, DealOutcome, Pipeline, PipelineStage } from './types.ts';
|
|
3
|
+
|
|
4
|
+
/** A pipeline's stages in order. */
|
|
5
|
+
export const orderedStages = (pipeline: Pipeline): PipelineStage[] =>
|
|
6
|
+
pipeline.stages.toSorted((a, b) => a.order - b.order);
|
|
7
|
+
|
|
8
|
+
/** The stage a deal is at, when it's in this pipeline. */
|
|
9
|
+
export const stageOf = (deal: Deal, pipeline: Pipeline): PipelineStage | undefined =>
|
|
10
|
+
pipeline.stages.find((stage) => stage.urn === deal.workflowStage?.urn);
|
|
11
|
+
|
|
12
|
+
/** The pipeline a deal is in, among several. */
|
|
13
|
+
export const pipelineOf = (deal: Deal, pipelines: readonly Pipeline[]): Pipeline | undefined =>
|
|
14
|
+
pipelines.find((pipeline) => stageOf(deal, pipeline));
|
|
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
|
+
|
|
37
|
+
/** How a deal stands: its own outcome, open when it has none. */
|
|
38
|
+
export const dealOutcome = (deal: Deal): DealOutcome => deal.outcome ?? 'OPEN';
|
|
39
|
+
|
|
40
|
+
export const isOpenDeal = (deal: Deal): boolean => dealOutcome(deal) === 'OPEN';
|
|
41
|
+
|
|
42
|
+
/** A deal's customer company: its first contact company, when it has one. */
|
|
43
|
+
export const dealCompany = (deal: Pick<Deal, 'contactCompanies'>) => deal.contactCompanies?.[0];
|
|
44
|
+
|
|
45
|
+
/** Whether a deal is with a company: among its contact companies. */
|
|
46
|
+
export const isDealWith = (deal: Pick<Deal, 'contactCompanies'>, company: string): boolean =>
|
|
47
|
+
(deal.contactCompanies ?? []).some((other) => other.urn === company);
|
|
48
|
+
|
|
49
|
+
/** The chance a deal is won, 0 to 100: won is 100 and lost 0, otherwise the deal's own probability. */
|
|
50
|
+
export function dealProbability(deal: Deal): number | undefined {
|
|
51
|
+
const outcome = dealOutcome(deal);
|
|
52
|
+
if (outcome === 'WON') return 100;
|
|
53
|
+
if (outcome === 'LOST') return 0;
|
|
54
|
+
return deal.probability ?? undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface StageSummary {
|
|
58
|
+
stage: PipelineStage;
|
|
59
|
+
deals: Deal[];
|
|
60
|
+
/** The deals' target values per currency. */
|
|
61
|
+
value: MoneyTotals;
|
|
62
|
+
/** The values weighted by each deal's probability; deals without one aren't counted. */
|
|
63
|
+
weighted: MoneyTotals;
|
|
64
|
+
/** This stage's share of the pipeline's deals, 0 to 1. */
|
|
65
|
+
share: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** One row per stage, in order, for the pipeline card: its deals, their value, weighted value and share. */
|
|
69
|
+
export function pipelineByStage(deals: readonly Deal[], pipeline: Pipeline): StageSummary[] {
|
|
70
|
+
const inPipeline = deals.filter((deal) => stageOf(deal, pipeline));
|
|
71
|
+
return orderedStages(pipeline).map((stage) => {
|
|
72
|
+
const here = inPipeline.filter((deal) => deal.workflowStage?.urn === stage.urn);
|
|
73
|
+
let value: MoneyTotals = {};
|
|
74
|
+
let weighted: MoneyTotals = {};
|
|
75
|
+
for (const deal of here) {
|
|
76
|
+
value = addMoney(value, deal.targetValue);
|
|
77
|
+
const probability = dealProbability(deal);
|
|
78
|
+
if (probability !== undefined) weighted = addMoney(weighted, deal.targetValue, probability / 100);
|
|
79
|
+
}
|
|
80
|
+
return { stage, deals: here, value, weighted, share: inPipeline.length ? here.length / inPipeline.length : 0 };
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useId } from 'react';
|
|
2
|
+
import { Area, AreaChart, Bar, BarChart, CartesianGrid, XAxis, YAxis } from 'recharts';
|
|
3
|
+
import { SOURCE_LABELS, type SourceCount } from '../leads.ts';
|
|
4
|
+
import { formatMoney, fractionDigits, fromMinor, type MoneyTotals } from '../money.ts';
|
|
5
|
+
import { CrmCard } from './parts.tsx';
|
|
6
|
+
import { withText, type CrmText } from './text.ts';
|
|
7
|
+
import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from './ui/chart.tsx';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Charts as the Baack console draws them: shadcn's chart wrapper on Recharts, coloured by the theme's chart tokens.
|
|
11
|
+
* Each chart is hidden from screen readers, which get the same figures as a table.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const formatDay = (day: string) =>
|
|
15
|
+
new Date(`${day}T00:00:00Z`).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' });
|
|
16
|
+
|
|
17
|
+
/** Payments received each day, as an area like the console's usage chart. */
|
|
18
|
+
export function RevenueChart({
|
|
19
|
+
days,
|
|
20
|
+
currencyCode,
|
|
21
|
+
text,
|
|
22
|
+
}: {
|
|
23
|
+
days: { day: string; totals: MoneyTotals }[];
|
|
24
|
+
/** The currency charted; others aren't added in. */
|
|
25
|
+
currencyCode: string | undefined;
|
|
26
|
+
text?: Partial<CrmText> | undefined;
|
|
27
|
+
}) {
|
|
28
|
+
const words = withText(text);
|
|
29
|
+
const id = useId().replace(/:/g, '');
|
|
30
|
+
const currency = currencyCode ?? 'GBP';
|
|
31
|
+
const scale = 10 ** fractionDigits(currency);
|
|
32
|
+
const points = days.map(({ day, totals }) => ({ day, revenue: (totals[currency] ?? 0) / scale }));
|
|
33
|
+
const config = { revenue: { label: words.revenue, color: 'var(--chart-1)' } } satisfies ChartConfig;
|
|
34
|
+
const money = (value: number) => formatMoney(fromMinor(Math.round(value * scale), currency), 'en-GB');
|
|
35
|
+
const short = (value: number) =>
|
|
36
|
+
new Intl.NumberFormat('en-GB', { style: 'currency', currency, notation: 'compact' }).format(value);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<CrmCard title={words.revenueOverTime} description={words.revenueHint} text={text}>
|
|
40
|
+
<ChartContainer config={config} className="aspect-auto h-60 w-full" aria-hidden="true">
|
|
41
|
+
<AreaChart data={points} accessibilityLayer={false} margin={{ left: 0, right: 8 }}>
|
|
42
|
+
<defs>
|
|
43
|
+
<linearGradient id={`${id}-revenue`} x1="0" y1="0" x2="0" y2="1">
|
|
44
|
+
<stop offset="5%" stopColor="var(--color-revenue)" stopOpacity={0.8} />
|
|
45
|
+
<stop offset="95%" stopColor="var(--color-revenue)" stopOpacity={0.1} />
|
|
46
|
+
</linearGradient>
|
|
47
|
+
</defs>
|
|
48
|
+
<CartesianGrid vertical={false} />
|
|
49
|
+
<XAxis
|
|
50
|
+
dataKey="day"
|
|
51
|
+
tickLine={false}
|
|
52
|
+
axisLine={false}
|
|
53
|
+
tickMargin={8}
|
|
54
|
+
minTickGap={32}
|
|
55
|
+
tickFormatter={formatDay}
|
|
56
|
+
/>
|
|
57
|
+
<YAxis tickLine={false} axisLine={false} width={56} tickFormatter={short} />
|
|
58
|
+
<ChartTooltip
|
|
59
|
+
cursor={false}
|
|
60
|
+
content={
|
|
61
|
+
<ChartTooltipContent
|
|
62
|
+
labelFormatter={(value) => formatDay(String(value))}
|
|
63
|
+
formatter={(value) => money(Number(value))}
|
|
64
|
+
indicator="dot"
|
|
65
|
+
/>
|
|
66
|
+
}
|
|
67
|
+
/>
|
|
68
|
+
<Area
|
|
69
|
+
dataKey="revenue"
|
|
70
|
+
type="monotone"
|
|
71
|
+
fill={`url(#${id}-revenue)`}
|
|
72
|
+
stroke="var(--color-revenue)"
|
|
73
|
+
isAnimationActive={false}
|
|
74
|
+
/>
|
|
75
|
+
</AreaChart>
|
|
76
|
+
</ChartContainer>
|
|
77
|
+
{/* Tables ignore sr-only's 1px height, so the wrapper hides it. */}
|
|
78
|
+
<div className="sr-only">
|
|
79
|
+
<table>
|
|
80
|
+
<caption>{words.revenueOverTime}</caption>
|
|
81
|
+
<thead>
|
|
82
|
+
<tr>
|
|
83
|
+
<th scope="col">{words.date}</th>
|
|
84
|
+
<th scope="col">{words.revenue}</th>
|
|
85
|
+
</tr>
|
|
86
|
+
</thead>
|
|
87
|
+
<tbody>
|
|
88
|
+
{points
|
|
89
|
+
.filter((point) => point.revenue !== 0)
|
|
90
|
+
.map((point) => (
|
|
91
|
+
<tr key={point.day}>
|
|
92
|
+
<th scope="row">{formatDay(point.day)}</th>
|
|
93
|
+
<td>{money(point.revenue)}</td>
|
|
94
|
+
</tr>
|
|
95
|
+
))}
|
|
96
|
+
</tbody>
|
|
97
|
+
</table>
|
|
98
|
+
</div>
|
|
99
|
+
</CrmCard>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** How many leads came from each source, as a shadcn bar chart. */
|
|
104
|
+
export function LeadsBySourceCard({ counts, text }: { counts: SourceCount[]; text?: Partial<CrmText> | undefined }) {
|
|
105
|
+
const words = withText(text);
|
|
106
|
+
const total = counts.reduce((sum, row) => sum + row.count, 0);
|
|
107
|
+
const points = counts
|
|
108
|
+
.filter((row) => row.count > 0)
|
|
109
|
+
.map((row) => ({ source: SOURCE_LABELS[row.source], leads: row.count }));
|
|
110
|
+
const config = { leads: { label: words.leads, color: 'var(--chart-2)' } } satisfies ChartConfig;
|
|
111
|
+
return (
|
|
112
|
+
<CrmCard title={words.leadsBySource} description={`${total} ${words.leads.toLowerCase()}`} text={text}>
|
|
113
|
+
<ChartContainer config={config} className="aspect-auto h-60 w-full" aria-hidden="true">
|
|
114
|
+
<BarChart data={points} layout="vertical" accessibilityLayer={false} margin={{ left: 0, right: 8 }}>
|
|
115
|
+
<CartesianGrid horizontal={false} />
|
|
116
|
+
<YAxis dataKey="source" type="category" tickLine={false} axisLine={false} width={72} />
|
|
117
|
+
<XAxis type="number" dataKey="leads" allowDecimals={false} tickLine={false} axisLine={false} />
|
|
118
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent indicator="dot" />} />
|
|
119
|
+
<Bar dataKey="leads" fill="var(--color-leads)" radius={4} isAnimationActive={false} />
|
|
120
|
+
</BarChart>
|
|
121
|
+
</ChartContainer>
|
|
122
|
+
<div className="sr-only">
|
|
123
|
+
<table>
|
|
124
|
+
<caption>{words.leadsBySource}</caption>
|
|
125
|
+
<thead>
|
|
126
|
+
<tr>
|
|
127
|
+
<th scope="col">{words.source}</th>
|
|
128
|
+
<th scope="col">{words.leads}</th>
|
|
129
|
+
</tr>
|
|
130
|
+
</thead>
|
|
131
|
+
<tbody>
|
|
132
|
+
{points.map((point) => (
|
|
133
|
+
<tr key={point.source}>
|
|
134
|
+
<th scope="row">{point.source}</th>
|
|
135
|
+
<td>{point.leads}</td>
|
|
136
|
+
</tr>
|
|
137
|
+
))}
|
|
138
|
+
</tbody>
|
|
139
|
+
</table>
|
|
140
|
+
</div>
|
|
141
|
+
</CrmCard>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -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
|
+
}
|