@contractspec/example.crm-pipeline 3.7.17 → 3.7.18

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.
Files changed (135) hide show
  1. package/.turbo/turbo-build.log +135 -135
  2. package/CHANGELOG.md +20 -0
  3. package/dist/browser/crm-pipeline.feature.js +1 -82
  4. package/dist/browser/deal/deal.enum.js +1 -18
  5. package/dist/browser/deal/deal.operation.js +1 -396
  6. package/dist/browser/deal/deal.schema.js +1 -141
  7. package/dist/browser/deal/deal.test-spec.js +1 -58
  8. package/dist/browser/deal/index.js +1 -408
  9. package/dist/browser/docs/crm-pipeline.docblock.js +5 -49
  10. package/dist/browser/docs/index.js +5 -49
  11. package/dist/browser/entities/company.entity.js +1 -52
  12. package/dist/browser/entities/contact.entity.js +1 -66
  13. package/dist/browser/entities/deal.entity.js +1 -107
  14. package/dist/browser/entities/index.js +1 -343
  15. package/dist/browser/entities/task.entity.js +1 -99
  16. package/dist/browser/events/contact.event.js +1 -31
  17. package/dist/browser/events/deal.event.js +1 -101
  18. package/dist/browser/events/index.js +1 -158
  19. package/dist/browser/events/task.event.js +1 -28
  20. package/dist/browser/example.js +1 -39
  21. package/dist/browser/handlers/crm.handlers.js +2 -171
  22. package/dist/browser/handlers/deal.handlers.js +1 -293
  23. package/dist/browser/handlers/index.js +2 -467
  24. package/dist/browser/handlers/mock-data.js +1 -165
  25. package/dist/browser/index.js +8 -3461
  26. package/dist/browser/operations/index.js +1 -407
  27. package/dist/browser/presentations/dashboard.presentation.js +1 -55
  28. package/dist/browser/presentations/index.js +1 -290
  29. package/dist/browser/presentations/pipeline.presentation.js +1 -236
  30. package/dist/browser/seeders/index.js +1 -22
  31. package/dist/browser/ui/CrmDashboard.js +1 -1547
  32. package/dist/browser/ui/CrmDealCard.js +1 -50
  33. package/dist/browser/ui/CrmPipelineBoard.js +1 -160
  34. package/dist/browser/ui/hooks/index.js +1 -197
  35. package/dist/browser/ui/hooks/useDealList.js +1 -95
  36. package/dist/browser/ui/hooks/useDealMutations.js +1 -100
  37. package/dist/browser/ui/index.js +4 -2205
  38. package/dist/browser/ui/modals/CreateDealModal.js +1 -211
  39. package/dist/browser/ui/modals/DealActionsModal.js +1 -428
  40. package/dist/browser/ui/modals/index.js +1 -638
  41. package/dist/browser/ui/overlays/demo-overlays.js +1 -55
  42. package/dist/browser/ui/overlays/index.js +1 -55
  43. package/dist/browser/ui/renderers/index.js +4 -849
  44. package/dist/browser/ui/renderers/pipeline.markdown.js +4 -575
  45. package/dist/browser/ui/renderers/pipeline.renderer.js +1 -275
  46. package/dist/browser/ui/tables/DealListTab.js +1 -390
  47. package/dist/crm-pipeline.feature.js +1 -82
  48. package/dist/deal/deal.enum.js +1 -18
  49. package/dist/deal/deal.operation.js +1 -396
  50. package/dist/deal/deal.schema.js +1 -141
  51. package/dist/deal/deal.test-spec.js +1 -58
  52. package/dist/deal/index.js +1 -408
  53. package/dist/docs/crm-pipeline.docblock.js +5 -49
  54. package/dist/docs/index.js +5 -49
  55. package/dist/entities/company.entity.js +1 -52
  56. package/dist/entities/contact.entity.js +1 -66
  57. package/dist/entities/deal.entity.js +1 -107
  58. package/dist/entities/index.js +1 -343
  59. package/dist/entities/task.entity.js +1 -99
  60. package/dist/events/contact.event.js +1 -31
  61. package/dist/events/deal.event.js +1 -101
  62. package/dist/events/index.js +1 -158
  63. package/dist/events/task.event.js +1 -28
  64. package/dist/example.js +1 -39
  65. package/dist/handlers/crm.handlers.js +2 -171
  66. package/dist/handlers/deal.handlers.js +1 -293
  67. package/dist/handlers/index.js +2 -467
  68. package/dist/handlers/mock-data.js +1 -165
  69. package/dist/index.js +8 -3461
  70. package/dist/node/crm-pipeline.feature.js +1 -82
  71. package/dist/node/deal/deal.enum.js +1 -18
  72. package/dist/node/deal/deal.operation.js +1 -396
  73. package/dist/node/deal/deal.schema.js +1 -141
  74. package/dist/node/deal/deal.test-spec.js +1 -58
  75. package/dist/node/deal/index.js +1 -408
  76. package/dist/node/docs/crm-pipeline.docblock.js +5 -49
  77. package/dist/node/docs/index.js +5 -49
  78. package/dist/node/entities/company.entity.js +1 -52
  79. package/dist/node/entities/contact.entity.js +1 -66
  80. package/dist/node/entities/deal.entity.js +1 -107
  81. package/dist/node/entities/index.js +1 -343
  82. package/dist/node/entities/task.entity.js +1 -99
  83. package/dist/node/events/contact.event.js +1 -31
  84. package/dist/node/events/deal.event.js +1 -101
  85. package/dist/node/events/index.js +1 -158
  86. package/dist/node/events/task.event.js +1 -28
  87. package/dist/node/example.js +1 -39
  88. package/dist/node/handlers/crm.handlers.js +2 -171
  89. package/dist/node/handlers/deal.handlers.js +1 -293
  90. package/dist/node/handlers/index.js +2 -467
  91. package/dist/node/handlers/mock-data.js +1 -165
  92. package/dist/node/index.js +8 -3461
  93. package/dist/node/operations/index.js +1 -407
  94. package/dist/node/presentations/dashboard.presentation.js +1 -55
  95. package/dist/node/presentations/index.js +1 -290
  96. package/dist/node/presentations/pipeline.presentation.js +1 -236
  97. package/dist/node/seeders/index.js +1 -22
  98. package/dist/node/ui/CrmDashboard.js +1 -1547
  99. package/dist/node/ui/CrmDealCard.js +1 -50
  100. package/dist/node/ui/CrmPipelineBoard.js +1 -160
  101. package/dist/node/ui/hooks/index.js +1 -197
  102. package/dist/node/ui/hooks/useDealList.js +1 -95
  103. package/dist/node/ui/hooks/useDealMutations.js +1 -100
  104. package/dist/node/ui/index.js +4 -2205
  105. package/dist/node/ui/modals/CreateDealModal.js +1 -211
  106. package/dist/node/ui/modals/DealActionsModal.js +1 -428
  107. package/dist/node/ui/modals/index.js +1 -638
  108. package/dist/node/ui/overlays/demo-overlays.js +1 -55
  109. package/dist/node/ui/overlays/index.js +1 -55
  110. package/dist/node/ui/renderers/index.js +4 -849
  111. package/dist/node/ui/renderers/pipeline.markdown.js +4 -575
  112. package/dist/node/ui/renderers/pipeline.renderer.js +1 -275
  113. package/dist/node/ui/tables/DealListTab.js +1 -390
  114. package/dist/operations/index.js +1 -407
  115. package/dist/presentations/dashboard.presentation.js +1 -55
  116. package/dist/presentations/index.js +1 -290
  117. package/dist/presentations/pipeline.presentation.js +1 -236
  118. package/dist/seeders/index.js +1 -22
  119. package/dist/ui/CrmDashboard.js +1 -1547
  120. package/dist/ui/CrmDealCard.js +1 -50
  121. package/dist/ui/CrmPipelineBoard.js +1 -160
  122. package/dist/ui/hooks/index.js +1 -197
  123. package/dist/ui/hooks/useDealList.js +1 -95
  124. package/dist/ui/hooks/useDealMutations.js +1 -100
  125. package/dist/ui/index.js +4 -2205
  126. package/dist/ui/modals/CreateDealModal.js +1 -211
  127. package/dist/ui/modals/DealActionsModal.js +1 -428
  128. package/dist/ui/modals/index.js +1 -638
  129. package/dist/ui/overlays/demo-overlays.js +1 -55
  130. package/dist/ui/overlays/index.js +1 -55
  131. package/dist/ui/renderers/index.js +4 -849
  132. package/dist/ui/renderers/pipeline.markdown.js +4 -575
  133. package/dist/ui/renderers/pipeline.renderer.js +1 -275
  134. package/dist/ui/tables/DealListTab.js +1 -390
  135. package/package.json +13 -13
