@contractspec/example.saas-boilerplate 3.8.9 → 3.8.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 +156 -156
- package/CHANGELOG.md +20 -0
- package/dist/billing/billing.entity.js +1 -113
- package/dist/billing/billing.enum.js +1 -19
- package/dist/billing/billing.event.js +1 -90
- package/dist/billing/billing.handler.js +1 -148
- package/dist/billing/billing.operations.js +1 -278
- package/dist/billing/billing.presentation.js +1 -55
- package/dist/billing/billing.schema.js +1 -121
- package/dist/billing/index.js +1 -691
- package/dist/browser/billing/billing.entity.js +1 -113
- package/dist/browser/billing/billing.enum.js +1 -19
- package/dist/browser/billing/billing.event.js +1 -90
- package/dist/browser/billing/billing.handler.js +1 -148
- package/dist/browser/billing/billing.operations.js +1 -278
- package/dist/browser/billing/billing.presentation.js +1 -55
- package/dist/browser/billing/billing.schema.js +1 -121
- package/dist/browser/billing/index.js +1 -691
- package/dist/browser/dashboard/dashboard.presentation.js +1 -55
- package/dist/browser/dashboard/index.js +1 -55
- package/dist/browser/docs/index.js +5 -49
- package/dist/browser/docs/saas-boilerplate.docblock.js +5 -49
- package/dist/browser/example.js +1 -39
- package/dist/browser/handlers/index.js +2 -358
- package/dist/browser/handlers/saas.handlers.js +2 -134
- package/dist/browser/index.js +9 -3591
- package/dist/browser/presentations/index.js +1 -299
- package/dist/browser/project/index.js +1 -793
- package/dist/browser/project/project.entity.js +1 -77
- package/dist/browser/project/project.enum.js +1 -18
- package/dist/browser/project/project.event.js +1 -103
- package/dist/browser/project/project.handler.js +1 -178
- package/dist/browser/project/project.operations.js +1 -372
- package/dist/browser/project/project.presentation.js +1 -180
- package/dist/browser/project/project.schema.js +1 -134
- package/dist/browser/saas-boilerplate.feature.js +1 -304
- package/dist/browser/seeders/index.js +2 -20
- package/dist/browser/settings/index.js +1 -75
- package/dist/browser/settings/settings.entity.js +1 -74
- package/dist/browser/settings/settings.enum.js +1 -11
- package/dist/browser/shared/mock-data.js +1 -104
- package/dist/browser/tests/operations.test-spec.js +1 -112
- package/dist/browser/ui/SaasDashboard.js +1 -1239
- package/dist/browser/ui/SaasDashboard.visualizations.js +1 -249
- package/dist/browser/ui/SaasProjectList.js +1 -162
- package/dist/browser/ui/SaasSettingsPanel.js +1 -145
- package/dist/browser/ui/hooks/index.js +1 -159
- package/dist/browser/ui/hooks/useProjectList.js +1 -66
- package/dist/browser/ui/hooks/useProjectMutations.js +1 -91
- package/dist/browser/ui/index.js +5 -2077
- package/dist/browser/ui/modals/CreateProjectModal.js +1 -153
- package/dist/browser/ui/modals/ProjectActionsModal.js +1 -335
- package/dist/browser/ui/modals/index.js +1 -487
- package/dist/browser/ui/overlays/demo-overlays.js +1 -61
- package/dist/browser/ui/overlays/index.js +1 -61
- package/dist/browser/ui/renderers/index.js +5 -901
- package/dist/browser/ui/renderers/project-list.markdown.js +5 -725
- package/dist/browser/ui/renderers/project-list.renderer.js +1 -177
- package/dist/browser/visualizations/catalog.js +1 -155
- package/dist/browser/visualizations/index.js +1 -217
- package/dist/browser/visualizations/selectors.js +1 -210
- package/dist/dashboard/dashboard.presentation.js +1 -55
- package/dist/dashboard/index.js +1 -55
- package/dist/docs/index.js +5 -49
- package/dist/docs/saas-boilerplate.docblock.js +5 -49
- package/dist/example.js +1 -39
- package/dist/handlers/index.js +2 -358
- package/dist/handlers/saas.handlers.js +2 -134
- package/dist/index.js +9 -3591
- package/dist/node/billing/billing.entity.js +1 -113
- package/dist/node/billing/billing.enum.js +1 -19
- package/dist/node/billing/billing.event.js +1 -90
- package/dist/node/billing/billing.handler.js +1 -148
- package/dist/node/billing/billing.operations.js +1 -278
- package/dist/node/billing/billing.presentation.js +1 -55
- package/dist/node/billing/billing.schema.js +1 -121
- package/dist/node/billing/index.js +1 -691
- package/dist/node/dashboard/dashboard.presentation.js +1 -55
- package/dist/node/dashboard/index.js +1 -55
- package/dist/node/docs/index.js +5 -49
- package/dist/node/docs/saas-boilerplate.docblock.js +5 -49
- package/dist/node/example.js +1 -39
- package/dist/node/handlers/index.js +2 -358
- package/dist/node/handlers/saas.handlers.js +2 -134
- package/dist/node/index.js +9 -3591
- package/dist/node/presentations/index.js +1 -299
- package/dist/node/project/index.js +1 -793
- package/dist/node/project/project.entity.js +1 -77
- package/dist/node/project/project.enum.js +1 -18
- package/dist/node/project/project.event.js +1 -103
- package/dist/node/project/project.handler.js +1 -178
- package/dist/node/project/project.operations.js +1 -372
- package/dist/node/project/project.presentation.js +1 -180
- package/dist/node/project/project.schema.js +1 -134
- package/dist/node/saas-boilerplate.feature.js +1 -304
- package/dist/node/seeders/index.js +2 -20
- package/dist/node/settings/index.js +1 -75
- package/dist/node/settings/settings.entity.js +1 -74
- package/dist/node/settings/settings.enum.js +1 -11
- package/dist/node/shared/mock-data.js +1 -104
- package/dist/node/tests/operations.test-spec.js +1 -112
- package/dist/node/ui/SaasDashboard.js +1 -1239
- package/dist/node/ui/SaasDashboard.visualizations.js +1 -249
- package/dist/node/ui/SaasProjectList.js +1 -162
- package/dist/node/ui/SaasSettingsPanel.js +1 -145
- package/dist/node/ui/hooks/index.js +1 -159
- package/dist/node/ui/hooks/useProjectList.js +1 -66
- package/dist/node/ui/hooks/useProjectMutations.js +1 -91
- package/dist/node/ui/index.js +5 -2077
- package/dist/node/ui/modals/CreateProjectModal.js +1 -153
- package/dist/node/ui/modals/ProjectActionsModal.js +1 -335
- package/dist/node/ui/modals/index.js +1 -487
- package/dist/node/ui/overlays/demo-overlays.js +1 -61
- package/dist/node/ui/overlays/index.js +1 -61
- package/dist/node/ui/renderers/index.js +5 -901
- package/dist/node/ui/renderers/project-list.markdown.js +5 -725
- package/dist/node/ui/renderers/project-list.renderer.js +1 -177
- package/dist/node/visualizations/catalog.js +1 -155
- package/dist/node/visualizations/index.js +1 -217
- package/dist/node/visualizations/selectors.js +1 -210
- package/dist/presentations/index.js +1 -299
- package/dist/project/index.js +1 -793
- package/dist/project/project.entity.js +1 -77
- package/dist/project/project.enum.js +1 -18
- package/dist/project/project.event.js +1 -103
- package/dist/project/project.handler.js +1 -178
- package/dist/project/project.operations.js +1 -372
- package/dist/project/project.presentation.js +1 -180
- package/dist/project/project.schema.js +1 -134
- package/dist/saas-boilerplate.feature.js +1 -304
- package/dist/seeders/index.js +2 -20
- package/dist/settings/index.js +1 -75
- package/dist/settings/settings.entity.js +1 -74
- package/dist/settings/settings.enum.js +1 -11
- package/dist/shared/mock-data.js +1 -104
- package/dist/tests/operations.test-spec.js +1 -112
- package/dist/ui/SaasDashboard.js +1 -1239
- package/dist/ui/SaasDashboard.visualizations.js +1 -249
- package/dist/ui/SaasProjectList.js +1 -162
- package/dist/ui/SaasSettingsPanel.js +1 -145
- package/dist/ui/hooks/index.js +1 -159
- package/dist/ui/hooks/useProjectList.js +1 -66
- package/dist/ui/hooks/useProjectMutations.js +1 -91
- package/dist/ui/index.js +5 -2077
- package/dist/ui/modals/CreateProjectModal.js +1 -153
- package/dist/ui/modals/ProjectActionsModal.js +1 -335
- package/dist/ui/modals/index.js +1 -487
- package/dist/ui/overlays/demo-overlays.js +1 -61
- package/dist/ui/overlays/index.js +1 -61
- package/dist/ui/renderers/index.js +5 -901
- package/dist/ui/renderers/project-list.markdown.js +5 -725
- package/dist/ui/renderers/project-list.renderer.js +1 -177
- package/dist/visualizations/catalog.js +1 -155
- package/dist/visualizations/index.js +1 -217
- package/dist/visualizations/selectors.js +1 -210
- package/package.json +12 -12
package/dist/ui/hooks/index.js
CHANGED
|
@@ -1,160 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
4
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
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
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/ui/hooks/useProjectMutations.ts
|
|
67
|
-
import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
|
|
68
|
-
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
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
|
-
}
|
|
154
|
-
|
|
155
|
-
// src/ui/hooks/index.ts
|
|
156
|
-
"use client";
|
|
157
|
-
export {
|
|
158
|
-
useProjectMutations,
|
|
159
|
-
useProjectList
|
|
160
|
-
};
|
|
2
|
+
import{useTemplateRuntime as v}from"@contractspec/lib.example-shared-ui";import{useCallback as M,useEffect as T,useMemo as x,useState as V}from"react";function E(w={}){let{handlers:_,projectId:H}=v(),{saas:B}=_,[F,N]=V(null),[X,O]=V(null),[Y,J]=V(!0),[$,G]=V(null),[K,Z]=V(1),Q=M(async()=>{J(!0),G(null);try{let[q,z]=await Promise.all([B.listProjects({projectId:H,status:w.status==="all"?void 0:w.status,search:w.search,limit:w.limit??20,offset:(K-1)*(w.limit??20)}),B.getSubscription({projectId:H})]);N({items:q.items,total:q.total}),O(z)}catch(q){G(q instanceof Error?q:Error("Unknown error"))}finally{J(!1)}},[B,H,w.status,w.search,w.limit,K]);T(()=>{Q()},[Q]);let A=x(()=>{if(!F)return null;let q=F.items;return{total:F.total,activeCount:q.filter((z)=>z.status==="ACTIVE").length,draftCount:q.filter((z)=>z.status==="DRAFT").length,projectLimit:10,usagePercent:Math.min(F.total/10*100,100)}},[F]);return{data:F,subscription:X,loading:Y,error:$,stats:A,page:K,refetch:Q,nextPage:()=>Z((q)=>q+1),prevPage:()=>K>1&&Z((q)=>q-1)}}import{useTemplateRuntime as L}from"@contractspec/lib.example-shared-ui";import{useCallback as W,useState as y}from"react";function U(w={}){let{handlers:_,projectId:H}=L(),{saas:B}=_,[F,N]=y({loading:!1,error:null,data:null}),[X,O]=y({loading:!1,error:null,data:null}),[Y,J]=y({loading:!1,error:null,data:null}),$=W(async(A)=>{N({loading:!0,error:null,data:null});try{let q=await B.createProject(A,{projectId:H,organizationId:"demo-org"});return N({loading:!1,error:null,data:q}),w.onSuccess?.(),q}catch(q){let z=q instanceof Error?q:Error("Failed to create project");return N({loading:!1,error:z,data:null}),w.onError?.(z),null}},[B,H,w]),G=W(async(A)=>{O({loading:!0,error:null,data:null});try{let q=await B.updateProject(A);return O({loading:!1,error:null,data:q}),w.onSuccess?.(),q}catch(q){let z=q instanceof Error?q:Error("Failed to update project");return O({loading:!1,error:z,data:null}),w.onError?.(z),null}},[B,w]),K=W(async(A)=>{J({loading:!0,error:null,data:null});try{return await B.deleteProject(A),J({loading:!1,error:null,data:{success:!0}}),w.onSuccess?.(),!0}catch(q){let z=q instanceof Error?q:Error("Failed to delete project");return J({loading:!1,error:z,data:null}),w.onError?.(z),!1}},[B,w]),Z=W(async(A)=>{return G({id:A,status:"ARCHIVED"})},[G]),Q=W(async(A)=>{return G({id:A,status:"ACTIVE"})},[G]);return{createProject:$,updateProject:G,deleteProject:K,archiveProject:Z,activateProject:Q,createState:F,updateState:X,deleteState:Y,isLoading:F.loading||X.loading||Y.loading}}export{U as useProjectMutations,E as useProjectList};
|
|
@@ -1,67 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
4
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
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
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
useProjectList
|
|
67
|
-
};
|
|
2
|
+
import{useTemplateRuntime as Y}from"@contractspec/lib.example-shared-ui";import{useCallback as Z,useEffect as _,useMemo as $,useState as z}from"react";function C(v={}){let{handlers:N,projectId:B}=Y(),{saas:F}=N,[w,O]=z(null),[Q,U]=z(null),[V,H]=z(!0),[W,J]=z(null),[A,K]=z(1),G=Z(async()=>{H(!0),J(null);try{let[q,y]=await Promise.all([F.listProjects({projectId:B,status:v.status==="all"?void 0:v.status,search:v.search,limit:v.limit??20,offset:(A-1)*(v.limit??20)}),F.getSubscription({projectId:B})]);O({items:q.items,total:q.total}),U(y)}catch(q){J(q instanceof Error?q:Error("Unknown error"))}finally{H(!1)}},[F,B,v.status,v.search,v.limit,A]);_(()=>{G()},[G]);let X=$(()=>{if(!w)return null;let q=w.items;return{total:w.total,activeCount:q.filter((y)=>y.status==="ACTIVE").length,draftCount:q.filter((y)=>y.status==="DRAFT").length,projectLimit:10,usagePercent:Math.min(w.total/10*100,100)}},[w]);return{data:w,subscription:Q,loading:V,error:W,stats:X,page:A,refetch:G,nextPage:()=>K((q)=>q+1),prevPage:()=>A>1&&K((q)=>q-1)}}export{C as useProjectList};
|
|
@@ -1,92 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
4
|
-
import { useCallback, useState } from "react";
|
|
5
|
-
function useProjectMutations(options = {}) {
|
|
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
|
-
};
|
|
89
|
-
}
|
|
90
|
-
export {
|
|
91
|
-
useProjectMutations
|
|
92
|
-
};
|
|
2
|
+
import{useTemplateRuntime as W}from"@contractspec/lib.example-shared-ui";import{useCallback as A,useState as G}from"react";function Z(g={}){let{handlers:M,projectId:H}=W(),{saas:y}=M,[J,B]=G({loading:!1,error:null,data:null}),[K,E]=G({loading:!1,error:null,data:null}),[L,F]=G({loading:!1,error:null,data:null}),N=A(async(q)=>{B({loading:!0,error:null,data:null});try{let f=await y.createProject(q,{projectId:H,organizationId:"demo-org"});return B({loading:!1,error:null,data:f}),g.onSuccess?.(),f}catch(f){let w=f instanceof Error?f:Error("Failed to create project");return B({loading:!1,error:w,data:null}),g.onError?.(w),null}},[y,H,g]),z=A(async(q)=>{E({loading:!0,error:null,data:null});try{let f=await y.updateProject(q);return E({loading:!1,error:null,data:f}),g.onSuccess?.(),f}catch(f){let w=f instanceof Error?f:Error("Failed to update project");return E({loading:!1,error:w,data:null}),g.onError?.(w),null}},[y,g]),O=A(async(q)=>{F({loading:!0,error:null,data:null});try{return await y.deleteProject(q),F({loading:!1,error:null,data:{success:!0}}),g.onSuccess?.(),!0}catch(f){let w=f instanceof Error?f:Error("Failed to delete project");return F({loading:!1,error:w,data:null}),g.onError?.(w),!1}},[y,g]),Q=A(async(q)=>{return z({id:q,status:"ARCHIVED"})},[z]),V=A(async(q)=>{return z({id:q,status:"ACTIVE"})},[z]);return{createProject:N,updateProject:z,deleteProject:O,archiveProject:Q,activateProject:V,createState:J,updateState:K,deleteState:L,isLoading:J.loading||K.loading||L.loading}}export{Z as useProjectMutations};
|