@contractspec/example.crm-pipeline 3.7.6 → 3.7.10
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 +45 -42
- package/AGENTS.md +51 -33
- package/CHANGELOG.md +36 -0
- package/README.md +67 -148
- package/dist/browser/docs/crm-pipeline.docblock.js +1 -1
- package/dist/browser/docs/index.js +1 -1
- package/dist/browser/events/contact.event.js +1 -1
- package/dist/browser/events/deal.event.js +1 -1
- package/dist/browser/events/index.js +3 -3
- package/dist/browser/events/task.event.js +1 -1
- package/dist/browser/handlers/crm.handlers.js +13 -2
- package/dist/browser/handlers/index.js +13 -2
- package/dist/browser/index.js +680 -447
- package/dist/browser/ui/CrmDashboard.js +574 -352
- package/dist/browser/ui/CrmDealCard.js +5 -5
- package/dist/browser/ui/CrmPipelineBoard.js +13 -13
- package/dist/browser/ui/hooks/index.js +21 -10
- package/dist/browser/ui/hooks/useDealList.js +20 -9
- package/dist/browser/ui/hooks/useDealMutations.js +1 -1
- package/dist/browser/ui/index.js +683 -450
- package/dist/browser/ui/modals/CreateDealModal.js +12 -12
- package/dist/browser/ui/modals/DealActionsModal.js +21 -21
- package/dist/browser/ui/modals/index.js +33 -33
- package/dist/browser/ui/renderers/index.js +140 -118
- package/dist/browser/ui/renderers/pipeline.markdown.js +13 -2
- package/dist/browser/ui/renderers/pipeline.renderer.js +108 -97
- package/dist/browser/ui/tables/DealListTab.js +390 -0
- package/dist/deal/index.d.ts +2 -2
- package/dist/docs/crm-pipeline.docblock.js +1 -1
- package/dist/docs/index.js +1 -1
- package/dist/events/contact.event.js +1 -1
- package/dist/events/deal.event.js +1 -1
- package/dist/events/index.js +3 -3
- package/dist/events/task.event.js +1 -1
- package/dist/handlers/crm.handlers.d.ts +2 -0
- package/dist/handlers/crm.handlers.js +13 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +13 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +680 -447
- package/dist/node/docs/crm-pipeline.docblock.js +1 -1
- package/dist/node/docs/index.js +1 -1
- package/dist/node/events/contact.event.js +1 -1
- package/dist/node/events/deal.event.js +1 -1
- package/dist/node/events/index.js +3 -3
- package/dist/node/events/task.event.js +1 -1
- package/dist/node/handlers/crm.handlers.js +13 -2
- package/dist/node/handlers/index.js +13 -2
- package/dist/node/index.js +680 -447
- package/dist/node/ui/CrmDashboard.js +574 -352
- package/dist/node/ui/CrmDealCard.js +5 -5
- package/dist/node/ui/CrmPipelineBoard.js +13 -13
- package/dist/node/ui/hooks/index.js +21 -10
- package/dist/node/ui/hooks/useDealList.js +20 -9
- package/dist/node/ui/hooks/useDealMutations.js +1 -1
- package/dist/node/ui/index.js +683 -450
- package/dist/node/ui/modals/CreateDealModal.js +12 -12
- package/dist/node/ui/modals/DealActionsModal.js +21 -21
- package/dist/node/ui/modals/index.js +33 -33
- package/dist/node/ui/renderers/index.js +140 -118
- package/dist/node/ui/renderers/pipeline.markdown.js +13 -2
- package/dist/node/ui/renderers/pipeline.renderer.js +108 -97
- package/dist/node/ui/tables/DealListTab.js +390 -0
- package/dist/operations/index.d.ts +1 -1
- package/dist/ui/CrmDashboard.js +574 -352
- package/dist/ui/CrmDealCard.js +5 -5
- package/dist/ui/CrmPipelineBoard.js +13 -13
- package/dist/ui/hooks/index.d.ts +2 -2
- package/dist/ui/hooks/index.js +21 -10
- package/dist/ui/hooks/useDealList.d.ts +8 -2
- package/dist/ui/hooks/useDealList.js +20 -9
- package/dist/ui/hooks/useDealMutations.d.ts +9 -0
- package/dist/ui/hooks/useDealMutations.js +1 -1
- package/dist/ui/index.d.ts +3 -3
- package/dist/ui/index.js +683 -450
- package/dist/ui/modals/CreateDealModal.js +12 -12
- package/dist/ui/modals/DealActionsModal.js +21 -21
- package/dist/ui/modals/index.js +33 -33
- package/dist/ui/renderers/index.d.ts +1 -1
- package/dist/ui/renderers/index.js +140 -118
- package/dist/ui/renderers/pipeline.markdown.js +13 -2
- package/dist/ui/renderers/pipeline.renderer.d.ts +1 -1
- package/dist/ui/renderers/pipeline.renderer.js +108 -97
- package/dist/ui/tables/DealListTab.d.ts +20 -0
- package/dist/ui/tables/DealListTab.js +391 -0
- package/dist/ui/tables/DealListTab.smoke.test.d.ts +1 -0
- package/package.json +29 -14
- package/src/crm-pipeline.feature.ts +86 -86
- package/src/deal/deal.enum.ts +8 -8
- package/src/deal/deal.operation.ts +255 -255
- package/src/deal/deal.schema.ts +92 -92
- package/src/deal/deal.test-spec.ts +48 -48
- package/src/deal/index.ts +17 -19
- package/src/docs/crm-pipeline.docblock.ts +44 -44
- package/src/entities/company.entity.ts +52 -52
- package/src/entities/contact.entity.ts +67 -67
- package/src/entities/deal.entity.ts +134 -134
- package/src/entities/index.ts +27 -27
- package/src/entities/task.entity.ts +105 -105
- package/src/events/contact.event.ts +22 -22
- package/src/events/deal.event.ts +77 -77
- package/src/events/task.event.ts +19 -19
- package/src/example.ts +32 -32
- package/src/handlers/crm.handlers.ts +375 -357
- package/src/handlers/deal.handlers.ts +179 -179
- package/src/handlers/index.ts +18 -19
- package/src/handlers/mock-data.ts +167 -167
- package/src/index.ts +11 -11
- package/src/operations/index.ts +16 -16
- package/src/presentations/dashboard.presentation.ts +45 -45
- package/src/presentations/pipeline.presentation.ts +90 -90
- package/src/seeders/index.ts +26 -26
- package/src/shared/overlay-types.ts +23 -23
- package/src/ui/CrmDashboard.tsx +210 -279
- package/src/ui/CrmDealCard.tsx +64 -64
- package/src/ui/CrmPipelineBoard.tsx +105 -105
- package/src/ui/hooks/index.ts +3 -3
- package/src/ui/hooks/useDealList.ts +113 -85
- package/src/ui/hooks/useDealMutations.ts +151 -150
- package/src/ui/index.ts +5 -10
- package/src/ui/modals/CreateDealModal.tsx +217 -217
- package/src/ui/modals/DealActionsModal.tsx +390 -390
- package/src/ui/overlays/demo-overlays.ts +43 -43
- package/src/ui/renderers/index.ts +4 -3
- package/src/ui/renderers/pipeline.markdown.ts +165 -165
- package/src/ui/renderers/pipeline.renderer.tsx +17 -16
- package/src/ui/tables/DealListTab.smoke.test.tsx +149 -0
- package/src/ui/tables/DealListTab.tsx +276 -0
- package/tsconfig.json +7 -8
- package/tsdown.config.js +7 -3
package/src/ui/CrmDashboard.tsx
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
ErrorState,
|
|
6
|
+
LoaderBlock,
|
|
7
|
+
StatCard,
|
|
8
|
+
StatCardGroup,
|
|
9
|
+
} from '@contractspec/lib.design-system';
|
|
10
|
+
import {
|
|
11
|
+
Tabs,
|
|
12
|
+
TabsContent,
|
|
13
|
+
TabsList,
|
|
14
|
+
TabsTrigger,
|
|
15
|
+
} from '@contractspec/lib.ui-kit-web/ui/tabs';
|
|
3
16
|
/**
|
|
4
17
|
* CRM Dashboard
|
|
5
18
|
*
|
|
@@ -13,299 +26,217 @@
|
|
|
13
26
|
* - LoseDealContract -> Mark deal as lost
|
|
14
27
|
*/
|
|
15
28
|
import { useCallback, useState } from 'react';
|
|
16
|
-
import {
|
|
17
|
-
Button,
|
|
18
|
-
ErrorState,
|
|
19
|
-
LoaderBlock,
|
|
20
|
-
StatCard,
|
|
21
|
-
StatCardGroup,
|
|
22
|
-
} from '@contractspec/lib.design-system';
|
|
23
|
-
import {
|
|
24
|
-
Tabs,
|
|
25
|
-
TabsContent,
|
|
26
|
-
TabsList,
|
|
27
|
-
TabsTrigger,
|
|
28
|
-
} from '@contractspec/lib.ui-kit-web/ui/tabs';
|
|
29
|
+
import { CrmPipelineBoard } from './CrmPipelineBoard';
|
|
29
30
|
import { type Deal, useDealList } from './hooks/useDealList';
|
|
30
31
|
import { useDealMutations } from './hooks/useDealMutations';
|
|
31
|
-
import { CrmPipelineBoard } from './CrmPipelineBoard';
|
|
32
32
|
import { CreateDealModal } from './modals/CreateDealModal';
|
|
33
33
|
import { DealActionsModal } from './modals/DealActionsModal';
|
|
34
|
+
import { DealListTab } from './tables/DealListTab';
|
|
34
35
|
|
|
35
36
|
// type Tab = 'pipeline' | 'list' | 'metrics';
|
|
36
37
|
|
|
37
38
|
function formatCurrency(value: number, currency = 'USD'): string {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
return new Intl.NumberFormat('en-US', {
|
|
40
|
+
style: 'currency',
|
|
41
|
+
currency,
|
|
42
|
+
minimumFractionDigits: 0,
|
|
43
|
+
maximumFractionDigits: 0,
|
|
44
|
+
}).format(value);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export function CrmDashboard() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
interface DealListTabProps {
|
|
203
|
-
data: ReturnType<typeof useDealList>['data'];
|
|
204
|
-
onDealClick?: (dealId: string) => void;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function DealListTab({ data, onDealClick }: DealListTabProps) {
|
|
208
|
-
if (!data?.deals.length) {
|
|
209
|
-
return (
|
|
210
|
-
<div className="text-muted-foreground flex h-64 items-center justify-center">
|
|
211
|
-
No deals found
|
|
212
|
-
</div>
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return (
|
|
217
|
-
<div className="border-border rounded-lg border">
|
|
218
|
-
<table className="w-full">
|
|
219
|
-
<thead className="border-border bg-muted/30 border-b">
|
|
220
|
-
<tr>
|
|
221
|
-
<th className="px-4 py-3 text-left text-sm font-medium">Deal</th>
|
|
222
|
-
<th className="px-4 py-3 text-left text-sm font-medium">Value</th>
|
|
223
|
-
<th className="px-4 py-3 text-left text-sm font-medium">Status</th>
|
|
224
|
-
<th className="px-4 py-3 text-left text-sm font-medium">
|
|
225
|
-
Expected Close
|
|
226
|
-
</th>
|
|
227
|
-
<th className="px-4 py-3 text-left text-sm font-medium">Actions</th>
|
|
228
|
-
</tr>
|
|
229
|
-
</thead>
|
|
230
|
-
<tbody className="divide-border divide-y">
|
|
231
|
-
{data.deals.map((deal: Deal) => (
|
|
232
|
-
<tr key={deal.id} className="hover:bg-muted/50">
|
|
233
|
-
<td className="px-4 py-3">
|
|
234
|
-
<div className="font-medium">{deal.name}</div>
|
|
235
|
-
</td>
|
|
236
|
-
<td className="px-4 py-3 font-mono">
|
|
237
|
-
{formatCurrency(deal.value, deal.currency)}
|
|
238
|
-
</td>
|
|
239
|
-
<td className="px-4 py-3">
|
|
240
|
-
<span
|
|
241
|
-
className={`inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${
|
|
242
|
-
deal.status === 'WON'
|
|
243
|
-
? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
|
|
244
|
-
: deal.status === 'LOST'
|
|
245
|
-
? 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400'
|
|
246
|
-
: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400'
|
|
247
|
-
}`}
|
|
248
|
-
>
|
|
249
|
-
{deal.status}
|
|
250
|
-
</span>
|
|
251
|
-
</td>
|
|
252
|
-
<td className="text-muted-foreground px-4 py-3">
|
|
253
|
-
{deal.expectedCloseDate?.toLocaleDateString() ?? '-'}
|
|
254
|
-
</td>
|
|
255
|
-
<td className="px-4 py-3">
|
|
256
|
-
<Button
|
|
257
|
-
variant="ghost"
|
|
258
|
-
size="sm"
|
|
259
|
-
onPress={() => onDealClick?.(deal.id)}
|
|
260
|
-
>
|
|
261
|
-
Actions
|
|
262
|
-
</Button>
|
|
263
|
-
</td>
|
|
264
|
-
</tr>
|
|
265
|
-
))}
|
|
266
|
-
</tbody>
|
|
267
|
-
</table>
|
|
268
|
-
</div>
|
|
269
|
-
);
|
|
48
|
+
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
|
49
|
+
const [selectedDeal, setSelectedDeal] = useState<Deal | null>(null);
|
|
50
|
+
const [isDealActionsOpen, setIsDealActionsOpen] = useState(false);
|
|
51
|
+
|
|
52
|
+
const { data, dealsByStage, stages, loading, error, stats, refetch } =
|
|
53
|
+
useDealList();
|
|
54
|
+
|
|
55
|
+
const mutations = useDealMutations({
|
|
56
|
+
onSuccess: () => {
|
|
57
|
+
refetch();
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const handleDealClick = useCallback(
|
|
62
|
+
(dealId: string) => {
|
|
63
|
+
// Find deal in data
|
|
64
|
+
const deal = dealsByStage
|
|
65
|
+
? Object.values(dealsByStage)
|
|
66
|
+
.flat()
|
|
67
|
+
.find((d) => d.id === dealId)
|
|
68
|
+
: null;
|
|
69
|
+
|
|
70
|
+
if (deal) {
|
|
71
|
+
setSelectedDeal(deal);
|
|
72
|
+
setIsDealActionsOpen(true);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
[dealsByStage]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const handleDealMove = useCallback(
|
|
79
|
+
async (dealId: string, toStageId: string) => {
|
|
80
|
+
await mutations.moveDeal({ dealId, stageId: toStageId });
|
|
81
|
+
},
|
|
82
|
+
[mutations]
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (loading && !data) {
|
|
86
|
+
return <LoaderBlock label="Loading CRM..." />;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (error) {
|
|
90
|
+
return (
|
|
91
|
+
<ErrorState
|
|
92
|
+
title="Failed to load CRM"
|
|
93
|
+
description={error.message}
|
|
94
|
+
onRetry={refetch}
|
|
95
|
+
retryLabel="Retry"
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div className="space-y-6">
|
|
102
|
+
{/* Header with Create Button */}
|
|
103
|
+
<div className="flex items-center justify-between">
|
|
104
|
+
<h2 className="font-bold text-2xl">CRM Pipeline</h2>
|
|
105
|
+
<Button onClick={() => setIsCreateModalOpen(true)}>
|
|
106
|
+
<span className="mr-2">+</span> Create Deal
|
|
107
|
+
</Button>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
{/* Stats Row */}
|
|
111
|
+
{stats && (
|
|
112
|
+
<StatCardGroup>
|
|
113
|
+
<StatCard
|
|
114
|
+
label="Total Pipeline"
|
|
115
|
+
value={formatCurrency(stats.totalValue)}
|
|
116
|
+
hint={`${stats.total} deals`}
|
|
117
|
+
/>
|
|
118
|
+
<StatCard
|
|
119
|
+
label="Open Deals"
|
|
120
|
+
value={formatCurrency(stats.openValue)}
|
|
121
|
+
hint={`${stats.openCount} active`}
|
|
122
|
+
/>
|
|
123
|
+
<StatCard
|
|
124
|
+
label="Won"
|
|
125
|
+
value={formatCurrency(stats.wonValue)}
|
|
126
|
+
hint={`${stats.wonCount} closed`}
|
|
127
|
+
/>
|
|
128
|
+
<StatCard label="Lost" value={stats.lostCount} hint="deals lost" />
|
|
129
|
+
</StatCardGroup>
|
|
130
|
+
)}
|
|
131
|
+
|
|
132
|
+
{/* Tabs */}
|
|
133
|
+
<Tabs defaultValue="pipeline" className="w-full">
|
|
134
|
+
<TabsList>
|
|
135
|
+
<TabsTrigger value="pipeline">
|
|
136
|
+
<span className="mr-2">📊</span>
|
|
137
|
+
Pipeline
|
|
138
|
+
</TabsTrigger>
|
|
139
|
+
<TabsTrigger value="list">
|
|
140
|
+
<span className="mr-2">📋</span>
|
|
141
|
+
All Deals
|
|
142
|
+
</TabsTrigger>
|
|
143
|
+
<TabsTrigger value="metrics">
|
|
144
|
+
<span className="mr-2">📈</span>
|
|
145
|
+
Metrics
|
|
146
|
+
</TabsTrigger>
|
|
147
|
+
</TabsList>
|
|
148
|
+
|
|
149
|
+
<TabsContent value="pipeline" className="min-h-[400px]">
|
|
150
|
+
<CrmPipelineBoard
|
|
151
|
+
dealsByStage={dealsByStage}
|
|
152
|
+
stages={stages}
|
|
153
|
+
onDealClick={handleDealClick}
|
|
154
|
+
onDealMove={handleDealMove}
|
|
155
|
+
/>
|
|
156
|
+
</TabsContent>
|
|
157
|
+
|
|
158
|
+
<TabsContent value="list" className="min-h-[400px]">
|
|
159
|
+
<DealListTab onDealClick={handleDealClick} />
|
|
160
|
+
</TabsContent>
|
|
161
|
+
|
|
162
|
+
<TabsContent value="metrics" className="min-h-[400px]">
|
|
163
|
+
<MetricsTab stats={stats} />
|
|
164
|
+
</TabsContent>
|
|
165
|
+
</Tabs>
|
|
166
|
+
|
|
167
|
+
{/* Create Deal Modal */}
|
|
168
|
+
<CreateDealModal
|
|
169
|
+
isOpen={isCreateModalOpen}
|
|
170
|
+
onClose={() => setIsCreateModalOpen(false)}
|
|
171
|
+
onSubmit={async (input) => {
|
|
172
|
+
await mutations.createDeal(input);
|
|
173
|
+
}}
|
|
174
|
+
stages={stages}
|
|
175
|
+
isLoading={mutations.createState.loading}
|
|
176
|
+
/>
|
|
177
|
+
|
|
178
|
+
{/* Deal Actions Modal */}
|
|
179
|
+
<DealActionsModal
|
|
180
|
+
isOpen={isDealActionsOpen}
|
|
181
|
+
deal={selectedDeal}
|
|
182
|
+
stages={stages}
|
|
183
|
+
onClose={() => {
|
|
184
|
+
setIsDealActionsOpen(false);
|
|
185
|
+
setSelectedDeal(null);
|
|
186
|
+
}}
|
|
187
|
+
onWin={async (input) => {
|
|
188
|
+
await mutations.winDeal(input);
|
|
189
|
+
}}
|
|
190
|
+
onLose={async (input) => {
|
|
191
|
+
await mutations.loseDeal(input);
|
|
192
|
+
}}
|
|
193
|
+
onMove={async (input) => {
|
|
194
|
+
await mutations.moveDeal(input);
|
|
195
|
+
refetch();
|
|
196
|
+
}}
|
|
197
|
+
isLoading={mutations.isLoading}
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
270
201
|
}
|
|
271
202
|
|
|
272
203
|
function MetricsTab({
|
|
273
|
-
|
|
204
|
+
stats,
|
|
274
205
|
}: {
|
|
275
|
-
|
|
206
|
+
stats: ReturnType<typeof useDealList>['stats'];
|
|
276
207
|
}) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
208
|
+
if (!stats) return null;
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<div className="space-y-6">
|
|
212
|
+
<div className="rounded-xl border border-border bg-card p-6">
|
|
213
|
+
<h3 className="mb-4 font-semibold text-lg">Pipeline Overview</h3>
|
|
214
|
+
<dl className="grid gap-4 sm:grid-cols-3">
|
|
215
|
+
<div>
|
|
216
|
+
<dt className="text-muted-foreground text-sm">Win Rate</dt>
|
|
217
|
+
<dd className="font-semibold text-2xl">
|
|
218
|
+
{stats.total > 0
|
|
219
|
+
? ((stats.wonCount / stats.total) * 100).toFixed(0)
|
|
220
|
+
: 0}
|
|
221
|
+
%
|
|
222
|
+
</dd>
|
|
223
|
+
</div>
|
|
224
|
+
<div>
|
|
225
|
+
<dt className="text-muted-foreground text-sm">Avg Deal Size</dt>
|
|
226
|
+
<dd className="font-semibold text-2xl">
|
|
227
|
+
{formatCurrency(
|
|
228
|
+
stats.total > 0 ? stats.totalValue / stats.total : 0
|
|
229
|
+
)}
|
|
230
|
+
</dd>
|
|
231
|
+
</div>
|
|
232
|
+
<div>
|
|
233
|
+
<dt className="text-muted-foreground text-sm">Conversion</dt>
|
|
234
|
+
<dd className="font-semibold text-2xl">
|
|
235
|
+
{stats.wonCount} / {stats.total}
|
|
236
|
+
</dd>
|
|
237
|
+
</div>
|
|
238
|
+
</dl>
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
);
|
|
311
242
|
}
|
package/src/ui/CrmDealCard.tsx
CHANGED
|
@@ -6,78 +6,78 @@
|
|
|
6
6
|
import type { Deal } from './hooks/useDealList';
|
|
7
7
|
|
|
8
8
|
interface CrmDealCardProps {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
deal: Deal;
|
|
10
|
+
onClick?: () => void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function formatCurrency(value: number, currency: string): string {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
return new Intl.NumberFormat('en-US', {
|
|
15
|
+
style: 'currency',
|
|
16
|
+
currency,
|
|
17
|
+
minimumFractionDigits: 0,
|
|
18
|
+
maximumFractionDigits: 0,
|
|
19
|
+
}).format(value);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function CrmDealCard({ deal, onClick }: CrmDealCardProps) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const daysUntilClose = deal.expectedCloseDate
|
|
24
|
+
? Math.ceil(
|
|
25
|
+
(deal.expectedCloseDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)
|
|
26
|
+
)
|
|
27
|
+
: null;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
onClick={onClick}
|
|
32
|
+
className="cursor-pointer rounded-lg border border-border bg-card p-3 shadow-sm transition-shadow hover:shadow-md"
|
|
33
|
+
role="button"
|
|
34
|
+
tabIndex={0}
|
|
35
|
+
onKeyDown={(e) => {
|
|
36
|
+
if (e.key === 'Enter' || e.key === ' ') onClick?.();
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
{/* Deal Name */}
|
|
40
|
+
<h4 className="font-medium leading-snug">{deal.name}</h4>
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
{/* Deal Value */}
|
|
43
|
+
<div className="mt-2 font-semibold text-lg text-primary">
|
|
44
|
+
{formatCurrency(deal.value, deal.currency)}
|
|
45
|
+
</div>
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
47
|
+
{/* Meta Info */}
|
|
48
|
+
<div className="mt-3 flex items-center justify-between text-muted-foreground text-xs">
|
|
49
|
+
{/* Expected Close */}
|
|
50
|
+
{daysUntilClose !== null && (
|
|
51
|
+
<span
|
|
52
|
+
className={
|
|
53
|
+
daysUntilClose < 0
|
|
54
|
+
? 'text-red-500'
|
|
55
|
+
: daysUntilClose <= 7
|
|
56
|
+
? 'text-yellow-600 dark:text-yellow-500'
|
|
57
|
+
: ''
|
|
58
|
+
}
|
|
59
|
+
>
|
|
60
|
+
{daysUntilClose < 0
|
|
61
|
+
? `${Math.abs(daysUntilClose)}d overdue`
|
|
62
|
+
: daysUntilClose === 0
|
|
63
|
+
? 'Due today'
|
|
64
|
+
: `${daysUntilClose}d left`}
|
|
65
|
+
</span>
|
|
66
|
+
)}
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
{/* Status Badge */}
|
|
69
|
+
<span
|
|
70
|
+
className={`rounded px-1.5 py-0.5 font-medium text-xs ${
|
|
71
|
+
deal.status === 'WON'
|
|
72
|
+
? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
|
|
73
|
+
: deal.status === 'LOST'
|
|
74
|
+
? 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400'
|
|
75
|
+
: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400'
|
|
76
|
+
}`}
|
|
77
|
+
>
|
|
78
|
+
{deal.status}
|
|
79
|
+
</span>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
83
|
}
|