@contember/create 1.4.0-rc.4 → 1.4.0-rc.6

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 (223) hide show
  1. package/dist/src/commands/WorkspaceCreateCommand.d.ts +4 -3
  2. package/dist/src/commands/WorkspaceCreateCommand.d.ts.map +1 -1
  3. package/dist/src/commands/WorkspaceCreateCommand.js +10 -4
  4. package/dist/src/commands/WorkspaceCreateCommand.js.map +1 -1
  5. package/dist/src/lib/FileSystem.d.ts +14 -0
  6. package/dist/src/lib/FileSystem.d.ts.map +1 -0
  7. package/dist/src/lib/FileSystem.js +54 -0
  8. package/dist/src/lib/FileSystem.js.map +1 -0
  9. package/dist/src/lib/PackageDownloader.d.ts +7 -0
  10. package/dist/src/lib/PackageDownloader.d.ts.map +1 -0
  11. package/dist/src/lib/PackageDownloader.js +32 -0
  12. package/dist/src/lib/PackageDownloader.js.map +1 -0
  13. package/dist/src/lib/TemplateInstaller.d.ts +13 -0
  14. package/dist/src/lib/TemplateInstaller.d.ts.map +1 -0
  15. package/dist/src/lib/TemplateInstaller.js +75 -0
  16. package/dist/src/lib/TemplateInstaller.js.map +1 -0
  17. package/dist/src/lib/pathUtils.d.ts +3 -0
  18. package/dist/src/lib/pathUtils.d.ts.map +1 -0
  19. package/dist/src/lib/pathUtils.js +7 -0
  20. package/dist/src/lib/pathUtils.js.map +1 -0
  21. package/dist/src/run.js +7 -3
  22. package/dist/src/run.js.map +1 -1
  23. package/dist/src/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +9 -3
  25. package/resources/templates/template-workspace/.gitignore.dist +3 -0
  26. package/resources/templates/template-workspace/admin/.env.development +3 -0
  27. package/resources/templates/template-workspace/admin/.env.production +3 -0
  28. package/resources/templates/template-workspace/admin/app/components/layout.tsx +32 -0
  29. package/resources/templates/template-workspace/admin/app/components/logo.tsx +16 -0
  30. package/resources/templates/template-workspace/admin/app/components/navigation.tsx +1 -0
  31. package/resources/templates/template-workspace/admin/app/config.ts +27 -0
  32. package/resources/templates/template-workspace/admin/app/index.html +15 -0
  33. package/resources/templates/template-workspace/admin/app/index.tsx +40 -0
  34. package/resources/templates/template-workspace/admin/app/pages/index.tsx +5 -0
  35. package/resources/templates/template-workspace/admin/index.css +53 -0
  36. package/resources/templates/template-workspace/admin/index.html +13 -0
  37. package/resources/templates/template-workspace/admin/index.tsx +268 -0
  38. package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +45 -0
  39. package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +43 -0
  40. package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +71 -0
  41. package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +19 -0
  42. package/resources/templates/template-workspace/admin/lib/binding/index.ts +5 -0
  43. package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +70 -0
  44. package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +224 -0
  45. package/resources/templates/template-workspace/admin/lib/block-repeater/index.ts +1 -0
  46. package/resources/templates/template-workspace/admin/lib/board/board.tsx +240 -0
  47. package/resources/templates/template-workspace/admin/lib/board/index.ts +1 -0
  48. package/resources/templates/template-workspace/admin/lib/buttons/back-button.tsx +20 -0
  49. package/resources/templates/template-workspace/admin/lib/buttons/index.ts +2 -0
  50. package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +21 -0
  51. package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +64 -0
  52. package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +65 -0
  53. package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +166 -0
  54. package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +42 -0
  55. package/resources/templates/template-workspace/admin/lib/datagrid/empty.tsx +8 -0
  56. package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +17 -0
  57. package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +76 -0
  58. package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +29 -0
  59. package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +153 -0
  60. package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +115 -0
  61. package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +7 -0
  62. package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +19 -0
  63. package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +100 -0
  64. package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +180 -0
  65. package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +121 -0
  66. package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +61 -0
  67. package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +16 -0
  68. package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +32 -0
  69. package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +10 -0
  70. package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +103 -0
  71. package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +69 -0
  72. package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +24 -0
  73. package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +66 -0
  74. package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +153 -0
  75. package/resources/templates/template-workspace/admin/lib/dev/index.ts +2 -0
  76. package/resources/templates/template-workspace/admin/lib/dev/login-panel.tsx +56 -0
  77. package/resources/templates/template-workspace/admin/lib/dev/todo.tsx +14 -0
  78. package/resources/templates/template-workspace/admin/lib/dict.ts +324 -0
  79. package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +135 -0
  80. package/resources/templates/template-workspace/admin/lib/dimensions/index.ts +1 -0
  81. package/resources/templates/template-workspace/admin/lib/editor/block-editor.tsx +111 -0
  82. package/resources/templates/template-workspace/admin/lib/editor/common/baseEditorPlugins.tsx +66 -0
  83. package/resources/templates/template-workspace/admin/lib/editor/common/buttons.tsx +83 -0
  84. package/resources/templates/template-workspace/admin/lib/editor/common/editor-block-toolbar.tsx +17 -0
  85. package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +30 -0
  86. package/resources/templates/template-workspace/admin/lib/editor/common/editor-editable-canvas.tsx +50 -0
  87. package/resources/templates/template-workspace/admin/lib/editor/common/editor-inline-toolbar.tsx +63 -0
  88. package/resources/templates/template-workspace/admin/lib/editor/common/elements/AnchorRenderer.tsx +36 -0
  89. package/resources/templates/template-workspace/admin/lib/editor/common/elements/BlockElement.tsx +48 -0
  90. package/resources/templates/template-workspace/admin/lib/editor/common/elements/HeadingRenderer.tsx +48 -0
  91. package/resources/templates/template-workspace/admin/lib/editor/common/elements/HorizontalRuleRenderer.tsx +28 -0
  92. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ListItemRenderer.tsx +13 -0
  93. package/resources/templates/template-workspace/admin/lib/editor/common/elements/OrderedListRenderer.tsx +13 -0
  94. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ParagraphRenderer.tsx +15 -0
  95. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ScrollTargetRenderer.tsx +30 -0
  96. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableCellElementRenderer.tsx +20 -0
  97. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableElementRenderer.tsx +96 -0
  98. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableRowElementRenderer.tsx +15 -0
  99. package/resources/templates/template-workspace/admin/lib/editor/common/elements/UnorderedListRenderer.tsx +13 -0
  100. package/resources/templates/template-workspace/admin/lib/editor/common/index.ts +6 -0
  101. package/resources/templates/template-workspace/admin/lib/editor/editor-block.tsx +96 -0
  102. package/resources/templates/template-workspace/admin/lib/editor/index.ts +5 -0
  103. package/resources/templates/template-workspace/admin/lib/editor/plugins.tsx +36 -0
  104. package/resources/templates/template-workspace/admin/lib/editor/rich-text.tsx +54 -0
  105. package/resources/templates/template-workspace/admin/lib/editor/sortable-block.tsx +51 -0
  106. package/resources/templates/template-workspace/admin/lib/errors/index.ts +1 -0
  107. package/resources/templates/template-workspace/admin/lib/errors/use-error-formatter.ts +26 -0
  108. package/resources/templates/template-workspace/admin/lib/form/container.tsx +63 -0
  109. package/resources/templates/template-workspace/admin/lib/form/index.ts +5 -0
  110. package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +99 -0
  111. package/resources/templates/template-workspace/admin/lib/form/select.tsx +123 -0
  112. package/resources/templates/template-workspace/admin/lib/form/ui.tsx +29 -0
  113. package/resources/templates/template-workspace/admin/lib/form/upload.tsx +243 -0
  114. package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +62 -0
  115. package/resources/templates/template-workspace/admin/lib/formatting/index.ts +1 -0
  116. package/resources/templates/template-workspace/admin/lib/images/formatImageResizeUrl.ts +23 -0
  117. package/resources/templates/template-workspace/admin/lib/images/index.ts +1 -0
  118. package/resources/templates/template-workspace/admin/lib/layout/index.ts +2 -0
  119. package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +167 -0
  120. package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +24 -0
  121. package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/index.ts +1 -0
  122. package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/outdated-application-dialog.tsx +41 -0
  123. package/resources/templates/template-workspace/admin/lib/repeater/index.ts +1 -0
  124. package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +142 -0
  125. package/resources/templates/template-workspace/admin/lib/select/create-new.tsx +34 -0
  126. package/resources/templates/template-workspace/admin/lib/select/filter.tsx +13 -0
  127. package/resources/templates/template-workspace/admin/lib/select/highlight.tsx +16 -0
  128. package/resources/templates/template-workspace/admin/lib/select/index.ts +7 -0
  129. package/resources/templates/template-workspace/admin/lib/select/list.tsx +49 -0
  130. package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +95 -0
  131. package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +48 -0
  132. package/resources/templates/template-workspace/admin/lib/select/select.tsx +87 -0
  133. package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +129 -0
  134. package/resources/templates/template-workspace/admin/lib/select/ui.tsx +80 -0
  135. package/resources/templates/template-workspace/admin/lib/tenant/forms/change-my-password.tsx +40 -0
  136. package/resources/templates/template-workspace/admin/lib/tenant/forms/common.tsx +94 -0
  137. package/resources/templates/template-workspace/admin/lib/tenant/forms/create-api-key.tsx +39 -0
  138. package/resources/templates/template-workspace/admin/lib/tenant/forms/index.ts +8 -0
  139. package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +46 -0
  140. package/resources/templates/template-workspace/admin/lib/tenant/forms/login.tsx +52 -0
  141. package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +128 -0
  142. package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset-request.tsx +31 -0
  143. package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +44 -0
  144. package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +32 -0
  145. package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +28 -0
  146. package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInviteUser.tsx +45 -0
  147. package/resources/templates/template-workspace/admin/lib/tenant/index.ts +3 -0
  148. package/resources/templates/template-workspace/admin/lib/tenant/listing/api-key-list.tsx +25 -0
  149. package/resources/templates/template-workspace/admin/lib/tenant/listing/index.ts +4 -0
  150. package/resources/templates/template-workspace/admin/lib/tenant/listing/member-delete-dialog.tsx +38 -0
  151. package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +147 -0
  152. package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +25 -0
  153. package/resources/templates/template-workspace/admin/lib/tenant/otp/index.ts +1 -0
  154. package/resources/templates/template-workspace/admin/lib/tenant/otp/otp-setup.tsx +146 -0
  155. package/resources/templates/template-workspace/admin/lib/toast/index.ts +2 -0
  156. package/resources/templates/template-workspace/admin/lib/toast/toast.tsx +112 -0
  157. package/resources/templates/template-workspace/admin/lib/toast/toaster.tsx +104 -0
  158. package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +59 -0
  159. package/resources/templates/template-workspace/admin/lib/ui/button.tsx +29 -0
  160. package/resources/templates/template-workspace/admin/lib/ui/card.tsx +25 -0
  161. package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +51 -0
  162. package/resources/templates/template-workspace/admin/lib/ui/divider.tsx +11 -0
  163. package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +108 -0
  164. package/resources/templates/template-workspace/admin/lib/ui/input.tsx +62 -0
  165. package/resources/templates/template-workspace/admin/lib/ui/label.tsx +7 -0
  166. package/resources/templates/template-workspace/admin/lib/ui/loader.tsx +30 -0
  167. package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +103 -0
  168. package/resources/templates/template-workspace/admin/lib/ui/overlay.tsx +33 -0
  169. package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +31 -0
  170. package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +25 -0
  171. package/resources/templates/template-workspace/admin/lib/ui/scroll-area.tsx +45 -0
  172. package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +67 -0
  173. package/resources/templates/template-workspace/admin/lib/ui/sortable.tsx +13 -0
  174. package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +10 -0
  175. package/resources/templates/template-workspace/admin/lib/ui/table.tsx +46 -0
  176. package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +18 -0
  177. package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +44 -0
  178. package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +29 -0
  179. package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +24 -0
  180. package/resources/templates/template-workspace/admin/lib/upload/dropzone.tsx +21 -0
  181. package/resources/templates/template-workspace/admin/lib/upload/index.ts +3 -0
  182. package/resources/templates/template-workspace/admin/lib/upload/repeater.tsx +12 -0
  183. package/resources/templates/template-workspace/admin/lib/upload/ui.tsx +57 -0
  184. package/resources/templates/template-workspace/admin/lib/upload/upload-progress.tsx +130 -0
  185. package/resources/templates/template-workspace/admin/lib/upload/view.tsx +219 -0
  186. package/resources/templates/template-workspace/admin/lib/utils/cn.ts +4 -0
  187. package/resources/templates/template-workspace/admin/lib/utils/dict-format.tsx +3 -0
  188. package/resources/templates/template-workspace/admin/lib/utils/format-image-resize-url.ts +17 -0
  189. package/resources/templates/template-workspace/admin/lib/utils/formatting.ts +60 -0
  190. package/resources/templates/template-workspace/admin/lib/utils/index.ts +2 -0
  191. package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +79 -0
  192. package/resources/templates/template-workspace/admin/package.json +63 -0
  193. package/resources/templates/template-workspace/admin/postcss.config.js +6 -0
  194. package/resources/templates/template-workspace/admin/public/favicon.png +0 -0
  195. package/resources/templates/template-workspace/admin/tailwind.config.js +73 -0
  196. package/resources/templates/template-workspace/admin/tsconfig.json +23 -0
  197. package/resources/templates/template-workspace/admin/vite-env.d.ts +7 -0
  198. package/resources/templates/template-workspace/admin/vite.config.ts +39 -0
  199. package/resources/templates/template-workspace/api/index.ts +7 -0
  200. package/resources/templates/template-workspace/api/migrations/.gitkeep +1 -0
  201. package/resources/templates/template-workspace/api/model/index.ts +1 -0
  202. package/resources/templates/template-workspace/api/package.json +16 -0
  203. package/resources/templates/template-workspace/api/tsconfig.json +10 -0
  204. package/resources/templates/template-workspace/biome.json +45 -0
  205. package/resources/templates/template-workspace/client/package.json +16 -0
  206. package/resources/templates/template-workspace/client/src/index.ts +1 -0
  207. package/resources/templates/template-workspace/client/tsconfig.json +9 -0
  208. package/resources/templates/template-workspace/contember.template.yaml +7 -0
  209. package/resources/templates/template-workspace/docker-compose.yaml +124 -0
  210. package/resources/templates/template-workspace/package.json +32 -0
  211. package/resources/templates/template-workspace/scripts/generate-client.sh +8 -0
  212. package/resources/templates/template-workspace/tsconfig.json +9 -0
  213. package/resources/templates/template-workspace/tsconfig.settings.json +15 -0
  214. package/src/commands/WorkspaceCreateCommand.ts +15 -6
  215. package/src/lib/FileSystem.ts +24 -0
  216. package/src/lib/PackageDownloader.ts +33 -0
  217. package/src/lib/TemplateInstaller.ts +102 -0
  218. package/src/lib/pathUtils.ts +4 -0
  219. package/src/run.ts +14 -5
  220. package/tsconfig.settings.json +5 -1
  221. package/types/download-tarball/index.d.ts +7 -0
  222. package/types/get-package-json-from-registry/index.d.ts +3 -0
  223. package/types/registry-info/index.d.ts +7 -0
