@contractspec/example.saas-boilerplate 1.57.0 → 1.58.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 +160 -180
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +20 -0
- package/dist/billing/billing.entity.d.ts +40 -45
- package/dist/billing/billing.entity.d.ts.map +1 -1
- package/dist/billing/billing.entity.js +110 -118
- package/dist/billing/billing.enum.d.ts +2 -7
- package/dist/billing/billing.enum.d.ts.map +1 -1
- package/dist/billing/billing.enum.js +17 -24
- package/dist/billing/billing.event.d.ts +67 -73
- package/dist/billing/billing.event.d.ts.map +1 -1
- package/dist/billing/billing.event.js +84 -146
- package/dist/billing/billing.handler.d.ts +59 -62
- package/dist/billing/billing.handler.d.ts.map +1 -1
- package/dist/billing/billing.handler.js +140 -49
- package/dist/billing/billing.operations.d.ts +138 -144
- package/dist/billing/billing.operations.d.ts.map +1 -1
- package/dist/billing/billing.operations.js +273 -175
- package/dist/billing/billing.presentation.d.ts +2 -7
- package/dist/billing/billing.presentation.d.ts.map +1 -1
- package/dist/billing/billing.presentation.js +51 -57
- package/dist/billing/billing.schema.d.ts +159 -164
- package/dist/billing/billing.schema.d.ts.map +1 -1
- package/dist/billing/billing.schema.js +112 -204
- package/dist/billing/index.d.ts +11 -8
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +689 -9
- package/dist/browser/billing/billing.entity.js +113 -0
- package/dist/browser/billing/billing.enum.js +19 -0
- package/dist/browser/billing/billing.event.js +90 -0
- package/dist/browser/billing/billing.handler.js +148 -0
- package/dist/browser/billing/billing.operations.js +278 -0
- package/dist/browser/billing/billing.presentation.js +52 -0
- package/dist/browser/billing/billing.schema.js +121 -0
- package/dist/browser/billing/index.js +688 -0
- package/dist/browser/dashboard/dashboard.presentation.js +52 -0
- package/dist/browser/dashboard/index.js +52 -0
- package/dist/browser/docs/index.js +93 -0
- package/dist/browser/docs/saas-boilerplate.docblock.js +93 -0
- package/dist/browser/example.js +39 -0
- package/dist/browser/handlers/index.js +358 -0
- package/dist/browser/handlers/saas.handlers.js +134 -0
- package/dist/browser/index.js +3340 -0
- package/dist/browser/presentations/index.js +290 -0
- package/dist/browser/project/index.js +790 -0
- package/dist/browser/project/project.entity.js +77 -0
- package/dist/browser/project/project.enum.js +18 -0
- package/dist/browser/project/project.event.js +103 -0
- package/dist/browser/project/project.handler.js +178 -0
- package/dist/browser/project/project.operations.js +372 -0
- package/dist/browser/project/project.presentation.js +177 -0
- package/dist/browser/project/project.schema.js +134 -0
- package/dist/browser/saas-boilerplate.feature.js +88 -0
- package/dist/browser/seeders/index.js +20 -0
- package/dist/browser/settings/index.js +75 -0
- package/dist/browser/settings/settings.entity.js +74 -0
- package/dist/browser/settings/settings.enum.js +11 -0
- package/dist/browser/shared/mock-data.js +104 -0
- package/dist/browser/shared/overlay-types.js +0 -0
- package/dist/browser/tests/operations.test-spec.js +112 -0
- package/dist/browser/ui/SaasDashboard.js +988 -0
- package/dist/browser/ui/SaasProjectList.js +162 -0
- package/dist/browser/ui/SaasSettingsPanel.js +145 -0
- package/dist/browser/ui/hooks/index.js +159 -0
- package/dist/browser/ui/hooks/useProjectList.js +66 -0
- package/dist/browser/ui/hooks/useProjectMutations.js +91 -0
- package/dist/browser/ui/index.js +1808 -0
- package/dist/browser/ui/modals/CreateProjectModal.js +153 -0
- package/dist/browser/ui/modals/ProjectActionsModal.js +335 -0
- package/dist/browser/ui/modals/index.js +487 -0
- package/dist/browser/ui/overlays/demo-overlays.js +61 -0
- package/dist/browser/ui/overlays/index.js +61 -0
- package/dist/browser/ui/renderers/index.js +675 -0
- package/dist/browser/ui/renderers/project-list.markdown.js +499 -0
- package/dist/browser/ui/renderers/project-list.renderer.js +177 -0
- package/dist/dashboard/dashboard.presentation.d.ts +2 -7
- package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
- package/dist/dashboard/dashboard.presentation.js +51 -53
- package/dist/dashboard/index.d.ts +5 -2
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +53 -3
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +94 -1
- package/dist/docs/saas-boilerplate.docblock.d.ts +2 -1
- package/dist/docs/saas-boilerplate.docblock.d.ts.map +1 -0
- package/dist/docs/saas-boilerplate.docblock.js +45 -51
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +38 -50
- package/dist/handlers/index.d.ts +7 -4
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +358 -4
- package/dist/handlers/saas.handlers.d.ts +60 -59
- package/dist/handlers/saas.handlers.d.ts.map +1 -1
- package/dist/handlers/saas.handlers.js +127 -140
- package/dist/index.d.ts +15 -45
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3335 -75
- package/dist/node/billing/billing.entity.js +113 -0
- package/dist/node/billing/billing.enum.js +19 -0
- package/dist/node/billing/billing.event.js +90 -0
- package/dist/node/billing/billing.handler.js +148 -0
- package/dist/node/billing/billing.operations.js +278 -0
- package/dist/node/billing/billing.presentation.js +52 -0
- package/dist/node/billing/billing.schema.js +121 -0
- package/dist/node/billing/index.js +688 -0
- package/dist/node/dashboard/dashboard.presentation.js +52 -0
- package/dist/node/dashboard/index.js +52 -0
- package/dist/node/docs/index.js +93 -0
- package/dist/node/docs/saas-boilerplate.docblock.js +93 -0
- package/dist/node/example.js +39 -0
- package/dist/node/handlers/index.js +358 -0
- package/dist/node/handlers/saas.handlers.js +134 -0
- package/dist/node/index.js +3340 -0
- package/dist/node/presentations/index.js +290 -0
- package/dist/node/project/index.js +790 -0
- package/dist/node/project/project.entity.js +77 -0
- package/dist/node/project/project.enum.js +18 -0
- package/dist/node/project/project.event.js +103 -0
- package/dist/node/project/project.handler.js +178 -0
- package/dist/node/project/project.operations.js +372 -0
- package/dist/node/project/project.presentation.js +177 -0
- package/dist/node/project/project.schema.js +134 -0
- package/dist/node/saas-boilerplate.feature.js +88 -0
- package/dist/node/seeders/index.js +20 -0
- package/dist/node/settings/index.js +75 -0
- package/dist/node/settings/settings.entity.js +74 -0
- package/dist/node/settings/settings.enum.js +11 -0
- package/dist/node/shared/mock-data.js +104 -0
- package/dist/node/shared/overlay-types.js +0 -0
- package/dist/node/tests/operations.test-spec.js +112 -0
- package/dist/node/ui/SaasDashboard.js +988 -0
- package/dist/node/ui/SaasProjectList.js +162 -0
- package/dist/node/ui/SaasSettingsPanel.js +145 -0
- package/dist/node/ui/hooks/index.js +159 -0
- package/dist/node/ui/hooks/useProjectList.js +66 -0
- package/dist/node/ui/hooks/useProjectMutations.js +91 -0
- package/dist/node/ui/index.js +1808 -0
- package/dist/node/ui/modals/CreateProjectModal.js +153 -0
- package/dist/node/ui/modals/ProjectActionsModal.js +335 -0
- package/dist/node/ui/modals/index.js +487 -0
- package/dist/node/ui/overlays/demo-overlays.js +61 -0
- package/dist/node/ui/overlays/index.js +61 -0
- package/dist/node/ui/renderers/index.js +675 -0
- package/dist/node/ui/renderers/project-list.markdown.js +499 -0
- package/dist/node/ui/renderers/project-list.renderer.js +177 -0
- package/dist/presentations/index.d.ts +13 -14
- package/dist/presentations/index.d.ts.map +1 -1
- package/dist/presentations/index.js +289 -15
- package/dist/project/index.d.ts +11 -8
- package/dist/project/index.d.ts.map +1 -0
- package/dist/project/index.js +791 -9
- package/dist/project/project.entity.d.ts +23 -28
- package/dist/project/project.entity.d.ts.map +1 -1
- package/dist/project/project.entity.js +75 -82
- package/dist/project/project.enum.d.ts +2 -7
- package/dist/project/project.enum.d.ts.map +1 -1
- package/dist/project/project.enum.js +16 -23
- package/dist/project/project.event.d.ts +69 -75
- package/dist/project/project.event.d.ts.map +1 -1
- package/dist/project/project.event.js +95 -156
- package/dist/project/project.handler.d.ts +44 -47
- package/dist/project/project.handler.d.ts.map +1 -1
- package/dist/project/project.handler.js +168 -71
- package/dist/project/project.operations.d.ts +341 -347
- package/dist/project/project.operations.d.ts.map +1 -1
- package/dist/project/project.operations.js +366 -253
- package/dist/project/project.presentation.d.ts +2 -7
- package/dist/project/project.presentation.d.ts.map +1 -1
- package/dist/project/project.presentation.js +174 -61
- package/dist/project/project.schema.d.ts +191 -196
- package/dist/project/project.schema.d.ts.map +1 -1
- package/dist/project/project.schema.js +125 -205
- package/dist/saas-boilerplate.feature.d.ts +1 -6
- package/dist/saas-boilerplate.feature.d.ts.map +1 -1
- package/dist/saas-boilerplate.feature.js +87 -206
- package/dist/seeders/index.d.ts +4 -8
- package/dist/seeders/index.d.ts.map +1 -1
- package/dist/seeders/index.js +18 -16
- package/dist/settings/index.d.ts +6 -3
- package/dist/settings/index.d.ts.map +1 -0
- package/dist/settings/index.js +75 -3
- package/dist/settings/settings.entity.d.ts +23 -28
- package/dist/settings/settings.entity.d.ts.map +1 -1
- package/dist/settings/settings.entity.js +72 -75
- package/dist/settings/settings.enum.d.ts +1 -6
- package/dist/settings/settings.enum.d.ts.map +1 -1
- package/dist/settings/settings.enum.js +10 -19
- package/dist/shared/mock-data.d.ts +74 -77
- package/dist/shared/mock-data.d.ts.map +1 -1
- package/dist/shared/mock-data.js +102 -135
- 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/tests/operations.test-spec.d.ts +4 -9
- package/dist/tests/operations.test-spec.d.ts.map +1 -1
- package/dist/tests/operations.test-spec.js +108 -118
- package/dist/ui/SaasDashboard.d.ts +1 -6
- package/dist/ui/SaasDashboard.d.ts.map +1 -1
- package/dist/ui/SaasDashboard.js +977 -286
- package/dist/ui/SaasProjectList.d.ts +4 -11
- package/dist/ui/SaasProjectList.d.ts.map +1 -1
- package/dist/ui/SaasProjectList.js +159 -72
- package/dist/ui/SaasSettingsPanel.d.ts +1 -6
- package/dist/ui/SaasSettingsPanel.d.ts.map +1 -1
- package/dist/ui/SaasSettingsPanel.js +142 -134
- 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 +158 -4
- package/dist/ui/hooks/useProjectList.d.ts +26 -30
- package/dist/ui/hooks/useProjectList.d.ts.map +1 -1
- package/dist/ui/hooks/useProjectList.js +63 -71
- package/dist/ui/hooks/useProjectMutations.d.ts +20 -24
- package/dist/ui/hooks/useProjectMutations.d.ts.map +1 -1
- package/dist/ui/hooks/useProjectMutations.js +88 -142
- package/dist/ui/index.d.ts +8 -14
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +1809 -15
- package/dist/ui/modals/CreateProjectModal.d.ts +10 -19
- package/dist/ui/modals/CreateProjectModal.d.ts.map +1 -1
- package/dist/ui/modals/CreateProjectModal.js +150 -135
- package/dist/ui/modals/ProjectActionsModal.d.ts +20 -33
- package/dist/ui/modals/ProjectActionsModal.d.ts.map +1 -1
- package/dist/ui/modals/ProjectActionsModal.js +333 -289
- 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 +487 -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 +60 -68
- 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 +62 -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 +675 -3
- package/dist/ui/renderers/project-list.markdown.d.ts +15 -14
- package/dist/ui/renderers/project-list.markdown.d.ts.map +1 -1
- package/dist/ui/renderers/project-list.markdown.js +496 -146
- package/dist/ui/renderers/project-list.renderer.d.ts +6 -7
- package/dist/ui/renderers/project-list.renderer.d.ts.map +1 -1
- package/dist/ui/renderers/project-list.renderer.js +176 -15
- package/package.json +508 -98
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -180
- package/dist/billing/billing.entity.js.map +0 -1
- package/dist/billing/billing.enum.js.map +0 -1
- package/dist/billing/billing.event.js.map +0 -1
- package/dist/billing/billing.handler.js.map +0 -1
- package/dist/billing/billing.operations.js.map +0 -1
- package/dist/billing/billing.presentation.js.map +0 -1
- package/dist/billing/billing.schema.js.map +0 -1
- package/dist/dashboard/dashboard.presentation.js.map +0 -1
- package/dist/docs/saas-boilerplate.docblock.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/saas.handlers.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/presentations/index.js.map +0 -1
- package/dist/project/project.entity.js.map +0 -1
- package/dist/project/project.enum.js.map +0 -1
- package/dist/project/project.event.js.map +0 -1
- package/dist/project/project.handler.js.map +0 -1
- package/dist/project/project.operations.js.map +0 -1
- package/dist/project/project.presentation.js.map +0 -1
- package/dist/project/project.schema.js.map +0 -1
- package/dist/saas-boilerplate.feature.js.map +0 -1
- package/dist/seeders/index.js.map +0 -1
- package/dist/settings/settings.entity.js.map +0 -1
- package/dist/settings/settings.enum.js.map +0 -1
- package/dist/shared/mock-data.js.map +0 -1
- package/dist/tests/operations.test-spec.js.map +0 -1
- package/dist/ui/SaasDashboard.js.map +0 -1
- package/dist/ui/SaasProjectList.js.map +0 -1
- package/dist/ui/SaasSettingsPanel.js.map +0 -1
- package/dist/ui/hooks/useProjectList.js.map +0 -1
- package/dist/ui/hooks/useProjectMutations.js.map +0 -1
- package/dist/ui/modals/CreateProjectModal.js.map +0 -1
- package/dist/ui/modals/ProjectActionsModal.js.map +0 -1
- package/dist/ui/overlays/demo-overlays.js.map +0 -1
- package/dist/ui/renderers/project-list.markdown.js.map +0 -1
- package/dist/ui/renderers/project-list.renderer.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/dist/ui/hooks/index.js
CHANGED
|
@@ -1,6 +1,160 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/ui/hooks/useProjectList.ts
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
5
|
+
function useProjectList(options = {}) {
|
|
6
|
+
const { handlers, projectId } = useTemplateRuntime();
|
|
7
|
+
const { saas } = handlers;
|
|
8
|
+
const [data, setData] = useState(null);
|
|
9
|
+
const [subscription, setSubscription] = useState(null);
|
|
10
|
+
const [loading, setLoading] = useState(true);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const [page, setPage] = useState(1);
|
|
13
|
+
const fetchData = useCallback(async () => {
|
|
14
|
+
setLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
try {
|
|
17
|
+
const [projectsResult, subscriptionResult] = await Promise.all([
|
|
18
|
+
saas.listProjects({
|
|
19
|
+
projectId,
|
|
20
|
+
status: options.status === "all" ? undefined : options.status,
|
|
21
|
+
search: options.search,
|
|
22
|
+
limit: options.limit ?? 20,
|
|
23
|
+
offset: (page - 1) * (options.limit ?? 20)
|
|
24
|
+
}),
|
|
25
|
+
saas.getSubscription({ projectId })
|
|
26
|
+
]);
|
|
27
|
+
setData({
|
|
28
|
+
items: projectsResult.items,
|
|
29
|
+
total: projectsResult.total
|
|
30
|
+
});
|
|
31
|
+
setSubscription(subscriptionResult);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
34
|
+
} finally {
|
|
35
|
+
setLoading(false);
|
|
36
|
+
}
|
|
37
|
+
}, [saas, projectId, options.status, options.search, options.limit, page]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
fetchData();
|
|
40
|
+
}, [fetchData]);
|
|
41
|
+
const stats = useMemo(() => {
|
|
42
|
+
if (!data)
|
|
43
|
+
return null;
|
|
44
|
+
const items = data.items;
|
|
45
|
+
return {
|
|
46
|
+
total: data.total,
|
|
47
|
+
activeCount: items.filter((p) => p.status === "ACTIVE").length,
|
|
48
|
+
draftCount: items.filter((p) => p.status === "DRAFT").length,
|
|
49
|
+
projectLimit: 10,
|
|
50
|
+
usagePercent: Math.min(data.total / 10 * 100, 100)
|
|
51
|
+
};
|
|
52
|
+
}, [data]);
|
|
53
|
+
return {
|
|
54
|
+
data,
|
|
55
|
+
subscription,
|
|
56
|
+
loading,
|
|
57
|
+
error,
|
|
58
|
+
stats,
|
|
59
|
+
page,
|
|
60
|
+
refetch: fetchData,
|
|
61
|
+
nextPage: () => setPage((p) => p + 1),
|
|
62
|
+
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
2
65
|
|
|
3
|
-
|
|
4
|
-
import {
|
|
66
|
+
// src/ui/hooks/useProjectMutations.ts
|
|
67
|
+
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
68
|
+
import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
|
|
69
|
+
function useProjectMutations(options = {}) {
|
|
70
|
+
const { handlers, projectId } = useTemplateRuntime2();
|
|
71
|
+
const { saas } = handlers;
|
|
72
|
+
const [createState, setCreateState] = useState2({
|
|
73
|
+
loading: false,
|
|
74
|
+
error: null,
|
|
75
|
+
data: null
|
|
76
|
+
});
|
|
77
|
+
const [updateState, setUpdateState] = useState2({
|
|
78
|
+
loading: false,
|
|
79
|
+
error: null,
|
|
80
|
+
data: null
|
|
81
|
+
});
|
|
82
|
+
const [deleteState, setDeleteState] = useState2({
|
|
83
|
+
loading: false,
|
|
84
|
+
error: null,
|
|
85
|
+
data: null
|
|
86
|
+
});
|
|
87
|
+
const createProject = useCallback2(async (input) => {
|
|
88
|
+
setCreateState({ loading: true, error: null, data: null });
|
|
89
|
+
try {
|
|
90
|
+
const result = await saas.createProject(input, {
|
|
91
|
+
projectId,
|
|
92
|
+
organizationId: "demo-org"
|
|
93
|
+
});
|
|
94
|
+
setCreateState({ loading: false, error: null, data: result });
|
|
95
|
+
options.onSuccess?.();
|
|
96
|
+
return result;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const error = err instanceof Error ? err : new Error("Failed to create project");
|
|
99
|
+
setCreateState({ loading: false, error, data: null });
|
|
100
|
+
options.onError?.(error);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}, [saas, projectId, options]);
|
|
104
|
+
const updateProject = useCallback2(async (input) => {
|
|
105
|
+
setUpdateState({ loading: true, error: null, data: null });
|
|
106
|
+
try {
|
|
107
|
+
const result = await saas.updateProject(input);
|
|
108
|
+
setUpdateState({ loading: false, error: null, data: result });
|
|
109
|
+
options.onSuccess?.();
|
|
110
|
+
return result;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
const error = err instanceof Error ? err : new Error("Failed to update project");
|
|
113
|
+
setUpdateState({ loading: false, error, data: null });
|
|
114
|
+
options.onError?.(error);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}, [saas, options]);
|
|
118
|
+
const deleteProject = useCallback2(async (id) => {
|
|
119
|
+
setDeleteState({ loading: true, error: null, data: null });
|
|
120
|
+
try {
|
|
121
|
+
await saas.deleteProject(id);
|
|
122
|
+
setDeleteState({
|
|
123
|
+
loading: false,
|
|
124
|
+
error: null,
|
|
125
|
+
data: { success: true }
|
|
126
|
+
});
|
|
127
|
+
options.onSuccess?.();
|
|
128
|
+
return true;
|
|
129
|
+
} catch (err) {
|
|
130
|
+
const error = err instanceof Error ? err : new Error("Failed to delete project");
|
|
131
|
+
setDeleteState({ loading: false, error, data: null });
|
|
132
|
+
options.onError?.(error);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}, [saas, options]);
|
|
136
|
+
const archiveProject = useCallback2(async (id) => {
|
|
137
|
+
return updateProject({ id, status: "ARCHIVED" });
|
|
138
|
+
}, [updateProject]);
|
|
139
|
+
const activateProject = useCallback2(async (id) => {
|
|
140
|
+
return updateProject({ id, status: "ACTIVE" });
|
|
141
|
+
}, [updateProject]);
|
|
142
|
+
return {
|
|
143
|
+
createProject,
|
|
144
|
+
updateProject,
|
|
145
|
+
deleteProject,
|
|
146
|
+
archiveProject,
|
|
147
|
+
activateProject,
|
|
148
|
+
createState,
|
|
149
|
+
updateState,
|
|
150
|
+
deleteState,
|
|
151
|
+
isLoading: createState.loading || updateState.loading || deleteState.loading
|
|
152
|
+
};
|
|
153
|
+
}
|
|
5
154
|
|
|
6
|
-
|
|
155
|
+
// src/ui/hooks/index.ts
|
|
156
|
+
"use client";
|
|
157
|
+
export {
|
|
158
|
+
useProjectMutations,
|
|
159
|
+
useProjectList
|
|
160
|
+
};
|
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
import { Project as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
items: Project[];
|
|
8
|
-
total: number;
|
|
1
|
+
import type { Project as RuntimeProject, Subscription as RuntimeSubscription } from '../../handlers/saas.handlers';
|
|
2
|
+
export type Project = RuntimeProject;
|
|
3
|
+
export type Subscription = RuntimeSubscription;
|
|
4
|
+
export interface ListProjectsOutput {
|
|
5
|
+
items: Project[];
|
|
6
|
+
total: number;
|
|
9
7
|
}
|
|
10
|
-
interface UseProjectListOptions {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export interface UseProjectListOptions {
|
|
9
|
+
status?: 'DRAFT' | 'ACTIVE' | 'ARCHIVED' | 'all';
|
|
10
|
+
search?: string;
|
|
11
|
+
limit?: number;
|
|
14
12
|
}
|
|
15
|
-
declare function useProjectList(options?: UseProjectListOptions): {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
export declare function useProjectList(options?: UseProjectListOptions): {
|
|
14
|
+
data: ListProjectsOutput | null;
|
|
15
|
+
subscription: RuntimeSubscription | null;
|
|
16
|
+
loading: boolean;
|
|
17
|
+
error: Error | null;
|
|
18
|
+
stats: {
|
|
19
|
+
total: number;
|
|
20
|
+
activeCount: number;
|
|
21
|
+
draftCount: number;
|
|
22
|
+
projectLimit: number;
|
|
23
|
+
usagePercent: number;
|
|
24
|
+
} | null;
|
|
25
|
+
page: number;
|
|
26
|
+
refetch: () => Promise<void>;
|
|
27
|
+
nextPage: () => void;
|
|
28
|
+
prevPage: () => false | void;
|
|
31
29
|
};
|
|
32
|
-
//#endregion
|
|
33
|
-
export { ListProjectsOutput, Project, Subscription, UseProjectListOptions, useProjectList };
|
|
34
30
|
//# sourceMappingURL=useProjectList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProjectList.d.ts","
|
|
1
|
+
{"version":3,"file":"useProjectList.d.ts","sourceRoot":"","sources":["../../../src/ui/hooks/useProjectList.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,OAAO,IAAI,cAAc,EACzB,YAAY,IAAI,mBAAmB,EAEpC,MAAM,8BAA8B,CAAC;AAGtC,MAAM,MAAM,OAAO,GAAG,cAAc,CAAC;AACrC,MAAM,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,KAAK,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B;;;;;;;;;;;;;;;;EAkEjE"}
|
|
@@ -1,75 +1,67 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/ui/hooks/useProjectList.ts
|
|
1
3
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
4
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
3
|
-
|
|
4
|
-
//#region src/ui/hooks/useProjectList.ts
|
|
5
|
-
/**
|
|
6
|
-
* Hook for fetching and managing project list data
|
|
7
|
-
*
|
|
8
|
-
* Uses runtime-local database-backed handlers.
|
|
9
|
-
*/
|
|
10
5
|
function useProjectList(options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
70
|
-
};
|
|
6
|
+
const { handlers, projectId } = useTemplateRuntime();
|
|
7
|
+
const { saas } = handlers;
|
|
8
|
+
const [data, setData] = useState(null);
|
|
9
|
+
const [subscription, setSubscription] = useState(null);
|
|
10
|
+
const [loading, setLoading] = useState(true);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const [page, setPage] = useState(1);
|
|
13
|
+
const fetchData = useCallback(async () => {
|
|
14
|
+
setLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
try {
|
|
17
|
+
const [projectsResult, subscriptionResult] = await Promise.all([
|
|
18
|
+
saas.listProjects({
|
|
19
|
+
projectId,
|
|
20
|
+
status: options.status === "all" ? undefined : options.status,
|
|
21
|
+
search: options.search,
|
|
22
|
+
limit: options.limit ?? 20,
|
|
23
|
+
offset: (page - 1) * (options.limit ?? 20)
|
|
24
|
+
}),
|
|
25
|
+
saas.getSubscription({ projectId })
|
|
26
|
+
]);
|
|
27
|
+
setData({
|
|
28
|
+
items: projectsResult.items,
|
|
29
|
+
total: projectsResult.total
|
|
30
|
+
});
|
|
31
|
+
setSubscription(subscriptionResult);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
34
|
+
} finally {
|
|
35
|
+
setLoading(false);
|
|
36
|
+
}
|
|
37
|
+
}, [saas, projectId, options.status, options.search, options.limit, page]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
fetchData();
|
|
40
|
+
}, [fetchData]);
|
|
41
|
+
const stats = useMemo(() => {
|
|
42
|
+
if (!data)
|
|
43
|
+
return null;
|
|
44
|
+
const items = data.items;
|
|
45
|
+
return {
|
|
46
|
+
total: data.total,
|
|
47
|
+
activeCount: items.filter((p) => p.status === "ACTIVE").length,
|
|
48
|
+
draftCount: items.filter((p) => p.status === "DRAFT").length,
|
|
49
|
+
projectLimit: 10,
|
|
50
|
+
usagePercent: Math.min(data.total / 10 * 100, 100)
|
|
51
|
+
};
|
|
52
|
+
}, [data]);
|
|
53
|
+
return {
|
|
54
|
+
data,
|
|
55
|
+
subscription,
|
|
56
|
+
loading,
|
|
57
|
+
error,
|
|
58
|
+
stats,
|
|
59
|
+
page,
|
|
60
|
+
refetch: fetchData,
|
|
61
|
+
nextPage: () => setPage((p) => p + 1),
|
|
62
|
+
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
63
|
+
};
|
|
71
64
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//# sourceMappingURL=useProjectList.js.map
|
|
65
|
+
export {
|
|
66
|
+
useProjectList
|
|
67
|
+
};
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
import { CreateProjectInput, Project, UpdateProjectInput } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
error: Error | null;
|
|
7
|
-
data: T | null;
|
|
1
|
+
import type { CreateProjectInput, Project, UpdateProjectInput } from '../../handlers/saas.handlers';
|
|
2
|
+
export interface MutationState<T> {
|
|
3
|
+
loading: boolean;
|
|
4
|
+
error: Error | null;
|
|
5
|
+
data: T | null;
|
|
8
6
|
}
|
|
9
|
-
interface UseProjectMutationsOptions {
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export interface UseProjectMutationsOptions {
|
|
8
|
+
onSuccess?: () => void;
|
|
9
|
+
onError?: (error: Error) => void;
|
|
12
10
|
}
|
|
13
|
-
declare function useProjectMutations(options?: UseProjectMutationsOptions): {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
export declare function useProjectMutations(options?: UseProjectMutationsOptions): {
|
|
12
|
+
createProject: (input: CreateProjectInput) => Promise<Project | null>;
|
|
13
|
+
updateProject: (input: UpdateProjectInput) => Promise<Project | null>;
|
|
14
|
+
deleteProject: (id: string) => Promise<boolean>;
|
|
15
|
+
archiveProject: (id: string) => Promise<Project | null>;
|
|
16
|
+
activateProject: (id: string) => Promise<Project | null>;
|
|
17
|
+
createState: MutationState<Project>;
|
|
18
|
+
updateState: MutationState<Project>;
|
|
19
|
+
deleteState: MutationState<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
isLoading: boolean;
|
|
25
23
|
};
|
|
26
|
-
//#endregion
|
|
27
|
-
export { MutationState, UseProjectMutationsOptions, useProjectMutations };
|
|
28
24
|
//# sourceMappingURL=useProjectMutations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProjectMutations.d.ts","
|
|
1
|
+
{"version":3,"file":"useProjectMutations.d.ts","sourceRoot":"","sources":["../../../src/ui/hooks/useProjectMutations.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,kBAAkB,EAClB,OAAO,EACP,kBAAkB,EAEnB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B;2BA4B1D,kBAAkB,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;2BAyB5C,kBAAkB,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;wBAsB/C,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;yBA0BzB,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;0BAUhC,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;;;;iBA9FlB,OAAO;;;EAqHnC"}
|
|
@@ -1,146 +1,92 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/ui/hooks/useProjectMutations.ts
|
|
1
3
|
import { useCallback, useState } from "react";
|
|
2
4
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
3
|
-
|
|
4
|
-
//#region src/ui/hooks/useProjectMutations.ts
|
|
5
|
-
/**
|
|
6
|
-
* Hook for SaaS project mutations (commands)
|
|
7
|
-
*
|
|
8
|
-
* Uses runtime-local database-backed handlers for:
|
|
9
|
-
* - CreateProjectContract
|
|
10
|
-
* - UpdateProjectContract
|
|
11
|
-
* - DeleteProjectContract
|
|
12
|
-
*/
|
|
13
5
|
function useProjectMutations(options = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
createProject,
|
|
98
|
-
updateProject,
|
|
99
|
-
deleteProject: useCallback(async (id) => {
|
|
100
|
-
setDeleteState({
|
|
101
|
-
loading: true,
|
|
102
|
-
error: null,
|
|
103
|
-
data: null
|
|
104
|
-
});
|
|
105
|
-
try {
|
|
106
|
-
await saas.deleteProject(id);
|
|
107
|
-
setDeleteState({
|
|
108
|
-
loading: false,
|
|
109
|
-
error: null,
|
|
110
|
-
data: { success: true }
|
|
111
|
-
});
|
|
112
|
-
options.onSuccess?.();
|
|
113
|
-
return true;
|
|
114
|
-
} catch (err) {
|
|
115
|
-
const error = err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to delete project");
|
|
116
|
-
setDeleteState({
|
|
117
|
-
loading: false,
|
|
118
|
-
error,
|
|
119
|
-
data: null
|
|
120
|
-
});
|
|
121
|
-
options.onError?.(error);
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
}, [saas, options]),
|
|
125
|
-
archiveProject: useCallback(async (id) => {
|
|
126
|
-
return updateProject({
|
|
127
|
-
id,
|
|
128
|
-
status: "ARCHIVED"
|
|
129
|
-
});
|
|
130
|
-
}, [updateProject]),
|
|
131
|
-
activateProject: useCallback(async (id) => {
|
|
132
|
-
return updateProject({
|
|
133
|
-
id,
|
|
134
|
-
status: "ACTIVE"
|
|
135
|
-
});
|
|
136
|
-
}, [updateProject]),
|
|
137
|
-
createState,
|
|
138
|
-
updateState,
|
|
139
|
-
deleteState,
|
|
140
|
-
isLoading: createState.loading || updateState.loading || deleteState.loading
|
|
141
|
-
};
|
|
6
|
+
const { handlers, projectId } = useTemplateRuntime();
|
|
7
|
+
const { saas } = handlers;
|
|
8
|
+
const [createState, setCreateState] = useState({
|
|
9
|
+
loading: false,
|
|
10
|
+
error: null,
|
|
11
|
+
data: null
|
|
12
|
+
});
|
|
13
|
+
const [updateState, setUpdateState] = useState({
|
|
14
|
+
loading: false,
|
|
15
|
+
error: null,
|
|
16
|
+
data: null
|
|
17
|
+
});
|
|
18
|
+
const [deleteState, setDeleteState] = useState({
|
|
19
|
+
loading: false,
|
|
20
|
+
error: null,
|
|
21
|
+
data: null
|
|
22
|
+
});
|
|
23
|
+
const createProject = useCallback(async (input) => {
|
|
24
|
+
setCreateState({ loading: true, error: null, data: null });
|
|
25
|
+
try {
|
|
26
|
+
const result = await saas.createProject(input, {
|
|
27
|
+
projectId,
|
|
28
|
+
organizationId: "demo-org"
|
|
29
|
+
});
|
|
30
|
+
setCreateState({ loading: false, error: null, data: result });
|
|
31
|
+
options.onSuccess?.();
|
|
32
|
+
return result;
|
|
33
|
+
} catch (err) {
|
|
34
|
+
const error = err instanceof Error ? err : new Error("Failed to create project");
|
|
35
|
+
setCreateState({ loading: false, error, data: null });
|
|
36
|
+
options.onError?.(error);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}, [saas, projectId, options]);
|
|
40
|
+
const updateProject = useCallback(async (input) => {
|
|
41
|
+
setUpdateState({ loading: true, error: null, data: null });
|
|
42
|
+
try {
|
|
43
|
+
const result = await saas.updateProject(input);
|
|
44
|
+
setUpdateState({ loading: false, error: null, data: result });
|
|
45
|
+
options.onSuccess?.();
|
|
46
|
+
return result;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
const error = err instanceof Error ? err : new Error("Failed to update project");
|
|
49
|
+
setUpdateState({ loading: false, error, data: null });
|
|
50
|
+
options.onError?.(error);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}, [saas, options]);
|
|
54
|
+
const deleteProject = useCallback(async (id) => {
|
|
55
|
+
setDeleteState({ loading: true, error: null, data: null });
|
|
56
|
+
try {
|
|
57
|
+
await saas.deleteProject(id);
|
|
58
|
+
setDeleteState({
|
|
59
|
+
loading: false,
|
|
60
|
+
error: null,
|
|
61
|
+
data: { success: true }
|
|
62
|
+
});
|
|
63
|
+
options.onSuccess?.();
|
|
64
|
+
return true;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const error = err instanceof Error ? err : new Error("Failed to delete project");
|
|
67
|
+
setDeleteState({ loading: false, error, data: null });
|
|
68
|
+
options.onError?.(error);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}, [saas, options]);
|
|
72
|
+
const archiveProject = useCallback(async (id) => {
|
|
73
|
+
return updateProject({ id, status: "ARCHIVED" });
|
|
74
|
+
}, [updateProject]);
|
|
75
|
+
const activateProject = useCallback(async (id) => {
|
|
76
|
+
return updateProject({ id, status: "ACTIVE" });
|
|
77
|
+
}, [updateProject]);
|
|
78
|
+
return {
|
|
79
|
+
createProject,
|
|
80
|
+
updateProject,
|
|
81
|
+
deleteProject,
|
|
82
|
+
archiveProject,
|
|
83
|
+
activateProject,
|
|
84
|
+
createState,
|
|
85
|
+
updateState,
|
|
86
|
+
deleteState,
|
|
87
|
+
isLoading: createState.loading || updateState.loading || deleteState.loading
|
|
88
|
+
};
|
|
142
89
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//# sourceMappingURL=useProjectMutations.js.map
|
|
90
|
+
export {
|
|
91
|
+
useProjectMutations
|
|
92
|
+
};
|