@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,198 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { CompanyAccount } from '../account.ts';
|
|
3
|
+
import { isOverdueInvoice, outstanding } from '../invoices.ts';
|
|
4
|
+
import { dealOutcome, stageOf } from '../pipeline.ts';
|
|
5
|
+
import type { Deal, Invoice, Lead, Pipeline } from '../types.ts';
|
|
6
|
+
import { enumLabel, formatDate, formatMaybeMoney, formatTotals } from './format.ts';
|
|
7
|
+
import { CrmCard, InvoiceStatusBadge, LeadStatusBadge, OutcomeBadge } from './parts.tsx';
|
|
8
|
+
import { withText, type CrmText } from './text.ts';
|
|
9
|
+
import { Card, CardDescription, CardHeader, CardTitle } from './ui/card.tsx';
|
|
10
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from './ui/table.tsx';
|
|
11
|
+
|
|
12
|
+
function Figure({ label, value, emphasis }: { label: string; value: string; emphasis?: boolean }) {
|
|
13
|
+
return (
|
|
14
|
+
<Card size="sm">
|
|
15
|
+
<CardHeader>
|
|
16
|
+
<CardDescription>
|
|
17
|
+
<h3>{label}</h3>
|
|
18
|
+
</CardDescription>
|
|
19
|
+
<CardTitle>
|
|
20
|
+
<span className={emphasis ? 'text-destructive text-xl tabular-nums' : 'text-xl tabular-nums'}>{value}</span>
|
|
21
|
+
</CardTitle>
|
|
22
|
+
</CardHeader>
|
|
23
|
+
</Card>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* One customer company's account: its figures (open and won deals, outstanding, overdue, received), deals, open
|
|
29
|
+
* leads, invoices and payments. `people` and `tasks` are the host's own panels (from the identity search and
|
|
30
|
+
* baack-ts-tasks), placed beside the CRM's.
|
|
31
|
+
*/
|
|
32
|
+
export function CompanyAccountView({
|
|
33
|
+
account,
|
|
34
|
+
pipelines,
|
|
35
|
+
onOpenDeal,
|
|
36
|
+
onOpenLead,
|
|
37
|
+
people,
|
|
38
|
+
tasks,
|
|
39
|
+
sample,
|
|
40
|
+
now = new Date(),
|
|
41
|
+
text,
|
|
42
|
+
}: {
|
|
43
|
+
account: CompanyAccount;
|
|
44
|
+
pipelines: readonly Pipeline[];
|
|
45
|
+
onOpenDeal?: ((deal: Deal) => void) | undefined;
|
|
46
|
+
onOpenLead?: ((lead: Lead) => void) | undefined;
|
|
47
|
+
people?: ReactNode;
|
|
48
|
+
tasks?: ReactNode;
|
|
49
|
+
sample?: boolean | undefined;
|
|
50
|
+
now?: Date;
|
|
51
|
+
text?: Partial<CrmText> | undefined;
|
|
52
|
+
}) {
|
|
53
|
+
const words = withText(text);
|
|
54
|
+
const overdue = Object.values(account.overdue).some((minor) => minor > 0);
|
|
55
|
+
const opener = <T extends { title: string }>(record: T, open?: (record: T) => void) =>
|
|
56
|
+
open ? (
|
|
57
|
+
<button type="button" className="text-left font-medium hover:underline" onClick={() => open(record)}>
|
|
58
|
+
{record.title}
|
|
59
|
+
</button>
|
|
60
|
+
) : (
|
|
61
|
+
<span className="font-medium">{record.title}</span>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div className="grid gap-6">
|
|
66
|
+
<section aria-label={words.account} className="grid gap-4 sm:grid-cols-2 xl:grid-cols-5">
|
|
67
|
+
<Figure label={words.openValue} value={formatTotals(account.openValue)} />
|
|
68
|
+
<Figure label={words.wonValue} value={formatTotals(account.wonValue)} />
|
|
69
|
+
<Figure label={words.outstanding} value={formatTotals(account.outstanding)} />
|
|
70
|
+
<Figure label={words.overdue} value={formatTotals(account.overdue)} emphasis={overdue} />
|
|
71
|
+
<Figure label={words.received} value={formatTotals(account.received)} />
|
|
72
|
+
</section>
|
|
73
|
+
|
|
74
|
+
<div className="grid items-start gap-6 lg:grid-cols-2">
|
|
75
|
+
<CrmCard title={words.deals} sample={sample} text={text}>
|
|
76
|
+
{account.deals.length === 0 ? (
|
|
77
|
+
<p className="text-muted-foreground text-sm">{words.noDeals}</p>
|
|
78
|
+
) : (
|
|
79
|
+
<Table>
|
|
80
|
+
<caption className="sr-only">{words.deals}</caption>
|
|
81
|
+
<TableHeader>
|
|
82
|
+
<TableRow>
|
|
83
|
+
<TableHead>{words.deals}</TableHead>
|
|
84
|
+
<TableHead>{words.stage}</TableHead>
|
|
85
|
+
<TableHead className="text-right">{words.value}</TableHead>
|
|
86
|
+
</TableRow>
|
|
87
|
+
</TableHeader>
|
|
88
|
+
<TableBody>
|
|
89
|
+
{account.deals.map((deal) => {
|
|
90
|
+
const pipeline = pipelines.find((candidate) => stageOf(deal, candidate));
|
|
91
|
+
const stage = pipeline && stageOf(deal, pipeline);
|
|
92
|
+
return (
|
|
93
|
+
<TableRow key={deal.urn}>
|
|
94
|
+
<TableCell className="whitespace-normal">{opener(deal, onOpenDeal)}</TableCell>
|
|
95
|
+
<TableCell>
|
|
96
|
+
<OutcomeBadge outcome={dealOutcome(deal)} label={stage?.name ?? '-'} />
|
|
97
|
+
</TableCell>
|
|
98
|
+
<TableCell className="text-right tabular-nums">{formatMaybeMoney(deal.targetValue)}</TableCell>
|
|
99
|
+
</TableRow>
|
|
100
|
+
);
|
|
101
|
+
})}
|
|
102
|
+
</TableBody>
|
|
103
|
+
</Table>
|
|
104
|
+
)}
|
|
105
|
+
</CrmCard>
|
|
106
|
+
|
|
107
|
+
<CrmCard title={words.openLeads} sample={sample} text={text}>
|
|
108
|
+
{account.openLeads.length === 0 ? (
|
|
109
|
+
<p className="text-muted-foreground text-sm">{words.none}</p>
|
|
110
|
+
) : (
|
|
111
|
+
<ul className="grid gap-2 text-sm">
|
|
112
|
+
{account.openLeads.map((lead) => (
|
|
113
|
+
<li key={lead.urn} className="flex items-center justify-between gap-2">
|
|
114
|
+
{opener(lead, onOpenLead)}
|
|
115
|
+
<LeadStatusBadge lead={lead} />
|
|
116
|
+
</li>
|
|
117
|
+
))}
|
|
118
|
+
</ul>
|
|
119
|
+
)}
|
|
120
|
+
</CrmCard>
|
|
121
|
+
|
|
122
|
+
{people && <div>{people}</div>}
|
|
123
|
+
{tasks && <div>{tasks}</div>}
|
|
124
|
+
|
|
125
|
+
<CrmCard title={words.invoices} sample={sample} text={text} className="lg:col-span-2">
|
|
126
|
+
{account.invoices.length === 0 ? (
|
|
127
|
+
<p className="text-muted-foreground text-sm">{words.noInvoices}</p>
|
|
128
|
+
) : (
|
|
129
|
+
<Table>
|
|
130
|
+
<caption className="sr-only">{words.invoices}</caption>
|
|
131
|
+
<TableHeader>
|
|
132
|
+
<TableRow>
|
|
133
|
+
<TableHead>{words.invoice}</TableHead>
|
|
134
|
+
<TableHead>{words.status}</TableHead>
|
|
135
|
+
<TableHead className="text-right">{words.total}</TableHead>
|
|
136
|
+
<TableHead className="text-right">{words.outstanding}</TableHead>
|
|
137
|
+
<TableHead>{words.due}</TableHead>
|
|
138
|
+
</TableRow>
|
|
139
|
+
</TableHeader>
|
|
140
|
+
<TableBody>
|
|
141
|
+
{account.invoices.map((invoice: Invoice) => (
|
|
142
|
+
<TableRow key={invoice.urn}>
|
|
143
|
+
<TableCell className="whitespace-normal">
|
|
144
|
+
{invoice.lines?.[0]?.description ?? invoice.urn.slice(-6)}
|
|
145
|
+
</TableCell>
|
|
146
|
+
<TableCell>
|
|
147
|
+
<InvoiceStatusBadge status={invoice.status} overdue={isOverdueInvoice(invoice, now)} />
|
|
148
|
+
</TableCell>
|
|
149
|
+
<TableCell className="text-right tabular-nums">
|
|
150
|
+
{formatMaybeMoney(invoice.total)}
|
|
151
|
+
</TableCell>
|
|
152
|
+
<TableCell className="text-right tabular-nums">{formatMaybeMoney(outstanding(invoice))}</TableCell>
|
|
153
|
+
<TableCell>{formatDate(invoice.dueTimestamp)}</TableCell>
|
|
154
|
+
</TableRow>
|
|
155
|
+
))}
|
|
156
|
+
</TableBody>
|
|
157
|
+
</Table>
|
|
158
|
+
)}
|
|
159
|
+
</CrmCard>
|
|
160
|
+
|
|
161
|
+
<CrmCard title={words.payments} sample={sample} text={text} className="lg:col-span-2">
|
|
162
|
+
{account.payments.length === 0 ? (
|
|
163
|
+
<p className="text-muted-foreground text-sm">{words.noPayments}</p>
|
|
164
|
+
) : (
|
|
165
|
+
<Table>
|
|
166
|
+
<caption className="sr-only">{words.payments}</caption>
|
|
167
|
+
<TableHeader>
|
|
168
|
+
<TableRow>
|
|
169
|
+
<TableHead>{words.date}</TableHead>
|
|
170
|
+
<TableHead>{words.method}</TableHead>
|
|
171
|
+
<TableHead>{words.reference}</TableHead>
|
|
172
|
+
<TableHead>{words.status}</TableHead>
|
|
173
|
+
<TableHead className="text-right">{words.amount}</TableHead>
|
|
174
|
+
</TableRow>
|
|
175
|
+
</TableHeader>
|
|
176
|
+
<TableBody>
|
|
177
|
+
{account.payments.map((payment) => (
|
|
178
|
+
<TableRow key={payment.urn}>
|
|
179
|
+
<TableCell>{formatDate(payment.receivedTimestamp)}</TableCell>
|
|
180
|
+
<TableCell>{enumLabel(payment.remittanceMethod)}</TableCell>
|
|
181
|
+
<TableCell>{payment.reference ?? '-'}</TableCell>
|
|
182
|
+
<TableCell>
|
|
183
|
+
{enumLabel(payment.remittanceDirection)}, {enumLabel(payment.remittanceStatus).toLowerCase()}
|
|
184
|
+
</TableCell>
|
|
185
|
+
<TableCell className="text-right tabular-nums">
|
|
186
|
+
{payment.remittanceDirection === 'REFUND' ? '-' : ''}
|
|
187
|
+
{formatMaybeMoney(payment.value)}
|
|
188
|
+
</TableCell>
|
|
189
|
+
</TableRow>
|
|
190
|
+
))}
|
|
191
|
+
</TableBody>
|
|
192
|
+
</Table>
|
|
193
|
+
)}
|
|
194
|
+
</CrmCard>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { useId } from 'react';
|
|
2
|
+
import { fromMinor, formatMoney } from '../money.ts';
|
|
3
|
+
import type { StageSummary } from '../pipeline.ts';
|
|
4
|
+
import type { Dashboard } from '../store.ts';
|
|
5
|
+
import type { SalesTarget } from '../target.ts';
|
|
6
|
+
import { formatPercent, formatTotals } from './format.ts';
|
|
7
|
+
import { ChangeIndicator, CrmCard, SampleDataBadge } from './parts.tsx';
|
|
8
|
+
import { withText, type CrmText } from './text.ts';
|
|
9
|
+
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from './ui/card.tsx';
|
|
10
|
+
import { Progress } from './ui/progress.tsx';
|
|
11
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from './ui/table.tsx';
|
|
12
|
+
|
|
13
|
+
/** One figure with its change against the previous period. */
|
|
14
|
+
export function MetricCard({
|
|
15
|
+
label,
|
|
16
|
+
value,
|
|
17
|
+
change,
|
|
18
|
+
hint,
|
|
19
|
+
sample,
|
|
20
|
+
text,
|
|
21
|
+
}: {
|
|
22
|
+
label: string;
|
|
23
|
+
value: string;
|
|
24
|
+
change: number | undefined;
|
|
25
|
+
hint?: string;
|
|
26
|
+
sample?: boolean | undefined;
|
|
27
|
+
text?: Partial<CrmText> | undefined;
|
|
28
|
+
}) {
|
|
29
|
+
return (
|
|
30
|
+
<Card size="sm">
|
|
31
|
+
<CardHeader>
|
|
32
|
+
<CardDescription>
|
|
33
|
+
<h2>{label}</h2>
|
|
34
|
+
</CardDescription>
|
|
35
|
+
<CardTitle>
|
|
36
|
+
<span className="text-2xl font-semibold tabular-nums">{value}</span>
|
|
37
|
+
</CardTitle>
|
|
38
|
+
{sample && (
|
|
39
|
+
<CardAction>
|
|
40
|
+
<SampleDataBadge text={text} />
|
|
41
|
+
</CardAction>
|
|
42
|
+
)}
|
|
43
|
+
</CardHeader>
|
|
44
|
+
<CardContent className="grid gap-1">
|
|
45
|
+
<ChangeIndicator change={change} text={text} />
|
|
46
|
+
{hint && <p className="text-muted-foreground text-xs">{hint}</p>}
|
|
47
|
+
</CardContent>
|
|
48
|
+
</Card>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The dashboard's four figures: customers, open deals, revenue and new leads, each against the period before. */
|
|
53
|
+
export function MetricCards({
|
|
54
|
+
dashboard,
|
|
55
|
+
sample,
|
|
56
|
+
text,
|
|
57
|
+
}: {
|
|
58
|
+
dashboard: Dashboard;
|
|
59
|
+
sample?: boolean | undefined;
|
|
60
|
+
text?: Partial<CrmText> | undefined;
|
|
61
|
+
}) {
|
|
62
|
+
const words = withText(text);
|
|
63
|
+
const { customers, openDeals, revenue, newLeads } = dashboard;
|
|
64
|
+
const shared = { sample, text };
|
|
65
|
+
return (
|
|
66
|
+
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
|
67
|
+
<MetricCard
|
|
68
|
+
label={words.customers}
|
|
69
|
+
value={String(customers.total)}
|
|
70
|
+
change={customers.added.change}
|
|
71
|
+
hint={words.customersHint}
|
|
72
|
+
{...shared}
|
|
73
|
+
/>
|
|
74
|
+
<MetricCard
|
|
75
|
+
label={words.openDeals}
|
|
76
|
+
value={String(openDeals.count)}
|
|
77
|
+
change={openDeals.created.change}
|
|
78
|
+
hint={formatTotals(openDeals.value)}
|
|
79
|
+
{...shared}
|
|
80
|
+
/>
|
|
81
|
+
<MetricCard
|
|
82
|
+
label={words.revenue}
|
|
83
|
+
value={formatTotals(revenue.current, revenue.currencyCode)}
|
|
84
|
+
change={revenue.change}
|
|
85
|
+
hint={words.revenueHint}
|
|
86
|
+
{...shared}
|
|
87
|
+
/>
|
|
88
|
+
<MetricCard label={words.newLeads} value={String(newLeads.current)} change={newLeads.change} {...shared} />
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Progress towards the sales target, one bar per currency. */
|
|
94
|
+
export function TargetCard({
|
|
95
|
+
target,
|
|
96
|
+
sample,
|
|
97
|
+
text,
|
|
98
|
+
}: {
|
|
99
|
+
target: SalesTarget;
|
|
100
|
+
sample?: boolean | undefined;
|
|
101
|
+
text?: Partial<CrmText> | undefined;
|
|
102
|
+
}) {
|
|
103
|
+
const words = withText(text);
|
|
104
|
+
const id = useId();
|
|
105
|
+
const currencies = Object.keys(target.progress);
|
|
106
|
+
return (
|
|
107
|
+
<CrmCard title={words.target} description={words.targetSummary} sample={sample} text={text}>
|
|
108
|
+
{currencies.length === 0 ? (
|
|
109
|
+
<p className="text-muted-foreground text-sm">{words.none}</p>
|
|
110
|
+
) : (
|
|
111
|
+
<ul className="grid gap-4">
|
|
112
|
+
{currencies.map((currency) => {
|
|
113
|
+
const progress = target.progress[currency] ?? 0;
|
|
114
|
+
const received = formatMoney(fromMinor(target.received[currency] ?? 0, currency));
|
|
115
|
+
const goal = formatMoney(fromMinor(target.target[currency] ?? 0, currency));
|
|
116
|
+
return (
|
|
117
|
+
<li key={currency} className="grid gap-2">
|
|
118
|
+
<p className="flex items-baseline justify-between gap-2">
|
|
119
|
+
<span className="text-2xl font-semibold tabular-nums">{formatPercent(progress)}</span>
|
|
120
|
+
<span id={`${id}-${currency}`} className="text-muted-foreground text-sm">
|
|
121
|
+
{received} {words.targetReceived} {goal}
|
|
122
|
+
</span>
|
|
123
|
+
</p>
|
|
124
|
+
<Progress value={Math.min(100, progress * 100)} aria-labelledby={`${id}-${currency}`} />
|
|
125
|
+
</li>
|
|
126
|
+
);
|
|
127
|
+
})}
|
|
128
|
+
</ul>
|
|
129
|
+
)}
|
|
130
|
+
</CrmCard>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The pipeline by stage: deals, value, weighted value and share. */
|
|
135
|
+
export function PipelineCard({
|
|
136
|
+
stages,
|
|
137
|
+
sample,
|
|
138
|
+
text,
|
|
139
|
+
}: {
|
|
140
|
+
stages: StageSummary[];
|
|
141
|
+
sample?: boolean | undefined;
|
|
142
|
+
text?: Partial<CrmText> | undefined;
|
|
143
|
+
}) {
|
|
144
|
+
const words = withText(text);
|
|
145
|
+
return (
|
|
146
|
+
<CrmCard title={words.pipeline} sample={sample} text={text}>
|
|
147
|
+
<Table>
|
|
148
|
+
<TableHeader>
|
|
149
|
+
<TableRow>
|
|
150
|
+
<TableHead>{words.stage}</TableHead>
|
|
151
|
+
<TableHead className="text-right">{words.deals}</TableHead>
|
|
152
|
+
<TableHead className="text-right">{words.value}</TableHead>
|
|
153
|
+
<TableHead className="text-right">{words.weighted}</TableHead>
|
|
154
|
+
<TableHead className="text-right">{words.share}</TableHead>
|
|
155
|
+
</TableRow>
|
|
156
|
+
</TableHeader>
|
|
157
|
+
<TableBody>
|
|
158
|
+
{stages.map((row) => (
|
|
159
|
+
<TableRow key={row.stage.urn}>
|
|
160
|
+
<TableCell className="font-medium">{row.stage.name}</TableCell>
|
|
161
|
+
<TableCell className="text-right tabular-nums">{row.deals.length}</TableCell>
|
|
162
|
+
<TableCell className="text-right tabular-nums">{formatTotals(row.value)}</TableCell>
|
|
163
|
+
<TableCell className="text-right tabular-nums">{formatTotals(row.weighted)}</TableCell>
|
|
164
|
+
<TableCell className="text-right tabular-nums">{formatPercent(row.share)}</TableCell>
|
|
165
|
+
</TableRow>
|
|
166
|
+
))}
|
|
167
|
+
</TableBody>
|
|
168
|
+
</Table>
|
|
169
|
+
</CrmCard>
|
|
170
|
+
);
|
|
171
|
+
}
|