@@ -0,0 +1,268 @@
1
+ import './index.css'
2
+ import { dict } from '@app/lib/dict'
3
+ import { LoginFormFields, PasswordResetRequestFormFields } from '@app/lib/tenant'
4
+ import { PasswordResetFormFields } from '@app/lib/tenant'
5
+ import { ToastContent, Toaster, useShowToast } from '@app/lib/toast'
6
+ import { AnchorButton, Button } from '@app/lib/ui/button'
7
+ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@app/lib/ui/card'
8
+ import { Loader } from '@app/lib/ui/loader'
9
+ import { Overlay } from '@app/lib/ui/overlay'
10
+ import { Pages, useIdentity } from '@contember/interface'
11
+ import { ContemberClient } from '@contember/react-client'
12
+ import { createErrorHandler } from '@contember/react-devbar'
13
+ import {
14
+ IDP,
15
+ IDPInitTrigger,
16
+ IDPState,
17
+ IdentityProvider,
18
+ IdentityState,
19
+ LoginForm,
20
+ LogoutTrigger,
21
+ PasswordResetForm,
22
+ PasswordResetRequestForm,
23
+ } from '@contember/react-identity'
24
+ import { Link, RoutingProvider, useCurrentRequest, useRedirect } from '@contember/react-routing'
25
+ import { MailIcon } from 'lucide-react'
26
+ import { useEffect } from 'react'
27
+ import { createRoot } from 'react-dom/client'
28
+
29
+ const errorHandler = createErrorHandler((dom, react, onRecoverableError) => createRoot(dom, { onRecoverableError }).render(react))
30
+
31
+ const rootEl = document.body.appendChild(document.createElement('div'))
32
+
33
+ // Un-comment this to setup idp sign in
34
+ // const Idps = {
35
+ // google: 'Login with Google',
36
+ // }
37
+
38
+ const hasTokenFromEnv = import.meta.env.VITE_CONTEMBER_ADMIN_SESSION_TOKEN !== '__SESSION_TOKEN__'
39
+ const appUrl = '/app'
40
+
41
+ const Login = () => {
42
+ const showToast = useShowToast()
43
+ return (
44
+ <>
45
+ <IDP
46
+ onInitError={error =>
47
+ showToast(
48
+ <ToastContent>
49
+ {dict.tenant.login.idpInitError} {error}
50
+ </ToastContent>,
51
+ { type: 'error' },
52
+ )
53
+ }
54
+ onResponseError={error =>
55
+ showToast(
56
+ <ToastContent>
57
+ {dict.tenant.login.idpResponseError} {error}
58
+ </ToastContent>,
59
+ { type: 'error' },
60
+ )
61
+ }
62
+ >
63
+ <Card className="w-96 relative">
64
+ <CardHeader>
65
+ <CardTitle className="text-2xl">{dict.tenant.login.title}</CardTitle>
66
+ <CardDescription>{dict.tenant.login.description}</CardDescription>
67
+ </CardHeader>
68
+ <CardContent>
69
+ {hasTokenFromEnv && (
70
+ <AnchorButton href={appUrl} size="lg" className="w-full" variant="destructive">
71
+ Continue as default user
72
+ </AnchorButton>
73
+ )}
74
+ <LoginForm>
75
+ <form className="grid gap-4">
76
+ <LoginFormFields />
77
+ </form>
78
+ </LoginForm>
79
+
80
+ {/* Un-comment this to setup idp sign in */}
81
+ {/*{Object.entries(Idps).map(([idp, label]) => (*/}
82
+ {/* <IDPInitTrigger key={idp} identityProvider={idp}>*/}
83
+ {/* <Button variant="outline" className="w-full">*/}
84
+ {/* {label}*/}
85
+ {/* </Button>*/}
86
+ {/* </IDPInitTrigger>*/}
87
+ {/*))}*/}
88
+ </CardContent>
89
+ <IDPState state={['processing_init', 'processing_response', 'success']}>
90
+ <Loader />
91
+ </IDPState>
92
+ </Card>
93
+ </IDP>
94
+ </>
95
+ )
96
+ }
97
+
98
+ const LoggedIn = () => {
99
+ const identity = useIdentity()
100
+ useEffect(() => {
101
+ setTimeout(() => {
102
+ window.location.href = appUrl
103
+ }, 500)
104
+ }, [])
105
+
106
+ return (
107
+ <Card className="w-96 relative">
108
+ <CardHeader>
109
+ <CardTitle className="text-2xl">Logged in </CardTitle>
110
+ <CardDescription>as {identity?.person?.email ?? 'unknown'}</CardDescription>
111
+ </CardHeader>
112
+ <Loader position="static" />
113
+ </Card>
114
+ )
115
+ }
116
+
117
+ const IndexPage = () => {
118
+ return (
119
+ <IdentityProvider>
120
+ <IdentityState state={['none', 'cleared']}>
121
+ <Login />
122
+ </IdentityState>
123
+ <IdentityState state="success">
124
+ <LoggedIn />
125
+ </IdentityState>
126
+ <IdentityState state="loading">
127
+ <Loader />
128
+ </IdentityState>
129
+ <IdentityState state="failed">
130
+ <Overlay>
131
+ <div className="bg-gray-100 flex flex-col gap-4 items-center justify-center p-16 rounded-lg shadow-lg border">
132
+ <p className="text-lg">Failed to load identity.</p>
133
+ <LogoutTrigger>
134
+ <Button className="w-full" variant="outline">
135
+ Logout
136
+ </Button>
137
+ </LogoutTrigger>
138
+ </div>
139
+ </Overlay>
140
+ </IdentityState>
141
+ </IdentityProvider>
142
+ )
143
+ }
144
+
145
+ const PasswordResetRequestPage = () => {
146
+ const redirect = useRedirect()
147
+ return (
148
+ <Card className="w-96">
149
+ <CardHeader>
150
+ <CardTitle className="text-2xl">{dict.tenant.passwordResetRequest.title}</CardTitle>
151
+ <CardDescription>{dict.tenant.passwordResetRequest.description}</CardDescription>
152
+ </CardHeader>
153
+ <CardContent>
154
+ <PasswordResetRequestForm onSuccess={() => redirect('resetRequestSuccess')}>
155
+ <form>
156
+ <PasswordResetRequestFormFields />
157
+ </form>
158
+ </PasswordResetRequestForm>
159
+ </CardContent>
160
+ <CardFooter>
161
+ <Link to="index">
162
+ <AnchorButton variant="link" className="ml-auto">
163
+ {dict.tenant.login.backToLogin}
164
+ </AnchorButton>
165
+ </Link>
166
+ </CardFooter>
167
+ </Card>
168
+ )
169
+ }
170
+
171
+ const PasswordResetPage = () => {
172
+ const request = useCurrentRequest()
173
+ const redirect = useRedirect()
174
+ const showToast = useShowToast()
175
+ const token = request?.parameters.token as string | undefined
176
+ return (
177
+ <Card className="w-96">
178
+ <CardHeader>
179
+ <CardTitle className="text-2xl">{dict.tenant.passwordReset.title}</CardTitle>
180
+ <CardDescription>{dict.tenant.passwordReset.description}</CardDescription>
181
+ </CardHeader>
182
+ <CardContent>
183
+ <PasswordResetForm
184
+ onSuccess={() => {
185
+ showToast(<ToastContent>Password has been reset</ToastContent>, { type: 'success' })
186
+ redirect('index')
187
+ }}
188
+ token={token}
189
+ >
190
+ <form>
191
+ <PasswordResetFormFields hasToken={!!token} />
192
+ </form>
193
+ </PasswordResetForm>
194
+ </CardContent>
195
+ <CardFooter>
196
+ <Link to="index">
197
+ <AnchorButton variant="link" className="ml-auto">
198
+ {dict.tenant.login.backToLogin}
199
+ </AnchorButton>
200
+ </Link>
201
+ </CardFooter>
202
+ </Card>
203
+ )
204
+ }
205
+
206
+ const PasswordResetRequestSuccessPage = () => (
207
+ <Card className="w-96">
208
+ <CardHeader>
209
+ <CardTitle className="text-2xl">{dict.tenant.passwordResetRequest.title}</CardTitle>
210
+ <CardDescription>{dict.tenant.passwordResetRequest.description}</CardDescription>
211
+ </CardHeader>
212
+ <CardContent>
213
+ <div className="flex flex-col items-center justify-center gap-4">
214
+ <MailIcon className="text-gray-300 w-16 h-16" />
215
+ <div className="text-center">An email with password reset instructions has been sent to your email address.</div>
216
+ <div className="text-center text-gray-500">
217
+ <Link to="passwordReset">
218
+ <a className="underline">{dict.tenant.passwordResetRequest.entryCode}</a>
219
+ </Link>
220
+ </div>
221
+ </div>
222
+ </CardContent>
223
+ <CardFooter>
224
+ <Link to="index">
225
+ <AnchorButton variant="link" className="ml-auto">
226
+ {dict.tenant.login.backToLogin}
227
+ </AnchorButton>
228
+ </Link>
229
+ </CardFooter>
230
+ </Card>
231
+ )
232
+
233
+ const Layout = ({ children }: { children?: React.ReactNode }) => (
234
+ <div className="grid md:grid-cols-2 min-h-screen ">
235
+ <div className="bg-gray-100 p-4 flex items-center justify-center">{children}</div>
236
+ <div className="bg-gray-700 text-white p-4 flex items-center justify-center">
237
+ <div className="w-full max-w-md">
238
+ <div className="text-center text-2xl">Welcome to your app</div>
239
+ {/*<p className="mt-8 text-center text-gray-300">*/}
240
+ {/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, sem eget ultricies ultricies, sapien urna tristique eros, ac*/}
241
+ {/* tincidunt felis lacus nec nunc.*/}
242
+ {/*</p>*/}
243
+ </div>
244
+ </div>
245
+ </div>
246
+ )
247
+
248
+ errorHandler(onRecoverableError =>
249
+ createRoot(rootEl, { onRecoverableError }).render(
250
+ <>
251
+ <ContemberClient apiBaseUrl={import.meta.env.VITE_CONTEMBER_ADMIN_API_BASE_URL} loginToken={import.meta.env.VITE_CONTEMBER_ADMIN_LOGIN_TOKEN}>
252
+ <RoutingProvider pageInQuery>
253
+ <Toaster>
254
+ <Pages
255
+ layout={Layout}
256
+ children={{
257
+ index: IndexPage,
258
+ resetRequest: PasswordResetRequestPage,
259
+ resetRequestSuccess: PasswordResetRequestSuccessPage,
260
+ passwordReset: PasswordResetPage,
261
+ }}
262
+ />
263
+ </Toaster>
264
+ </RoutingProvider>
265
+ </ContemberClient>
266
+ </>,
267
+ ),
268
+ )
@@ -0,0 +1,45 @@
1
+ import { ReactNode, useEffect } from 'react'
2
+ import { AccessorTreeState, DataBindingProvider } from '@contember/interface'
3
+ import { Loader } from '../ui/loader'
4
+
5
+ export const Binding = ({ children }: {
6
+ children: ReactNode
7
+ }) => {
8
+ return (
9
+ <DataBindingProvider stateComponent={BindingStateRenderer}>
10
+ {children}
11
+ </DataBindingProvider>
12
+ )
13
+ }
14
+
15
+ export interface BindingStateRendererProps {
16
+ accessorTreeState: AccessorTreeState
17
+ children?: ReactNode
18
+ }
19
+
20
+
21
+ function BindingStateRenderer({ accessorTreeState, children }: BindingStateRendererProps) {
22
+ useEffect(() => {
23
+ if (accessorTreeState.name === 'error' && accessorTreeState.error.type === 'unauthorized') {
24
+ window.location.href = '/' // redirect to login
25
+ }
26
+ }, [accessorTreeState])
27
+
28
+ if (accessorTreeState.name === 'initializing') {
29
+ return <Loader />
30
+ }
31
+
32
+ if (accessorTreeState.name === 'error') {
33
+ if (accessorTreeState.error.type === 'unauthorized') {
34
+ return null // This results in a redirect for now, and so the actual handling is in an effect
35
+ }
36
+ if (import.meta.env.DEV) {
37
+ throw accessorTreeState.error
38
+ }
39
+
40
+ return <div>{accessorTreeState.error.type}</div>
41
+ }
42
+
43
+ return <>{children}</>
44
+ }
45
+
@@ -0,0 +1,43 @@
1
+ import {
2
+ AlertDialog,
3
+ AlertDialogAction,
4
+ AlertDialogCancel,
5
+ AlertDialogContent,
6
+ AlertDialogDescription,
7
+ AlertDialogFooter,
8
+ AlertDialogHeader,
9
+ AlertDialogTitle,
10
+ AlertDialogTrigger,
11
+ } from '../ui/alert-dialog'
12
+ import { Button } from '../ui/button'
13
+ import * as React from 'react'
14
+ import { ReactElement } from 'react'
15
+ import { DeleteEntityTrigger } from '@contember/interface'
16
+ import { FeedbackTrigger } from './persist'
17
+ import { dict } from '../dict'
18
+
19
+ export const DeleteEntityDialog = ({ trigger, immediatePersist }: { trigger: ReactElement, immediatePersist?: boolean }) => {
20
+ return (
21
+ <AlertDialog>
22
+ <AlertDialogTrigger asChild>
23
+ {trigger}
24
+ </AlertDialogTrigger>
25
+ <AlertDialogContent>
26
+ <AlertDialogHeader>
27
+ <AlertDialogTitle>{dict.deleteEntityDialog.title}</AlertDialogTitle>
28
+ <AlertDialogDescription>{dict.deleteEntityDialog.description}</AlertDialogDescription>
29
+ </AlertDialogHeader>
30
+ <AlertDialogFooter>
31
+ <AlertDialogCancel>{dict.deleteEntityDialog.cancelButton}</AlertDialogCancel>
32
+ <FeedbackTrigger>
33
+ <DeleteEntityTrigger immediatePersist={immediatePersist ?? true}>
34
+ <AlertDialogAction asChild>
35
+ <Button variant={'destructive'}>{dict.deleteEntityDialog.confirmButton}</Button>
36
+ </AlertDialogAction>
37
+ </DeleteEntityTrigger>
38
+ </FeedbackTrigger>
39
+ </AlertDialogFooter>
40
+ </AlertDialogContent>
41
+ </AlertDialog>
42
+ )
43
+ }
@@ -0,0 +1,71 @@
1
+ import { ReactNode, useCallback } from 'react'
2
+ import { dict } from '../dict'
3
+ import { ToastContent, useShowToast } from '../toast'
4
+ import { ErrorAccessor, ErrorPersistResult, SuccessfulPersistResult, usePersist } from '@contember/interface'
5
+ import { useErrorFormatter } from '../errors'
6
+
7
+ export const usePersistWithFeedback = () => {
8
+ const triggerPersist = usePersist()
9
+ const { onPersistSuccess, onPersistError } = usePersistFeedbackHandlers()
10
+ return useCallback(() => {
11
+ return triggerPersist()
12
+ .then(onPersistSuccess)
13
+ .catch(onPersistError)
14
+ }, [onPersistError, onPersistSuccess, triggerPersist])
15
+ }
16
+
17
+
18
+ export const usePersistFeedbackHandlers = () => {
19
+ return {
20
+ onPersistError: usePersistErrorHandler(),
21
+ onPersistSuccess: usePersistSuccessHandler(),
22
+ }
23
+ }
24
+
25
+ export const usePersistErrorHandler = () => {
26
+ const showToast = useShowToast()
27
+ const errorFormatter = useErrorFormatter()
28
+ return useCallback((result: ErrorPersistResult) => {
29
+ if (result.type === 'invalidInput') {
30
+ const errorList = errorFormatter(result.errors)
31
+ showToast(
32
+ <ToastContent
33
+ title={dict.persist.invalidInputError}
34
+ children={<ul>{errorList.map((it, i) => <li key={i}>{it}</li>)}</ul>}
35
+ details={result.response?.errorMessage}
36
+ />, {
37
+ type: 'error',
38
+ })
39
+ } else if (result.type === 'invalidResponse') {
40
+ showToast(
41
+ <ToastContent
42
+ title={dict.persist.invalidResponseError}
43
+ children={dict.persist.invalidResponseErrorDetails}
44
+ />, {
45
+ type: 'error',
46
+ },
47
+ )
48
+ }
49
+ }, [errorFormatter, showToast])
50
+ }
51
+
52
+ export const usePersistSuccessHandler = () => {
53
+ const showToast = useShowToast()
54
+
55
+ return useCallback((result: SuccessfulPersistResult) => {
56
+ showToast(
57
+ <ToastContent
58
+ title={dict.persist.success}
59
+ />, {
60
+ type: 'success',
61
+ })
62
+ if (result.type === 'justSuccess' && result.afterPersistError) {
63
+ showToast(
64
+ <ToastContent
65
+ title={dict.persist.afterPersistError}
66
+ />, {
67
+ type: 'warning',
68
+ })
69
+ }
70
+ }, [showToast])
71
+ }
@@ -0,0 +1,19 @@
1
+ import { IdentityState } from '@contember/react-identity'
2
+ import { Loader } from '../ui/loader'
3
+ import { dict } from '../dict'
4
+
5
+ export const IdentityLoader = ({ children }: {
6
+ children: React.ReactNode
7
+ }) => {
8
+ return <>
9
+ <IdentityState state={['loading', 'none', 'cleared']}>
10
+ <Loader />
11
+ </IdentityState>
12
+ <IdentityState state={'failed'}>
13
+ {dict.identityLoader.fail}
14
+ </IdentityState>
15
+ <IdentityState state={'success'}>
16
+ {children}
17
+ </IdentityState>
18
+ </>
19
+ }
@@ -0,0 +1,5 @@
1
+ export * from './binding'
2
+ export * from './delete'
3
+ export * from './hooks'
4
+ export * from './identity'
5
+ export * from './persist'
@@ -0,0 +1,70 @@
1
+ import { PersistTrigger, SugaredRelativeSingleField, useField } from '@contember/interface'
2
+ import { Button } from '../ui/button'
3
+ import { Loader } from '../ui/loader'
4
+ import { ReactElement, ReactNode, useEffect } from 'react'
5
+ import { Slot } from '@radix-ui/react-slot'
6
+ import { usePersist } from '@contember/interface'
7
+ import { dict } from '../dict'
8
+ import { usePersistErrorHandler, usePersistFeedbackHandlers, usePersistWithFeedback } from './hooks'
9
+
10
+ export const FeedbackTrigger = (props: { children: ReactElement }) => {
11
+ return <Slot {...props} {...usePersistFeedbackHandlers()} />
12
+ }
13
+
14
+ export const PersistButton = ({ label }: {
15
+ label?: ReactNode
16
+ }) => {
17
+ return (
18
+ <FeedbackTrigger>
19
+ <PersistTrigger>
20
+ <Button className="group">
21
+ <Loader size="sm" position="absolute" className="hidden group-data-[loading]:block" />
22
+ {label ?? dict.persist.persistButton}
23
+ </Button>
24
+ </PersistTrigger>
25
+ </FeedbackTrigger>
26
+ )
27
+ }
28
+
29
+
30
+ export const PersistOnCmdS = () => {
31
+ const persist = usePersistWithFeedback()
32
+ useEffect(() => {
33
+ const listener = (event: KeyboardEvent) => {
34
+ if (event.ctrlKey && event.key === 's') {
35
+ event.preventDefault()
36
+ persist()
37
+ }
38
+ }
39
+ document.body.addEventListener('keydown', listener)
40
+ return () => document.body.removeEventListener('keydown', listener)
41
+ }, [persist])
42
+
43
+ return null
44
+ }
45
+
46
+
47
+ export const PersistOnFieldChange = ({ field }: {
48
+ field: SugaredRelativeSingleField['field']
49
+ }) => {
50
+ const triggerPersist = usePersist()
51
+ const onError = usePersistErrorHandler()
52
+ const getField = useField(field).getAccessor
53
+ useEffect(() => {
54
+ let persisting = false
55
+ return getField().addEventListener({ type: 'update' }, async field => {
56
+ if (persisting || field.value === field.valueOnServer) {
57
+ return
58
+ }
59
+ persisting = true
60
+ try {
61
+ await Promise.resolve()
62
+ await triggerPersist().catch(onError)
63
+ } finally {
64
+ persisting = false
65
+ }
66
+ })
67
+ }, [getField, onError, triggerPersist])
68
+
69
+ return null
70
+ }