@@ -1,51 +1,2 @@
1
1
  // @bun
2
- // src/ui/CrmDealCard.tsx
3
- import { jsxDEV } from "react/jsx-dev-runtime";
4
- "use client";
5
- function formatCurrency(value, currency) {
6
- return new Intl.NumberFormat("en-US", {
7
- style: "currency",
8
- currency,
9
- minimumFractionDigits: 0,
10
- maximumFractionDigits: 0
11
- }).format(value);
12
- }
13
- function CrmDealCard({ deal, onClick }) {
14
- const daysUntilClose = deal.expectedCloseDate ? Math.ceil((deal.expectedCloseDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)) : null;
15
- return /* @__PURE__ */ jsxDEV("div", {
16
- onClick,
17
- className: "cursor-pointer rounded-lg border border-border bg-card p-3 shadow-sm transition-shadow hover:shadow-md",
18
- role: "button",
19
- tabIndex: 0,
20
- onKeyDown: (e) => {
21
- if (e.key === "Enter" || e.key === " ")
22
- onClick?.();
23
- },
24
- children: [
25
- /* @__PURE__ */ jsxDEV("h4", {
26
- className: "font-medium leading-snug",
27
- children: deal.name
28
- }, undefined, false, undefined, this),
29
- /* @__PURE__ */ jsxDEV("div", {
30
- className: "mt-2 font-semibold text-lg text-primary",
31
- children: formatCurrency(deal.value, deal.currency)
32
- }, undefined, false, undefined, this),
33
- /* @__PURE__ */ jsxDEV("div", {
34
- className: "mt-3 flex items-center justify-between text-muted-foreground text-xs",
35
- children: [
36
- daysUntilClose !== null && /* @__PURE__ */ jsxDEV("span", {
37
- className: daysUntilClose < 0 ? "text-red-500" : daysUntilClose <= 7 ? "text-yellow-600 dark:text-yellow-500" : "",
38
- children: daysUntilClose < 0 ? `${Math.abs(daysUntilClose)}d overdue` : daysUntilClose === 0 ? "Due today" : `${daysUntilClose}d left`
39
- }, undefined, false, undefined, this),
40
- /* @__PURE__ */ jsxDEV("span", {
41
- className: `rounded px-1.5 py-0.5 font-medium text-xs ${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"}`,
42
- children: deal.status
43
- }, undefined, false, undefined, this)
44
- ]
45
- }, undefined, true, undefined, this)
46
- ]
47
- }, undefined, true, undefined, this);
48
- }
49
- export {
50
- CrmDealCard
51
- };
2
+ import{jsx as z,jsxs as F}from"react/jsx-runtime";function G(h,w){return new Intl.NumberFormat("en-US",{style:"currency",currency:w,minimumFractionDigits:0,maximumFractionDigits:0}).format(h)}function H({deal:h,onClick:w}){let q=h.expectedCloseDate?Math.ceil((h.expectedCloseDate.getTime()-Date.now())/86400000):null;return F("div",{onClick:w,className:"cursor-pointer rounded-lg border border-border bg-card p-3 shadow-sm transition-shadow hover:shadow-md",role:"button",tabIndex:0,onKeyDown:(A)=>{if(A.key==="Enter"||A.key===" ")w?.()},children:[z("h4",{className:"font-medium leading-snug",children:h.name}),z("div",{className:"mt-2 font-semibold text-lg text-primary",children:G(h.value,h.currency)}),F("div",{className:"mt-3 flex items-center justify-between text-muted-foreground text-xs",children:[q!==null&&z("span",{className:q<0?"text-red-500":q<=7?"text-yellow-600 dark:text-yellow-500":"",children:q<0?`${Math.abs(q)}d overdue`:q===0?"Due today":`${q}d left`}),z("span",{className:`rounded px-1.5 py-0.5 font-medium text-xs ${h.status==="WON"?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":h.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"}`,children:h.status})]})]})}export{H as CrmDealCard};
@@ -1,161 +1,2 @@
1
1
  // @bun
