@contractspec/example.saas-boilerplate 1.57.0 → 1.59.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.
Files changed (283) hide show
  1. package/.turbo/turbo-build.log +160 -180
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +39 -0
  4. package/dist/billing/billing.entity.d.ts +40 -45
  5. package/dist/billing/billing.entity.d.ts.map +1 -1
  6. package/dist/billing/billing.entity.js +110 -118
  7. package/dist/billing/billing.enum.d.ts +2 -7
  8. package/dist/billing/billing.enum.d.ts.map +1 -1
  9. package/dist/billing/billing.enum.js +17 -24
  10. package/dist/billing/billing.event.d.ts +67 -73
  11. package/dist/billing/billing.event.d.ts.map +1 -1
  12. package/dist/billing/billing.event.js +84 -146
  13. package/dist/billing/billing.handler.d.ts +59 -62
  14. package/dist/billing/billing.handler.d.ts.map +1 -1
  15. package/dist/billing/billing.handler.js +140 -49
  16. package/dist/billing/billing.operations.d.ts +138 -144
  17. package/dist/billing/billing.operations.d.ts.map +1 -1
  18. package/dist/billing/billing.operations.js +273 -175
  19. package/dist/billing/billing.presentation.d.ts +2 -7
  20. package/dist/billing/billing.presentation.d.ts.map +1 -1
  21. package/dist/billing/billing.presentation.js +51 -57
  22. package/dist/billing/billing.schema.d.ts +159 -164
  23. package/dist/billing/billing.schema.d.ts.map +1 -1
  24. package/dist/billing/billing.schema.js +112 -204
  25. package/dist/billing/index.d.ts +11 -8
  26. package/dist/billing/index.d.ts.map +1 -0
  27. package/dist/billing/index.js +689 -9
  28. package/dist/browser/billing/billing.entity.js +113 -0
  29. package/dist/browser/billing/billing.enum.js +19 -0
  30. package/dist/browser/billing/billing.event.js +90 -0
  31. package/dist/browser/billing/billing.handler.js +148 -0
  32. package/dist/browser/billing/billing.operations.js +278 -0
  33. package/dist/browser/billing/billing.presentation.js +52 -0
  34. package/dist/browser/billing/billing.schema.js +121 -0
  35. package/dist/browser/billing/index.js +688 -0
  36. package/dist/browser/dashboard/dashboard.presentation.js +52 -0
  37. package/dist/browser/dashboard/index.js +52 -0
  38. package/dist/browser/docs/index.js +93 -0
  39. package/dist/browser/docs/saas-boilerplate.docblock.js +93 -0
  40. package/dist/browser/example.js +39 -0
  41. package/dist/browser/handlers/index.js +358 -0
  42. package/dist/browser/handlers/saas.handlers.js +134 -0
  43. package/dist/browser/index.js +3340 -0
  44. package/dist/browser/presentations/index.js +290 -0
  45. package/dist/browser/project/index.js +790 -0
  46. package/dist/browser/project/project.entity.js +77 -0
  47. package/dist/browser/project/project.enum.js +18 -0
  48. package/dist/browser/project/project.event.js +103 -0
  49. package/dist/browser/project/project.handler.js +178 -0
  50. package/dist/browser/project/project.operations.js +372 -0
  51. package/dist/browser/project/project.presentation.js +177 -0
  52. package/dist/browser/project/project.schema.js +134 -0
  53. package/dist/browser/saas-boilerplate.feature.js +88 -0
  54. package/dist/browser/seeders/index.js +20 -0
  55. package/dist/browser/settings/index.js +75 -0
  56. package/dist/browser/settings/settings.entity.js +74 -0
  57. package/dist/browser/settings/settings.enum.js +11 -0
  58. package/dist/browser/shared/mock-data.js +104 -0
  59. package/dist/browser/shared/overlay-types.js +0 -0
  60. package/dist/browser/tests/operations.test-spec.js +112 -0
  61. package/dist/browser/ui/SaasDashboard.js +988 -0
  62. package/dist/browser/ui/SaasProjectList.js +162 -0
  63. package/dist/browser/ui/SaasSettingsPanel.js +145 -0
  64. package/dist/browser/ui/hooks/index.js +159 -0
  65. package/dist/browser/ui/hooks/useProjectList.js +66 -0
  66. package/dist/browser/ui/hooks/useProjectMutations.js +91 -0
  67. package/dist/browser/ui/index.js +1808 -0
  68. package/dist/browser/ui/modals/CreateProjectModal.js +153 -0
  69. package/dist/browser/ui/modals/ProjectActionsModal.js +335 -0
  70. package/dist/browser/ui/modals/index.js +487 -0
  71. package/dist/browser/ui/overlays/demo-overlays.js +61 -0
  72. package/dist/browser/ui/overlays/index.js +61 -0
  73. package/dist/browser/ui/renderers/index.js +675 -0
  74. package/dist/browser/ui/renderers/project-list.markdown.js +499 -0
  75. package/dist/browser/ui/renderers/project-list.renderer.js +177 -0
  76. package/dist/dashboard/dashboard.presentation.d.ts +2 -7
  77. package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
  78. package/dist/dashboard/dashboard.presentation.js +51 -53
  79. package/dist/dashboard/index.d.ts +5 -2
  80. package/dist/dashboard/index.d.ts.map +1 -0
  81. package/dist/dashboard/index.js +53 -3
  82. package/dist/docs/index.d.ts +2 -1
  83. package/dist/docs/index.d.ts.map +1 -0
  84. package/dist/docs/index.js +94 -1
  85. package/dist/docs/saas-boilerplate.docblock.d.ts +2 -1
  86. package/dist/docs/saas-boilerplate.docblock.d.ts.map +1 -0
  87. package/dist/docs/saas-boilerplate.docblock.js +45 -51
  88. package/dist/example.d.ts +2 -6
  89. package/dist/example.d.ts.map +1 -1
  90. package/dist/example.js +38 -50
  91. package/dist/handlers/index.d.ts +7 -4
  92. package/dist/handlers/index.d.ts.map +1 -0
  93. package/dist/handlers/index.js +358 -4
  94. package/dist/handlers/saas.handlers.d.ts +60 -59
  95. package/dist/handlers/saas.handlers.d.ts.map +1 -1
  96. package/dist/handlers/saas.handlers.js +127 -140
  97. package/dist/index.d.ts +15 -45
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +3335 -75
  100. package/dist/node/billing/billing.entity.js +113 -0
  101. package/dist/node/billing/billing.enum.js +19 -0
  102. package/dist/node/billing/billing.event.js +90 -0
  103. package/dist/node/billing/billing.handler.js +148 -0
  104. package/dist/node/billing/billing.operations.js +278 -0
  105. package/dist/node/billing/billing.presentation.js +52 -0
  106. package/dist/node/billing/billing.schema.js +121 -0
  107. package/dist/node/billing/index.js +688 -0
  108. package/dist/node/dashboard/dashboard.presentation.js +52 -0
  109. package/dist/node/dashboard/index.js +52 -0
  110. package/dist/node/docs/index.js +93 -0
  111. package/dist/node/docs/saas-boilerplate.docblock.js +93 -0
  112. package/dist/node/example.js +39 -0
  113. package/dist/node/handlers/index.js +358 -0
  114. package/dist/node/handlers/saas.handlers.js +134 -0
  115. package/dist/node/index.js +3340 -0
  116. package/dist/node/presentations/index.js +290 -0
  117. package/dist/node/project/index.js +790 -0
  118. package/dist/node/project/project.entity.js +77 -0
  119. package/dist/node/project/project.enum.js +18 -0
  120. package/dist/node/project/project.event.js +103 -0
  121. package/dist/node/project/project.handler.js +178 -0
  122. package/dist/node/project/project.operations.js +372 -0
  123. package/dist/node/project/project.presentation.js +177 -0
  124. package/dist/node/project/project.schema.js +134 -0
  125. package/dist/node/saas-boilerplate.feature.js +88 -0
  126. package/dist/node/seeders/index.js +20 -0
  127. package/dist/node/settings/index.js +75 -0
  128. package/dist/node/settings/settings.entity.js +74 -0
  129. package/dist/node/settings/settings.enum.js +11 -0
  130. package/dist/node/shared/mock-data.js +104 -0
  131. package/dist/node/shared/overlay-types.js +0 -0
  132. package/dist/node/tests/operations.test-spec.js +112 -0
  133. package/dist/node/ui/SaasDashboard.js +988 -0
  134. package/dist/node/ui/SaasProjectList.js +162 -0
  135. package/dist/node/ui/SaasSettingsPanel.js +145 -0
  136. package/dist/node/ui/hooks/index.js +159 -0
  137. package/dist/node/ui/hooks/useProjectList.js +66 -0
  138. package/dist/node/ui/hooks/useProjectMutations.js +91 -0
  139. package/dist/node/ui/index.js +1808 -0
  140. package/dist/node/ui/modals/CreateProjectModal.js +153 -0
  141. package/dist/node/ui/modals/ProjectActionsModal.js +335 -0
  142. package/dist/node/ui/modals/index.js +487 -0
  143. package/dist/node/ui/overlays/demo-overlays.js +61 -0
  144. package/dist/node/ui/overlays/index.js +61 -0
  145. package/dist/node/ui/renderers/index.js +675 -0
  146. package/dist/node/ui/renderers/project-list.markdown.js +499 -0
  147. package/dist/node/ui/renderers/project-list.renderer.js +177 -0
  148. package/dist/presentations/index.d.ts +13 -14
  149. package/dist/presentations/index.d.ts.map +1 -1
  150. package/dist/presentations/index.js +289 -15
  151. package/dist/project/index.d.ts +11 -8
  152. package/dist/project/index.d.ts.map +1 -0
  153. package/dist/project/index.js +791 -9
  154. package/dist/project/project.entity.d.ts +23 -28
  155. package/dist/project/project.entity.d.ts.map +1 -1
  156. package/dist/project/project.entity.js +75 -82
  157. package/dist/project/project.enum.d.ts +2 -7
  158. package/dist/project/project.enum.d.ts.map +1 -1
  159. package/dist/project/project.enum.js +16 -23
  160. package/dist/project/project.event.d.ts +69 -75
  161. package/dist/project/project.event.d.ts.map +1 -1
  162. package/dist/project/project.event.js +95 -156
  163. package/dist/project/project.handler.d.ts +44 -47
  164. package/dist/project/project.handler.d.ts.map +1 -1
  165. package/dist/project/project.handler.js +168 -71
  166. package/dist/project/project.operations.d.ts +341 -347
  167. package/dist/project/project.operations.d.ts.map +1 -1
  168. package/dist/project/project.operations.js +366 -253
  169. package/dist/project/project.presentation.d.ts +2 -7
  170. package/dist/project/project.presentation.d.ts.map +1 -1
  171. package/dist/project/project.presentation.js +174 -61
  172. package/dist/project/project.schema.d.ts +191 -196
  173. package/dist/project/project.schema.d.ts.map +1 -1
  174. package/dist/project/project.schema.js +125 -205
  175. package/dist/saas-boilerplate.feature.d.ts +1 -6
  176. package/dist/saas-boilerplate.feature.d.ts.map +1 -1
  177. package/dist/saas-boilerplate.feature.js +87 -206
  178. package/dist/seeders/index.d.ts +4 -8
  179. package/dist/seeders/index.d.ts.map +1 -1
  180. package/dist/seeders/index.js +18 -16
  181. package/dist/settings/index.d.ts +6 -3
  182. package/dist/settings/index.d.ts.map +1 -0
  183. package/dist/settings/index.js +75 -3
  184. package/dist/settings/settings.entity.d.ts +23 -28
  185. package/dist/settings/settings.entity.d.ts.map +1 -1
  186. package/dist/settings/settings.entity.js +72 -75
  187. package/dist/settings/settings.enum.d.ts +1 -6
  188. package/dist/settings/settings.enum.d.ts.map +1 -1
  189. package/dist/settings/settings.enum.js +10 -19
  190. package/dist/shared/mock-data.d.ts +74 -77
  191. package/dist/shared/mock-data.d.ts.map +1 -1
  192. package/dist/shared/mock-data.js +102 -135
  193. package/dist/shared/overlay-types.d.ts +25 -28
  194. package/dist/shared/overlay-types.d.ts.map +1 -1
  195. package/dist/shared/overlay-types.js +1 -0
  196. package/dist/tests/operations.test-spec.d.ts +4 -9
  197. package/dist/tests/operations.test-spec.d.ts.map +1 -1
  198. package/dist/tests/operations.test-spec.js +108 -118
  199. package/dist/ui/SaasDashboard.d.ts +1 -6
  200. package/dist/ui/SaasDashboard.d.ts.map +1 -1
  201. package/dist/ui/SaasDashboard.js +977 -286
  202. package/dist/ui/SaasProjectList.d.ts +4 -11
  203. package/dist/ui/SaasProjectList.d.ts.map +1 -1
  204. package/dist/ui/SaasProjectList.js +159 -72
  205. package/dist/ui/SaasSettingsPanel.d.ts +1 -6
  206. package/dist/ui/SaasSettingsPanel.d.ts.map +1 -1
  207. package/dist/ui/SaasSettingsPanel.js +142 -134
  208. package/dist/ui/hooks/index.d.ts +3 -3
  209. package/dist/ui/hooks/index.d.ts.map +1 -0
  210. package/dist/ui/hooks/index.js +158 -4
  211. package/dist/ui/hooks/useProjectList.d.ts +26 -30
  212. package/dist/ui/hooks/useProjectList.d.ts.map +1 -1
  213. package/dist/ui/hooks/useProjectList.js +63 -71
  214. package/dist/ui/hooks/useProjectMutations.d.ts +20 -24
  215. package/dist/ui/hooks/useProjectMutations.d.ts.map +1 -1
  216. package/dist/ui/hooks/useProjectMutations.js +88 -142
  217. package/dist/ui/index.d.ts +8 -14
  218. package/dist/ui/index.d.ts.map +1 -0
  219. package/dist/ui/index.js +1809 -15
  220. package/dist/ui/modals/CreateProjectModal.d.ts +10 -19
  221. package/dist/ui/modals/CreateProjectModal.d.ts.map +1 -1
  222. package/dist/ui/modals/CreateProjectModal.js +150 -135
  223. package/dist/ui/modals/ProjectActionsModal.d.ts +20 -33
  224. package/dist/ui/modals/ProjectActionsModal.d.ts.map +1 -1
  225. package/dist/ui/modals/ProjectActionsModal.js +333 -289
  226. package/dist/ui/modals/index.d.ts +3 -3
  227. package/dist/ui/modals/index.d.ts.map +1 -0
  228. package/dist/ui/modals/index.js +487 -3
  229. package/dist/ui/overlays/demo-overlays.d.ts +10 -8
  230. package/dist/ui/overlays/demo-overlays.d.ts.map +1 -1
  231. package/dist/ui/overlays/demo-overlays.js +60 -68
  232. package/dist/ui/overlays/index.d.ts +2 -2
  233. package/dist/ui/overlays/index.d.ts.map +1 -0
  234. package/dist/ui/overlays/index.js +62 -3
  235. package/dist/ui/renderers/index.d.ts +3 -3
  236. package/dist/ui/renderers/index.d.ts.map +1 -0
  237. package/dist/ui/renderers/index.js +675 -3
  238. package/dist/ui/renderers/project-list.markdown.d.ts +15 -14
  239. package/dist/ui/renderers/project-list.markdown.d.ts.map +1 -1
  240. package/dist/ui/renderers/project-list.markdown.js +496 -146
  241. package/dist/ui/renderers/project-list.renderer.d.ts +6 -7
  242. package/dist/ui/renderers/project-list.renderer.d.ts.map +1 -1
  243. package/dist/ui/renderers/project-list.renderer.js +176 -15
  244. package/package.json +508 -98
  245. package/tsdown.config.js +1 -2
  246. package/.turbo/turbo-build$colon$bundle.log +0 -180
  247. package/dist/billing/billing.entity.js.map +0 -1
  248. package/dist/billing/billing.enum.js.map +0 -1
  249. package/dist/billing/billing.event.js.map +0 -1
  250. package/dist/billing/billing.handler.js.map +0 -1
  251. package/dist/billing/billing.operations.js.map +0 -1
  252. package/dist/billing/billing.presentation.js.map +0 -1
  253. package/dist/billing/billing.schema.js.map +0 -1
  254. package/dist/dashboard/dashboard.presentation.js.map +0 -1
  255. package/dist/docs/saas-boilerplate.docblock.js.map +0 -1
  256. package/dist/example.js.map +0 -1
  257. package/dist/handlers/saas.handlers.js.map +0 -1
  258. package/dist/index.js.map +0 -1
  259. package/dist/presentations/index.js.map +0 -1
  260. package/dist/project/project.entity.js.map +0 -1
  261. package/dist/project/project.enum.js.map +0 -1
  262. package/dist/project/project.event.js.map +0 -1
  263. package/dist/project/project.handler.js.map +0 -1
  264. package/dist/project/project.operations.js.map +0 -1
  265. package/dist/project/project.presentation.js.map +0 -1
  266. package/dist/project/project.schema.js.map +0 -1
  267. package/dist/saas-boilerplate.feature.js.map +0 -1
  268. package/dist/seeders/index.js.map +0 -1
  269. package/dist/settings/settings.entity.js.map +0 -1
  270. package/dist/settings/settings.enum.js.map +0 -1
  271. package/dist/shared/mock-data.js.map +0 -1
  272. package/dist/tests/operations.test-spec.js.map +0 -1
  273. package/dist/ui/SaasDashboard.js.map +0 -1
  274. package/dist/ui/SaasProjectList.js.map +0 -1
  275. package/dist/ui/SaasSettingsPanel.js.map +0 -1
  276. package/dist/ui/hooks/useProjectList.js.map +0 -1
  277. package/dist/ui/hooks/useProjectMutations.js.map +0 -1
  278. package/dist/ui/modals/CreateProjectModal.js.map +0 -1
  279. package/dist/ui/modals/ProjectActionsModal.js.map +0 -1
  280. package/dist/ui/overlays/demo-overlays.js.map +0 -1
  281. package/dist/ui/renderers/project-list.markdown.js.map +0 -1
  282. package/dist/ui/renderers/project-list.renderer.js.map +0 -1
  283. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,162 @@
