@baack-software/baack-ts-crm 0.0.2 → 0.0.4
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 +18 -3
- 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 +22 -11
- 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/react/parts.tsx
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { FlaskConical, TrendingDown, TrendingUp } from 'lucide-react';
|
|
2
2
|
import { cn } from 'cn';
|
|
3
|
-
import type
|
|
3
|
+
import { useContext, useId, type ReactNode } from 'react';
|
|
4
4
|
import { INVOICE_STATUS_LABELS } from '../invoices.ts';
|
|
5
5
|
import { LEAD_STATE_LABELS, leadState, type LeadState } from '../leads.ts';
|
|
6
|
+
import { REPORTING_PERIODS, type ReportingPeriod } from '../period.ts';
|
|
6
7
|
import type { DealOutcome, InvoiceStatus, Lead } from '../types.ts';
|
|
7
8
|
import { formatChange } from './format.ts';
|
|
9
|
+
import { PanelClose, PanelCloseButton } from './SidePanel.tsx';
|
|
8
10
|
import { withText, type CrmText } from './text.ts';
|
|
9
11
|
import { Badge } from './ui/badge.tsx';
|
|
10
12
|
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from './ui/card.tsx';
|
|
13
|
+
import { Label } from './ui/label.tsx';
|
|
14
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select.tsx';
|
|
11
15
|
|
|
12
16
|
/** Marks a view or card whose records come from sample data, so nobody takes them for real ones. */
|
|
13
17
|
export function SampleDataBadge({ text }: { text?: Partial<CrmText> | undefined }) {
|
|
@@ -49,7 +53,8 @@ export function SampleDataNotice({
|
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
/**
|
|
52
|
-
* A titled card for the CRM views. `sample` adds the sample data badge; `action` sits at the top right.
|
|
56
|
+
* A titled card for the CRM views. `sample` adds the sample data badge; `action` sits at the top right. In a side
|
|
57
|
+
* panel, the panel's close button sits there too, in line with the title; cards inside this one don't repeat it.
|
|
53
58
|
*/
|
|
54
59
|
export function CrmCard({
|
|
55
60
|
title,
|
|
@@ -68,6 +73,7 @@ export function CrmCard({
|
|
|
68
73
|
className?: string;
|
|
69
74
|
children: ReactNode;
|
|
70
75
|
}) {
|
|
76
|
+
const inPanel = useContext(PanelClose) !== undefined;
|
|
71
77
|
return (
|
|
72
78
|
<Card className={className}>
|
|
73
79
|
<CardHeader>
|
|
@@ -75,14 +81,17 @@ export function CrmCard({
|
|
|
75
81
|
<h2 className="text-base font-semibold">{title}</h2>
|
|
76
82
|
</CardTitle>
|
|
77
83
|
{description && <CardDescription>{description}</CardDescription>}
|
|
78
|
-
{(sample || action) && (
|
|
84
|
+
{(sample || action || inPanel) && (
|
|
79
85
|
<CardAction className="flex items-center gap-2">
|
|
80
86
|
{sample && <SampleDataBadge text={text} />}
|
|
81
87
|
{action}
|
|
88
|
+
<PanelCloseButton />
|
|
82
89
|
</CardAction>
|
|
83
90
|
)}
|
|
84
91
|
</CardHeader>
|
|
85
|
-
<CardContent>
|
|
92
|
+
<CardContent>
|
|
93
|
+
<PanelClose.Provider value={undefined}>{children}</PanelClose.Provider>
|
|
94
|
+
</CardContent>
|
|
86
95
|
</Card>
|
|
87
96
|
);
|
|
88
97
|
}
|
|
@@ -129,3 +138,46 @@ export function InvoiceStatusBadge({ status, overdue }: { status: InvoiceStatus;
|
|
|
129
138
|
</Badge>
|
|
130
139
|
);
|
|
131
140
|
}
|
|
141
|
+
|
|
142
|
+
const PERIOD_WORDS: Record<ReportingPeriod, { label: keyof CrmText; versus: keyof CrmText }> = {
|
|
143
|
+
last30: { label: 'periodLast30', versus: 'vsPrevious30' },
|
|
144
|
+
quarter: { label: 'periodQuarter', versus: 'vsLastQuarter' },
|
|
145
|
+
year: { label: 'periodYear', versus: 'vsLastYear' },
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/** The words for figures in `period`: what each change is against. */
|
|
149
|
+
export const periodText = (period: ReportingPeriod, text?: Partial<CrmText>): Partial<CrmText> => ({
|
|
150
|
+
...text,
|
|
151
|
+
vsPrevious: withText(text)[PERIOD_WORDS[period].versus],
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
/** Picks the reporting period a view's figures are for. */
|
|
155
|
+
export function PeriodSelect({
|
|
156
|
+
value,
|
|
157
|
+
onChange,
|
|
158
|
+
text,
|
|
159
|
+
}: {
|
|
160
|
+
value: ReportingPeriod;
|
|
161
|
+
onChange: (period: ReportingPeriod) => void;
|
|
162
|
+
text?: Partial<CrmText> | undefined;
|
|
163
|
+
}) {
|
|
164
|
+
const words = withText(text);
|
|
165
|
+
const id = useId();
|
|
166
|
+
return (
|
|
167
|
+
<div className="flex items-center gap-2">
|
|
168
|
+
<Label htmlFor={id}>{words.period}</Label>
|
|
169
|
+
<Select value={value} onValueChange={(next) => onChange(next as ReportingPeriod)}>
|
|
170
|
+
<SelectTrigger id={id} className="w-40">
|
|
171
|
+
<SelectValue />
|
|
172
|
+
</SelectTrigger>
|
|
173
|
+
<SelectContent>
|
|
174
|
+
{REPORTING_PERIODS.map((period) => (
|
|
175
|
+
<SelectItem key={period} value={period}>
|
|
176
|
+
{words[PERIOD_WORDS[period].label]}
|
|
177
|
+
</SelectItem>
|
|
178
|
+
))}
|
|
179
|
+
</SelectContent>
|
|
180
|
+
</Select>
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { defaultPipeline } from '../pipeline.ts';
|
|
3
|
+
import type { Deal, Pipeline } from '../types.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What this user last chose in the deals, per company, kept in the browser: the workflow they work in (shared by the
|
|
7
|
+
* dashboard, converting leads and the deals board) and the board's order. One record, so each writer keeps the other's.
|
|
8
|
+
*/
|
|
9
|
+
export interface DealsMemory {
|
|
10
|
+
pipeline?: string | undefined;
|
|
11
|
+
order?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const memoryKey = (owner: string) => `baack-crm:deals-board:${owner}`;
|
|
15
|
+
|
|
16
|
+
export function recallDeals(owner: string): DealsMemory {
|
|
17
|
+
try {
|
|
18
|
+
const saved = JSON.parse(localStorage.getItem(memoryKey(owner)) ?? '{}') as { pipeline?: unknown; order?: unknown };
|
|
19
|
+
return {
|
|
20
|
+
pipeline: typeof saved.pipeline === 'string' ? saved.pipeline : undefined,
|
|
21
|
+
order: typeof saved.order === 'string' ? saved.order : undefined,
|
|
22
|
+
};
|
|
23
|
+
} catch {
|
|
24
|
+
// No storage (private browsing, blocked, or no browser): start afresh.
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Keeps `changes`, merged into what's stored, so a change to one field never puts back an old value of another. */
|
|
30
|
+
export function rememberDeals(owner: string, changes: DealsMemory): void {
|
|
31
|
+
try {
|
|
32
|
+
localStorage.setItem(memoryKey(owner), JSON.stringify({ ...recallDeals(owner), ...changes }));
|
|
33
|
+
} catch {
|
|
34
|
+
// Not kept; the views still work.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The pipeline this user works in, for the company `owner`: the one they last chose (their team may work in a
|
|
40
|
+
* different workflow from other users'), else the default (`defaultPipeline`: the workflow with the most deals).
|
|
41
|
+
* Choosing one remembers it.
|
|
42
|
+
*/
|
|
43
|
+
export function usePipeline(
|
|
44
|
+
owner: string,
|
|
45
|
+
pipelines: readonly Pipeline[],
|
|
46
|
+
deals: readonly Deal[],
|
|
47
|
+
): [Pipeline | undefined, (urn: string) => void] {
|
|
48
|
+
const [chosen, setChosen] = useState(() => recallDeals(owner).pipeline);
|
|
49
|
+
const choose = (urn: string) => {
|
|
50
|
+
setChosen(urn);
|
|
51
|
+
rememberDeals(owner, { pipeline: urn });
|
|
52
|
+
};
|
|
53
|
+
return [defaultPipeline(pipelines, deals, chosen), choose];
|
|
54
|
+
}
|
package/src/react/text.ts
CHANGED
|
@@ -9,6 +9,9 @@ export const CRM_TEXT = {
|
|
|
9
9
|
loading: 'Loading',
|
|
10
10
|
noChange: 'No earlier figures',
|
|
11
11
|
vsPrevious: 'vs previous period',
|
|
12
|
+
vsPrevious30: 'vs the 30 days before',
|
|
13
|
+
vsLastQuarter: 'vs the same time last quarter',
|
|
14
|
+
vsLastYear: 'vs the same time last year',
|
|
12
15
|
customers: 'Customers',
|
|
13
16
|
customersHint: 'Companies with a won deal',
|
|
14
17
|
openDeals: 'Open deals',
|
|
@@ -22,6 +25,7 @@ export const CRM_TEXT = {
|
|
|
22
25
|
leadsBySource: 'Leads by source',
|
|
23
26
|
pipeline: 'Sales pipeline',
|
|
24
27
|
stage: 'Stage',
|
|
28
|
+
workflow: 'Workflow',
|
|
25
29
|
deals: 'Deals',
|
|
26
30
|
value: 'Value',
|
|
27
31
|
weighted: 'Weighted',
|
|
@@ -112,8 +116,31 @@ export const CRM_TEXT = {
|
|
|
112
116
|
title: 'Title',
|
|
113
117
|
titleRequired: 'Enter a title.',
|
|
114
118
|
noCompany: 'No company',
|
|
115
|
-
newCompany: '
|
|
116
|
-
newCompanyHint: 'Makes the company, owned by yours
|
|
119
|
+
newCompany: 'New company',
|
|
120
|
+
newCompanyHint: 'Makes the client company, owned by yours, when the lead is saved.',
|
|
121
|
+
addCompany: 'Add a new company',
|
|
122
|
+
companyNameRequired: 'Enter the company name.',
|
|
123
|
+
noContact: 'No contact',
|
|
124
|
+
newContact: 'New contact',
|
|
125
|
+
newContactHint:
|
|
126
|
+
"Makes a person owned by your company when the lead is saved, linked to the lead's company when it has one.",
|
|
127
|
+
addContact: 'Add a new person',
|
|
128
|
+
addPerson: 'Add a person',
|
|
129
|
+
givenName: 'Given name',
|
|
130
|
+
familyName: 'Family name',
|
|
131
|
+
email: 'Email',
|
|
132
|
+
givenNameRequired: 'Enter a given name.',
|
|
133
|
+
telephone: 'Telephone',
|
|
134
|
+
contactDetails: "Contact's details",
|
|
135
|
+
contactEmail: "Contact's email",
|
|
136
|
+
contactTelephone: "Contact's telephone",
|
|
137
|
+
contactDetailsUnavailable: "The contact's email and telephone couldn't be read.",
|
|
138
|
+
unassigned: 'Unassigned',
|
|
139
|
+
toBeCreated: 'new',
|
|
140
|
+
useThis: 'Use this',
|
|
141
|
+
saving: 'Saving',
|
|
142
|
+
back: 'Back',
|
|
143
|
+
saveFailed: "The change couldn't be saved.",
|
|
117
144
|
createLead: 'Create lead',
|
|
118
145
|
createDeal: 'Create deal',
|
|
119
146
|
createInvoice: 'Create invoice',
|
|
@@ -133,9 +160,70 @@ export const CRM_TEXT = {
|
|
|
133
160
|
subTotal: 'Subtotal',
|
|
134
161
|
tax: 'Tax',
|
|
135
162
|
customerRequired: 'Choose the customer.',
|
|
163
|
+
amountAs: 'Amount as',
|
|
164
|
+
amountAsLines: 'Line items',
|
|
165
|
+
amountAsTotal: 'A total',
|
|
166
|
+
totalWithTax: 'Total, including tax',
|
|
167
|
+
totalHint: 'The subtotal and tax are worked out from it at the tax rate.',
|
|
168
|
+
totalRequired: 'Enter the total, above zero, such as 1,200.00.',
|
|
136
169
|
linesRequired: 'Give each line a description, a quantity and a unit price above zero.',
|
|
137
170
|
invalidRate: 'Enter a tax rate from 0 to 100.',
|
|
138
171
|
invalidProbability: 'Enter a probability from 0 to 100.',
|
|
172
|
+
companies: 'Companies',
|
|
173
|
+
contacts: 'Contacts',
|
|
174
|
+
searchCompanies: 'Search companies by name',
|
|
175
|
+
searchContacts: 'Search people by name, email or telephone',
|
|
176
|
+
chosen: 'Chosen',
|
|
177
|
+
remove: 'Remove',
|
|
178
|
+
noMatches: 'No matches.',
|
|
179
|
+
filterDeals: 'Filter deals',
|
|
180
|
+
allOutcomes: 'All outcomes',
|
|
181
|
+
anyone: 'Anyone',
|
|
182
|
+
allCompanies: 'All companies',
|
|
183
|
+
clearFilters: 'Clear filters',
|
|
184
|
+
sortBy: 'Sort by',
|
|
185
|
+
orderWeighted: 'Weighted',
|
|
186
|
+
orderSize: 'Deal size',
|
|
187
|
+
orderUrgency: 'Urgency',
|
|
188
|
+
dealsShown: 'deals shown',
|
|
189
|
+
remitter: 'Remitter: who pays',
|
|
190
|
+
remitterCompany: 'Company that pays',
|
|
191
|
+
remitterPerson: 'Person who pays',
|
|
192
|
+
recipient: 'Recipient: who is paid',
|
|
193
|
+
recipientCompany: 'Company paid',
|
|
194
|
+
recipientPerson: 'Person who is paid',
|
|
195
|
+
recipientHint: 'Usually your company, or one of its companies; another company for an invoice you pay.',
|
|
196
|
+
remitterRequired: 'Choose the company or person who pays.',
|
|
197
|
+
recipientRequired: 'Choose the company or person who is paid.',
|
|
198
|
+
searchPeople: 'Search people by name, email or telephone',
|
|
199
|
+
noPerson: 'No person',
|
|
200
|
+
line: 'Line',
|
|
201
|
+
lineDetails: 'All fields',
|
|
202
|
+
itemCode: 'Item code',
|
|
203
|
+
discountRate: 'Discount (%)',
|
|
204
|
+
taxability: 'Tax treatment',
|
|
205
|
+
taxName: 'Tax name',
|
|
206
|
+
price: 'Price',
|
|
207
|
+
done: 'Done',
|
|
208
|
+
invalidDiscount: 'Enter a discount from 0 to 100.',
|
|
209
|
+
costs: 'Costs',
|
|
210
|
+
costsHint: 'Invoices you pay, issued in the period',
|
|
211
|
+
toPay: 'To pay',
|
|
212
|
+
party: 'Customer or supplier',
|
|
213
|
+
paidBy: 'Paid by',
|
|
214
|
+
paidTo: 'Paid to',
|
|
215
|
+
allKinds: 'Sales and costs',
|
|
216
|
+
salesOnly: 'Sales',
|
|
217
|
+
costsOnly: 'Costs',
|
|
218
|
+
cost: 'Cost',
|
|
219
|
+
drafts: 'Drafts',
|
|
220
|
+
draftsHint: 'Not yet sent, so not counted above',
|
|
221
|
+
draftInvoice: 'draft invoice',
|
|
222
|
+
draftInvoices: 'draft invoices',
|
|
223
|
+
period: 'Period',
|
|
224
|
+
periodLast30: 'Last 30 days',
|
|
225
|
+
periodQuarter: 'This quarter',
|
|
226
|
+
periodYear: 'This year',
|
|
139
227
|
} as const;
|
|
140
228
|
|
|
141
229
|
export type CrmText = { readonly [K in keyof typeof CRM_TEXT]: string };
|