@contractspec/example.crm-pipeline 3.7.5 → 3.7.7
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 +8 -8
- package/AGENTS.md +51 -33
- package/CHANGELOG.md +16 -0
- package/README.md +66 -148
- 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/index.js +293 -293
- package/dist/browser/ui/CrmDashboard.js +221 -221
- package/dist/browser/ui/CrmDealCard.js +5 -5
- package/dist/browser/ui/CrmPipelineBoard.js +13 -13
- package/dist/browser/ui/hooks/index.js +2 -2
- package/dist/browser/ui/hooks/useDealList.js +1 -1
- package/dist/browser/ui/hooks/useDealMutations.js +1 -1
- package/dist/browser/ui/index.js +290 -290
- 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 +116 -116
- package/dist/browser/ui/renderers/pipeline.renderer.js +97 -97
- package/dist/deal/index.d.ts +2 -2
- 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/index.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +293 -293
- 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/index.js +293 -293
- package/dist/node/ui/CrmDashboard.js +221 -221
- package/dist/node/ui/CrmDealCard.js +5 -5
- package/dist/node/ui/CrmPipelineBoard.js +13 -13
- package/dist/node/ui/hooks/index.js +2 -2
- package/dist/node/ui/hooks/useDealList.js +1 -1
- package/dist/node/ui/hooks/useDealMutations.js +1 -1
- package/dist/node/ui/index.js +290 -290
- 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 +116 -116
- package/dist/node/ui/renderers/pipeline.renderer.js +97 -97
- package/dist/operations/index.d.ts +1 -1
- package/dist/ui/CrmDashboard.js +221 -221
- 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 +2 -2
- package/dist/ui/hooks/useDealList.js +1 -1
- 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 +290 -290
- 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 +116 -116
- package/dist/ui/renderers/pipeline.renderer.d.ts +1 -1
- package/dist/ui/renderers/pipeline.renderer.js +97 -97
- package/package.json +14 -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 +43 -43
- 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 +358 -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 +256 -256
- 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 +85 -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/tsconfig.json +7 -8
- package/tsdown.config.js +7 -3
|
@@ -7,167 +7,168 @@
|
|
|
7
7
|
* - WinDealContract
|
|
8
8
|
* - LoseDealContract
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
import { useTemplateRuntime } from '@contractspec/lib.example-shared-ui';
|
|
12
|
+
import { useCallback, useState } from 'react';
|
|
12
13
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
CreateDealInput,
|
|
15
|
+
CrmHandlers,
|
|
16
|
+
Deal,
|
|
17
|
+
LoseDealInput,
|
|
18
|
+
MoveDealInput,
|
|
19
|
+
WinDealInput,
|
|
19
20
|
} from '../../handlers/crm.handlers';
|
|
20
21
|
|
|
21
22
|
export interface MutationState<T> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
loading: boolean;
|
|
24
|
+
error: Error | null;
|
|
25
|
+
data: T | null;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export interface UseDealMutationsOptions {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
onSuccess?: () => void;
|
|
30
|
+
onError?: (error: Error) => void;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export function useDealMutations(options: UseDealMutationsOptions = {}) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
34
|
+
const { handlers, projectId } = useTemplateRuntime<{ crm: CrmHandlers }>();
|
|
35
|
+
const { crm } = handlers;
|
|
36
|
+
|
|
37
|
+
const [createState, setCreateState] = useState<MutationState<Deal>>({
|
|
38
|
+
loading: false,
|
|
39
|
+
error: null,
|
|
40
|
+
data: null,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const [moveState, setMoveState] = useState<MutationState<Deal>>({
|
|
44
|
+
loading: false,
|
|
45
|
+
error: null,
|
|
46
|
+
data: null,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const [winState, setWinState] = useState<MutationState<Deal>>({
|
|
50
|
+
loading: false,
|
|
51
|
+
error: null,
|
|
52
|
+
data: null,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const [loseState, setLoseState] = useState<MutationState<Deal>>({
|
|
56
|
+
loading: false,
|
|
57
|
+
error: null,
|
|
58
|
+
data: null,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a new deal
|
|
63
|
+
*/
|
|
64
|
+
const createDeal = useCallback(
|
|
65
|
+
async (input: CreateDealInput): Promise<Deal | null> => {
|
|
66
|
+
setCreateState({ loading: true, error: null, data: null });
|
|
67
|
+
try {
|
|
68
|
+
const result = await crm.createDeal(input, {
|
|
69
|
+
projectId,
|
|
70
|
+
ownerId: 'user-1', // Demo user
|
|
71
|
+
});
|
|
72
|
+
setCreateState({ loading: false, error: null, data: result });
|
|
73
|
+
options.onSuccess?.();
|
|
74
|
+
return result;
|
|
75
|
+
} catch (err) {
|
|
76
|
+
const error =
|
|
77
|
+
err instanceof Error ? err : new Error('Failed to create deal');
|
|
78
|
+
setCreateState({ loading: false, error, data: null });
|
|
79
|
+
options.onError?.(error);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
[crm, projectId, options]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Move a deal to a different stage
|
|
88
|
+
*/
|
|
89
|
+
const moveDeal = useCallback(
|
|
90
|
+
async (input: MoveDealInput): Promise<Deal | null> => {
|
|
91
|
+
setMoveState({ loading: true, error: null, data: null });
|
|
92
|
+
try {
|
|
93
|
+
const result = await crm.moveDeal(input);
|
|
94
|
+
setMoveState({ loading: false, error: null, data: result });
|
|
95
|
+
options.onSuccess?.();
|
|
96
|
+
return result;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const error =
|
|
99
|
+
err instanceof Error ? err : new Error('Failed to move deal');
|
|
100
|
+
setMoveState({ loading: false, error, data: null });
|
|
101
|
+
options.onError?.(error);
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
[crm, options]
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Mark a deal as won
|
|
110
|
+
*/
|
|
111
|
+
const winDeal = useCallback(
|
|
112
|
+
async (input: WinDealInput): Promise<Deal | null> => {
|
|
113
|
+
setWinState({ loading: true, error: null, data: null });
|
|
114
|
+
try {
|
|
115
|
+
const result = await crm.winDeal(input);
|
|
116
|
+
setWinState({ loading: false, error: null, data: result });
|
|
117
|
+
options.onSuccess?.();
|
|
118
|
+
return result;
|
|
119
|
+
} catch (err) {
|
|
120
|
+
const error =
|
|
121
|
+
err instanceof Error ? err : new Error('Failed to mark deal as won');
|
|
122
|
+
setWinState({ loading: false, error, data: null });
|
|
123
|
+
options.onError?.(error);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
[crm, options]
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Mark a deal as lost
|
|
132
|
+
*/
|
|
133
|
+
const loseDeal = useCallback(
|
|
134
|
+
async (input: LoseDealInput): Promise<Deal | null> => {
|
|
135
|
+
setLoseState({ loading: true, error: null, data: null });
|
|
136
|
+
try {
|
|
137
|
+
const result = await crm.loseDeal(input);
|
|
138
|
+
setLoseState({ loading: false, error: null, data: result });
|
|
139
|
+
options.onSuccess?.();
|
|
140
|
+
return result;
|
|
141
|
+
} catch (err) {
|
|
142
|
+
const error =
|
|
143
|
+
err instanceof Error ? err : new Error('Failed to mark deal as lost');
|
|
144
|
+
setLoseState({ loading: false, error, data: null });
|
|
145
|
+
options.onError?.(error);
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
[crm, options]
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
// Mutations
|
|
154
|
+
createDeal,
|
|
155
|
+
moveDeal,
|
|
156
|
+
winDeal,
|
|
157
|
+
loseDeal,
|
|
158
|
+
|
|
159
|
+
// State
|
|
160
|
+
createState,
|
|
161
|
+
moveState,
|
|
162
|
+
winState,
|
|
163
|
+
loseState,
|
|
164
|
+
|
|
165
|
+
// Convenience
|
|
166
|
+
isLoading:
|
|
167
|
+
createState.loading ||
|
|
168
|
+
moveState.loading ||
|
|
169
|
+
winState.loading ||
|
|
170
|
+
loseState.loading,
|
|
171
|
+
};
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
// Note: Types are re-exported from the handlers package
|
package/src/ui/index.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
// Main dashboard
|
|
2
2
|
export * from './CrmDashboard';
|
|
3
|
-
|
|
3
|
+
export * from './CrmDealCard';
|
|
4
4
|
// Components
|
|
5
5
|
export * from './CrmPipelineBoard';
|
|
6
|
-
export * from './CrmDealCard';
|
|
7
|
-
|
|
8
|
-
// Modals
|
|
9
|
-
export * from './modals';
|
|
10
|
-
|
|
11
6
|
// Hooks
|
|
12
7
|
export * from './hooks';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export * from './renderers';
|
|
16
|
-
|
|
8
|
+
// Modals
|
|
9
|
+
export * from './modals';
|
|
17
10
|
// Overlays
|
|
18
11
|
export * from './overlays';
|
|
12
|
+
// Renderers
|
|
13
|
+
export * from './renderers';
|