1
+ // src/ui/hooks/useProjectList.ts
2
+ import { useCallback, useEffect, useMemo, useState } from "react";
3
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ function useProjectList(options = {}) {
5
+ const { handlers, projectId } = useTemplateRuntime();
6
+ const { saas } = handlers;
7
+ const [data, setData] = useState(null);
8
+ const [subscription, setSubscription] = useState(null);
9
+ const [loading, setLoading] = useState(true);
10
+ const [error, setError] = useState(null);
11
+ const [page, setPage] = useState(1);
12
+ const fetchData = useCallback(async () => {
13
+ setLoading(true);
14
+ setError(null);
15
+ try {
16
+ const [projectsResult, subscriptionResult] = await Promise.all([
17
+ saas.listProjects({
18
+ projectId,
19
+ status: options.status === "all" ? undefined : options.status,
20
+ search: options.search,
21
+ limit: options.limit ?? 20,
22
+ offset: (page - 1) * (options.limit ?? 20)
23
+ }),
24
+ saas.getSubscription({ projectId })
25
+ ]);
26
+ setData({
27
+ items: projectsResult.items,
28
+ total: projectsResult.total
29
+ });
30
+ setSubscription(subscriptionResult);
31
+ } catch (err) {
32
+ setError(err instanceof Error ? err : new Error("Unknown error"));
33
+ } finally {
34
+ setLoading(false);
35
+ }
36
+ }, [saas, projectId, options.status, options.search, options.limit, page]);
37
+ useEffect(() => {
38
+ fetchData();
39
+ }, [fetchData]);
40
+ const stats = useMemo(() => {
41
+ if (!data)
42
+ return null;
43
+ const items = data.items;
44
+ return {
45
+ total: data.total,
46
+ activeCount: items.filter((p) => p.status === "ACTIVE").length,
47
+ draftCount: items.filter((p) => p.status === "DRAFT").length,
48
+ projectLimit: 10,
49
+ usagePercent: Math.min(data.total / 10 * 100, 100)
50
+ };
51
+ }, [data]);
52
+ return {
53
+ data,
54
+ subscription,
55
+ loading,
56
+ error,
57
+ stats,
58
+ page,
59
+ refetch: fetchData,
60
+ nextPage: () => setPage((p) => p + 1),
61
+ prevPage: () => page > 1 && setPage((p) => p - 1)
62
+ };
63
+ }
64
+
65
+ // src/ui/SaasProjectList.tsx
66
+ import {
67
+ StatCard,
68
+ StatCardGroup,
69
+ StatusChip,
70
+ EntityCard,
71
+ EmptyState,
72
+ LoaderBlock,
73
+ ErrorState,
74
+ Button
75
+ } from "@contractspec/lib.design-system";
76
+ import { jsxDEV } from "react/jsx-dev-runtime";
77
+ "use client";
78
+ function getStatusTone(status) {
79
+ switch (status) {
80
+ case "ACTIVE":
81
+ return "success";
82
+ case "DRAFT":
83
+ return "neutral";
84
+ case "ARCHIVED":
85
+ return "danger";
86
+ default:
87
+ return "neutral";
88
+ }
89
+ }
90
+ function SaasProjectList({
91
+ onProjectClick,
92
+ onCreateProject
93
+ }) {
94
+ const { data, loading, error, stats, refetch } = useProjectList();
95
+ if (loading && !data) {
96
+ return /* @__PURE__ */ jsxDEV(LoaderBlock, {
97
+ label: "Loading projects..."
98
+ }, undefined, false, undefined, this);
99
+ }
100
+ if (error) {
101
+ return /* @__PURE__ */ jsxDEV(ErrorState, {
102
+ title: "Failed to load projects",
103
+ description: error.message,
104
+ onRetry: refetch,
105
+ retryLabel: "Retry"
106
+ }, undefined, false, undefined, this);
107
+ }
108
+ if (!data?.items.length) {
109
+ return /* @__PURE__ */ jsxDEV(EmptyState, {
110
+ title: "No projects found",
111
+ description: "Create your first project to get started.",
112
+ primaryAction: onCreateProject ? /* @__PURE__ */ jsxDEV(Button, {
113
+ onPress: onCreateProject,
114
+ children: "Create Project"
115
+ }, undefined, false, undefined, this) : undefined
116
+ }, undefined, false, undefined, this);
117
+ }
118
+ return /* @__PURE__ */ jsxDEV("div", {
119
+ className: "space-y-6",
120
+ children: [
121
+ stats && /* @__PURE__ */ jsxDEV(StatCardGroup, {
122
+ children: [
123
+ /* @__PURE__ */ jsxDEV(StatCard, {
124
+ label: "Total Projects",
125
+ value: stats.total.toString()
126
+ }, undefined, false, undefined, this),
127
+ /* @__PURE__ */ jsxDEV(StatCard, {
128
+ label: "Active",
129
+ value: stats.activeCount.toString()
130
+ }, undefined, false, undefined, this),
131
+ /* @__PURE__ */ jsxDEV(StatCard, {
132
+ label: "Draft",
133
+ value: stats.draftCount.toString()
134
+ }, undefined, false, undefined, this)
135
+ ]
136
+ }, undefined, true, undefined, this),
137
+ /* @__PURE__ */ jsxDEV("div", {
138
+ className: "grid gap-4 md:grid-cols-2 lg:grid-cols-3",
139
+ children: data.items.map((project) => /* @__PURE__ */ jsxDEV(EntityCard, {
140
+ cardTitle: project.name,
141
+ cardSubtitle: project.tier,
142
+ meta: /* @__PURE__ */ jsxDEV("p", {
143
+ className: "text-muted-foreground text-sm",
144
+ children: project.description
145
+ }, undefined, false, undefined, this),
146
+ chips: /* @__PURE__ */ jsxDEV(StatusChip, {
147
+ tone: getStatusTone(project.status),
148
+ label: project.status
149
+ }, undefined, false, undefined, this),
150
+ footer: /* @__PURE__ */ jsxDEV("span", {
151
+ className: "text-muted-foreground text-xs",
152
+ children: project.updatedAt.toLocaleDateString()
153
+ }, undefined, false, undefined, this),
154
+ onClick: onProjectClick ? () => onProjectClick(project.id) : undefined
155
+ }, project.id, false, undefined, this))
156
+ }, undefined, false, undefined, this)
157
+ ]
158
+ }, undefined, true, undefined, this);
159
+ }
160
+ export {
161
+ SaasProjectList
162
+ };
@@ -0,0 +1,145 @@
1
+ // src/ui/SaasSettingsPanel.tsx
2
+ import { useState } from "react";
3
+ import { Button } from "@contractspec/lib.design-system";
4
+ import { jsxDEV } from "react/jsx-dev-runtime";
5
+ "use client";
6
+ function SaasSettingsPanel() {
7
+ const [orgName, setOrgName] = useState("Demo Organization");
8
+ const [timezone, setTimezone] = useState("UTC");
9
+ return /* @__PURE__ */ jsxDEV("div", {
10
+ className: "space-y-6",
11
+ children: [
12
+ /* @__PURE__ */ jsxDEV("div", {
13
+ className: "border-border bg-card rounded-xl border p-6",
14
+ children: [
15
+ /* @__PURE__ */ jsxDEV("h3", {
16
+ className: "mb-4 text-lg font-semibold",
17
+ children: "Organization Settings"
18
+ }, undefined, false, undefined, this),
19
+ /* @__PURE__ */ jsxDEV("div", {
20
+ className: "space-y-4",
21
+ children: [
22
+ /* @__PURE__ */ jsxDEV("div", {
23
+ children: [
24
+ /* @__PURE__ */ jsxDEV("label", {
25
+ htmlFor: "setting-org-name",
26
+ className: "block text-sm font-medium",
27
+ children: "Organization Name"
28
+ }, undefined, false, undefined, this),
29
+ /* @__PURE__ */ jsxDEV("input", {
30
+ id: "setting-org-name",
31
+ type: "text",
32
+ value: orgName,
33
+ onChange: (e) => setOrgName(e.target.value),
34
+ className: "border-input bg-background mt-1 block w-full rounded-md border px-3 py-2"
35
+ }, undefined, false, undefined, this)
36
+ ]
37
+ }, undefined, true, undefined, this),
38
+ /* @__PURE__ */ jsxDEV("div", {
39
+ children: [
40
+ /* @__PURE__ */ jsxDEV("label", {
41
+ htmlFor: "setting-timezone",
42
+ className: "block text-sm font-medium",
43
+ children: "Default Timezone"
44
+ }, undefined, false, undefined, this),
45
+ /* @__PURE__ */ jsxDEV("select", {
46
+ id: "setting-timezone",
47
+ value: timezone,
48
+ onChange: (e) => setTimezone(e.target.value),
49
+ className: "border-input bg-background mt-1 block w-full rounded-md border px-3 py-2",
50
+ children: [
51
+ /* @__PURE__ */ jsxDEV("option", {
52
+ value: "UTC",
53
+ children: "UTC"
54
+ }, undefined, false, undefined, this),
55
+ /* @__PURE__ */ jsxDEV("option", {
56
+ value: "America/New_York",
57
+ children: "America/New_York"
58
+ }, undefined, false, undefined, this),
59
+ /* @__PURE__ */ jsxDEV("option", {
60
+ value: "Europe/London",
61
+ children: "Europe/London"
62
+ }, undefined, false, undefined, this),
63
+ /* @__PURE__ */ jsxDEV("option", {
64
+ value: "Asia/Tokyo",
65
+ children: "Asia/Tokyo"
66
+ }, undefined, false, undefined, this)
67
+ ]
68
+ }, undefined, true, undefined, this)
69
+ ]
70
+ }, undefined, true, undefined, this)
71
+ ]
72
+ }, undefined, true, undefined, this),
73
+ /* @__PURE__ */ jsxDEV("div", {
74
+ className: "mt-6",
75
+ children: /* @__PURE__ */ jsxDEV(Button, {
76
+ variant: "default",
77
+ children: "Save Changes"
78
+ }, undefined, false, undefined, this)
79
+ }, undefined, false, undefined, this)
80
+ ]
81
+ }, undefined, true, undefined, this),
82
+ /* @__PURE__ */ jsxDEV("div", {
83
+ className: "border-border bg-card rounded-xl border p-6",
84
+ children: [
85
+ /* @__PURE__ */ jsxDEV("h3", {
86
+ className: "mb-4 text-lg font-semibold",
87
+ children: "Notifications"
88
+ }, undefined, false, undefined, this),
89
+ /* @__PURE__ */ jsxDEV("div", {
90
+ className: "space-y-3",
91
+ children: [
92
+ { label: "Email notifications", defaultChecked: true },
93
+ { label: "Usage alerts", defaultChecked: true },
94
+ { label: "Weekly digest", defaultChecked: false }
95
+ ].map((item) => /* @__PURE__ */ jsxDEV("label", {
96
+ className: "flex items-center gap-3",
97
+ children: [
98
+ /* @__PURE__ */ jsxDEV("input", {
99
+ type: "checkbox",
100
+ defaultChecked: item.defaultChecked,
101
+ className: "border-input h-4 w-4 rounded"
102
+ }, undefined, false, undefined, this),
103
+ /* @__PURE__ */ jsxDEV("span", {
104
+ className: "text-sm",
105
+ children: item.label
106
+ }, undefined, false, undefined, this)
107
+ ]
108
+ }, item.label, true, undefined, this))
109
+ }, undefined, false, undefined, this)
110
+ ]
111
+ }, undefined, true, undefined, this),
112
+ /* @__PURE__ */ jsxDEV("div", {
113
+ className: "rounded-xl border border-red-200 bg-red-50 p-6 dark:border-red-900 dark:bg-red-950/20",
114
+ children: [
115
+ /* @__PURE__ */ jsxDEV("h3", {
116
+ className: "mb-2 text-lg font-semibold text-red-700 dark:text-red-400",
117
+ children: "Danger Zone"
118
+ }, undefined, false, undefined, this),
119
+ /* @__PURE__ */ jsxDEV("p", {
120
+ className: "mb-4 text-sm text-red-600 dark:text-red-300",
121
+ children: "These actions are irreversible. Please proceed with caution."
122
+ }, undefined, false, undefined, this),
123
+ /* @__PURE__ */ jsxDEV("div", {
124
+ className: "flex gap-3",
125
+ children: [
126
+ /* @__PURE__ */ jsxDEV(Button, {
127
+ variant: "secondary",
128
+ size: "sm",
129
+ children: "Export Data"
130
+ }, undefined, false, undefined, this),
131
+ /* @__PURE__ */ jsxDEV(Button, {
132
+ variant: "secondary",
133
+ size: "sm",
134
+ children: "Delete Organization"
135
+ }, undefined, false, undefined, this)
136
+ ]
137
+ }, undefined, true, undefined, this)
138
+ ]
139
+ }, undefined, true, undefined, this)
140
+ ]
141
+ }, undefined, true, undefined, this);
142
+ }
143
+ export {
144
+ SaasSettingsPanel
145
+ };
@@ -0,0 +1,159 @@
1
+ // src/ui/hooks/useProjectList.ts
2
+ import { useCallback, useEffect, useMemo, useState } from "react";
3
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ function useProjectList(options = {}) {
5
+ const { handlers, projectId } = useTemplateRuntime();
6
+ const { saas } = handlers;
7
+ const [data, setData] = useState(null);
8
+ const [subscription, setSubscription] = useState(null);
9
+ const [loading, setLoading] = useState(true);
10
+ const [error, setError] = useState(null);
11
+ const [page, setPage] = useState(1);
12
+ const fetchData = useCallback(async () => {
13
+ setLoading(true);
14
+ setError(null);
15
+ try {
16
+ const [projectsResult, subscriptionResult] = await Promise.all([
17
+ saas.listProjects({
18
+ projectId,
19
+ status: options.status === "all" ? undefined : options.status,
20
+ search: options.search,
21
+ limit: options.limit ?? 20,
22
+ offset: (page - 1) * (options.limit ?? 20)
23
+ }),
24
+ saas.getSubscription({ projectId })
25
+ ]);
26
+ setData({
27
+ items: projectsResult.items,
28
+ total: projectsResult.total
29
+ });
30
+ setSubscription(subscriptionResult);
31
+ } catch (err) {
32
+ setError(err instanceof Error ? err : new Error("Unknown error"));
33
+ } finally {
34
+ setLoading(false);
35
+ }
36
+ }, [saas, projectId, options.status, options.search, options.limit, page]);
37
+ useEffect(() => {
38
+ fetchData();
39
+ }, [fetchData]);
40
+ const stats = useMemo(() => {
41
+ if (!data)
42
+ return null;
43
+ const items = data.items;
44
+ return {
45
+ total: data.total,
46
+ activeCount: items.filter((p) => p.status === "ACTIVE").length,
47
+ draftCount: items.filter((p) => p.status === "DRAFT").length,
48
+ projectLimit: 10,
49
+ usagePercent: Math.min(data.total / 10 * 100, 100)
50
+ };
51
+ }, [data]);
52
+ return {
53
+ data,
54
+ subscription,
55
+ loading,
56
+ error,
57
+ stats,
58
+ page,
59
+ refetch: fetchData,
60
+ nextPage: () => setPage((p) => p + 1),
61
+ prevPage: () => page > 1 && setPage((p) => p - 1)
62
+ };
63
+ }
64
+
65
+ // src/ui/hooks/useProjectMutations.ts
66
+ import { useCallback as useCallback2, useState as useState2 } from "react";
67
+ import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
68
+ function useProjectMutations(options = {}) {
69
+ const { handlers, projectId } = useTemplateRuntime2();
70
+ const { saas } = handlers;
71
+ const [createState, setCreateState] = useState2({
72
+ loading: false,
73
+ error: null,
74
+ data: null
75
+ });
76
+ const [updateState, setUpdateState] = useState2({
77
+ loading: false,
78
+ error: null,
79
+ data: null
80
+ });
81
+ const [deleteState, setDeleteState] = useState2({
82
+ loading: false,
83
+ error: null,
84
+ data: null
85
+ });
86
+ const createProject = useCallback2(async (input) => {
87
+ setCreateState({ loading: true, error: null, data: null });
88
+ try {
89
+ const result = await saas.createProject(input, {
90
+ projectId,
91
+ organizationId: "demo-org"
92
+ });
93
+ setCreateState({ loading: false, error: null, data: result });
94
+ options.onSuccess?.();
95
+ return result;
96
+ } catch (err) {
97
+ const error = err instanceof Error ? err : new Error("Failed to create project");
98
+ setCreateState({ loading: false, error, data: null });
99
+ options.onError?.(error);
100
+ return null;
101
+ }
102
+ }, [saas, projectId, options]);
103
+ const updateProject = useCallback2(async (input) => {
104
+ setUpdateState({ loading: true, error: null, data: null });
105
+ try {
106
+ const result = await saas.updateProject(input);
107
+ setUpdateState({ loading: false, error: null, data: result });
108
+ options.onSuccess?.();
109
+ return result;
110
+ } catch (err) {
111
+ const error = err instanceof Error ? err : new Error("Failed to update project");
112
+ setUpdateState({ loading: false, error, data: null });
113
+ options.onError?.(error);
114
+ return null;
115
+ }
116
+ }, [saas, options]);
117
+ const deleteProject = useCallback2(async (id) => {
118
+ setDeleteState({ loading: true, error: null, data: null });
119
+ try {
120
+ await saas.deleteProject(id);
121
+ setDeleteState({
122
+ loading: false,
123
+ error: null,
124
+ data: { success: true }
125
+ });
126
+ options.onSuccess?.();
127
+ return true;
128
+ } catch (err) {
129
+ const error = err instanceof Error ? err : new Error("Failed to delete project");
130
+ setDeleteState({ loading: false, error, data: null });
131
+ options.onError?.(error);
132
+ return false;
133
+ }
134
+ }, [saas, options]);
135
+ const archiveProject = useCallback2(async (id) => {
136
+ return updateProject({ id, status: "ARCHIVED" });
137
+ }, [updateProject]);
138
+ const activateProject = useCallback2(async (id) => {
139
+ return updateProject({ id, status: "ACTIVE" });
140
+ }, [updateProject]);
141
+ return {
142
+ createProject,
143
+ updateProject,
144
+ deleteProject,
145
+ archiveProject,
146
+ activateProject,
147
+ createState,
148
+ updateState,
149
+ deleteState,
150
+ isLoading: createState.loading || updateState.loading || deleteState.loading
151
+ };
152
+ }
153
+
154
+ // src/ui/hooks/index.ts
155
+ "use client";
156
+ export {
157
+ useProjectMutations,
158
+ useProjectList
159
+ };
@@ -0,0 +1,66 @@
1
+ // src/ui/hooks/useProjectList.ts
2
+ import { useCallback, useEffect, useMemo, useState } from "react";
3
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ function useProjectList(options = {}) {
5
+ const { handlers, projectId } = useTemplateRuntime();
6
+ const { saas } = handlers;
7
+ const [data, setData] = useState(null);
8
+ const [subscription, setSubscription] = useState(null);
9
+ const [loading, setLoading] = useState(true);
10
+ const [error, setError] = useState(null);
11
+ const [page, setPage] = useState(1);
12
+ const fetchData = useCallback(async () => {
13
+ setLoading(true);
14
+ setError(null);
15
+ try {
16
+ const [projectsResult, subscriptionResult] = await Promise.all([
17
+ saas.listProjects({
18
+ projectId,
19
+ status: options.status === "all" ? undefined : options.status,
20
+ search: options.search,
21
+ limit: options.limit ?? 20,
22
+ offset: (page - 1) * (options.limit ?? 20)
23
+ }),
24
+ saas.getSubscription({ projectId })
25
+ ]);
26
+ setData({
27
+ items: projectsResult.items,
28
+ total: projectsResult.total
29
+ });
30
+ setSubscription(subscriptionResult);
31
+ } catch (err) {
32
+ setError(err instanceof Error ? err : new Error("Unknown error"));
33
+ } finally {
34
+ setLoading(false);
35
+ }
36
+ }, [saas, projectId, options.status, options.search, options.limit, page]);
37
+ useEffect(() => {
38
+ fetchData();
39
+ }, [fetchData]);
40
+ const stats = useMemo(() => {
41
+ if (!data)
42
+ return null;
43
+ const items = data.items;
44
+ return {
45
+ total: data.total,
46
+ activeCount: items.filter((p) => p.status === "ACTIVE").length,
47
+ draftCount: items.filter((p) => p.status === "DRAFT").length,
48
+ projectLimit: 10,
49
+ usagePercent: Math.min(data.total / 10 * 100, 100)
50
+ };
51
+ }, [data]);
52
+ return {
53
+ data,
54
+ subscription,
55
+ loading,
56
+ error,
57
+ stats,
58
+ page,
59
+ refetch: fetchData,
60
+ nextPage: () => setPage((p) => p + 1),
61
+ prevPage: () => page > 1 && setPage((p) => p - 1)
62
+ };
63
+ }
64
+ export {
65
+ useProjectList
66
+ };
@@ -0,0 +1,91 @@
1
+ // src/ui/hooks/useProjectMutations.ts
2
+ import { useCallback, useState } from "react";
3
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ function useProjectMutations(options = {}) {
5
+ const { handlers, projectId } = useTemplateRuntime();
6
+ const { saas } = handlers;
7
+ const [createState, setCreateState] = useState({
8
+ loading: false,
9
+ error: null,
10
+ data: null
11
+ });
12
+ const [updateState, setUpdateState] = useState({
13
+ loading: false,
14
+ error: null,
15
+ data: null
16
+ });
17
+ const [deleteState, setDeleteState] = useState({
18
+ loading: false,
19
+ error: null,
20
+ data: null
21
+ });
22
+ const createProject = useCallback(async (input) => {
23
+ setCreateState({ loading: true, error: null, data: null });
24
+ try {
25
+ const result = await saas.createProject(input, {
26
+ projectId,
27
+ organizationId: "demo-org"
28
+ });
29
+ setCreateState({ loading: false, error: null, data: result });
30
+ options.onSuccess?.();
31
+ return result;
32
+ } catch (err) {
33
+ const error = err instanceof Error ? err : new Error("Failed to create project");
34
+ setCreateState({ loading: false, error, data: null });
35
+ options.onError?.(error);
36
+ return null;
37
+ }
38
+ }, [saas, projectId, options]);
39
+ const updateProject = useCallback(async (input) => {
40
+ setUpdateState({ loading: true, error: null, data: null });
41
+ try {
42
+ const result = await saas.updateProject(input);
43
+ setUpdateState({ loading: false, error: null, data: result });
44
+ options.onSuccess?.();
45
+ return result;
46
+ } catch (err) {
47
+ const error = err instanceof Error ? err : new Error("Failed to update project");
48
+ setUpdateState({ loading: false, error, data: null });
49
+ options.onError?.(error);
50
+ return null;
51
+ }
52
+ }, [saas, options]);
53
+ const deleteProject = useCallback(async (id) => {
54
+ setDeleteState({ loading: true, error: null, data: null });
55
+ try {
56
+ await saas.deleteProject(id);
57
+ setDeleteState({
58
+ loading: false,
59
+ error: null,
60
+ data: { success: true }
61
+ });
62
+ options.onSuccess?.();
63
+ return true;
64
+ } catch (err) {
65
+ const error = err instanceof Error ? err : new Error("Failed to delete project");
66
+ setDeleteState({ loading: false, error, data: null });
67
+ options.onError?.(error);
68
+ return false;
69
+ }
70
+ }, [saas, options]);
71
+ const archiveProject = useCallback(async (id) => {
72
+ return updateProject({ id, status: "ARCHIVED" });
73
+ }, [updateProject]);
74
+ const activateProject = useCallback(async (id) => {
75
+ return updateProject({ id, status: "ACTIVE" });
76
+ }, [updateProject]);
77
+ return {
78
+ createProject,
79
+ updateProject,
80
+ deleteProject,
81
+ archiveProject,
82
+ activateProject,
83
+ createState,
84
+ updateState,
85
+ deleteState,
86
+ isLoading: createState.loading || updateState.loading || deleteState.loading
87
+ };
88
+ }
89
+ export {
90
+ useProjectMutations
91
+ };