2
- // src/ui/CrmDealCard.tsx
3
- import { jsxDEV } from "react/jsx-dev-runtime";
4
- "use client";
5
- function formatCurrency(value, currency) {
6
- return new Intl.NumberFormat("en-US", {
7
- style: "currency",
8
- currency,
9
- minimumFractionDigits: 0,
10
- maximumFractionDigits: 0
11
- }).format(value);
12
- }
13
- function CrmDealCard({ deal, onClick }) {
14
- const daysUntilClose = deal.expectedCloseDate ? Math.ceil((deal.expectedCloseDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)) : null;
15
- return /* @__PURE__ */ jsxDEV("div", {
16
- onClick,
17
- className: "cursor-pointer rounded-lg border border-border bg-card p-3 shadow-sm transition-shadow hover:shadow-md",
18
- role: "button",
19
- tabIndex: 0,
20
- onKeyDown: (e) => {
21
- if (e.key === "Enter" || e.key === " ")
22
- onClick?.();
23
- },
24
- children: [
25
- /* @__PURE__ */ jsxDEV("h4", {
26
- className: "font-medium leading-snug",
27
- children: deal.name
28
- }, undefined, false, undefined, this),
29
- /* @__PURE__ */ jsxDEV("div", {
30
- className: "mt-2 font-semibold text-lg text-primary",
31
- children: formatCurrency(deal.value, deal.currency)
32
- }, undefined, false, undefined, this),
33
- /* @__PURE__ */ jsxDEV("div", {
34
- className: "mt-3 flex items-center justify-between text-muted-foreground text-xs",
35
- children: [
36
- daysUntilClose !== null && /* @__PURE__ */ jsxDEV("span", {
37
- className: daysUntilClose < 0 ? "text-red-500" : daysUntilClose <= 7 ? "text-yellow-600 dark:text-yellow-500" : "",
38
- children: daysUntilClose < 0 ? `${Math.abs(daysUntilClose)}d overdue` : daysUntilClose === 0 ? "Due today" : `${daysUntilClose}d left`
39
- }, undefined, false, undefined, this),
40
- /* @__PURE__ */ jsxDEV("span", {
41
- className: `rounded px-1.5 py-0.5 font-medium text-xs ${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"}`,
42
- children: deal.status
43
- }, undefined, false, undefined, this)
44
- ]
45
- }, undefined, true, undefined, this)
46
- ]
47
- }, undefined, true, undefined, this);
48
- }
49
-
50
- // src/ui/CrmPipelineBoard.tsx
51
- import { useState } from "react";
52
- import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
53
- "use client";
54
- function formatCurrency2(value) {
55
- if (value >= 1e6)
56
- return `$${(value / 1e6).toFixed(1)}M`;
57
- if (value >= 1000)
58
- return `$${(value / 1000).toFixed(0)}K`;
59
- return `$${value}`;
60
- }
61
- function CrmPipelineBoard({
62
- dealsByStage,
63
- stages,
64
- onDealClick,
65
- onDealMove
66
- }) {
67
- const [quickMoveOpen, setQuickMoveOpen] = useState(null);
68
- const sortedStages = [...stages].sort((a, b) => a.position - b.position);
69
- const handleQuickMove = (dealId, toStageId) => {
70
- onDealMove?.(dealId, toStageId);
71
- setQuickMoveOpen(null);
72
- };
73
- return /* @__PURE__ */ jsxDEV2("div", {
74
- className: "flex gap-4 overflow-x-auto pb-4",
75
- children: sortedStages.map((stage) => {
76
- const deals = dealsByStage[stage.id] ?? [];
77
- const stageValue = deals.reduce((sum, d) => sum + d.value, 0);
78
- return /* @__PURE__ */ jsxDEV2("div", {
79
- className: "flex w-72 flex-shrink-0 flex-col rounded-lg bg-muted/30",
80
- children: [
81
- /* @__PURE__ */ jsxDEV2("div", {
82
- className: "flex items-center justify-between border-border border-b px-3 py-2",
83
- children: [
84
- /* @__PURE__ */ jsxDEV2("div", {
85
- children: [
86
- /* @__PURE__ */ jsxDEV2("h3", {
87
- className: "font-medium",
88
- children: stage.name
89
- }, undefined, false, undefined, this),
90
- /* @__PURE__ */ jsxDEV2("p", {
91
- className: "text-muted-foreground text-xs",
92
- children: [
93
- deals.length,
94
- " deals \xB7 ",
95
- formatCurrency2(stageValue)
96
- ]
97
- }, undefined, true, undefined, this)
98
- ]
99
- }, undefined, true, undefined, this),
100
- /* @__PURE__ */ jsxDEV2("span", {
101
- className: "flex h-6 w-6 items-center justify-center rounded-full bg-muted font-medium text-xs",
102
- children: deals.length
103
- }, undefined, false, undefined, this)
104
- ]
105
- }, undefined, true, undefined, this),
106
- /* @__PURE__ */ jsxDEV2("div", {
107
- className: "flex flex-1 flex-col gap-2 p-2",
108
- children: deals.length === 0 ? /* @__PURE__ */ jsxDEV2("div", {
109
- className: "flex h-24 items-center justify-center rounded-md border-2 border-muted-foreground/20 border-dashed text-muted-foreground text-xs",
110
- children: "No deals"
111
- }, undefined, false, undefined, this) : deals.map((deal) => /* @__PURE__ */ jsxDEV2("div", {
112
- className: "group relative",
113
- children: [
114
- /* @__PURE__ */ jsxDEV2(CrmDealCard, {
115
- deal,
116
- onClick: () => onDealClick?.(deal.id)
117
- }, undefined, false, undefined, this),
118
- deal.status === "OPEN" && onDealMove && /* @__PURE__ */ jsxDEV2("div", {
119
- className: "absolute top-1 right-1 opacity-0 transition-opacity group-hover:opacity-100",
120
- children: [
121
- /* @__PURE__ */ jsxDEV2("button", {
122
- type: "button",
123
- onClick: (e) => {
124
- e.stopPropagation();
125
- setQuickMoveOpen(quickMoveOpen === deal.id ? null : deal.id);
126
- },
127
- className: "flex h-6 w-6 items-center justify-center rounded border border-border bg-background text-xs shadow-sm hover:bg-muted",
128
- title: "Quick move",
129
- children: "\u27A1\uFE0F"
130
- }, undefined, false, undefined, this),
131
- quickMoveOpen === deal.id && /* @__PURE__ */ jsxDEV2("div", {
132
- className: "absolute top-7 right-0 z-20 min-w-[140px] rounded-lg border border-border bg-card py-1 shadow-lg",
133
- children: [
134
- /* @__PURE__ */ jsxDEV2("p", {
135
- className: "px-3 py-1 font-medium text-muted-foreground text-xs",
136
- children: "Move to:"
137
- }, undefined, false, undefined, this),
138
- sortedStages.filter((s) => s.id !== deal.stageId).map((s) => /* @__PURE__ */ jsxDEV2("button", {
139
- type: "button",
140
- onClick: (e) => {
141
- e.stopPropagation();
142
- handleQuickMove(deal.id, s.id);
143
- },
144
- className: "w-full px-3 py-1.5 text-left text-sm hover:bg-muted",
145
- children: s.name
146
- }, s.id, false, undefined, this))
147
- ]
148
- }, undefined, true, undefined, this)
149
- ]
150
- }, undefined, true, undefined, this)
151
- ]
152
- }, deal.id, true, undefined, this))
153
- }, undefined, false, undefined, this)
154
- ]
155
- }, stage.id, true, undefined, this);
156
- })
157
- }, undefined, false, undefined, this);
158
- }
159
- export {
160
- CrmPipelineBoard
161
- };
2
+ import{jsx as Y,jsxs as E}from"react/jsx-runtime";function V(z,W){return new Intl.NumberFormat("en-US",{style:"currency",currency:W,minimumFractionDigits:0,maximumFractionDigits:0}).format(z)}function H({deal:z,onClick:W}){let F=z.expectedCloseDate?Math.ceil((z.expectedCloseDate.getTime()-Date.now())/86400000):null;return E("div",{onClick:W,className:"cursor-pointer rounded-lg border border-border bg-card p-3 shadow-sm transition-shadow hover:shadow-md",role:"button",tabIndex:0,onKeyDown:(X)=>{if(X.key==="Enter"||X.key===" ")W?.()},children:[Y("h4",{className:"font-medium leading-snug",children:z.name}),Y("div",{className:"mt-2 font-semibold text-lg text-primary",children:V(z.value,z.currency)}),E("div",{className:"mt-3 flex items-center justify-between text-muted-foreground text-xs",children:[F!==null&&Y("span",{className:F<0?"text-red-500":F<=7?"text-yellow-600 dark:text-yellow-500":"",children:F<0?`${Math.abs(F)}d overdue`:F===0?"Due today":`${F}d left`}),Y("span",{className:`rounded px-1.5 py-0.5 font-medium text-xs ${z.status==="WON"?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":z.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"}`,children:z.status})]})]})}import{useState as q}from"react";import{jsx as K,jsxs as P}from"react/jsx-runtime";function w(z){if(z>=1e6)return`$${(z/1e6).toFixed(1)}M`;if(z>=1000)return`$${(z/1000).toFixed(0)}K`;return`$${z}`}function h({dealsByStage:z,stages:W,onDealClick:F,onDealMove:X}){let[Z,_]=q(null),$=[...W].sort((L,G)=>L.position-G.position),N=(L,G)=>{X?.(L,G),_(null)};return K("div",{className:"flex gap-4 overflow-x-auto pb-4",children:$.map((L)=>{let G=z[L.id]??[],R=G.reduce((A,J)=>A+J.value,0);return P("div",{className:"flex w-72 flex-shrink-0 flex-col rounded-lg bg-muted/30",children:[P("div",{className:"flex items-center justify-between border-border border-b px-3 py-2",children:[P("div",{children:[K("h3",{className:"font-medium",children:L.name}),P("p",{className:"text-muted-foreground text-xs",children:[G.length," deals \xB7 ",w(R)]})]}),K("span",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-muted font-medium text-xs",children:G.length})]}),K("div",{className:"flex flex-1 flex-col gap-2 p-2",children:G.length===0?K("div",{className:"flex h-24 items-center justify-center rounded-md border-2 border-muted-foreground/20 border-dashed text-muted-foreground text-xs",children:"No deals"}):G.map((A)=>P("div",{className:"group relative",children:[K(H,{deal:A,onClick:()=>F?.(A.id)}),A.status==="OPEN"&&X&&P("div",{className:"absolute top-1 right-1 opacity-0 transition-opacity group-hover:opacity-100",children:[K("button",{type:"button",onClick:(J)=>{J.stopPropagation(),_(Z===A.id?null:A.id)},className:"flex h-6 w-6 items-center justify-center rounded border border-border bg-background text-xs shadow-sm hover:bg-muted",title:"Quick move",children:"\u27A1\uFE0F"}),Z===A.id&&P("div",{className:"absolute top-7 right-0 z-20 min-w-[140px] rounded-lg border border-border bg-card py-1 shadow-lg",children:[K("p",{className:"px-3 py-1 font-medium text-muted-foreground text-xs",children:"Move to:"}),$.filter((J)=>J.id!==A.stageId).map((J)=>K("button",{type:"button",onClick:(T)=>{T.stopPropagation(),N(A.id,J.id)},className:"w-full px-3 py-1.5 text-left text-sm hover:bg-muted",children:J.name},J.id))]})]})]},A.id))})]},L.id)})})}export{h as CrmPipelineBoard};
@@ -1,198 +1,2 @@
1
1
  // @bun
2
- // src/ui/hooks/useDealList.ts
3
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
- import { useCallback, useEffect, useMemo, useState } from "react";
5
- "use client";
6
- function useDealList(options = {}) {
7
- const { handlers, projectId } = useTemplateRuntime();
8
- const { crm } = handlers;
9
- const [data, setData] = useState(null);
10
- const [dealsByStage, setDealsByStage] = useState({});
11
- const [stages, setStages] = useState([]);
12
- const [loading, setLoading] = useState(true);
13
- const [error, setError] = useState(null);
14
- const [internalPage, setInternalPage] = useState(0);
15
- const pipelineId = options.pipelineId ?? "pipeline-1";
16
- const pageIndex = options.pageIndex ?? internalPage;
17
- const pageSize = options.pageSize ?? options.limit ?? 50;
18
- const [sort] = options.sorting ?? [];
19
- const sortBy = sort?.id;
20
- const sortDirection = sort ? sort.desc ? "desc" : "asc" : undefined;
21
- const fetchData = useCallback(async () => {
22
- setLoading(true);
23
- setError(null);
24
- try {
25
- const [dealsResult, stageDealsResult, stagesResult] = await Promise.all([
26
- crm.listDeals({
27
- projectId,
28
- pipelineId,
29
- stageId: options.stageId,
30
- status: options.status === "all" ? undefined : options.status,
31
- search: options.search,
32
- limit: pageSize,
33
- offset: pageIndex * pageSize,
34
- sortBy: sortBy === "name" || sortBy === "value" || sortBy === "status" || sortBy === "expectedCloseDate" || sortBy === "updatedAt" ? sortBy : undefined,
35
- sortDirection
36
- }),
37
- crm.getDealsByStage({ projectId, pipelineId }),
38
- crm.getPipelineStages({ pipelineId })
39
- ]);
40
- setData(dealsResult);
41
- setDealsByStage(stageDealsResult);
42
- setStages(stagesResult);
43
- } catch (err) {
44
- setError(err instanceof Error ? err : new Error("Unknown error"));
45
- } finally {
46
- setLoading(false);
47
- }
48
- }, [
49
- crm,
50
- projectId,
51
- pipelineId,
52
- options.stageId,
53
- options.status,
54
- options.search,
55
- pageIndex,
56
- pageSize,
57
- sortBy,
58
- sortDirection
59
- ]);
60
- useEffect(() => {
61
- fetchData();
62
- }, [fetchData]);
63
- const stats = useMemo(() => {
64
- if (!data)
65
- return null;
66
- const open = data.deals.filter((d) => d.status === "OPEN");
67
- const won = data.deals.filter((d) => d.status === "WON");
68
- const lost = data.deals.filter((d) => d.status === "LOST");
69
- return {
70
- total: data.total,
71
- totalValue: data.totalValue,
72
- openCount: open.length,
73
- openValue: open.reduce((sum, d) => sum + d.value, 0),
74
- wonCount: won.length,
75
- wonValue: won.reduce((sum, d) => sum + d.value, 0),
76
- lostCount: lost.length
77
- };
78
- }, [data]);
79
- return {
80
- data,
81
- dealsByStage,
82
- stages,
83
- loading,
84
- error,
85
- stats,
86
- page: pageIndex + 1,
87
- pageIndex,
88
- pageSize,
89
- refetch: fetchData,
90
- nextPage: options.pageIndex === undefined ? () => setInternalPage((page) => page + 1) : undefined,
91
- prevPage: options.pageIndex === undefined ? () => pageIndex > 0 && setInternalPage((page) => page - 1) : undefined
92
- };
93
- }
94
-
95
- // src/ui/hooks/useDealMutations.ts
96
- import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
97
- import { useCallback as useCallback2, useState as useState2 } from "react";
98
- function useDealMutations(options = {}) {
99
- const { handlers, projectId } = useTemplateRuntime2();
100
- const { crm } = handlers;
101
- const [createState, setCreateState] = useState2({
102
- loading: false,
103
- error: null,
104
- data: null
105
- });
106
- const [moveState, setMoveState] = useState2({
107
- loading: false,
108
- error: null,
109
- data: null
110
- });
111
- const [winState, setWinState] = useState2({
112
- loading: false,
113
- error: null,
114
- data: null
115
- });
116
- const [loseState, setLoseState] = useState2({
117
- loading: false,
118
- error: null,
119
- data: null
120
- });
121
- const createDeal = useCallback2(async (input) => {
122
- setCreateState({ loading: true, error: null, data: null });
123
- try {
124
- const result = await crm.createDeal(input, {
125
- projectId,
126
- ownerId: "user-1"
127
- });
128
- setCreateState({ loading: false, error: null, data: result });
129
- options.onSuccess?.();
130
- return result;
131
- } catch (err) {
132
- const error = err instanceof Error ? err : new Error("Failed to create deal");
133
- setCreateState({ loading: false, error, data: null });
134
- options.onError?.(error);
135
- return null;
136
- }
137
- }, [crm, projectId, options]);
138
- const moveDeal = useCallback2(async (input) => {
139
- setMoveState({ loading: true, error: null, data: null });
140
- try {
141
- const result = await crm.moveDeal(input);
142
- setMoveState({ loading: false, error: null, data: result });
143
- options.onSuccess?.();
144
- return result;
145
- } catch (err) {
146
- const error = err instanceof Error ? err : new Error("Failed to move deal");
147
- setMoveState({ loading: false, error, data: null });
148
- options.onError?.(error);
149
- return null;
150
- }
151
- }, [crm, options]);
152
- const winDeal = useCallback2(async (input) => {
153
- setWinState({ loading: true, error: null, data: null });
154
- try {
155
- const result = await crm.winDeal(input);
156
- setWinState({ loading: false, error: null, data: result });
157
- options.onSuccess?.();
158
- return result;
159
- } catch (err) {
160
- const error = err instanceof Error ? err : new Error("Failed to mark deal as won");
161
- setWinState({ loading: false, error, data: null });
162
- options.onError?.(error);
163
- return null;
164
- }
165
- }, [crm, options]);
166
- const loseDeal = useCallback2(async (input) => {
167
- setLoseState({ loading: true, error: null, data: null });
168
- try {
169
- const result = await crm.loseDeal(input);
170
- setLoseState({ loading: false, error: null, data: result });
171
- options.onSuccess?.();
172
- return result;
173
- } catch (err) {
174
- const error = err instanceof Error ? err : new Error("Failed to mark deal as lost");
175
- setLoseState({ loading: false, error, data: null });
176
- options.onError?.(error);
177
- return null;
178
- }
179
- }, [crm, options]);
180
- return {
181
- createDeal,
182
- moveDeal,
183
- winDeal,
184
- loseDeal,
185
- createState,
186
- moveState,
187
- winState,
188
- loseState,
189
- isLoading: createState.loading || moveState.loading || winState.loading || loseState.loading
190
- };
191
- }
192
-
193
- // src/ui/hooks/index.ts
194
- "use client";
195
- export {
196
- useDealMutations,
197
- useDealList
198
- };
2
+ import{useTemplateRuntime as x}from"@contractspec/lib.example-shared-ui";import{useCallback as B,useEffect as C,useMemo as y,useState as V}from"react";function D(A={}){let{handlers:k,projectId:Q}=x(),{crm:G}=k,[J,X]=V(null),[_,Y]=V({}),[$,Z]=V([]),[T,U]=V(!0),[w,E]=V(null),[M,P]=V(0),H=A.pipelineId??"pipeline-1",q=A.pageIndex??M,F=A.pageSize??A.limit??50,[R]=A.sorting??[],O=R?.id,b=R?R.desc?"desc":"asc":void 0,f=B(async()=>{U(!0),E(null);try{let[K,W,v]=await Promise.all([G.listDeals({projectId:Q,pipelineId:H,stageId:A.stageId,status:A.status==="all"?void 0:A.status,search:A.search,limit:F,offset:q*F,sortBy:O==="name"||O==="value"||O==="status"||O==="expectedCloseDate"||O==="updatedAt"?O:void 0,sortDirection:b}),G.getDealsByStage({projectId:Q,pipelineId:H}),G.getPipelineStages({pipelineId:H})]);X(K),Y(W),Z(v)}catch(K){E(K instanceof Error?K:Error("Unknown error"))}finally{U(!1)}},[G,Q,H,A.stageId,A.status,A.search,q,F,O,b]);C(()=>{f()},[f]);let h=y(()=>{if(!J)return null;let K=J.deals.filter((N)=>N.status==="OPEN"),W=J.deals.filter((N)=>N.status==="WON"),v=J.deals.filter((N)=>N.status==="LOST");return{total:J.total,totalValue:J.totalValue,openCount:K.length,openValue:K.reduce((N,L)=>N+L.value,0),wonCount:W.length,wonValue:W.reduce((N,L)=>N+L.value,0),lostCount:v.length}},[J]);return{data:J,dealsByStage:_,stages:$,loading:T,error:w,stats:h,page:q+1,pageIndex:q,pageSize:F,refetch:f,nextPage:A.pageIndex===void 0?()=>P((K)=>K+1):void 0,prevPage:A.pageIndex===void 0?()=>q>0&&P((K)=>K-1):void 0}}import{useTemplateRuntime as I}from"@contractspec/lib.example-shared-ui";import{useCallback as z,useState as j}from"react";function g(A={}){let{handlers:k,projectId:Q}=I(),{crm:G}=k,[J,X]=j({loading:!1,error:null,data:null}),[_,Y]=j({loading:!1,error:null,data:null}),[$,Z]=j({loading:!1,error:null,data:null}),[T,U]=j({loading:!1,error:null,data:null}),w=z(async(H)=>{X({loading:!0,error:null,data:null});try{let q=await G.createDeal(H,{projectId:Q,ownerId:"user-1"});return X({loading:!1,error:null,data:q}),A.onSuccess?.(),q}catch(q){let F=q instanceof Error?q:Error("Failed to create deal");return X({loading:!1,error:F,data:null}),A.onError?.(F),null}},[G,Q,A]),E=z(async(H)=>{Y({loading:!0,error:null,data:null});try{let q=await G.moveDeal(H);return Y({loading:!1,error:null,data:q}),A.onSuccess?.(),q}catch(q){let F=q instanceof Error?q:Error("Failed to move deal");return Y({loading:!1,error:F,data:null}),A.onError?.(F),null}},[G,A]),M=z(async(H)=>{Z({loading:!0,error:null,data:null});try{let q=await G.winDeal(H);return Z({loading:!1,error:null,data:q}),A.onSuccess?.(),q}catch(q){let F=q instanceof Error?q:Error("Failed to mark deal as won");return Z({loading:!1,error:F,data:null}),A.onError?.(F),null}},[G,A]),P=z(async(H)=>{U({loading:!0,error:null,data:null});try{let q=await G.loseDeal(H);return U({loading:!1,error:null,data:q}),A.onSuccess?.(),q}catch(q){let F=q instanceof Error?q:Error("Failed to mark deal as lost");return U({loading:!1,error:F,data:null}),A.onError?.(F),null}},[G,A]);return{createDeal:w,moveDeal:E,winDeal:M,loseDeal:P,createState:J,moveState:_,winState:$,loseState:T,isLoading:J.loading||_.loading||$.loading||T.loading}}export{g as useDealMutations,D as useDealList};
@@ -1,96 +1,2 @@
1
1
  // @bun
2
- // src/ui/hooks/useDealList.ts
3
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
- import { useCallback, useEffect, useMemo, useState } from "react";
5
- "use client";
6
- function useDealList(options = {}) {
7
- const { handlers, projectId } = useTemplateRuntime();
8
- const { crm } = handlers;
9
- const [data, setData] = useState(null);
10
- const [dealsByStage, setDealsByStage] = useState({});
11
- const [stages, setStages] = useState([]);
12
- const [loading, setLoading] = useState(true);
13
- const [error, setError] = useState(null);
14
- const [internalPage, setInternalPage] = useState(0);
15
- const pipelineId = options.pipelineId ?? "pipeline-1";
16
- const pageIndex = options.pageIndex ?? internalPage;
17
- const pageSize = options.pageSize ?? options.limit ?? 50;
18
- const [sort] = options.sorting ?? [];
19
- const sortBy = sort?.id;
20
- const sortDirection = sort ? sort.desc ? "desc" : "asc" : undefined;
21
- const fetchData = useCallback(async () => {
22
- setLoading(true);
23
- setError(null);
24
- try {
25
- const [dealsResult, stageDealsResult, stagesResult] = await Promise.all([
26
- crm.listDeals({
27
- projectId,
28
- pipelineId,
29
- stageId: options.stageId,
30
- status: options.status === "all" ? undefined : options.status,
31
- search: options.search,
32
- limit: pageSize,
33
- offset: pageIndex * pageSize,
34
- sortBy: sortBy === "name" || sortBy === "value" || sortBy === "status" || sortBy === "expectedCloseDate" || sortBy === "updatedAt" ? sortBy : undefined,
35
- sortDirection
36
- }),
37
- crm.getDealsByStage({ projectId, pipelineId }),
38
- crm.getPipelineStages({ pipelineId })
39
- ]);
40
- setData(dealsResult);
41
- setDealsByStage(stageDealsResult);
42
- setStages(stagesResult);
43
- } catch (err) {
44
- setError(err instanceof Error ? err : new Error("Unknown error"));
45
- } finally {
46
- setLoading(false);
47
- }
48
- }, [
49
- crm,
50
- projectId,
51
- pipelineId,
52
- options.stageId,
53
- options.status,
54
- options.search,
55
- pageIndex,
56
- pageSize,
57
- sortBy,
58
- sortDirection
59
- ]);
60
- useEffect(() => {
61
- fetchData();
62
- }, [fetchData]);
63
- const stats = useMemo(() => {
64
- if (!data)
65
- return null;
66
- const open = data.deals.filter((d) => d.status === "OPEN");
67
- const won = data.deals.filter((d) => d.status === "WON");
68
- const lost = data.deals.filter((d) => d.status === "LOST");
69
- return {
70
- total: data.total,
71
- totalValue: data.totalValue,
72
- openCount: open.length,
73
- openValue: open.reduce((sum, d) => sum + d.value, 0),
74
- wonCount: won.length,
75
- wonValue: won.reduce((sum, d) => sum + d.value, 0),
76
- lostCount: lost.length
77
- };
78
- }, [data]);
79
- return {
80
- data,
81
- dealsByStage,
82
- stages,
83
- loading,
84
- error,
85
- stats,
86
- page: pageIndex + 1,
87
- pageIndex,
88
- pageSize,
89
- refetch: fetchData,
90
- nextPage: options.pageIndex === undefined ? () => setInternalPage((page) => page + 1) : undefined,
91
- prevPage: options.pageIndex === undefined ? () => pageIndex > 0 && setInternalPage((page) => page - 1) : undefined
92
- };
93
- }
94
- export {
95
- useDealList
96
- };
2
+ import{useTemplateRuntime as R}from"@contractspec/lib.example-shared-ui";import{useCallback as f,useEffect as h,useMemo as x,useState as H}from"react";function B(q={}){let{handlers:C,projectId:U}=R(),{crm:K}=C,[F,M]=H(null),[T,b]=H({}),[w,L]=H([]),[j,Z]=H(!0),[E,_]=H(null),[P,$]=H(0),N=q.pipelineId??"pipeline-1",J=q.pageIndex??P,O=q.pageSize??q.limit??50,[V]=q.sorting??[],G=V?.id,k=V?V.desc?"desc":"asc":void 0,W=f(async()=>{Z(!0),_(null);try{let[v,Q,X]=await Promise.all([K.listDeals({projectId:U,pipelineId:N,stageId:q.stageId,status:q.status==="all"?void 0:q.status,search:q.search,limit:O,offset:J*O,sortBy:G==="name"||G==="value"||G==="status"||G==="expectedCloseDate"||G==="updatedAt"?G:void 0,sortDirection:k}),K.getDealsByStage({projectId:U,pipelineId:N}),K.getPipelineStages({pipelineId:N})]);M(v),b(Q),L(X)}catch(v){_(v instanceof Error?v:Error("Unknown error"))}finally{Z(!1)}},[K,U,N,q.stageId,q.status,q.search,J,O,G,k]);h(()=>{W()},[W]);let z=x(()=>{if(!F)return null;let v=F.deals.filter((A)=>A.status==="OPEN"),Q=F.deals.filter((A)=>A.status==="WON"),X=F.deals.filter((A)=>A.status==="LOST");return{total:F.total,totalValue:F.totalValue,openCount:v.length,openValue:v.reduce((A,Y)=>A+Y.value,0),wonCount:Q.length,wonValue:Q.reduce((A,Y)=>A+Y.value,0),lostCount:X.length}},[F]);return{data:F,dealsByStage:T,stages:w,loading:j,error:E,stats:z,page:J+1,pageIndex:J,pageSize:O,refetch:W,nextPage:q.pageIndex===void 0?()=>$((v)=>v+1):void 0,prevPage:q.pageIndex===void 0?()=>J>0&&$((v)=>v-1):void 0}}export{B as useDealList};
@@ -1,101 +1,2 @@
1
1
  // @bun
2
- // src/ui/hooks/useDealMutations.ts
3
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
- import { useCallback, useState } from "react";
5
- function useDealMutations(options = {}) {
6
- const { handlers, projectId } = useTemplateRuntime();
7
- const { crm } = handlers;
8
- const [createState, setCreateState] = useState({
9
- loading: false,
10
- error: null,
11
- data: null
12
- });
13
- const [moveState, setMoveState] = useState({
14
- loading: false,
15
- error: null,
16
- data: null
17
- });
18
- const [winState, setWinState] = useState({
19
- loading: false,
20
- error: null,
21
- data: null
22
- });
23
- const [loseState, setLoseState] = useState({
24
- loading: false,
25
- error: null,
26
- data: null
27
- });
28
- const createDeal = useCallback(async (input) => {
29
- setCreateState({ loading: true, error: null, data: null });
30
- try {
31
- const result = await crm.createDeal(input, {
32
- projectId,
33
- ownerId: "user-1"
34
- });
35
- setCreateState({ loading: false, error: null, data: result });
36
- options.onSuccess?.();
37
- return result;
38
- } catch (err) {
39
- const error = err instanceof Error ? err : new Error("Failed to create deal");
40
- setCreateState({ loading: false, error, data: null });
41
- options.onError?.(error);
42
- return null;
43
- }
44
- }, [crm, projectId, options]);
45
- const moveDeal = useCallback(async (input) => {
46
- setMoveState({ loading: true, error: null, data: null });
47
- try {
48
- const result = await crm.moveDeal(input);
49
- setMoveState({ loading: false, error: null, data: result });
50
- options.onSuccess?.();
51
- return result;
52
- } catch (err) {
53
- const error = err instanceof Error ? err : new Error("Failed to move deal");
54
- setMoveState({ loading: false, error, data: null });
55
- options.onError?.(error);
56
- return null;
57
- }
58
- }, [crm, options]);
59
- const winDeal = useCallback(async (input) => {
60
- setWinState({ loading: true, error: null, data: null });
61
- try {
62
- const result = await crm.winDeal(input);
63
- setWinState({ loading: false, error: null, data: result });
64
- options.onSuccess?.();
65
- return result;
66
- } catch (err) {
67
- const error = err instanceof Error ? err : new Error("Failed to mark deal as won");
68
- setWinState({ loading: false, error, data: null });
69
- options.onError?.(error);
70
- return null;
71
- }
72
- }, [crm, options]);
73
- const loseDeal = useCallback(async (input) => {
74
- setLoseState({ loading: true, error: null, data: null });
75
- try {
76
- const result = await crm.loseDeal(input);
77
- setLoseState({ loading: false, error: null, data: result });
78
- options.onSuccess?.();
79
- return result;
80
- } catch (err) {
81
- const error = err instanceof Error ? err : new Error("Failed to mark deal as lost");
82
- setLoseState({ loading: false, error, data: null });
83
- options.onError?.(error);
84
- return null;
85
- }
86
- }, [crm, options]);
87
- return {
88
- createDeal,
89
- moveDeal,
90
- winDeal,
91
- loseDeal,
92
- createState,
93
- moveState,
94
- winState,
95
- loseState,
96
- isLoading: createState.loading || moveState.loading || winState.loading || loseState.loading
97
- };
98
- }
99
- export {
100
- useDealMutations
101
- };
2
+ import{useTemplateRuntime as Z}from"@contractspec/lib.example-shared-ui";import{useCallback as A,useState as B}from"react";function x(g={}){let{handlers:Q,projectId:J}=Z(),{crm:y}=Q,[K,E]=B({loading:!1,error:null,data:null}),[N,F]=B({loading:!1,error:null,data:null}),[O,G]=B({loading:!1,error:null,data:null}),[P,H]=B({loading:!1,error:null,data:null}),U=A(async(z)=>{E({loading:!0,error:null,data:null});try{let f=await y.createDeal(z,{projectId:J,ownerId:"user-1"});return E({loading:!1,error:null,data:f}),g.onSuccess?.(),f}catch(f){let q=f instanceof Error?f:Error("Failed to create deal");return E({loading:!1,error:q,data:null}),g.onError?.(q),null}},[y,J,g]),V=A(async(z)=>{F({loading:!0,error:null,data:null});try{let f=await y.moveDeal(z);return F({loading:!1,error:null,data:f}),g.onSuccess?.(),f}catch(f){let q=f instanceof Error?f:Error("Failed to move deal");return F({loading:!1,error:q,data:null}),g.onError?.(q),null}},[y,g]),X=A(async(z)=>{G({loading:!0,error:null,data:null});try{let f=await y.winDeal(z);return G({loading:!1,error:null,data:f}),g.onSuccess?.(),f}catch(f){let q=f instanceof Error?f:Error("Failed to mark deal as won");return G({loading:!1,error:q,data:null}),g.onError?.(q),null}},[y,g]),Y=A(async(z)=>{H({loading:!0,error:null,data:null});try{let f=await y.loseDeal(z);return H({loading:!1,error:null,data:f}),g.onSuccess?.(),f}catch(f){let q=f instanceof Error?f:Error("Failed to mark deal as lost");return H({loading:!1,error:q,data:null}),g.onError?.(q),null}},[y,g]);return{createDeal:U,moveDeal:V,winDeal:X,loseDeal:Y,createState:K,moveState:N,winState:O,loseState:P,isLoading:K.loading||N.loading||O.loading||P.loading}}export{x as useDealMutations};