@contractspec/example.crm-pipeline 1.57.0 → 1.59.0
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/.turbo/turbo-build.log +148 -164
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +39 -0
- package/dist/browser/crm-pipeline.feature.js +75 -0
- package/dist/browser/deal/deal.enum.js +18 -0
- package/dist/browser/deal/deal.operation.js +396 -0
- package/dist/browser/deal/deal.schema.js +141 -0
- package/dist/browser/deal/deal.test-spec.js +58 -0
- package/dist/browser/deal/index.js +408 -0
- package/dist/browser/docs/crm-pipeline.docblock.js +113 -0
- package/dist/browser/docs/index.js +113 -0
- package/dist/browser/entities/company.entity.js +52 -0
- package/dist/browser/entities/contact.entity.js +66 -0
- package/dist/browser/entities/deal.entity.js +107 -0
- package/dist/browser/entities/index.js +343 -0
- package/dist/browser/entities/task.entity.js +99 -0
- package/dist/browser/events/contact.event.js +31 -0
- package/dist/browser/events/deal.event.js +101 -0
- package/dist/browser/events/index.js +158 -0
- package/dist/browser/events/task.event.js +28 -0
- package/dist/browser/example.js +39 -0
- package/dist/browser/handlers/crm.handlers.js +160 -0
- package/dist/browser/handlers/deal.handlers.js +293 -0
- package/dist/browser/handlers/index.js +456 -0
- package/dist/browser/handlers/mock-data.js +165 -0
- package/dist/browser/index.js +3279 -0
- package/dist/browser/operations/index.js +407 -0
- package/dist/browser/presentations/dashboard.presentation.js +52 -0
- package/dist/browser/presentations/index.js +284 -0
- package/dist/browser/presentations/pipeline.presentation.js +233 -0
- package/dist/browser/seeders/index.js +22 -0
- package/dist/browser/shared/overlay-types.js +0 -0
- package/dist/browser/ui/CrmDashboard.js +1325 -0
- package/dist/browser/ui/CrmDealCard.js +50 -0
- package/dist/browser/ui/CrmPipelineBoard.js +160 -0
- package/dist/browser/ui/hooks/index.js +186 -0
- package/dist/browser/ui/hooks/useDealList.js +84 -0
- package/dist/browser/ui/hooks/useDealMutations.js +100 -0
- package/dist/browser/ui/index.js +1972 -0
- package/dist/browser/ui/modals/CreateDealModal.js +211 -0
- package/dist/browser/ui/modals/DealActionsModal.js +428 -0
- package/dist/browser/ui/modals/index.js +638 -0
- package/dist/browser/ui/overlays/demo-overlays.js +55 -0
- package/dist/browser/ui/overlays/index.js +55 -0
- package/dist/browser/ui/renderers/index.js +827 -0
- package/dist/browser/ui/renderers/pipeline.markdown.js +564 -0
- package/dist/browser/ui/renderers/pipeline.renderer.js +264 -0
- package/dist/crm-pipeline.feature.d.ts +1 -6
- package/dist/crm-pipeline.feature.d.ts.map +1 -1
- package/dist/crm-pipeline.feature.js +74 -164
- package/dist/deal/deal.enum.d.ts +2 -7
- package/dist/deal/deal.enum.d.ts.map +1 -1
- package/dist/deal/deal.enum.js +16 -22
- package/dist/deal/deal.operation.d.ts +444 -450
- package/dist/deal/deal.operation.d.ts.map +1 -1
- package/dist/deal/deal.operation.js +390 -263
- package/dist/deal/deal.schema.d.ts +251 -256
- package/dist/deal/deal.schema.d.ts.map +1 -1
- package/dist/deal/deal.schema.js +131 -275
- package/dist/deal/deal.test-spec.d.ts +2 -7
- package/dist/deal/deal.test-spec.d.ts.map +1 -1
- package/dist/deal/deal.test-spec.js +56 -62
- package/dist/deal/index.d.ts +7 -4
- package/dist/deal/index.d.ts.map +1 -0
- package/dist/deal/index.js +408 -4
- package/dist/docs/crm-pipeline.docblock.d.ts +2 -1
- package/dist/docs/crm-pipeline.docblock.d.ts.map +1 -0
- package/dist/docs/crm-pipeline.docblock.js +45 -51
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +114 -1
- package/dist/entities/company.entity.d.ts +27 -32
- package/dist/entities/company.entity.d.ts.map +1 -1
- package/dist/entities/company.entity.js +51 -61
- package/dist/entities/contact.entity.d.ts +31 -36
- package/dist/entities/contact.entity.d.ts.map +1 -1
- package/dist/entities/contact.entity.js +65 -76
- package/dist/entities/deal.entity.d.ts +52 -57
- package/dist/entities/deal.entity.d.ts.map +1 -1
- package/dist/entities/deal.entity.js +104 -116
- package/dist/entities/index.d.ts +6 -10
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +342 -31
- package/dist/entities/task.entity.d.ts +42 -47
- package/dist/entities/task.entity.d.ts.map +1 -1
- package/dist/entities/task.entity.js +95 -124
- package/dist/events/contact.event.d.ts +21 -27
- package/dist/events/contact.event.d.ts.map +1 -1
- package/dist/events/contact.event.js +29 -42
- package/dist/events/deal.event.d.ts +100 -106
- package/dist/events/deal.event.d.ts.map +1 -1
- package/dist/events/deal.event.js +93 -163
- package/dist/events/index.d.ts +4 -4
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +158 -4
- package/dist/events/task.event.d.ts +21 -27
- package/dist/events/task.event.d.ts.map +1 -1
- package/dist/events/task.event.js +26 -42
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +38 -50
- package/dist/handlers/crm.handlers.d.ts +80 -78
- package/dist/handlers/crm.handlers.d.ts.map +1 -1
- package/dist/handlers/crm.handlers.js +155 -166
- package/dist/handlers/deal.handlers.d.ts +58 -63
- package/dist/handlers/deal.handlers.d.ts.map +1 -1
- package/dist/handlers/deal.handlers.js +279 -105
- package/dist/handlers/index.d.ts +10 -4
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +456 -4
- package/dist/handlers/mock-data.d.ts +38 -41
- package/dist/handlers/mock-data.d.ts.map +1 -1
- package/dist/handlers/mock-data.js +162 -184
- package/dist/index.d.ts +13 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3277 -53
- package/dist/node/crm-pipeline.feature.js +75 -0
- package/dist/node/deal/deal.enum.js +18 -0
- package/dist/node/deal/deal.operation.js +396 -0
- package/dist/node/deal/deal.schema.js +141 -0
- package/dist/node/deal/deal.test-spec.js +58 -0
- package/dist/node/deal/index.js +408 -0
- package/dist/node/docs/crm-pipeline.docblock.js +113 -0
- package/dist/node/docs/index.js +113 -0
- package/dist/node/entities/company.entity.js +52 -0
- package/dist/node/entities/contact.entity.js +66 -0
- package/dist/node/entities/deal.entity.js +107 -0
- package/dist/node/entities/index.js +343 -0
- package/dist/node/entities/task.entity.js +99 -0
- package/dist/node/events/contact.event.js +31 -0
- package/dist/node/events/deal.event.js +101 -0
- package/dist/node/events/index.js +158 -0
- package/dist/node/events/task.event.js +28 -0
- package/dist/node/example.js +39 -0
- package/dist/node/handlers/crm.handlers.js +160 -0
- package/dist/node/handlers/deal.handlers.js +293 -0
- package/dist/node/handlers/index.js +456 -0
- package/dist/node/handlers/mock-data.js +165 -0
- package/dist/node/index.js +3279 -0
- package/dist/node/operations/index.js +407 -0
- package/dist/node/presentations/dashboard.presentation.js +52 -0
- package/dist/node/presentations/index.js +284 -0
- package/dist/node/presentations/pipeline.presentation.js +233 -0
- package/dist/node/seeders/index.js +22 -0
- package/dist/node/shared/overlay-types.js +0 -0
- package/dist/node/ui/CrmDashboard.js +1325 -0
- package/dist/node/ui/CrmDealCard.js +50 -0
- package/dist/node/ui/CrmPipelineBoard.js +160 -0
- package/dist/node/ui/hooks/index.js +186 -0
- package/dist/node/ui/hooks/useDealList.js +84 -0
- package/dist/node/ui/hooks/useDealMutations.js +100 -0
- package/dist/node/ui/index.js +1972 -0
- package/dist/node/ui/modals/CreateDealModal.js +211 -0
- package/dist/node/ui/modals/DealActionsModal.js +428 -0
- package/dist/node/ui/modals/index.js +638 -0
- package/dist/node/ui/overlays/demo-overlays.js +55 -0
- package/dist/node/ui/overlays/index.js +55 -0
- package/dist/node/ui/renderers/index.js +827 -0
- package/dist/node/ui/renderers/pipeline.markdown.js +564 -0
- package/dist/node/ui/renderers/pipeline.renderer.js +264 -0
- package/dist/operations/index.d.ts +2 -5
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +407 -5
- package/dist/presentations/dashboard.presentation.d.ts +2 -7
- package/dist/presentations/dashboard.presentation.d.ts.map +1 -1
- package/dist/presentations/dashboard.presentation.js +51 -60
- package/dist/presentations/index.d.ts +3 -3
- package/dist/presentations/index.d.ts.map +1 -0
- package/dist/presentations/index.js +284 -3
- package/dist/presentations/pipeline.presentation.d.ts +4 -9
- package/dist/presentations/pipeline.presentation.d.ts.map +1 -1
- package/dist/presentations/pipeline.presentation.js +228 -116
- package/dist/seeders/index.d.ts +4 -8
- package/dist/seeders/index.d.ts.map +1 -1
- package/dist/seeders/index.js +21 -45
- package/dist/shared/overlay-types.d.ts +25 -28
- package/dist/shared/overlay-types.d.ts.map +1 -1
- package/dist/shared/overlay-types.js +1 -0
- package/dist/ui/CrmDashboard.d.ts +1 -6
- package/dist/ui/CrmDashboard.d.ts.map +1 -1
- package/dist/ui/CrmDashboard.js +1318 -296
- package/dist/ui/CrmDealCard.d.ts +8 -12
- package/dist/ui/CrmDealCard.d.ts.map +1 -1
- package/dist/ui/CrmDealCard.js +47 -45
- package/dist/ui/CrmPipelineBoard.d.ts +11 -20
- package/dist/ui/CrmPipelineBoard.d.ts.map +1 -1
- package/dist/ui/CrmPipelineBoard.js +157 -94
- package/dist/ui/hooks/index.d.ts +3 -3
- package/dist/ui/hooks/index.d.ts.map +1 -0
- package/dist/ui/hooks/index.js +185 -4
- package/dist/ui/hooks/useDealList.d.ts +28 -32
- package/dist/ui/hooks/useDealList.d.ts.map +1 -1
- package/dist/ui/hooks/useDealList.js +81 -90
- package/dist/ui/hooks/useDealMutations.d.ts +18 -22
- package/dist/ui/hooks/useDealMutations.d.ts.map +1 -1
- package/dist/ui/hooks/useDealMutations.js +97 -155
- package/dist/ui/index.d.ts +8 -14
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +1973 -15
- package/dist/ui/modals/CreateDealModal.d.ts +19 -29
- package/dist/ui/modals/CreateDealModal.d.ts.map +1 -1
- package/dist/ui/modals/CreateDealModal.js +209 -180
- package/dist/ui/modals/DealActionsModal.d.ts +31 -44
- package/dist/ui/modals/DealActionsModal.d.ts.map +1 -1
- package/dist/ui/modals/DealActionsModal.js +424 -367
- package/dist/ui/modals/index.d.ts +3 -3
- package/dist/ui/modals/index.d.ts.map +1 -0
- package/dist/ui/modals/index.js +638 -3
- package/dist/ui/overlays/demo-overlays.d.ts +10 -8
- package/dist/ui/overlays/demo-overlays.d.ts.map +1 -1
- package/dist/ui/overlays/demo-overlays.js +54 -66
- package/dist/ui/overlays/index.d.ts +2 -2
- package/dist/ui/overlays/index.d.ts.map +1 -0
- package/dist/ui/overlays/index.js +56 -3
- package/dist/ui/renderers/index.d.ts +3 -3
- package/dist/ui/renderers/index.d.ts.map +1 -0
- package/dist/ui/renderers/index.js +827 -3
- package/dist/ui/renderers/pipeline.markdown.d.ts +12 -11
- package/dist/ui/renderers/pipeline.markdown.d.ts.map +1 -1
- package/dist/ui/renderers/pipeline.markdown.js +560 -114
- package/dist/ui/renderers/pipeline.renderer.d.ts +9 -7
- package/dist/ui/renderers/pipeline.renderer.d.ts.map +1 -1
- package/dist/ui/renderers/pipeline.renderer.js +261 -24
- package/package.json +476 -90
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -164
- package/dist/crm-pipeline.feature.js.map +0 -1
- package/dist/deal/deal.enum.js.map +0 -1
- package/dist/deal/deal.operation.js.map +0 -1
- package/dist/deal/deal.schema.js.map +0 -1
- package/dist/deal/deal.test-spec.js.map +0 -1
- package/dist/docs/crm-pipeline.docblock.js.map +0 -1
- package/dist/entities/company.entity.js.map +0 -1
- package/dist/entities/contact.entity.js.map +0 -1
- package/dist/entities/deal.entity.js.map +0 -1
- package/dist/entities/index.js.map +0 -1
- package/dist/entities/task.entity.js.map +0 -1
- package/dist/events/contact.event.js.map +0 -1
- package/dist/events/deal.event.js.map +0 -1
- package/dist/events/task.event.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/crm.handlers.js.map +0 -1
- package/dist/handlers/deal.handlers.js.map +0 -1
- package/dist/handlers/mock-data.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/presentations/dashboard.presentation.js.map +0 -1
- package/dist/presentations/pipeline.presentation.js.map +0 -1
- package/dist/seeders/index.js.map +0 -1
- package/dist/ui/CrmDashboard.js.map +0 -1
- package/dist/ui/CrmDealCard.js.map +0 -1
- package/dist/ui/CrmPipelineBoard.js.map +0 -1
- package/dist/ui/hooks/useDealList.js.map +0 -1
- package/dist/ui/hooks/useDealMutations.js.map +0 -1
- package/dist/ui/modals/CreateDealModal.js.map +0 -1
- package/dist/ui/modals/DealActionsModal.js.map +0 -1
- package/dist/ui/overlays/demo-overlays.js.map +0 -1
- package/dist/ui/renderers/pipeline.markdown.js.map +0 -1
- package/dist/ui/renderers/pipeline.renderer.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/dist/ui/index.js
CHANGED
|
@@ -1,15 +1,1973 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/handlers/crm.handlers.ts
|
|
3
|
+
import { web } from "@contractspec/lib.runtime-sandbox";
|
|
4
|
+
var { generateId } = web;
|
|
5
|
+
function rowToDeal(row) {
|
|
6
|
+
return {
|
|
7
|
+
id: row.id,
|
|
8
|
+
projectId: row.projectId,
|
|
9
|
+
name: row.name,
|
|
10
|
+
value: row.value,
|
|
11
|
+
currency: row.currency,
|
|
12
|
+
pipelineId: row.pipelineId,
|
|
13
|
+
stageId: row.stageId,
|
|
14
|
+
status: row.status,
|
|
15
|
+
contactId: row.contactId ?? undefined,
|
|
16
|
+
companyId: row.companyId ?? undefined,
|
|
17
|
+
ownerId: row.ownerId,
|
|
18
|
+
expectedCloseDate: row.expectedCloseDate ? new Date(row.expectedCloseDate) : undefined,
|
|
19
|
+
wonSource: row.wonSource ?? undefined,
|
|
20
|
+
lostReason: row.lostReason ?? undefined,
|
|
21
|
+
notes: row.notes ?? undefined,
|
|
22
|
+
createdAt: new Date(row.createdAt),
|
|
23
|
+
updatedAt: new Date(row.updatedAt)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function createCrmHandlers(db) {
|
|
27
|
+
async function listDeals(input) {
|
|
28
|
+
const {
|
|
29
|
+
projectId,
|
|
30
|
+
pipelineId,
|
|
31
|
+
stageId,
|
|
32
|
+
status,
|
|
33
|
+
ownerId,
|
|
34
|
+
search,
|
|
35
|
+
limit = 20,
|
|
36
|
+
offset = 0
|
|
37
|
+
} = input;
|
|
38
|
+
let whereClause = "WHERE projectId = ?";
|
|
39
|
+
const params = [projectId];
|
|
40
|
+
if (pipelineId) {
|
|
41
|
+
whereClause += " AND pipelineId = ?";
|
|
42
|
+
params.push(pipelineId);
|
|
43
|
+
}
|
|
44
|
+
if (stageId) {
|
|
45
|
+
whereClause += " AND stageId = ?";
|
|
46
|
+
params.push(stageId);
|
|
47
|
+
}
|
|
48
|
+
if (status && status !== "all") {
|
|
49
|
+
whereClause += " AND status = ?";
|
|
50
|
+
params.push(status);
|
|
51
|
+
}
|
|
52
|
+
if (ownerId) {
|
|
53
|
+
whereClause += " AND ownerId = ?";
|
|
54
|
+
params.push(ownerId);
|
|
55
|
+
}
|
|
56
|
+
if (search) {
|
|
57
|
+
whereClause += " AND name LIKE ?";
|
|
58
|
+
params.push(`%${search}%`);
|
|
59
|
+
}
|
|
60
|
+
const countResult = (await db.query(`SELECT COUNT(*) as count FROM crm_deal ${whereClause}`, params)).rows;
|
|
61
|
+
const total = countResult[0]?.count ?? 0;
|
|
62
|
+
const valueResult = (await db.query(`SELECT COALESCE(SUM(value), 0) as total FROM crm_deal ${whereClause}`, params)).rows;
|
|
63
|
+
const totalValue = valueResult[0]?.total ?? 0;
|
|
64
|
+
const dealRows = (await db.query(`SELECT * FROM crm_deal ${whereClause} ORDER BY value DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
65
|
+
return {
|
|
66
|
+
deals: dealRows.map(rowToDeal),
|
|
67
|
+
total,
|
|
68
|
+
totalValue
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async function createDeal(input, context) {
|
|
72
|
+
const id = generateId("deal");
|
|
73
|
+
const now = new Date().toISOString();
|
|
74
|
+
await db.execute(`INSERT INTO crm_deal (id, projectId, pipelineId, stageId, name, value, currency, status, contactId, companyId, ownerId, expectedCloseDate, createdAt, updatedAt)
|
|
75
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
76
|
+
id,
|
|
77
|
+
context.projectId,
|
|
78
|
+
input.pipelineId,
|
|
79
|
+
input.stageId,
|
|
80
|
+
input.name,
|
|
81
|
+
input.value,
|
|
82
|
+
input.currency ?? "USD",
|
|
83
|
+
"OPEN",
|
|
84
|
+
input.contactId ?? null,
|
|
85
|
+
input.companyId ?? null,
|
|
86
|
+
context.ownerId,
|
|
87
|
+
input.expectedCloseDate?.toISOString() ?? null,
|
|
88
|
+
now,
|
|
89
|
+
now
|
|
90
|
+
]);
|
|
91
|
+
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [id])).rows;
|
|
92
|
+
if (!rows[0]) {
|
|
93
|
+
throw new Error("Failed to create deal");
|
|
94
|
+
}
|
|
95
|
+
return rowToDeal(rows[0]);
|
|
96
|
+
}
|
|
97
|
+
async function moveDeal(input) {
|
|
98
|
+
const now = new Date().toISOString();
|
|
99
|
+
const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
100
|
+
if (!existing[0]) {
|
|
101
|
+
throw new Error("NOT_FOUND");
|
|
102
|
+
}
|
|
103
|
+
const stage = (await db.query(`SELECT * FROM crm_stage WHERE id = ?`, [input.stageId])).rows;
|
|
104
|
+
if (!stage[0]) {
|
|
105
|
+
throw new Error("INVALID_STAGE");
|
|
106
|
+
}
|
|
107
|
+
await db.execute(`UPDATE crm_deal SET stageId = ?, updatedAt = ? WHERE id = ?`, [input.stageId, now, input.dealId]);
|
|
108
|
+
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
109
|
+
return rowToDeal(rows[0]);
|
|
110
|
+
}
|
|
111
|
+
async function winDeal(input) {
|
|
112
|
+
const now = new Date().toISOString();
|
|
113
|
+
const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
114
|
+
if (!existing[0]) {
|
|
115
|
+
throw new Error("NOT_FOUND");
|
|
116
|
+
}
|
|
117
|
+
await db.execute(`UPDATE crm_deal SET status = 'WON', wonSource = ?, notes = ?, updatedAt = ? WHERE id = ?`, [input.wonSource ?? null, input.notes ?? null, now, input.dealId]);
|
|
118
|
+
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
119
|
+
return rowToDeal(rows[0]);
|
|
120
|
+
}
|
|
121
|
+
async function loseDeal(input) {
|
|
122
|
+
const now = new Date().toISOString();
|
|
123
|
+
const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
124
|
+
if (!existing[0]) {
|
|
125
|
+
throw new Error("NOT_FOUND");
|
|
126
|
+
}
|
|
127
|
+
await db.execute(`UPDATE crm_deal SET status = 'LOST', lostReason = ?, notes = ?, updatedAt = ? WHERE id = ?`, [input.lostReason, input.notes ?? null, now, input.dealId]);
|
|
128
|
+
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
129
|
+
return rowToDeal(rows[0]);
|
|
130
|
+
}
|
|
131
|
+
async function getDealsByStage(input) {
|
|
132
|
+
const deals = (await db.query(`SELECT * FROM crm_deal WHERE projectId = ? AND pipelineId = ? AND status = 'OPEN' ORDER BY value DESC`, [input.projectId, input.pipelineId])).rows;
|
|
133
|
+
const stages = (await db.query(`SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`, [input.pipelineId])).rows;
|
|
134
|
+
const grouped = {};
|
|
135
|
+
for (const stage of stages) {
|
|
136
|
+
grouped[stage.id] = deals.filter((d) => d.stageId === stage.id).map(rowToDeal);
|
|
137
|
+
}
|
|
138
|
+
return grouped;
|
|
139
|
+
}
|
|
140
|
+
async function getPipelineStages(input) {
|
|
141
|
+
const rows = (await db.query(`SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`, [input.pipelineId])).rows;
|
|
142
|
+
return rows.map((row) => ({
|
|
143
|
+
id: row.id,
|
|
144
|
+
pipelineId: row.pipelineId,
|
|
145
|
+
name: row.name,
|
|
146
|
+
position: row.position
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
listDeals,
|
|
151
|
+
createDeal,
|
|
152
|
+
moveDeal,
|
|
153
|
+
winDeal,
|
|
154
|
+
loseDeal,
|
|
155
|
+
getDealsByStage,
|
|
156
|
+
getPipelineStages
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/handlers/mock-data.ts
|
|
161
|
+
var MOCK_STAGES = [
|
|
162
|
+
{ id: "stage-1", name: "Lead", position: 1, pipelineId: "pipeline-1" },
|
|
163
|
+
{ id: "stage-2", name: "Qualified", position: 2, pipelineId: "pipeline-1" },
|
|
164
|
+
{ id: "stage-3", name: "Proposal", position: 3, pipelineId: "pipeline-1" },
|
|
165
|
+
{ id: "stage-4", name: "Negotiation", position: 4, pipelineId: "pipeline-1" },
|
|
166
|
+
{ id: "stage-5", name: "Closed", position: 5, pipelineId: "pipeline-1" }
|
|
167
|
+
];
|
|
168
|
+
var MOCK_DEALS = [
|
|
169
|
+
{
|
|
170
|
+
id: "deal-1",
|
|
171
|
+
name: "Enterprise License - Acme Corp",
|
|
172
|
+
value: 75000,
|
|
173
|
+
currency: "USD",
|
|
174
|
+
pipelineId: "pipeline-1",
|
|
175
|
+
stageId: "stage-3",
|
|
176
|
+
status: "OPEN",
|
|
177
|
+
contactId: "contact-1",
|
|
178
|
+
companyId: "company-1",
|
|
179
|
+
ownerId: "user-1",
|
|
180
|
+
expectedCloseDate: new Date("2024-05-15T00:00:00Z"),
|
|
181
|
+
createdAt: new Date("2024-02-01T10:00:00Z"),
|
|
182
|
+
updatedAt: new Date("2024-04-10T14:30:00Z")
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: "deal-2",
|
|
186
|
+
name: "Startup Plan - TechStart Inc",
|
|
187
|
+
value: 12000,
|
|
188
|
+
currency: "USD",
|
|
189
|
+
pipelineId: "pipeline-1",
|
|
190
|
+
stageId: "stage-2",
|
|
191
|
+
status: "OPEN",
|
|
192
|
+
contactId: "contact-2",
|
|
193
|
+
companyId: "company-2",
|
|
194
|
+
ownerId: "user-2",
|
|
195
|
+
expectedCloseDate: new Date("2024-04-30T00:00:00Z"),
|
|
196
|
+
createdAt: new Date("2024-03-15T09:00:00Z"),
|
|
197
|
+
updatedAt: new Date("2024-04-08T11:15:00Z")
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "deal-3",
|
|
201
|
+
name: "Professional Services - Global Ltd",
|
|
202
|
+
value: 45000,
|
|
203
|
+
currency: "USD",
|
|
204
|
+
pipelineId: "pipeline-1",
|
|
205
|
+
stageId: "stage-4",
|
|
206
|
+
status: "OPEN",
|
|
207
|
+
contactId: "contact-3",
|
|
208
|
+
companyId: "company-3",
|
|
209
|
+
ownerId: "user-1",
|
|
210
|
+
expectedCloseDate: new Date("2024-04-20T00:00:00Z"),
|
|
211
|
+
createdAt: new Date("2024-01-20T08:00:00Z"),
|
|
212
|
+
updatedAt: new Date("2024-04-12T16:45:00Z")
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: "deal-4",
|
|
216
|
+
name: "Annual Contract - SmallBiz Co",
|
|
217
|
+
value: 8500,
|
|
218
|
+
currency: "USD",
|
|
219
|
+
pipelineId: "pipeline-1",
|
|
220
|
+
stageId: "stage-1",
|
|
221
|
+
status: "OPEN",
|
|
222
|
+
contactId: "contact-4",
|
|
223
|
+
companyId: "company-4",
|
|
224
|
+
ownerId: "user-3",
|
|
225
|
+
createdAt: new Date("2024-04-05T12:00:00Z"),
|
|
226
|
+
updatedAt: new Date("2024-04-05T12:00:00Z")
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
id: "deal-5",
|
|
230
|
+
name: "Custom Integration - MegaCorp",
|
|
231
|
+
value: 125000,
|
|
232
|
+
currency: "USD",
|
|
233
|
+
pipelineId: "pipeline-1",
|
|
234
|
+
stageId: "stage-5",
|
|
235
|
+
status: "WON",
|
|
236
|
+
contactId: "contact-5",
|
|
237
|
+
companyId: "company-5",
|
|
238
|
+
ownerId: "user-1",
|
|
239
|
+
expectedCloseDate: new Date("2024-03-31T00:00:00Z"),
|
|
240
|
+
createdAt: new Date("2023-11-10T10:00:00Z"),
|
|
241
|
+
updatedAt: new Date("2024-03-28T09:00:00Z")
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: "deal-6",
|
|
245
|
+
name: "Pilot Project - NewCo",
|
|
246
|
+
value: 5000,
|
|
247
|
+
currency: "USD",
|
|
248
|
+
pipelineId: "pipeline-1",
|
|
249
|
+
stageId: "stage-2",
|
|
250
|
+
status: "LOST",
|
|
251
|
+
contactId: "contact-6",
|
|
252
|
+
companyId: "company-6",
|
|
253
|
+
ownerId: "user-2",
|
|
254
|
+
createdAt: new Date("2024-01-15T14:00:00Z"),
|
|
255
|
+
updatedAt: new Date("2024-02-28T10:30:00Z")
|
|
256
|
+
}
|
|
257
|
+
];
|
|
258
|
+
var MOCK_COMPANIES = [
|
|
259
|
+
{
|
|
260
|
+
id: "company-1",
|
|
261
|
+
name: "Acme Corporation",
|
|
262
|
+
domain: "acme.com",
|
|
263
|
+
industry: "Technology",
|
|
264
|
+
size: "1000-5000",
|
|
265
|
+
website: "https://acme.com",
|
|
266
|
+
createdAt: new Date("2024-01-01T00:00:00Z")
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: "company-2",
|
|
270
|
+
name: "TechStart Inc",
|
|
271
|
+
domain: "techstart.io",
|
|
272
|
+
industry: "Software",
|
|
273
|
+
size: "10-50",
|
|
274
|
+
website: "https://techstart.io",
|
|
275
|
+
createdAt: new Date("2024-02-15T00:00:00Z")
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
id: "company-3",
|
|
279
|
+
name: "Global Ltd",
|
|
280
|
+
domain: "global.com",
|
|
281
|
+
industry: "Consulting",
|
|
282
|
+
size: "500-1000",
|
|
283
|
+
website: "https://global.com",
|
|
284
|
+
createdAt: new Date("2023-12-01T00:00:00Z")
|
|
285
|
+
}
|
|
286
|
+
];
|
|
287
|
+
var MOCK_CONTACTS = [
|
|
288
|
+
{
|
|
289
|
+
id: "contact-1",
|
|
290
|
+
firstName: "John",
|
|
291
|
+
lastName: "Smith",
|
|
292
|
+
email: "john.smith@acme.com",
|
|
293
|
+
phone: "+1-555-0101",
|
|
294
|
+
title: "VP of Engineering",
|
|
295
|
+
companyId: "company-1",
|
|
296
|
+
createdAt: new Date("2024-01-05T00:00:00Z")
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
id: "contact-2",
|
|
300
|
+
firstName: "Sarah",
|
|
301
|
+
lastName: "Johnson",
|
|
302
|
+
email: "sarah@techstart.io",
|
|
303
|
+
phone: "+1-555-0102",
|
|
304
|
+
title: "CEO",
|
|
305
|
+
companyId: "company-2",
|
|
306
|
+
createdAt: new Date("2024-02-20T00:00:00Z")
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
id: "contact-3",
|
|
310
|
+
firstName: "Michael",
|
|
311
|
+
lastName: "Brown",
|
|
312
|
+
email: "michael.brown@global.com",
|
|
313
|
+
phone: "+1-555-0103",
|
|
314
|
+
title: "CTO",
|
|
315
|
+
companyId: "company-3",
|
|
316
|
+
createdAt: new Date("2023-12-10T00:00:00Z")
|
|
317
|
+
}
|
|
318
|
+
];
|
|
319
|
+
|
|
320
|
+
// src/handlers/deal.handlers.ts
|
|
321
|
+
async function mockListDealsHandler(input) {
|
|
322
|
+
const {
|
|
323
|
+
pipelineId,
|
|
324
|
+
stageId,
|
|
325
|
+
status,
|
|
326
|
+
ownerId,
|
|
327
|
+
search,
|
|
328
|
+
limit = 20,
|
|
329
|
+
offset = 0
|
|
330
|
+
} = input;
|
|
331
|
+
let filtered = [...MOCK_DEALS];
|
|
332
|
+
if (pipelineId) {
|
|
333
|
+
filtered = filtered.filter((d) => d.pipelineId === pipelineId);
|
|
334
|
+
}
|
|
335
|
+
if (stageId) {
|
|
336
|
+
filtered = filtered.filter((d) => d.stageId === stageId);
|
|
337
|
+
}
|
|
338
|
+
if (status && status !== "all") {
|
|
339
|
+
filtered = filtered.filter((d) => d.status === status);
|
|
340
|
+
}
|
|
341
|
+
if (ownerId) {
|
|
342
|
+
filtered = filtered.filter((d) => d.ownerId === ownerId);
|
|
343
|
+
}
|
|
344
|
+
if (search) {
|
|
345
|
+
const q = search.toLowerCase();
|
|
346
|
+
filtered = filtered.filter((d) => d.name.toLowerCase().includes(q));
|
|
347
|
+
}
|
|
348
|
+
filtered.sort((a, b) => b.value - a.value);
|
|
349
|
+
const total = filtered.length;
|
|
350
|
+
const totalValue = filtered.reduce((sum, d) => sum + d.value, 0);
|
|
351
|
+
const deals = filtered.slice(offset, offset + limit);
|
|
352
|
+
return {
|
|
353
|
+
deals,
|
|
354
|
+
total,
|
|
355
|
+
totalValue
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
async function mockCreateDealHandler(input, context) {
|
|
359
|
+
const now = new Date;
|
|
360
|
+
const deal = {
|
|
361
|
+
id: `deal-${Date.now()}`,
|
|
362
|
+
name: input.name,
|
|
363
|
+
value: input.value,
|
|
364
|
+
currency: input.currency ?? "USD",
|
|
365
|
+
pipelineId: input.pipelineId,
|
|
366
|
+
stageId: input.stageId,
|
|
367
|
+
status: "OPEN",
|
|
368
|
+
contactId: input.contactId,
|
|
369
|
+
companyId: input.companyId,
|
|
370
|
+
ownerId: context.ownerId,
|
|
371
|
+
expectedCloseDate: input.expectedCloseDate,
|
|
372
|
+
createdAt: now,
|
|
373
|
+
updatedAt: now
|
|
374
|
+
};
|
|
375
|
+
MOCK_DEALS.push(deal);
|
|
376
|
+
return deal;
|
|
377
|
+
}
|
|
378
|
+
async function mockMoveDealHandler(input) {
|
|
379
|
+
const dealIndex = MOCK_DEALS.findIndex((d) => d.id === input.dealId);
|
|
380
|
+
if (dealIndex === -1) {
|
|
381
|
+
throw new Error("NOT_FOUND");
|
|
382
|
+
}
|
|
383
|
+
const deal = MOCK_DEALS[dealIndex];
|
|
384
|
+
if (!deal) {
|
|
385
|
+
throw new Error("NOT_FOUND");
|
|
386
|
+
}
|
|
387
|
+
const stage = MOCK_STAGES.find((s) => s.id === input.stageId);
|
|
388
|
+
if (!stage) {
|
|
389
|
+
throw new Error("INVALID_STAGE");
|
|
390
|
+
}
|
|
391
|
+
const updatedDeal = {
|
|
392
|
+
...deal,
|
|
393
|
+
stageId: input.stageId,
|
|
394
|
+
updatedAt: new Date
|
|
395
|
+
};
|
|
396
|
+
MOCK_DEALS[dealIndex] = updatedDeal;
|
|
397
|
+
return updatedDeal;
|
|
398
|
+
}
|
|
399
|
+
async function mockWinDealHandler(input) {
|
|
400
|
+
const dealIndex = MOCK_DEALS.findIndex((d) => d.id === input.dealId);
|
|
401
|
+
if (dealIndex === -1) {
|
|
402
|
+
throw new Error("NOT_FOUND");
|
|
403
|
+
}
|
|
404
|
+
const deal = MOCK_DEALS[dealIndex];
|
|
405
|
+
if (!deal) {
|
|
406
|
+
throw new Error("NOT_FOUND");
|
|
407
|
+
}
|
|
408
|
+
const updatedDeal = {
|
|
409
|
+
...deal,
|
|
410
|
+
status: "WON",
|
|
411
|
+
updatedAt: new Date
|
|
412
|
+
};
|
|
413
|
+
MOCK_DEALS[dealIndex] = updatedDeal;
|
|
414
|
+
return updatedDeal;
|
|
415
|
+
}
|
|
416
|
+
async function mockLoseDealHandler(input) {
|
|
417
|
+
const dealIndex = MOCK_DEALS.findIndex((d) => d.id === input.dealId);
|
|
418
|
+
if (dealIndex === -1) {
|
|
419
|
+
throw new Error("NOT_FOUND");
|
|
420
|
+
}
|
|
421
|
+
const deal = MOCK_DEALS[dealIndex];
|
|
422
|
+
if (!deal) {
|
|
423
|
+
throw new Error("NOT_FOUND");
|
|
424
|
+
}
|
|
425
|
+
const updatedDeal = {
|
|
426
|
+
...deal,
|
|
427
|
+
status: "LOST",
|
|
428
|
+
updatedAt: new Date
|
|
429
|
+
};
|
|
430
|
+
MOCK_DEALS[dealIndex] = updatedDeal;
|
|
431
|
+
return updatedDeal;
|
|
432
|
+
}
|
|
433
|
+
async function mockGetDealsByStageHandler(input) {
|
|
434
|
+
const deals = MOCK_DEALS.filter((d) => d.pipelineId === input.pipelineId && d.status === "OPEN");
|
|
435
|
+
const grouped = {};
|
|
436
|
+
for (const stage of MOCK_STAGES) {
|
|
437
|
+
grouped[stage.id] = deals.filter((d) => d.stageId === stage.id);
|
|
438
|
+
}
|
|
439
|
+
return grouped;
|
|
440
|
+
}
|
|
441
|
+
async function mockGetPipelineStagesHandler(input) {
|
|
442
|
+
return MOCK_STAGES.filter((s) => s.pipelineId === input.pipelineId);
|
|
443
|
+
}
|
|
444
|
+
// src/ui/hooks/useDealList.ts
|
|
445
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
446
|
+
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
447
|
+
"use client";
|
|
448
|
+
function useDealList(options = {}) {
|
|
449
|
+
const { handlers, projectId } = useTemplateRuntime();
|
|
450
|
+
const { crm: crm2 } = handlers;
|
|
451
|
+
const [data, setData] = useState(null);
|
|
452
|
+
const [dealsByStage, setDealsByStage] = useState({});
|
|
453
|
+
const [stages, setStages] = useState([]);
|
|
454
|
+
const [loading, setLoading] = useState(true);
|
|
455
|
+
const [error, setError] = useState(null);
|
|
456
|
+
const [page, setPage] = useState(1);
|
|
457
|
+
const pipelineId = options.pipelineId ?? "pipeline-1";
|
|
458
|
+
const fetchData = useCallback(async () => {
|
|
459
|
+
setLoading(true);
|
|
460
|
+
setError(null);
|
|
461
|
+
try {
|
|
462
|
+
const [dealsResult, stageDealsResult, stagesResult] = await Promise.all([
|
|
463
|
+
crm2.listDeals({
|
|
464
|
+
projectId,
|
|
465
|
+
pipelineId,
|
|
466
|
+
stageId: options.stageId,
|
|
467
|
+
status: options.status === "all" ? undefined : options.status,
|
|
468
|
+
search: options.search,
|
|
469
|
+
limit: options.limit ?? 50,
|
|
470
|
+
offset: (page - 1) * (options.limit ?? 50)
|
|
471
|
+
}),
|
|
472
|
+
crm2.getDealsByStage({ projectId, pipelineId }),
|
|
473
|
+
crm2.getPipelineStages({ pipelineId })
|
|
474
|
+
]);
|
|
475
|
+
setData(dealsResult);
|
|
476
|
+
setDealsByStage(stageDealsResult);
|
|
477
|
+
setStages(stagesResult);
|
|
478
|
+
} catch (err) {
|
|
479
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
480
|
+
} finally {
|
|
481
|
+
setLoading(false);
|
|
482
|
+
}
|
|
483
|
+
}, [
|
|
484
|
+
crm2,
|
|
485
|
+
projectId,
|
|
486
|
+
pipelineId,
|
|
487
|
+
options.stageId,
|
|
488
|
+
options.status,
|
|
489
|
+
options.search,
|
|
490
|
+
options.limit,
|
|
491
|
+
page
|
|
492
|
+
]);
|
|
493
|
+
useEffect(() => {
|
|
494
|
+
fetchData();
|
|
495
|
+
}, [fetchData]);
|
|
496
|
+
const stats = useMemo(() => {
|
|
497
|
+
if (!data)
|
|
498
|
+
return null;
|
|
499
|
+
const open = data.deals.filter((d) => d.status === "OPEN");
|
|
500
|
+
const won = data.deals.filter((d) => d.status === "WON");
|
|
501
|
+
const lost = data.deals.filter((d) => d.status === "LOST");
|
|
502
|
+
return {
|
|
503
|
+
total: data.total,
|
|
504
|
+
totalValue: data.totalValue,
|
|
505
|
+
openCount: open.length,
|
|
506
|
+
openValue: open.reduce((sum, d) => sum + d.value, 0),
|
|
507
|
+
wonCount: won.length,
|
|
508
|
+
wonValue: won.reduce((sum, d) => sum + d.value, 0),
|
|
509
|
+
lostCount: lost.length
|
|
510
|
+
};
|
|
511
|
+
}, [data]);
|
|
512
|
+
return {
|
|
513
|
+
data,
|
|
514
|
+
dealsByStage,
|
|
515
|
+
stages,
|
|
516
|
+
loading,
|
|
517
|
+
error,
|
|
518
|
+
stats,
|
|
519
|
+
page,
|
|
520
|
+
refetch: fetchData,
|
|
521
|
+
nextPage: () => setPage((p) => p + 1),
|
|
522
|
+
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// src/ui/hooks/useDealMutations.ts
|
|
527
|
+
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
528
|
+
import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
|
|
529
|
+
function useDealMutations(options = {}) {
|
|
530
|
+
const { handlers, projectId } = useTemplateRuntime2();
|
|
531
|
+
const { crm: crm2 } = handlers;
|
|
532
|
+
const [createState, setCreateState] = useState2({
|
|
533
|
+
loading: false,
|
|
534
|
+
error: null,
|
|
535
|
+
data: null
|
|
536
|
+
});
|
|
537
|
+
const [moveState, setMoveState] = useState2({
|
|
538
|
+
loading: false,
|
|
539
|
+
error: null,
|
|
540
|
+
data: null
|
|
541
|
+
});
|
|
542
|
+
const [winState, setWinState] = useState2({
|
|
543
|
+
loading: false,
|
|
544
|
+
error: null,
|
|
545
|
+
data: null
|
|
546
|
+
});
|
|
547
|
+
const [loseState, setLoseState] = useState2({
|
|
548
|
+
loading: false,
|
|
549
|
+
error: null,
|
|
550
|
+
data: null
|
|
551
|
+
});
|
|
552
|
+
const createDeal = useCallback2(async (input) => {
|
|
553
|
+
setCreateState({ loading: true, error: null, data: null });
|
|
554
|
+
try {
|
|
555
|
+
const result = await crm2.createDeal(input, {
|
|
556
|
+
projectId,
|
|
557
|
+
ownerId: "user-1"
|
|
558
|
+
});
|
|
559
|
+
setCreateState({ loading: false, error: null, data: result });
|
|
560
|
+
options.onSuccess?.();
|
|
561
|
+
return result;
|
|
562
|
+
} catch (err) {
|
|
563
|
+
const error = err instanceof Error ? err : new Error("Failed to create deal");
|
|
564
|
+
setCreateState({ loading: false, error, data: null });
|
|
565
|
+
options.onError?.(error);
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
}, [crm2, projectId, options]);
|
|
569
|
+
const moveDeal = useCallback2(async (input) => {
|
|
570
|
+
setMoveState({ loading: true, error: null, data: null });
|
|
571
|
+
try {
|
|
572
|
+
const result = await crm2.moveDeal(input);
|
|
573
|
+
setMoveState({ loading: false, error: null, data: result });
|
|
574
|
+
options.onSuccess?.();
|
|
575
|
+
return result;
|
|
576
|
+
} catch (err) {
|
|
577
|
+
const error = err instanceof Error ? err : new Error("Failed to move deal");
|
|
578
|
+
setMoveState({ loading: false, error, data: null });
|
|
579
|
+
options.onError?.(error);
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
}, [crm2, options]);
|
|
583
|
+
const winDeal = useCallback2(async (input) => {
|
|
584
|
+
setWinState({ loading: true, error: null, data: null });
|
|
585
|
+
try {
|
|
586
|
+
const result = await crm2.winDeal(input);
|
|
587
|
+
setWinState({ loading: false, error: null, data: result });
|
|
588
|
+
options.onSuccess?.();
|
|
589
|
+
return result;
|
|
590
|
+
} catch (err) {
|
|
591
|
+
const error = err instanceof Error ? err : new Error("Failed to mark deal as won");
|
|
592
|
+
setWinState({ loading: false, error, data: null });
|
|
593
|
+
options.onError?.(error);
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
}, [crm2, options]);
|
|
597
|
+
const loseDeal = useCallback2(async (input) => {
|
|
598
|
+
setLoseState({ loading: true, error: null, data: null });
|
|
599
|
+
try {
|
|
600
|
+
const result = await crm2.loseDeal(input);
|
|
601
|
+
setLoseState({ loading: false, error: null, data: result });
|
|
602
|
+
options.onSuccess?.();
|
|
603
|
+
return result;
|
|
604
|
+
} catch (err) {
|
|
605
|
+
const error = err instanceof Error ? err : new Error("Failed to mark deal as lost");
|
|
606
|
+
setLoseState({ loading: false, error, data: null });
|
|
607
|
+
options.onError?.(error);
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
}, [crm2, options]);
|
|
611
|
+
return {
|
|
612
|
+
createDeal,
|
|
613
|
+
moveDeal,
|
|
614
|
+
winDeal,
|
|
615
|
+
loseDeal,
|
|
616
|
+
createState,
|
|
617
|
+
moveState,
|
|
618
|
+
winState,
|
|
619
|
+
loseState,
|
|
620
|
+
isLoading: createState.loading || moveState.loading || winState.loading || loseState.loading
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// src/ui/CrmDealCard.tsx
|
|
625
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
626
|
+
"use client";
|
|
627
|
+
function formatCurrency(value, currency) {
|
|
628
|
+
return new Intl.NumberFormat("en-US", {
|
|
629
|
+
style: "currency",
|
|
630
|
+
currency,
|
|
631
|
+
minimumFractionDigits: 0,
|
|
632
|
+
maximumFractionDigits: 0
|
|
633
|
+
}).format(value);
|
|
634
|
+
}
|
|
635
|
+
function CrmDealCard({ deal, onClick }) {
|
|
636
|
+
const daysUntilClose = deal.expectedCloseDate ? Math.ceil((deal.expectedCloseDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)) : null;
|
|
637
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
638
|
+
onClick,
|
|
639
|
+
className: "border-border bg-card cursor-pointer rounded-lg border p-3 shadow-sm transition-shadow hover:shadow-md",
|
|
640
|
+
role: "button",
|
|
641
|
+
tabIndex: 0,
|
|
642
|
+
onKeyDown: (e) => {
|
|
643
|
+
if (e.key === "Enter" || e.key === " ")
|
|
644
|
+
onClick?.();
|
|
645
|
+
},
|
|
646
|
+
children: [
|
|
647
|
+
/* @__PURE__ */ jsxDEV("h4", {
|
|
648
|
+
className: "leading-snug font-medium",
|
|
649
|
+
children: deal.name
|
|
650
|
+
}, undefined, false, undefined, this),
|
|
651
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
652
|
+
className: "text-primary mt-2 text-lg font-semibold",
|
|
653
|
+
children: formatCurrency(deal.value, deal.currency)
|
|
654
|
+
}, undefined, false, undefined, this),
|
|
655
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
656
|
+
className: "text-muted-foreground mt-3 flex items-center justify-between text-xs",
|
|
657
|
+
children: [
|
|
658
|
+
daysUntilClose !== null && /* @__PURE__ */ jsxDEV("span", {
|
|
659
|
+
className: daysUntilClose < 0 ? "text-red-500" : daysUntilClose <= 7 ? "text-yellow-600 dark:text-yellow-500" : "",
|
|
660
|
+
children: daysUntilClose < 0 ? `${Math.abs(daysUntilClose)}d overdue` : daysUntilClose === 0 ? "Due today" : `${daysUntilClose}d left`
|
|
661
|
+
}, undefined, false, undefined, this),
|
|
662
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
663
|
+
className: `rounded px-1.5 py-0.5 text-xs font-medium ${deal.status === "WON" ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" : deal.status === "LOST" ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400" : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,
|
|
664
|
+
children: deal.status
|
|
665
|
+
}, undefined, false, undefined, this)
|
|
666
|
+
]
|
|
667
|
+
}, undefined, true, undefined, this)
|
|
668
|
+
]
|
|
669
|
+
}, undefined, true, undefined, this);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// src/ui/CrmPipelineBoard.tsx
|
|
673
|
+
import { useState as useState3 } from "react";
|
|
674
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
675
|
+
"use client";
|
|
676
|
+
function formatCurrency2(value) {
|
|
677
|
+
if (value >= 1e6)
|
|
678
|
+
return `$${(value / 1e6).toFixed(1)}M`;
|
|
679
|
+
if (value >= 1000)
|
|
680
|
+
return `$${(value / 1000).toFixed(0)}K`;
|
|
681
|
+
return `$${value}`;
|
|
682
|
+
}
|
|
683
|
+
function CrmPipelineBoard({
|
|
684
|
+
dealsByStage,
|
|
685
|
+
stages,
|
|
686
|
+
onDealClick,
|
|
687
|
+
onDealMove
|
|
688
|
+
}) {
|
|
689
|
+
const [quickMoveOpen, setQuickMoveOpen] = useState3(null);
|
|
690
|
+
const sortedStages = [...stages].sort((a, b) => a.position - b.position);
|
|
691
|
+
const handleQuickMove = (dealId, toStageId) => {
|
|
692
|
+
onDealMove?.(dealId, toStageId);
|
|
693
|
+
setQuickMoveOpen(null);
|
|
694
|
+
};
|
|
695
|
+
return /* @__PURE__ */ jsxDEV2("div", {
|
|
696
|
+
className: "flex gap-4 overflow-x-auto pb-4",
|
|
697
|
+
children: sortedStages.map((stage) => {
|
|
698
|
+
const deals = dealsByStage[stage.id] ?? [];
|
|
699
|
+
const stageValue = deals.reduce((sum, d) => sum + d.value, 0);
|
|
700
|
+
return /* @__PURE__ */ jsxDEV2("div", {
|
|
701
|
+
className: "bg-muted/30 flex w-72 flex-shrink-0 flex-col rounded-lg",
|
|
702
|
+
children: [
|
|
703
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
704
|
+
className: "border-border flex items-center justify-between border-b px-3 py-2",
|
|
705
|
+
children: [
|
|
706
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
707
|
+
children: [
|
|
708
|
+
/* @__PURE__ */ jsxDEV2("h3", {
|
|
709
|
+
className: "font-medium",
|
|
710
|
+
children: stage.name
|
|
711
|
+
}, undefined, false, undefined, this),
|
|
712
|
+
/* @__PURE__ */ jsxDEV2("p", {
|
|
713
|
+
className: "text-muted-foreground text-xs",
|
|
714
|
+
children: [
|
|
715
|
+
deals.length,
|
|
716
|
+
" deals \xB7 ",
|
|
717
|
+
formatCurrency2(stageValue)
|
|
718
|
+
]
|
|
719
|
+
}, undefined, true, undefined, this)
|
|
720
|
+
]
|
|
721
|
+
}, undefined, true, undefined, this),
|
|
722
|
+
/* @__PURE__ */ jsxDEV2("span", {
|
|
723
|
+
className: "bg-muted flex h-6 w-6 items-center justify-center rounded-full text-xs font-medium",
|
|
724
|
+
children: deals.length
|
|
725
|
+
}, undefined, false, undefined, this)
|
|
726
|
+
]
|
|
727
|
+
}, undefined, true, undefined, this),
|
|
728
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
729
|
+
className: "flex flex-1 flex-col gap-2 p-2",
|
|
730
|
+
children: deals.length === 0 ? /* @__PURE__ */ jsxDEV2("div", {
|
|
731
|
+
className: "border-muted-foreground/20 text-muted-foreground flex h-24 items-center justify-center rounded-md border-2 border-dashed text-xs",
|
|
732
|
+
children: "No deals"
|
|
733
|
+
}, undefined, false, undefined, this) : deals.map((deal) => /* @__PURE__ */ jsxDEV2("div", {
|
|
734
|
+
className: "group relative",
|
|
735
|
+
children: [
|
|
736
|
+
/* @__PURE__ */ jsxDEV2(CrmDealCard, {
|
|
737
|
+
deal,
|
|
738
|
+
onClick: () => onDealClick?.(deal.id)
|
|
739
|
+
}, undefined, false, undefined, this),
|
|
740
|
+
deal.status === "OPEN" && onDealMove && /* @__PURE__ */ jsxDEV2("div", {
|
|
741
|
+
className: "absolute top-1 right-1 opacity-0 transition-opacity group-hover:opacity-100",
|
|
742
|
+
children: [
|
|
743
|
+
/* @__PURE__ */ jsxDEV2("button", {
|
|
744
|
+
type: "button",
|
|
745
|
+
onClick: (e) => {
|
|
746
|
+
e.stopPropagation();
|
|
747
|
+
setQuickMoveOpen(quickMoveOpen === deal.id ? null : deal.id);
|
|
748
|
+
},
|
|
749
|
+
className: "bg-background border-border hover:bg-muted flex h-6 w-6 items-center justify-center rounded border text-xs shadow-sm",
|
|
750
|
+
title: "Quick move",
|
|
751
|
+
children: "\u27A1\uFE0F"
|
|
752
|
+
}, undefined, false, undefined, this),
|
|
753
|
+
quickMoveOpen === deal.id && /* @__PURE__ */ jsxDEV2("div", {
|
|
754
|
+
className: "bg-card border-border absolute top-7 right-0 z-20 min-w-[140px] rounded-lg border py-1 shadow-lg",
|
|
755
|
+
children: [
|
|
756
|
+
/* @__PURE__ */ jsxDEV2("p", {
|
|
757
|
+
className: "text-muted-foreground px-3 py-1 text-xs font-medium",
|
|
758
|
+
children: "Move to:"
|
|
759
|
+
}, undefined, false, undefined, this),
|
|
760
|
+
sortedStages.filter((s) => s.id !== deal.stageId).map((s) => /* @__PURE__ */ jsxDEV2("button", {
|
|
761
|
+
type: "button",
|
|
762
|
+
onClick: (e) => {
|
|
763
|
+
e.stopPropagation();
|
|
764
|
+
handleQuickMove(deal.id, s.id);
|
|
765
|
+
},
|
|
766
|
+
className: "hover:bg-muted w-full px-3 py-1.5 text-left text-sm",
|
|
767
|
+
children: s.name
|
|
768
|
+
}, s.id, false, undefined, this))
|
|
769
|
+
]
|
|
770
|
+
}, undefined, true, undefined, this)
|
|
771
|
+
]
|
|
772
|
+
}, undefined, true, undefined, this)
|
|
773
|
+
]
|
|
774
|
+
}, deal.id, true, undefined, this))
|
|
775
|
+
}, undefined, false, undefined, this)
|
|
776
|
+
]
|
|
777
|
+
}, stage.id, true, undefined, this);
|
|
778
|
+
})
|
|
779
|
+
}, undefined, false, undefined, this);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/ui/modals/CreateDealModal.tsx
|
|
783
|
+
import { useState as useState4 } from "react";
|
|
784
|
+
import { Button, Input } from "@contractspec/lib.design-system";
|
|
785
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
786
|
+
"use client";
|
|
787
|
+
var CURRENCIES = ["USD", "EUR", "GBP", "CAD"];
|
|
788
|
+
var DEFAULT_PIPELINE_ID = "pipeline-1";
|
|
789
|
+
function CreateDealModal({
|
|
790
|
+
isOpen,
|
|
791
|
+
onClose,
|
|
792
|
+
onSubmit,
|
|
793
|
+
stages,
|
|
794
|
+
isLoading = false
|
|
795
|
+
}) {
|
|
796
|
+
const [name, setName] = useState4("");
|
|
797
|
+
const [value, setValue] = useState4("");
|
|
798
|
+
const [currency, setCurrency] = useState4("USD");
|
|
799
|
+
const [stageId, setStageId] = useState4(stages[0]?.id ?? "");
|
|
800
|
+
const [expectedCloseDate, setExpectedCloseDate] = useState4("");
|
|
801
|
+
const [error, setError] = useState4(null);
|
|
802
|
+
const handleSubmit = async (e) => {
|
|
803
|
+
e.preventDefault();
|
|
804
|
+
setError(null);
|
|
805
|
+
if (!name.trim()) {
|
|
806
|
+
setError("Deal name is required");
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
const numericValue = parseFloat(value);
|
|
810
|
+
if (isNaN(numericValue) || numericValue <= 0) {
|
|
811
|
+
setError("Value must be a positive number");
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
if (!stageId) {
|
|
815
|
+
setError("Please select a pipeline stage");
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
try {
|
|
819
|
+
await onSubmit({
|
|
820
|
+
name: name.trim(),
|
|
821
|
+
value: numericValue,
|
|
822
|
+
currency,
|
|
823
|
+
pipelineId: DEFAULT_PIPELINE_ID,
|
|
824
|
+
stageId,
|
|
825
|
+
expectedCloseDate: expectedCloseDate ? new Date(expectedCloseDate) : undefined
|
|
826
|
+
});
|
|
827
|
+
setName("");
|
|
828
|
+
setValue("");
|
|
829
|
+
setCurrency("USD");
|
|
830
|
+
setStageId(stages[0]?.id ?? "");
|
|
831
|
+
setExpectedCloseDate("");
|
|
832
|
+
onClose();
|
|
833
|
+
} catch (err) {
|
|
834
|
+
setError(err instanceof Error ? err.message : "Failed to create deal");
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
if (!isOpen)
|
|
838
|
+
return null;
|
|
839
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
840
|
+
className: "fixed inset-0 z-50 flex items-center justify-center",
|
|
841
|
+
children: [
|
|
842
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
843
|
+
className: "bg-background/80 absolute inset-0 backdrop-blur-sm",
|
|
844
|
+
onClick: onClose,
|
|
845
|
+
role: "button",
|
|
846
|
+
tabIndex: 0,
|
|
847
|
+
onKeyDown: (e) => {
|
|
848
|
+
if (e.key === "Enter" || e.key === " ")
|
|
849
|
+
onClose();
|
|
850
|
+
},
|
|
851
|
+
"aria-label": "Close modal"
|
|
852
|
+
}, undefined, false, undefined, this),
|
|
853
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
854
|
+
className: "bg-card border-border relative z-10 w-full max-w-md rounded-xl border p-6 shadow-xl",
|
|
855
|
+
children: [
|
|
856
|
+
/* @__PURE__ */ jsxDEV3("h2", {
|
|
857
|
+
className: "mb-4 text-xl font-semibold",
|
|
858
|
+
children: "Create New Deal"
|
|
859
|
+
}, undefined, false, undefined, this),
|
|
860
|
+
/* @__PURE__ */ jsxDEV3("form", {
|
|
861
|
+
onSubmit: handleSubmit,
|
|
862
|
+
className: "space-y-4",
|
|
863
|
+
children: [
|
|
864
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
865
|
+
children: [
|
|
866
|
+
/* @__PURE__ */ jsxDEV3("label", {
|
|
867
|
+
htmlFor: "deal-name",
|
|
868
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
869
|
+
children: "Deal Name *"
|
|
870
|
+
}, undefined, false, undefined, this),
|
|
871
|
+
/* @__PURE__ */ jsxDEV3(Input, {
|
|
872
|
+
id: "deal-name",
|
|
873
|
+
value: name,
|
|
874
|
+
onChange: (e) => setName(e.target.value),
|
|
875
|
+
placeholder: "e.g., Enterprise License - Acme Corp",
|
|
876
|
+
disabled: isLoading
|
|
877
|
+
}, undefined, false, undefined, this)
|
|
878
|
+
]
|
|
879
|
+
}, undefined, true, undefined, this),
|
|
880
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
881
|
+
className: "flex gap-3",
|
|
882
|
+
children: [
|
|
883
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
884
|
+
className: "flex-1",
|
|
885
|
+
children: [
|
|
886
|
+
/* @__PURE__ */ jsxDEV3("label", {
|
|
887
|
+
htmlFor: "deal-value",
|
|
888
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
889
|
+
children: "Value *"
|
|
890
|
+
}, undefined, false, undefined, this),
|
|
891
|
+
/* @__PURE__ */ jsxDEV3(Input, {
|
|
892
|
+
id: "deal-value",
|
|
893
|
+
type: "number",
|
|
894
|
+
min: "0",
|
|
895
|
+
step: "0.01",
|
|
896
|
+
value,
|
|
897
|
+
onChange: (e) => setValue(e.target.value),
|
|
898
|
+
placeholder: "50000",
|
|
899
|
+
disabled: isLoading
|
|
900
|
+
}, undefined, false, undefined, this)
|
|
901
|
+
]
|
|
902
|
+
}, undefined, true, undefined, this),
|
|
903
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
904
|
+
className: "w-24",
|
|
905
|
+
children: [
|
|
906
|
+
/* @__PURE__ */ jsxDEV3("label", {
|
|
907
|
+
htmlFor: "deal-currency",
|
|
908
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
909
|
+
children: "Currency"
|
|
910
|
+
}, undefined, false, undefined, this),
|
|
911
|
+
/* @__PURE__ */ jsxDEV3("select", {
|
|
912
|
+
id: "deal-currency",
|
|
913
|
+
value: currency,
|
|
914
|
+
onChange: (e) => setCurrency(e.target.value),
|
|
915
|
+
disabled: isLoading,
|
|
916
|
+
className: "border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none disabled:opacity-50",
|
|
917
|
+
children: CURRENCIES.map((c) => /* @__PURE__ */ jsxDEV3("option", {
|
|
918
|
+
value: c,
|
|
919
|
+
children: c
|
|
920
|
+
}, c, false, undefined, this))
|
|
921
|
+
}, undefined, false, undefined, this)
|
|
922
|
+
]
|
|
923
|
+
}, undefined, true, undefined, this)
|
|
924
|
+
]
|
|
925
|
+
}, undefined, true, undefined, this),
|
|
926
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
927
|
+
children: [
|
|
928
|
+
/* @__PURE__ */ jsxDEV3("label", {
|
|
929
|
+
htmlFor: "deal-stage",
|
|
930
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
931
|
+
children: "Pipeline Stage *"
|
|
932
|
+
}, undefined, false, undefined, this),
|
|
933
|
+
/* @__PURE__ */ jsxDEV3("select", {
|
|
934
|
+
id: "deal-stage",
|
|
935
|
+
value: stageId,
|
|
936
|
+
onChange: (e) => setStageId(e.target.value),
|
|
937
|
+
disabled: isLoading,
|
|
938
|
+
className: "border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none disabled:opacity-50",
|
|
939
|
+
children: stages.map((stage) => /* @__PURE__ */ jsxDEV3("option", {
|
|
940
|
+
value: stage.id,
|
|
941
|
+
children: stage.name
|
|
942
|
+
}, stage.id, false, undefined, this))
|
|
943
|
+
}, undefined, false, undefined, this)
|
|
944
|
+
]
|
|
945
|
+
}, undefined, true, undefined, this),
|
|
946
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
947
|
+
children: [
|
|
948
|
+
/* @__PURE__ */ jsxDEV3("label", {
|
|
949
|
+
htmlFor: "deal-close-date",
|
|
950
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
951
|
+
children: "Expected Close Date"
|
|
952
|
+
}, undefined, false, undefined, this),
|
|
953
|
+
/* @__PURE__ */ jsxDEV3(Input, {
|
|
954
|
+
id: "deal-close-date",
|
|
955
|
+
type: "date",
|
|
956
|
+
value: expectedCloseDate,
|
|
957
|
+
onChange: (e) => setExpectedCloseDate(e.target.value),
|
|
958
|
+
disabled: isLoading
|
|
959
|
+
}, undefined, false, undefined, this)
|
|
960
|
+
]
|
|
961
|
+
}, undefined, true, undefined, this),
|
|
962
|
+
error && /* @__PURE__ */ jsxDEV3("div", {
|
|
963
|
+
className: "bg-destructive/10 text-destructive rounded-md p-3 text-sm",
|
|
964
|
+
children: error
|
|
965
|
+
}, undefined, false, undefined, this),
|
|
966
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
967
|
+
className: "flex justify-end gap-3 pt-2",
|
|
968
|
+
children: [
|
|
969
|
+
/* @__PURE__ */ jsxDEV3(Button, {
|
|
970
|
+
type: "button",
|
|
971
|
+
variant: "ghost",
|
|
972
|
+
onPress: onClose,
|
|
973
|
+
disabled: isLoading,
|
|
974
|
+
children: "Cancel"
|
|
975
|
+
}, undefined, false, undefined, this),
|
|
976
|
+
/* @__PURE__ */ jsxDEV3(Button, {
|
|
977
|
+
type: "submit",
|
|
978
|
+
disabled: isLoading,
|
|
979
|
+
children: isLoading ? "Creating..." : "Create Deal"
|
|
980
|
+
}, undefined, false, undefined, this)
|
|
981
|
+
]
|
|
982
|
+
}, undefined, true, undefined, this)
|
|
983
|
+
]
|
|
984
|
+
}, undefined, true, undefined, this)
|
|
985
|
+
]
|
|
986
|
+
}, undefined, true, undefined, this)
|
|
987
|
+
]
|
|
988
|
+
}, undefined, true, undefined, this);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// src/ui/modals/DealActionsModal.tsx
|
|
992
|
+
import { useState as useState5 } from "react";
|
|
993
|
+
import { Button as Button2 } from "@contractspec/lib.design-system";
|
|
994
|
+
import { jsxDEV as jsxDEV4, Fragment } from "react/jsx-dev-runtime";
|
|
995
|
+
"use client";
|
|
996
|
+
function formatCurrency3(value, currency) {
|
|
997
|
+
return new Intl.NumberFormat("en-US", {
|
|
998
|
+
style: "currency",
|
|
999
|
+
currency,
|
|
1000
|
+
minimumFractionDigits: 0,
|
|
1001
|
+
maximumFractionDigits: 0
|
|
1002
|
+
}).format(value);
|
|
1003
|
+
}
|
|
1004
|
+
function DealActionsModal({
|
|
1005
|
+
isOpen,
|
|
1006
|
+
deal,
|
|
1007
|
+
stages,
|
|
1008
|
+
onClose,
|
|
1009
|
+
onWin,
|
|
1010
|
+
onLose,
|
|
1011
|
+
onMove,
|
|
1012
|
+
isLoading = false
|
|
1013
|
+
}) {
|
|
1014
|
+
const [mode, setMode] = useState5("menu");
|
|
1015
|
+
const [wonSource, setWonSource] = useState5("");
|
|
1016
|
+
const [lostReason, setLostReason] = useState5("");
|
|
1017
|
+
const [notes, setNotes] = useState5("");
|
|
1018
|
+
const [selectedStageId, setSelectedStageId] = useState5("");
|
|
1019
|
+
const [error, setError] = useState5(null);
|
|
1020
|
+
const resetForm = () => {
|
|
1021
|
+
setMode("menu");
|
|
1022
|
+
setWonSource("");
|
|
1023
|
+
setLostReason("");
|
|
1024
|
+
setNotes("");
|
|
1025
|
+
setSelectedStageId("");
|
|
1026
|
+
setError(null);
|
|
1027
|
+
};
|
|
1028
|
+
const handleClose = () => {
|
|
1029
|
+
resetForm();
|
|
1030
|
+
onClose();
|
|
1031
|
+
};
|
|
1032
|
+
const handleWin = async () => {
|
|
1033
|
+
if (!deal)
|
|
1034
|
+
return;
|
|
1035
|
+
setError(null);
|
|
1036
|
+
try {
|
|
1037
|
+
await onWin({
|
|
1038
|
+
dealId: deal.id,
|
|
1039
|
+
wonSource: wonSource.trim() || undefined,
|
|
1040
|
+
notes: notes.trim() || undefined
|
|
1041
|
+
});
|
|
1042
|
+
handleClose();
|
|
1043
|
+
} catch (err) {
|
|
1044
|
+
setError(err instanceof Error ? err.message : "Failed to mark deal as won");
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
const handleLose = async () => {
|
|
1048
|
+
if (!deal)
|
|
1049
|
+
return;
|
|
1050
|
+
setError(null);
|
|
1051
|
+
if (!lostReason.trim()) {
|
|
1052
|
+
setError("Please provide a reason for losing the deal");
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
try {
|
|
1056
|
+
await onLose({
|
|
1057
|
+
dealId: deal.id,
|
|
1058
|
+
lostReason: lostReason.trim(),
|
|
1059
|
+
notes: notes.trim() || undefined
|
|
1060
|
+
});
|
|
1061
|
+
handleClose();
|
|
1062
|
+
} catch (err) {
|
|
1063
|
+
setError(err instanceof Error ? err.message : "Failed to mark deal as lost");
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
const handleMove = async () => {
|
|
1067
|
+
if (!deal)
|
|
1068
|
+
return;
|
|
1069
|
+
setError(null);
|
|
1070
|
+
if (!selectedStageId) {
|
|
1071
|
+
setError("Please select a stage");
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
if (selectedStageId === deal.stageId) {
|
|
1075
|
+
setError("Deal is already in this stage");
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
try {
|
|
1079
|
+
await onMove({
|
|
1080
|
+
dealId: deal.id,
|
|
1081
|
+
stageId: selectedStageId
|
|
1082
|
+
});
|
|
1083
|
+
handleClose();
|
|
1084
|
+
} catch (err) {
|
|
1085
|
+
setError(err instanceof Error ? err.message : "Failed to move deal");
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
if (!isOpen || !deal)
|
|
1089
|
+
return null;
|
|
1090
|
+
return /* @__PURE__ */ jsxDEV4("div", {
|
|
1091
|
+
className: "fixed inset-0 z-50 flex items-center justify-center",
|
|
1092
|
+
children: [
|
|
1093
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1094
|
+
className: "bg-background/80 absolute inset-0 backdrop-blur-sm",
|
|
1095
|
+
onClick: handleClose,
|
|
1096
|
+
role: "button",
|
|
1097
|
+
tabIndex: 0,
|
|
1098
|
+
onKeyDown: (e) => {
|
|
1099
|
+
if (e.key === "Enter" || e.key === " ")
|
|
1100
|
+
handleClose();
|
|
1101
|
+
},
|
|
1102
|
+
"aria-label": "Close modal"
|
|
1103
|
+
}, undefined, false, undefined, this),
|
|
1104
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1105
|
+
className: "bg-card border-border relative z-10 w-full max-w-md rounded-xl border p-6 shadow-xl",
|
|
1106
|
+
children: [
|
|
1107
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1108
|
+
className: "border-border mb-4 border-b pb-4",
|
|
1109
|
+
children: [
|
|
1110
|
+
/* @__PURE__ */ jsxDEV4("h2", {
|
|
1111
|
+
className: "text-xl font-semibold",
|
|
1112
|
+
children: deal.name
|
|
1113
|
+
}, undefined, false, undefined, this),
|
|
1114
|
+
/* @__PURE__ */ jsxDEV4("p", {
|
|
1115
|
+
className: "text-primary text-lg font-medium",
|
|
1116
|
+
children: formatCurrency3(deal.value, deal.currency)
|
|
1117
|
+
}, undefined, false, undefined, this),
|
|
1118
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1119
|
+
className: `mt-2 inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${deal.status === "WON" ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" : deal.status === "LOST" ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400" : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,
|
|
1120
|
+
children: deal.status
|
|
1121
|
+
}, undefined, false, undefined, this)
|
|
1122
|
+
]
|
|
1123
|
+
}, undefined, true, undefined, this),
|
|
1124
|
+
mode === "menu" && /* @__PURE__ */ jsxDEV4("div", {
|
|
1125
|
+
className: "space-y-3",
|
|
1126
|
+
children: [
|
|
1127
|
+
deal.status === "OPEN" && /* @__PURE__ */ jsxDEV4(Fragment, {
|
|
1128
|
+
children: [
|
|
1129
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1130
|
+
className: "w-full justify-start",
|
|
1131
|
+
variant: "ghost",
|
|
1132
|
+
onPress: () => setMode("win"),
|
|
1133
|
+
children: [
|
|
1134
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1135
|
+
className: "mr-2",
|
|
1136
|
+
children: "\uD83C\uDFC6"
|
|
1137
|
+
}, undefined, false, undefined, this),
|
|
1138
|
+
" Mark as Won"
|
|
1139
|
+
]
|
|
1140
|
+
}, undefined, true, undefined, this),
|
|
1141
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1142
|
+
className: "w-full justify-start",
|
|
1143
|
+
variant: "ghost",
|
|
1144
|
+
onPress: () => setMode("lose"),
|
|
1145
|
+
children: [
|
|
1146
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1147
|
+
className: "mr-2",
|
|
1148
|
+
children: "\u274C"
|
|
1149
|
+
}, undefined, false, undefined, this),
|
|
1150
|
+
" Mark as Lost"
|
|
1151
|
+
]
|
|
1152
|
+
}, undefined, true, undefined, this),
|
|
1153
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1154
|
+
className: "w-full justify-start",
|
|
1155
|
+
variant: "ghost",
|
|
1156
|
+
onPress: () => {
|
|
1157
|
+
setSelectedStageId(deal.stageId);
|
|
1158
|
+
setMode("move");
|
|
1159
|
+
},
|
|
1160
|
+
children: [
|
|
1161
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1162
|
+
className: "mr-2",
|
|
1163
|
+
children: "\u27A1\uFE0F"
|
|
1164
|
+
}, undefined, false, undefined, this),
|
|
1165
|
+
" Move to Stage"
|
|
1166
|
+
]
|
|
1167
|
+
}, undefined, true, undefined, this)
|
|
1168
|
+
]
|
|
1169
|
+
}, undefined, true, undefined, this),
|
|
1170
|
+
deal.status !== "OPEN" && /* @__PURE__ */ jsxDEV4("p", {
|
|
1171
|
+
className: "text-muted-foreground py-4 text-center",
|
|
1172
|
+
children: [
|
|
1173
|
+
"This deal is already ",
|
|
1174
|
+
deal.status.toLowerCase(),
|
|
1175
|
+
". No actions available."
|
|
1176
|
+
]
|
|
1177
|
+
}, undefined, true, undefined, this),
|
|
1178
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1179
|
+
className: "border-border border-t pt-3",
|
|
1180
|
+
children: /* @__PURE__ */ jsxDEV4(Button2, {
|
|
1181
|
+
className: "w-full",
|
|
1182
|
+
variant: "outline",
|
|
1183
|
+
onPress: handleClose,
|
|
1184
|
+
children: "Close"
|
|
1185
|
+
}, undefined, false, undefined, this)
|
|
1186
|
+
}, undefined, false, undefined, this)
|
|
1187
|
+
]
|
|
1188
|
+
}, undefined, true, undefined, this),
|
|
1189
|
+
mode === "win" && /* @__PURE__ */ jsxDEV4("div", {
|
|
1190
|
+
className: "space-y-4",
|
|
1191
|
+
children: [
|
|
1192
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1193
|
+
children: [
|
|
1194
|
+
/* @__PURE__ */ jsxDEV4("label", {
|
|
1195
|
+
htmlFor: "won-source",
|
|
1196
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
1197
|
+
children: "How did you win this deal?"
|
|
1198
|
+
}, undefined, false, undefined, this),
|
|
1199
|
+
/* @__PURE__ */ jsxDEV4("select", {
|
|
1200
|
+
id: "won-source",
|
|
1201
|
+
value: wonSource,
|
|
1202
|
+
onChange: (e) => setWonSource(e.target.value),
|
|
1203
|
+
className: "border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none",
|
|
1204
|
+
children: [
|
|
1205
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1206
|
+
value: "",
|
|
1207
|
+
children: "Select a source..."
|
|
1208
|
+
}, undefined, false, undefined, this),
|
|
1209
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1210
|
+
value: "referral",
|
|
1211
|
+
children: "Referral"
|
|
1212
|
+
}, undefined, false, undefined, this),
|
|
1213
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1214
|
+
value: "cold_outreach",
|
|
1215
|
+
children: "Cold Outreach"
|
|
1216
|
+
}, undefined, false, undefined, this),
|
|
1217
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1218
|
+
value: "inbound",
|
|
1219
|
+
children: "Inbound Lead"
|
|
1220
|
+
}, undefined, false, undefined, this),
|
|
1221
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1222
|
+
value: "upsell",
|
|
1223
|
+
children: "Upsell"
|
|
1224
|
+
}, undefined, false, undefined, this),
|
|
1225
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1226
|
+
value: "other",
|
|
1227
|
+
children: "Other"
|
|
1228
|
+
}, undefined, false, undefined, this)
|
|
1229
|
+
]
|
|
1230
|
+
}, undefined, true, undefined, this)
|
|
1231
|
+
]
|
|
1232
|
+
}, undefined, true, undefined, this),
|
|
1233
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1234
|
+
children: [
|
|
1235
|
+
/* @__PURE__ */ jsxDEV4("label", {
|
|
1236
|
+
htmlFor: "win-notes",
|
|
1237
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
1238
|
+
children: "Notes (optional)"
|
|
1239
|
+
}, undefined, false, undefined, this),
|
|
1240
|
+
/* @__PURE__ */ jsxDEV4("textarea", {
|
|
1241
|
+
id: "win-notes",
|
|
1242
|
+
value: notes,
|
|
1243
|
+
onChange: (e) => setNotes(e.target.value),
|
|
1244
|
+
placeholder: "Any additional notes about the win...",
|
|
1245
|
+
rows: 3,
|
|
1246
|
+
className: "border-input bg-background focus:ring-ring w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
|
|
1247
|
+
}, undefined, false, undefined, this)
|
|
1248
|
+
]
|
|
1249
|
+
}, undefined, true, undefined, this),
|
|
1250
|
+
error && /* @__PURE__ */ jsxDEV4("div", {
|
|
1251
|
+
className: "bg-destructive/10 text-destructive rounded-md p-3 text-sm",
|
|
1252
|
+
children: error
|
|
1253
|
+
}, undefined, false, undefined, this),
|
|
1254
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1255
|
+
className: "flex justify-end gap-3 pt-2",
|
|
1256
|
+
children: [
|
|
1257
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1258
|
+
variant: "ghost",
|
|
1259
|
+
onPress: () => setMode("menu"),
|
|
1260
|
+
disabled: isLoading,
|
|
1261
|
+
children: "Back"
|
|
1262
|
+
}, undefined, false, undefined, this),
|
|
1263
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1264
|
+
onPress: handleWin,
|
|
1265
|
+
disabled: isLoading,
|
|
1266
|
+
children: isLoading ? "Processing..." : "\uD83C\uDFC6 Confirm Win"
|
|
1267
|
+
}, undefined, false, undefined, this)
|
|
1268
|
+
]
|
|
1269
|
+
}, undefined, true, undefined, this)
|
|
1270
|
+
]
|
|
1271
|
+
}, undefined, true, undefined, this),
|
|
1272
|
+
mode === "lose" && /* @__PURE__ */ jsxDEV4("div", {
|
|
1273
|
+
className: "space-y-4",
|
|
1274
|
+
children: [
|
|
1275
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1276
|
+
children: [
|
|
1277
|
+
/* @__PURE__ */ jsxDEV4("label", {
|
|
1278
|
+
htmlFor: "lost-reason",
|
|
1279
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
1280
|
+
children: "Why was this deal lost? *"
|
|
1281
|
+
}, undefined, false, undefined, this),
|
|
1282
|
+
/* @__PURE__ */ jsxDEV4("select", {
|
|
1283
|
+
id: "lost-reason",
|
|
1284
|
+
value: lostReason,
|
|
1285
|
+
onChange: (e) => setLostReason(e.target.value),
|
|
1286
|
+
className: "border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none",
|
|
1287
|
+
children: [
|
|
1288
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1289
|
+
value: "",
|
|
1290
|
+
children: "Select a reason..."
|
|
1291
|
+
}, undefined, false, undefined, this),
|
|
1292
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1293
|
+
value: "price",
|
|
1294
|
+
children: "Price too high"
|
|
1295
|
+
}, undefined, false, undefined, this),
|
|
1296
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1297
|
+
value: "competitor",
|
|
1298
|
+
children: "Lost to competitor"
|
|
1299
|
+
}, undefined, false, undefined, this),
|
|
1300
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1301
|
+
value: "no_budget",
|
|
1302
|
+
children: "No budget"
|
|
1303
|
+
}, undefined, false, undefined, this),
|
|
1304
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1305
|
+
value: "no_decision",
|
|
1306
|
+
children: "No decision made"
|
|
1307
|
+
}, undefined, false, undefined, this),
|
|
1308
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1309
|
+
value: "timing",
|
|
1310
|
+
children: "Bad timing"
|
|
1311
|
+
}, undefined, false, undefined, this),
|
|
1312
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1313
|
+
value: "product_fit",
|
|
1314
|
+
children: "Product not a fit"
|
|
1315
|
+
}, undefined, false, undefined, this),
|
|
1316
|
+
/* @__PURE__ */ jsxDEV4("option", {
|
|
1317
|
+
value: "other",
|
|
1318
|
+
children: "Other"
|
|
1319
|
+
}, undefined, false, undefined, this)
|
|
1320
|
+
]
|
|
1321
|
+
}, undefined, true, undefined, this)
|
|
1322
|
+
]
|
|
1323
|
+
}, undefined, true, undefined, this),
|
|
1324
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1325
|
+
children: [
|
|
1326
|
+
/* @__PURE__ */ jsxDEV4("label", {
|
|
1327
|
+
htmlFor: "lose-notes",
|
|
1328
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
1329
|
+
children: "Notes (optional)"
|
|
1330
|
+
}, undefined, false, undefined, this),
|
|
1331
|
+
/* @__PURE__ */ jsxDEV4("textarea", {
|
|
1332
|
+
id: "lose-notes",
|
|
1333
|
+
value: notes,
|
|
1334
|
+
onChange: (e) => setNotes(e.target.value),
|
|
1335
|
+
placeholder: "Any additional details...",
|
|
1336
|
+
rows: 3,
|
|
1337
|
+
className: "border-input bg-background focus:ring-ring w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
|
|
1338
|
+
}, undefined, false, undefined, this)
|
|
1339
|
+
]
|
|
1340
|
+
}, undefined, true, undefined, this),
|
|
1341
|
+
error && /* @__PURE__ */ jsxDEV4("div", {
|
|
1342
|
+
className: "bg-destructive/10 text-destructive rounded-md p-3 text-sm",
|
|
1343
|
+
children: error
|
|
1344
|
+
}, undefined, false, undefined, this),
|
|
1345
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1346
|
+
className: "flex justify-end gap-3 pt-2",
|
|
1347
|
+
children: [
|
|
1348
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1349
|
+
variant: "ghost",
|
|
1350
|
+
onPress: () => setMode("menu"),
|
|
1351
|
+
disabled: isLoading,
|
|
1352
|
+
children: "Back"
|
|
1353
|
+
}, undefined, false, undefined, this),
|
|
1354
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1355
|
+
variant: "destructive",
|
|
1356
|
+
onPress: handleLose,
|
|
1357
|
+
disabled: isLoading,
|
|
1358
|
+
children: isLoading ? "Processing..." : "\u274C Confirm Loss"
|
|
1359
|
+
}, undefined, false, undefined, this)
|
|
1360
|
+
]
|
|
1361
|
+
}, undefined, true, undefined, this)
|
|
1362
|
+
]
|
|
1363
|
+
}, undefined, true, undefined, this),
|
|
1364
|
+
mode === "move" && /* @__PURE__ */ jsxDEV4("div", {
|
|
1365
|
+
className: "space-y-4",
|
|
1366
|
+
children: [
|
|
1367
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1368
|
+
children: [
|
|
1369
|
+
/* @__PURE__ */ jsxDEV4("label", {
|
|
1370
|
+
htmlFor: "move-stage",
|
|
1371
|
+
className: "text-muted-foreground mb-1 block text-sm font-medium",
|
|
1372
|
+
children: "Move to Stage"
|
|
1373
|
+
}, undefined, false, undefined, this),
|
|
1374
|
+
/* @__PURE__ */ jsxDEV4("select", {
|
|
1375
|
+
id: "move-stage",
|
|
1376
|
+
value: selectedStageId,
|
|
1377
|
+
onChange: (e) => setSelectedStageId(e.target.value),
|
|
1378
|
+
className: "border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none",
|
|
1379
|
+
children: stages.map((stage) => /* @__PURE__ */ jsxDEV4("option", {
|
|
1380
|
+
value: stage.id,
|
|
1381
|
+
children: [
|
|
1382
|
+
stage.name,
|
|
1383
|
+
stage.id === deal.stageId ? " (current)" : ""
|
|
1384
|
+
]
|
|
1385
|
+
}, stage.id, true, undefined, this))
|
|
1386
|
+
}, undefined, false, undefined, this)
|
|
1387
|
+
]
|
|
1388
|
+
}, undefined, true, undefined, this),
|
|
1389
|
+
error && /* @__PURE__ */ jsxDEV4("div", {
|
|
1390
|
+
className: "bg-destructive/10 text-destructive rounded-md p-3 text-sm",
|
|
1391
|
+
children: error
|
|
1392
|
+
}, undefined, false, undefined, this),
|
|
1393
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
1394
|
+
className: "flex justify-end gap-3 pt-2",
|
|
1395
|
+
children: [
|
|
1396
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1397
|
+
variant: "ghost",
|
|
1398
|
+
onPress: () => setMode("menu"),
|
|
1399
|
+
disabled: isLoading,
|
|
1400
|
+
children: "Back"
|
|
1401
|
+
}, undefined, false, undefined, this),
|
|
1402
|
+
/* @__PURE__ */ jsxDEV4(Button2, {
|
|
1403
|
+
onPress: handleMove,
|
|
1404
|
+
disabled: isLoading,
|
|
1405
|
+
children: isLoading ? "Moving..." : "\u27A1\uFE0F Move Deal"
|
|
1406
|
+
}, undefined, false, undefined, this)
|
|
1407
|
+
]
|
|
1408
|
+
}, undefined, true, undefined, this)
|
|
1409
|
+
]
|
|
1410
|
+
}, undefined, true, undefined, this)
|
|
1411
|
+
]
|
|
1412
|
+
}, undefined, true, undefined, this)
|
|
1413
|
+
]
|
|
1414
|
+
}, undefined, true, undefined, this);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// src/ui/CrmDashboard.tsx
|
|
1418
|
+
import { useCallback as useCallback3, useState as useState6 } from "react";
|
|
1419
|
+
import {
|
|
1420
|
+
Button as Button3,
|
|
1421
|
+
ErrorState,
|
|
1422
|
+
LoaderBlock,
|
|
1423
|
+
StatCard,
|
|
1424
|
+
StatCardGroup
|
|
1425
|
+
} from "@contractspec/lib.design-system";
|
|
1426
|
+
import {
|
|
1427
|
+
Tabs,
|
|
1428
|
+
TabsContent,
|
|
1429
|
+
TabsList,
|
|
1430
|
+
TabsTrigger
|
|
1431
|
+
} from "@contractspec/lib.ui-kit-web/ui/tabs";
|
|
1432
|
+
import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
|
|
1433
|
+
"use client";
|
|
1434
|
+
function formatCurrency4(value, currency = "USD") {
|
|
1435
|
+
return new Intl.NumberFormat("en-US", {
|
|
1436
|
+
style: "currency",
|
|
1437
|
+
currency,
|
|
1438
|
+
minimumFractionDigits: 0,
|
|
1439
|
+
maximumFractionDigits: 0
|
|
1440
|
+
}).format(value);
|
|
1441
|
+
}
|
|
1442
|
+
function CrmDashboard() {
|
|
1443
|
+
const [isCreateModalOpen, setIsCreateModalOpen] = useState6(false);
|
|
1444
|
+
const [selectedDeal, setSelectedDeal] = useState6(null);
|
|
1445
|
+
const [isDealActionsOpen, setIsDealActionsOpen] = useState6(false);
|
|
1446
|
+
const { data, dealsByStage, stages, loading, error, stats, refetch } = useDealList();
|
|
1447
|
+
const mutations = useDealMutations({
|
|
1448
|
+
onSuccess: () => {
|
|
1449
|
+
refetch();
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
const handleDealClick = useCallback3((dealId) => {
|
|
1453
|
+
const deal = dealsByStage ? Object.values(dealsByStage).flat().find((d) => d.id === dealId) : null;
|
|
1454
|
+
if (deal) {
|
|
1455
|
+
setSelectedDeal(deal);
|
|
1456
|
+
setIsDealActionsOpen(true);
|
|
1457
|
+
}
|
|
1458
|
+
}, [dealsByStage]);
|
|
1459
|
+
const handleDealMove = useCallback3(async (dealId, toStageId) => {
|
|
1460
|
+
await mutations.moveDeal({ dealId, stageId: toStageId });
|
|
1461
|
+
}, [mutations]);
|
|
1462
|
+
if (loading && !data) {
|
|
1463
|
+
return /* @__PURE__ */ jsxDEV5(LoaderBlock, {
|
|
1464
|
+
label: "Loading CRM..."
|
|
1465
|
+
}, undefined, false, undefined, this);
|
|
1466
|
+
}
|
|
1467
|
+
if (error) {
|
|
1468
|
+
return /* @__PURE__ */ jsxDEV5(ErrorState, {
|
|
1469
|
+
title: "Failed to load CRM",
|
|
1470
|
+
description: error.message,
|
|
1471
|
+
onRetry: refetch,
|
|
1472
|
+
retryLabel: "Retry"
|
|
1473
|
+
}, undefined, false, undefined, this);
|
|
1474
|
+
}
|
|
1475
|
+
return /* @__PURE__ */ jsxDEV5("div", {
|
|
1476
|
+
className: "space-y-6",
|
|
1477
|
+
children: [
|
|
1478
|
+
/* @__PURE__ */ jsxDEV5("div", {
|
|
1479
|
+
className: "flex items-center justify-between",
|
|
1480
|
+
children: [
|
|
1481
|
+
/* @__PURE__ */ jsxDEV5("h2", {
|
|
1482
|
+
className: "text-2xl font-bold",
|
|
1483
|
+
children: "CRM Pipeline"
|
|
1484
|
+
}, undefined, false, undefined, this),
|
|
1485
|
+
/* @__PURE__ */ jsxDEV5(Button3, {
|
|
1486
|
+
onClick: () => setIsCreateModalOpen(true),
|
|
1487
|
+
children: [
|
|
1488
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
1489
|
+
className: "mr-2",
|
|
1490
|
+
children: "+"
|
|
1491
|
+
}, undefined, false, undefined, this),
|
|
1492
|
+
" Create Deal"
|
|
1493
|
+
]
|
|
1494
|
+
}, undefined, true, undefined, this)
|
|
1495
|
+
]
|
|
1496
|
+
}, undefined, true, undefined, this),
|
|
1497
|
+
stats && /* @__PURE__ */ jsxDEV5(StatCardGroup, {
|
|
1498
|
+
children: [
|
|
1499
|
+
/* @__PURE__ */ jsxDEV5(StatCard, {
|
|
1500
|
+
label: "Total Pipeline",
|
|
1501
|
+
value: formatCurrency4(stats.totalValue),
|
|
1502
|
+
hint: `${stats.total} deals`
|
|
1503
|
+
}, undefined, false, undefined, this),
|
|
1504
|
+
/* @__PURE__ */ jsxDEV5(StatCard, {
|
|
1505
|
+
label: "Open Deals",
|
|
1506
|
+
value: formatCurrency4(stats.openValue),
|
|
1507
|
+
hint: `${stats.openCount} active`
|
|
1508
|
+
}, undefined, false, undefined, this),
|
|
1509
|
+
/* @__PURE__ */ jsxDEV5(StatCard, {
|
|
1510
|
+
label: "Won",
|
|
1511
|
+
value: formatCurrency4(stats.wonValue),
|
|
1512
|
+
hint: `${stats.wonCount} closed`
|
|
1513
|
+
}, undefined, false, undefined, this),
|
|
1514
|
+
/* @__PURE__ */ jsxDEV5(StatCard, {
|
|
1515
|
+
label: "Lost",
|
|
1516
|
+
value: stats.lostCount,
|
|
1517
|
+
hint: "deals lost"
|
|
1518
|
+
}, undefined, false, undefined, this)
|
|
1519
|
+
]
|
|
1520
|
+
}, undefined, true, undefined, this),
|
|
1521
|
+
/* @__PURE__ */ jsxDEV5(Tabs, {
|
|
1522
|
+
defaultValue: "pipeline",
|
|
1523
|
+
className: "w-full",
|
|
1524
|
+
children: [
|
|
1525
|
+
/* @__PURE__ */ jsxDEV5(TabsList, {
|
|
1526
|
+
children: [
|
|
1527
|
+
/* @__PURE__ */ jsxDEV5(TabsTrigger, {
|
|
1528
|
+
value: "pipeline",
|
|
1529
|
+
children: [
|
|
1530
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
1531
|
+
className: "mr-2",
|
|
1532
|
+
children: "\uD83D\uDCCA"
|
|
1533
|
+
}, undefined, false, undefined, this),
|
|
1534
|
+
"Pipeline"
|
|
1535
|
+
]
|
|
1536
|
+
}, undefined, true, undefined, this),
|
|
1537
|
+
/* @__PURE__ */ jsxDEV5(TabsTrigger, {
|
|
1538
|
+
value: "list",
|
|
1539
|
+
children: [
|
|
1540
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
1541
|
+
className: "mr-2",
|
|
1542
|
+
children: "\uD83D\uDCCB"
|
|
1543
|
+
}, undefined, false, undefined, this),
|
|
1544
|
+
"All Deals"
|
|
1545
|
+
]
|
|
1546
|
+
}, undefined, true, undefined, this),
|
|
1547
|
+
/* @__PURE__ */ jsxDEV5(TabsTrigger, {
|
|
1548
|
+
value: "metrics",
|
|
1549
|
+
children: [
|
|
1550
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
1551
|
+
className: "mr-2",
|
|
1552
|
+
children: "\uD83D\uDCC8"
|
|
1553
|
+
}, undefined, false, undefined, this),
|
|
1554
|
+
"Metrics"
|
|
1555
|
+
]
|
|
1556
|
+
}, undefined, true, undefined, this)
|
|
1557
|
+
]
|
|
1558
|
+
}, undefined, true, undefined, this),
|
|
1559
|
+
/* @__PURE__ */ jsxDEV5(TabsContent, {
|
|
1560
|
+
value: "pipeline",
|
|
1561
|
+
className: "min-h-[400px]",
|
|
1562
|
+
children: /* @__PURE__ */ jsxDEV5(CrmPipelineBoard, {
|
|
1563
|
+
dealsByStage,
|
|
1564
|
+
stages,
|
|
1565
|
+
onDealClick: handleDealClick,
|
|
1566
|
+
onDealMove: handleDealMove
|
|
1567
|
+
}, undefined, false, undefined, this)
|
|
1568
|
+
}, undefined, false, undefined, this),
|
|
1569
|
+
/* @__PURE__ */ jsxDEV5(TabsContent, {
|
|
1570
|
+
value: "list",
|
|
1571
|
+
className: "min-h-[400px]",
|
|
1572
|
+
children: /* @__PURE__ */ jsxDEV5(DealListTab, {
|
|
1573
|
+
data,
|
|
1574
|
+
onDealClick: handleDealClick
|
|
1575
|
+
}, undefined, false, undefined, this)
|
|
1576
|
+
}, undefined, false, undefined, this),
|
|
1577
|
+
/* @__PURE__ */ jsxDEV5(TabsContent, {
|
|
1578
|
+
value: "metrics",
|
|
1579
|
+
className: "min-h-[400px]",
|
|
1580
|
+
children: /* @__PURE__ */ jsxDEV5(MetricsTab, {
|
|
1581
|
+
stats
|
|
1582
|
+
}, undefined, false, undefined, this)
|
|
1583
|
+
}, undefined, false, undefined, this)
|
|
1584
|
+
]
|
|
1585
|
+
}, undefined, true, undefined, this),
|
|
1586
|
+
/* @__PURE__ */ jsxDEV5(CreateDealModal, {
|
|
1587
|
+
isOpen: isCreateModalOpen,
|
|
1588
|
+
onClose: () => setIsCreateModalOpen(false),
|
|
1589
|
+
onSubmit: async (input) => {
|
|
1590
|
+
await mutations.createDeal(input);
|
|
1591
|
+
},
|
|
1592
|
+
stages,
|
|
1593
|
+
isLoading: mutations.createState.loading
|
|
1594
|
+
}, undefined, false, undefined, this),
|
|
1595
|
+
/* @__PURE__ */ jsxDEV5(DealActionsModal, {
|
|
1596
|
+
isOpen: isDealActionsOpen,
|
|
1597
|
+
deal: selectedDeal,
|
|
1598
|
+
stages,
|
|
1599
|
+
onClose: () => {
|
|
1600
|
+
setIsDealActionsOpen(false);
|
|
1601
|
+
setSelectedDeal(null);
|
|
1602
|
+
},
|
|
1603
|
+
onWin: async (input) => {
|
|
1604
|
+
await mutations.winDeal(input);
|
|
1605
|
+
},
|
|
1606
|
+
onLose: async (input) => {
|
|
1607
|
+
await mutations.loseDeal(input);
|
|
1608
|
+
},
|
|
1609
|
+
onMove: async (input) => {
|
|
1610
|
+
await mutations.moveDeal(input);
|
|
1611
|
+
refetch();
|
|
1612
|
+
},
|
|
1613
|
+
isLoading: mutations.isLoading
|
|
1614
|
+
}, undefined, false, undefined, this)
|
|
1615
|
+
]
|
|
1616
|
+
}, undefined, true, undefined, this);
|
|
1617
|
+
}
|
|
1618
|
+
function DealListTab({ data, onDealClick }) {
|
|
1619
|
+
if (!data?.deals.length) {
|
|
1620
|
+
return /* @__PURE__ */ jsxDEV5("div", {
|
|
1621
|
+
className: "text-muted-foreground flex h-64 items-center justify-center",
|
|
1622
|
+
children: "No deals found"
|
|
1623
|
+
}, undefined, false, undefined, this);
|
|
1624
|
+
}
|
|
1625
|
+
return /* @__PURE__ */ jsxDEV5("div", {
|
|
1626
|
+
className: "border-border rounded-lg border",
|
|
1627
|
+
children: /* @__PURE__ */ jsxDEV5("table", {
|
|
1628
|
+
className: "w-full",
|
|
1629
|
+
children: [
|
|
1630
|
+
/* @__PURE__ */ jsxDEV5("thead", {
|
|
1631
|
+
className: "border-border bg-muted/30 border-b",
|
|
1632
|
+
children: /* @__PURE__ */ jsxDEV5("tr", {
|
|
1633
|
+
children: [
|
|
1634
|
+
/* @__PURE__ */ jsxDEV5("th", {
|
|
1635
|
+
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1636
|
+
children: "Deal"
|
|
1637
|
+
}, undefined, false, undefined, this),
|
|
1638
|
+
/* @__PURE__ */ jsxDEV5("th", {
|
|
1639
|
+
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1640
|
+
children: "Value"
|
|
1641
|
+
}, undefined, false, undefined, this),
|
|
1642
|
+
/* @__PURE__ */ jsxDEV5("th", {
|
|
1643
|
+
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1644
|
+
children: "Status"
|
|
1645
|
+
}, undefined, false, undefined, this),
|
|
1646
|
+
/* @__PURE__ */ jsxDEV5("th", {
|
|
1647
|
+
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1648
|
+
children: "Expected Close"
|
|
1649
|
+
}, undefined, false, undefined, this),
|
|
1650
|
+
/* @__PURE__ */ jsxDEV5("th", {
|
|
1651
|
+
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1652
|
+
children: "Actions"
|
|
1653
|
+
}, undefined, false, undefined, this)
|
|
1654
|
+
]
|
|
1655
|
+
}, undefined, true, undefined, this)
|
|
1656
|
+
}, undefined, false, undefined, this),
|
|
1657
|
+
/* @__PURE__ */ jsxDEV5("tbody", {
|
|
1658
|
+
className: "divide-border divide-y",
|
|
1659
|
+
children: data.deals.map((deal) => /* @__PURE__ */ jsxDEV5("tr", {
|
|
1660
|
+
className: "hover:bg-muted/50",
|
|
1661
|
+
children: [
|
|
1662
|
+
/* @__PURE__ */ jsxDEV5("td", {
|
|
1663
|
+
className: "px-4 py-3",
|
|
1664
|
+
children: /* @__PURE__ */ jsxDEV5("div", {
|
|
1665
|
+
className: "font-medium",
|
|
1666
|
+
children: deal.name
|
|
1667
|
+
}, undefined, false, undefined, this)
|
|
1668
|
+
}, undefined, false, undefined, this),
|
|
1669
|
+
/* @__PURE__ */ jsxDEV5("td", {
|
|
1670
|
+
className: "px-4 py-3 font-mono",
|
|
1671
|
+
children: formatCurrency4(deal.value, deal.currency)
|
|
1672
|
+
}, undefined, false, undefined, this),
|
|
1673
|
+
/* @__PURE__ */ jsxDEV5("td", {
|
|
1674
|
+
className: "px-4 py-3",
|
|
1675
|
+
children: /* @__PURE__ */ jsxDEV5("span", {
|
|
1676
|
+
className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${deal.status === "WON" ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" : deal.status === "LOST" ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400" : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,
|
|
1677
|
+
children: deal.status
|
|
1678
|
+
}, undefined, false, undefined, this)
|
|
1679
|
+
}, undefined, false, undefined, this),
|
|
1680
|
+
/* @__PURE__ */ jsxDEV5("td", {
|
|
1681
|
+
className: "text-muted-foreground px-4 py-3",
|
|
1682
|
+
children: deal.expectedCloseDate?.toLocaleDateString() ?? "-"
|
|
1683
|
+
}, undefined, false, undefined, this),
|
|
1684
|
+
/* @__PURE__ */ jsxDEV5("td", {
|
|
1685
|
+
className: "px-4 py-3",
|
|
1686
|
+
children: /* @__PURE__ */ jsxDEV5(Button3, {
|
|
1687
|
+
variant: "ghost",
|
|
1688
|
+
size: "sm",
|
|
1689
|
+
onPress: () => onDealClick?.(deal.id),
|
|
1690
|
+
children: "Actions"
|
|
1691
|
+
}, undefined, false, undefined, this)
|
|
1692
|
+
}, undefined, false, undefined, this)
|
|
1693
|
+
]
|
|
1694
|
+
}, deal.id, true, undefined, this))
|
|
1695
|
+
}, undefined, false, undefined, this)
|
|
1696
|
+
]
|
|
1697
|
+
}, undefined, true, undefined, this)
|
|
1698
|
+
}, undefined, false, undefined, this);
|
|
1699
|
+
}
|
|
1700
|
+
function MetricsTab({
|
|
1701
|
+
stats
|
|
1702
|
+
}) {
|
|
1703
|
+
if (!stats)
|
|
1704
|
+
return null;
|
|
1705
|
+
return /* @__PURE__ */ jsxDEV5("div", {
|
|
1706
|
+
className: "space-y-6",
|
|
1707
|
+
children: /* @__PURE__ */ jsxDEV5("div", {
|
|
1708
|
+
className: "border-border bg-card rounded-xl border p-6",
|
|
1709
|
+
children: [
|
|
1710
|
+
/* @__PURE__ */ jsxDEV5("h3", {
|
|
1711
|
+
className: "mb-4 text-lg font-semibold",
|
|
1712
|
+
children: "Pipeline Overview"
|
|
1713
|
+
}, undefined, false, undefined, this),
|
|
1714
|
+
/* @__PURE__ */ jsxDEV5("dl", {
|
|
1715
|
+
className: "grid gap-4 sm:grid-cols-3",
|
|
1716
|
+
children: [
|
|
1717
|
+
/* @__PURE__ */ jsxDEV5("div", {
|
|
1718
|
+
children: [
|
|
1719
|
+
/* @__PURE__ */ jsxDEV5("dt", {
|
|
1720
|
+
className: "text-muted-foreground text-sm",
|
|
1721
|
+
children: "Win Rate"
|
|
1722
|
+
}, undefined, false, undefined, this),
|
|
1723
|
+
/* @__PURE__ */ jsxDEV5("dd", {
|
|
1724
|
+
className: "text-2xl font-semibold",
|
|
1725
|
+
children: [
|
|
1726
|
+
stats.total > 0 ? (stats.wonCount / stats.total * 100).toFixed(0) : 0,
|
|
1727
|
+
"%"
|
|
1728
|
+
]
|
|
1729
|
+
}, undefined, true, undefined, this)
|
|
1730
|
+
]
|
|
1731
|
+
}, undefined, true, undefined, this),
|
|
1732
|
+
/* @__PURE__ */ jsxDEV5("div", {
|
|
1733
|
+
children: [
|
|
1734
|
+
/* @__PURE__ */ jsxDEV5("dt", {
|
|
1735
|
+
className: "text-muted-foreground text-sm",
|
|
1736
|
+
children: "Avg Deal Size"
|
|
1737
|
+
}, undefined, false, undefined, this),
|
|
1738
|
+
/* @__PURE__ */ jsxDEV5("dd", {
|
|
1739
|
+
className: "text-2xl font-semibold",
|
|
1740
|
+
children: formatCurrency4(stats.total > 0 ? stats.totalValue / stats.total : 0)
|
|
1741
|
+
}, undefined, false, undefined, this)
|
|
1742
|
+
]
|
|
1743
|
+
}, undefined, true, undefined, this),
|
|
1744
|
+
/* @__PURE__ */ jsxDEV5("div", {
|
|
1745
|
+
children: [
|
|
1746
|
+
/* @__PURE__ */ jsxDEV5("dt", {
|
|
1747
|
+
className: "text-muted-foreground text-sm",
|
|
1748
|
+
children: "Conversion"
|
|
1749
|
+
}, undefined, false, undefined, this),
|
|
1750
|
+
/* @__PURE__ */ jsxDEV5("dd", {
|
|
1751
|
+
className: "text-2xl font-semibold",
|
|
1752
|
+
children: [
|
|
1753
|
+
stats.wonCount,
|
|
1754
|
+
" / ",
|
|
1755
|
+
stats.total
|
|
1756
|
+
]
|
|
1757
|
+
}, undefined, true, undefined, this)
|
|
1758
|
+
]
|
|
1759
|
+
}, undefined, true, undefined, this)
|
|
1760
|
+
]
|
|
1761
|
+
}, undefined, true, undefined, this)
|
|
1762
|
+
]
|
|
1763
|
+
}, undefined, true, undefined, this)
|
|
1764
|
+
}, undefined, false, undefined, this);
|
|
1765
|
+
}
|
|
1766
|
+
// src/ui/hooks/index.ts
|
|
1767
|
+
"use client";
|
|
1768
|
+
|
|
1769
|
+
// src/ui/renderers/pipeline.renderer.tsx
|
|
1770
|
+
import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
|
|
1771
|
+
function CrmPipelineBoardWrapper() {
|
|
1772
|
+
const { dealsByStage, stages } = useDealList();
|
|
1773
|
+
return /* @__PURE__ */ jsxDEV6(CrmPipelineBoard, {
|
|
1774
|
+
dealsByStage,
|
|
1775
|
+
stages
|
|
1776
|
+
}, undefined, false, undefined, this);
|
|
1777
|
+
}
|
|
1778
|
+
var crmPipelineReactRenderer = {
|
|
1779
|
+
target: "react",
|
|
1780
|
+
render: async (desc, _ctx) => {
|
|
1781
|
+
if (desc.source.type !== "component") {
|
|
1782
|
+
throw new Error("Invalid source type");
|
|
1783
|
+
}
|
|
1784
|
+
if (desc.source.componentKey !== "CrmPipelineView") {
|
|
1785
|
+
throw new Error(`Unknown component: ${desc.source.componentKey}`);
|
|
1786
|
+
}
|
|
1787
|
+
return /* @__PURE__ */ jsxDEV6(CrmPipelineBoardWrapper, {}, undefined, false, undefined, this);
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
|
|
1791
|
+
// src/ui/renderers/pipeline.markdown.ts
|
|
1792
|
+
function formatCurrency5(value, currency = "USD") {
|
|
1793
|
+
return new Intl.NumberFormat("en-US", {
|
|
1794
|
+
style: "currency",
|
|
1795
|
+
currency,
|
|
1796
|
+
minimumFractionDigits: 0
|
|
1797
|
+
}).format(value);
|
|
1798
|
+
}
|
|
1799
|
+
var crmPipelineMarkdownRenderer = {
|
|
1800
|
+
target: "markdown",
|
|
1801
|
+
render: async (desc, _ctx) => {
|
|
1802
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "PipelineKanbanView") {
|
|
1803
|
+
throw new Error("crmPipelineMarkdownRenderer: not PipelineKanbanView");
|
|
1804
|
+
}
|
|
1805
|
+
const pipelineId = "pipeline-1";
|
|
1806
|
+
const [dealsResult, stages] = await Promise.all([
|
|
1807
|
+
mockListDealsHandler({ pipelineId, limit: 50 }),
|
|
1808
|
+
mockGetPipelineStagesHandler({ pipelineId })
|
|
1809
|
+
]);
|
|
1810
|
+
const deals = dealsResult.deals;
|
|
1811
|
+
const stageList = stages;
|
|
1812
|
+
const dealsByStage = {};
|
|
1813
|
+
for (const stage of stageList) {
|
|
1814
|
+
dealsByStage[stage.id] = deals.filter((d) => d.stageId === stage.id && d.status === "OPEN");
|
|
1815
|
+
}
|
|
1816
|
+
const lines = [
|
|
1817
|
+
"# CRM Pipeline",
|
|
1818
|
+
"",
|
|
1819
|
+
`**Total Value**: ${formatCurrency5(dealsResult.totalValue)}`,
|
|
1820
|
+
`**Total Deals**: ${dealsResult.total}`,
|
|
1821
|
+
""
|
|
1822
|
+
];
|
|
1823
|
+
for (const stage of stageList.sort((a, b) => a.position - b.position)) {
|
|
1824
|
+
const stageDeals = dealsByStage[stage.id] ?? [];
|
|
1825
|
+
const stageValue = stageDeals.reduce((sum, d) => sum + d.value, 0);
|
|
1826
|
+
lines.push(`## ${stage.name}`);
|
|
1827
|
+
lines.push(`_${stageDeals.length} deals \xB7 ${formatCurrency5(stageValue)}_`);
|
|
1828
|
+
lines.push("");
|
|
1829
|
+
if (stageDeals.length === 0) {
|
|
1830
|
+
lines.push("_No deals_");
|
|
1831
|
+
} else {
|
|
1832
|
+
for (const deal of stageDeals) {
|
|
1833
|
+
lines.push(`- **${deal.name}** - ${formatCurrency5(deal.value, deal.currency)}`);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
lines.push("");
|
|
1837
|
+
}
|
|
1838
|
+
return {
|
|
1839
|
+
mimeType: "text/markdown",
|
|
1840
|
+
body: lines.join(`
|
|
1841
|
+
`)
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
var crmDashboardMarkdownRenderer = {
|
|
1846
|
+
target: "markdown",
|
|
1847
|
+
render: async (desc, _ctx) => {
|
|
1848
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "CrmDashboard") {
|
|
1849
|
+
throw new Error("crmDashboardMarkdownRenderer: not CrmDashboard");
|
|
1850
|
+
}
|
|
1851
|
+
const pipelineId = "pipeline-1";
|
|
1852
|
+
const [dealsResult, stages] = await Promise.all([
|
|
1853
|
+
mockListDealsHandler({ pipelineId, limit: 100 }),
|
|
1854
|
+
mockGetPipelineStagesHandler({ pipelineId })
|
|
1855
|
+
]);
|
|
1856
|
+
const deals = dealsResult.deals;
|
|
1857
|
+
const stageList = stages;
|
|
1858
|
+
const openDeals = deals.filter((d) => d.status === "OPEN");
|
|
1859
|
+
const wonDeals = deals.filter((d) => d.status === "WON");
|
|
1860
|
+
const lostDeals = deals.filter((d) => d.status === "LOST");
|
|
1861
|
+
const openValue = openDeals.reduce((sum, d) => sum + d.value, 0);
|
|
1862
|
+
const wonValue = wonDeals.reduce((sum, d) => sum + d.value, 0);
|
|
1863
|
+
const lines = [
|
|
1864
|
+
"# CRM Dashboard",
|
|
1865
|
+
"",
|
|
1866
|
+
"> Sales pipeline overview and key metrics",
|
|
1867
|
+
"",
|
|
1868
|
+
"## Summary",
|
|
1869
|
+
"",
|
|
1870
|
+
"| Metric | Value |",
|
|
1871
|
+
"|--------|-------|",
|
|
1872
|
+
`| Total Deals | ${dealsResult.total} |`,
|
|
1873
|
+
`| Pipeline Value | ${formatCurrency5(dealsResult.totalValue)} |`,
|
|
1874
|
+
`| Open Deals | ${openDeals.length} (${formatCurrency5(openValue)}) |`,
|
|
1875
|
+
`| Won Deals | ${wonDeals.length} (${formatCurrency5(wonValue)}) |`,
|
|
1876
|
+
`| Lost Deals | ${lostDeals.length} |`,
|
|
1877
|
+
"",
|
|
1878
|
+
"## Pipeline Stages",
|
|
1879
|
+
""
|
|
1880
|
+
];
|
|
1881
|
+
lines.push("| Stage | Deals | Value |");
|
|
1882
|
+
lines.push("|-------|-------|-------|");
|
|
1883
|
+
for (const stage of stageList.sort((a, b) => a.position - b.position)) {
|
|
1884
|
+
const stageDeals = openDeals.filter((d) => d.stageId === stage.id);
|
|
1885
|
+
const stageValue = stageDeals.reduce((sum, d) => sum + d.value, 0);
|
|
1886
|
+
lines.push(`| ${stage.name} | ${stageDeals.length} | ${formatCurrency5(stageValue)} |`);
|
|
1887
|
+
}
|
|
1888
|
+
lines.push("");
|
|
1889
|
+
lines.push("## Recent Deals");
|
|
1890
|
+
lines.push("");
|
|
1891
|
+
const recentDeals = deals.slice(0, 10);
|
|
1892
|
+
if (recentDeals.length === 0) {
|
|
1893
|
+
lines.push("_No deals yet._");
|
|
1894
|
+
} else {
|
|
1895
|
+
lines.push("| Deal | Value | Stage | Status |");
|
|
1896
|
+
lines.push("|------|-------|-------|--------|");
|
|
1897
|
+
for (const deal of recentDeals) {
|
|
1898
|
+
const stage = stageList.find((s) => s.id === deal.stageId);
|
|
1899
|
+
lines.push(`| ${deal.name} | ${formatCurrency5(deal.value, deal.currency)} | ${stage?.name ?? "-"} | ${deal.status} |`);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
return {
|
|
1903
|
+
mimeType: "text/markdown",
|
|
1904
|
+
body: lines.join(`
|
|
1905
|
+
`)
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
};
|
|
1909
|
+
// src/ui/overlays/demo-overlays.ts
|
|
1910
|
+
var crmDemoOverlay = {
|
|
1911
|
+
overlayId: "crm-pipeline.demo-user",
|
|
1912
|
+
version: "1.0.0",
|
|
1913
|
+
description: "Demo mode with sample data",
|
|
1914
|
+
appliesTo: {
|
|
1915
|
+
feature: "crm-pipeline",
|
|
1916
|
+
role: "demo"
|
|
1917
|
+
},
|
|
1918
|
+
modifications: [
|
|
1919
|
+
{
|
|
1920
|
+
type: "hideField",
|
|
1921
|
+
field: "importButton",
|
|
1922
|
+
reason: "Not available in demo"
|
|
1923
|
+
},
|
|
1924
|
+
{
|
|
1925
|
+
type: "hideField",
|
|
1926
|
+
field: "exportButton",
|
|
1927
|
+
reason: "Not available in demo"
|
|
1928
|
+
},
|
|
1929
|
+
{
|
|
1930
|
+
type: "addBadge",
|
|
1931
|
+
position: "header",
|
|
1932
|
+
label: "Demo Mode",
|
|
1933
|
+
variant: "warning"
|
|
1934
|
+
}
|
|
1935
|
+
]
|
|
1936
|
+
};
|
|
1937
|
+
var crmSalesRepOverlay = {
|
|
1938
|
+
overlayId: "crm-pipeline.sales-rep",
|
|
1939
|
+
version: "1.0.0",
|
|
1940
|
+
description: "Sales rep focused view",
|
|
1941
|
+
appliesTo: {
|
|
1942
|
+
feature: "crm-pipeline",
|
|
1943
|
+
role: "sales-rep"
|
|
1944
|
+
},
|
|
1945
|
+
modifications: [
|
|
1946
|
+
{
|
|
1947
|
+
type: "hideField",
|
|
1948
|
+
field: "teamMetrics",
|
|
1949
|
+
reason: "Team metrics for managers only"
|
|
1950
|
+
},
|
|
1951
|
+
{ type: "hideField", field: "pipelineSettings", reason: "Admin only" },
|
|
1952
|
+
{ type: "renameLabel", field: "deals", newLabel: "My Deals" }
|
|
1953
|
+
]
|
|
1954
|
+
};
|
|
1955
|
+
var crmOverlays = [
|
|
1956
|
+
crmDemoOverlay,
|
|
1957
|
+
crmSalesRepOverlay
|
|
1958
|
+
];
|
|
1959
|
+
export {
|
|
1960
|
+
useDealMutations,
|
|
1961
|
+
useDealList,
|
|
1962
|
+
crmSalesRepOverlay,
|
|
1963
|
+
crmPipelineReactRenderer,
|
|
1964
|
+
crmPipelineMarkdownRenderer,
|
|
1965
|
+
crmOverlays,
|
|
1966
|
+
crmDemoOverlay,
|
|
1967
|
+
crmDashboardMarkdownRenderer,
|
|
1968
|
+
DealActionsModal,
|
|
1969
|
+
CrmPipelineBoard,
|
|
1970
|
+
CrmDealCard,
|
|
1971
|
+
CrmDashboard,
|
|
1972
|
+
CreateDealModal
|
|
1973
|
+
};
|