@btst/plugin-form-builder 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -0
- package/dist/api/getters.cjs +154 -0
- package/dist/api/getters.mjs +145 -0
- package/dist/api/index.cjs +25 -0
- package/dist/api/index.d.cts +119 -0
- package/dist/api/index.d.mts +119 -0
- package/dist/api/index.d.ts +119 -0
- package/dist/api/index.mjs +6 -0
- package/dist/api/lifecycle-migrations.cjs +15 -0
- package/dist/api/lifecycle-migrations.mjs +13 -0
- package/dist/api/operations.cjs +1093 -0
- package/dist/api/operations.mjs +1082 -0
- package/dist/api/plugin.cjs +201 -0
- package/dist/api/plugin.mjs +192 -0
- package/dist/api/query-key-defs.cjs +43 -0
- package/dist/api/query-key-defs.mjs +39 -0
- package/dist/client/components/forms/form-renderer.cjs +193 -0
- package/dist/client/components/forms/form-renderer.mjs +191 -0
- package/dist/client/components/index.cjs +29 -0
- package/dist/client/components/index.d.cts +97 -0
- package/dist/client/components/index.d.mts +97 -0
- package/dist/client/components/index.d.ts +97 -0
- package/dist/client/components/index.mjs +18 -0
- package/dist/client/components/loading/form-builder-skeleton.cjs +32 -0
- package/dist/client/components/loading/form-builder-skeleton.mjs +30 -0
- package/dist/client/components/loading/form-list-skeleton.cjs +21 -0
- package/dist/client/components/loading/form-list-skeleton.mjs +19 -0
- package/dist/client/components/loading/submissions-skeleton.cjs +34 -0
- package/dist/client/components/loading/submissions-skeleton.mjs +32 -0
- package/dist/client/components/pages/404-page.cjs +28 -0
- package/dist/client/components/pages/404-page.mjs +26 -0
- package/dist/client/components/pages/form-builder-page.cjs +77 -0
- package/dist/client/components/pages/form-builder-page.internal.cjs +217 -0
- package/dist/client/components/pages/form-builder-page.internal.mjs +215 -0
- package/dist/client/components/pages/form-builder-page.mjs +75 -0
- package/dist/client/components/pages/form-list-page.cjs +44 -0
- package/dist/client/components/pages/form-list-page.internal.cjs +282 -0
- package/dist/client/components/pages/form-list-page.internal.mjs +280 -0
- package/dist/client/components/pages/form-list-page.mjs +42 -0
- package/dist/client/components/pages/submissions-page.cjs +64 -0
- package/dist/client/components/pages/submissions-page.internal.cjs +255 -0
- package/dist/client/components/pages/submissions-page.internal.mjs +253 -0
- package/dist/client/components/pages/submissions-page.mjs +62 -0
- package/dist/client/components/shared/default-error.cjs +17 -0
- package/dist/client/components/shared/default-error.mjs +15 -0
- package/dist/client/components/shared/empty-state.cjs +16 -0
- package/dist/client/components/shared/empty-state.mjs +14 -0
- package/dist/client/components/shared/page-wrapper.cjs +29 -0
- package/dist/client/components/shared/page-wrapper.mjs +27 -0
- package/dist/client/components/shared/pagination.cjs +49 -0
- package/dist/client/components/shared/pagination.mjs +47 -0
- package/dist/client/constants.cjs +5 -0
- package/dist/client/constants.mjs +3 -0
- package/dist/client/hooks/form-builder-hooks.cjs +203 -0
- package/dist/client/hooks/form-builder-hooks.mjs +186 -0
- package/dist/client/hooks/form-builder-resource.cjs +13 -0
- package/dist/client/hooks/form-builder-resource.mjs +11 -0
- package/dist/client/hooks/index.cjs +22 -0
- package/dist/client/hooks/index.d.cts +378 -0
- package/dist/client/hooks/index.d.mts +378 -0
- package/dist/client/hooks/index.d.ts +378 -0
- package/dist/client/hooks/index.mjs +1 -0
- package/dist/client/index.cjs +13 -0
- package/dist/client/index.d.cts +410 -0
- package/dist/client/index.d.mts +410 -0
- package/dist/client/index.d.ts +410 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client/plugin.cjs +311 -0
- package/dist/client/plugin.mjs +309 -0
- package/dist/client.css +3 -0
- package/dist/db.cjs +99 -0
- package/dist/db.mjs +97 -0
- package/dist/permissions.cjs +95 -0
- package/dist/permissions.d.cts +94 -0
- package/dist/permissions.d.mts +94 -0
- package/dist/permissions.d.ts +94 -0
- package/dist/permissions.mjs +93 -0
- package/dist/query-keys.cjs +140 -0
- package/dist/query-keys.d.cts +392 -0
- package/dist/query-keys.d.mts +392 -0
- package/dist/query-keys.d.ts +392 -0
- package/dist/query-keys.mjs +137 -0
- package/dist/schemas.cjs +91 -0
- package/dist/schemas.mjs +82 -0
- package/dist/shared/plugin-form-builder.BZYGyFgT.d.mts +351 -0
- package/dist/shared/plugin-form-builder.Bbl9NufB.d.cts +408 -0
- package/dist/shared/plugin-form-builder.CSP5HR2O.d.ts +408 -0
- package/dist/shared/plugin-form-builder.Cmk083dA.d.cts +351 -0
- package/dist/shared/plugin-form-builder.D258Qpb8.d.ts +351 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.cts +118 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.mts +118 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.ts +118 -0
- package/dist/shared/plugin-form-builder.lp98rFNl.d.mts +408 -0
- package/dist/style.css +6 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +6 -0
- package/dist/types.d.mts +6 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.mjs +1 -0
- package/dist/ui/src/components/accordion.cjs +81 -0
- package/dist/ui/src/components/accordion.mjs +62 -0
- package/dist/ui/src/components/alert-dialog.cjs +157 -0
- package/dist/ui/src/components/alert-dialog.mjs +132 -0
- package/dist/ui/src/components/auto-form/common/label.cjs +18 -0
- package/dist/ui/src/components/auto-form/common/label.mjs +16 -0
- package/dist/ui/src/components/auto-form/common/tooltip.cjs +9 -0
- package/dist/ui/src/components/auto-form/common/tooltip.mjs +7 -0
- package/dist/ui/src/components/auto-form/config.cjs +40 -0
- package/dist/ui/src/components/auto-form/config.mjs +37 -0
- package/dist/ui/src/components/auto-form/dependencies.cjs +48 -0
- package/dist/ui/src/components/auto-form/dependencies.mjs +46 -0
- package/dist/ui/src/components/auto-form/fields/array.cjs +266 -0
- package/dist/ui/src/components/auto-form/fields/array.mjs +264 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/date.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/date.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/enum.cjs +73 -0
- package/dist/ui/src/components/auto-form/fields/enum.mjs +71 -0
- package/dist/ui/src/components/auto-form/fields/input.cjs +32 -0
- package/dist/ui/src/components/auto-form/fields/input.mjs +30 -0
- package/dist/ui/src/components/auto-form/fields/number.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/number.mjs +29 -0
- package/dist/ui/src/components/auto-form/fields/object.cjs +233 -0
- package/dist/ui/src/components/auto-form/fields/object.mjs +217 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/switch.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/switch.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/textarea.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/textarea.mjs +29 -0
- package/dist/ui/src/components/auto-form/helpers.cjs +270 -0
- package/dist/ui/src/components/auto-form/helpers.mjs +259 -0
- package/dist/ui/src/components/auto-form/index.cjs +92 -0
- package/dist/ui/src/components/auto-form/index.mjs +86 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.cjs +374 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
- package/dist/ui/src/components/auto-form/types.cjs +11 -0
- package/dist/ui/src/components/auto-form/types.mjs +9 -0
- package/dist/ui/src/components/button.cjs +56 -0
- package/dist/ui/src/components/button.mjs +53 -0
- package/dist/ui/src/components/calendar.cjs +207 -0
- package/dist/ui/src/components/calendar.mjs +190 -0
- package/dist/ui/src/components/checkbox.cjs +48 -0
- package/dist/ui/src/components/checkbox.mjs +32 -0
- package/dist/ui/src/components/date-picker.cjs +41 -0
- package/dist/ui/src/components/date-picker.mjs +39 -0
- package/dist/ui/src/components/dialog.cjs +141 -0
- package/dist/ui/src/components/dialog.mjs +118 -0
- package/dist/ui/src/components/dropdown-menu.cjs +81 -0
- package/dist/ui/src/components/dropdown-menu.mjs +62 -0
- package/dist/ui/src/components/form-builder/canvas.cjs +111 -0
- package/dist/ui/src/components/form-builder/canvas.mjs +109 -0
- package/dist/ui/src/components/form-builder/components/index.cjs +571 -0
- package/dist/ui/src/components/form-builder/components/index.mjs +554 -0
- package/dist/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
- package/dist/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
- package/dist/ui/src/components/form-builder/form-preview.cjs +73 -0
- package/dist/ui/src/components/form-builder/form-preview.mjs +71 -0
- package/dist/ui/src/components/form-builder/index.cjs +350 -0
- package/dist/ui/src/components/form-builder/index.mjs +344 -0
- package/dist/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
- package/dist/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
- package/dist/ui/src/components/form-builder/palette.cjs +52 -0
- package/dist/ui/src/components/form-builder/palette.mjs +49 -0
- package/dist/ui/src/components/form-builder/schema-utils.cjs +128 -0
- package/dist/ui/src/components/form-builder/schema-utils.mjs +122 -0
- package/dist/ui/src/components/form-builder/sortable-field.cjs +151 -0
- package/dist/ui/src/components/form-builder/sortable-field.mjs +148 -0
- package/dist/ui/src/components/form-builder/step-tabs.cjs +180 -0
- package/dist/ui/src/components/form-builder/step-tabs.mjs +178 -0
- package/dist/ui/src/components/form-builder/types.cjs +7 -0
- package/dist/ui/src/components/form-builder/types.mjs +5 -0
- package/dist/ui/src/components/form-builder/validation-schemas.cjs +67 -0
- package/dist/ui/src/components/form-builder/validation-schemas.mjs +56 -0
- package/dist/ui/src/components/form.cjs +120 -0
- package/dist/ui/src/components/form.mjs +98 -0
- package/dist/ui/src/components/input.cjs +23 -0
- package/dist/ui/src/components/input.mjs +21 -0
- package/dist/ui/src/components/label.cjs +39 -0
- package/dist/ui/src/components/label.mjs +23 -0
- package/dist/ui/src/components/page-layout.cjs +25 -0
- package/dist/ui/src/components/page-layout.mjs +23 -0
- package/dist/ui/src/components/page-wrapper.cjs +20 -0
- package/dist/ui/src/components/page-wrapper.mjs +18 -0
- package/dist/ui/src/components/popover.cjs +60 -0
- package/dist/ui/src/components/popover.mjs +42 -0
- package/dist/ui/src/components/radio-group.cjs +62 -0
- package/dist/ui/src/components/radio-group.mjs +45 -0
- package/dist/ui/src/components/select.cjs +161 -0
- package/dist/ui/src/components/select.mjs +139 -0
- package/dist/ui/src/components/separator.cjs +43 -0
- package/dist/ui/src/components/separator.mjs +27 -0
- package/dist/ui/src/components/skeleton.cjs +17 -0
- package/dist/ui/src/components/skeleton.mjs +15 -0
- package/dist/ui/src/components/stack-attribution.cjs +24 -0
- package/dist/ui/src/components/stack-attribution.mjs +22 -0
- package/dist/ui/src/components/switch.cjs +48 -0
- package/dist/ui/src/components/switch.mjs +32 -0
- package/dist/ui/src/components/table.cjs +89 -0
- package/dist/ui/src/components/table.mjs +82 -0
- package/dist/ui/src/components/tabs.cjs +84 -0
- package/dist/ui/src/components/tabs.mjs +65 -0
- package/dist/ui/src/components/textarea.cjs +20 -0
- package/dist/ui/src/components/textarea.mjs +18 -0
- package/dist/ui/src/lib/schema-converter.cjs +133 -0
- package/dist/ui/src/lib/schema-converter.mjs +127 -0
- package/dist/ui/src/lib/utils.cjs +10 -0
- package/dist/ui/src/lib/utils.mjs +8 -0
- package/dist/utils.cjs +41 -0
- package/dist/utils.mjs +32 -0
- package/package.json +175 -3
- package/README.md +0 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const skeleton = require('../../../ui/src/components/skeleton.cjs');
|
|
6
|
+
const pageWrapper = require('../shared/page-wrapper.cjs');
|
|
7
|
+
|
|
8
|
+
function SubmissionsSkeleton() {
|
|
9
|
+
return /* @__PURE__ */ jsxRuntime.jsx(pageWrapper.PageWrapper, { testId: "submissions-skeleton", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-5xl space-y-6", children: [
|
|
10
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
11
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
12
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-8 w-48" }),
|
|
13
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-64" })
|
|
14
|
+
] }),
|
|
15
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-10 w-32" })
|
|
16
|
+
] }),
|
|
17
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border", children: [
|
|
18
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-4", children: [
|
|
19
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-24" }),
|
|
20
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-48" }),
|
|
21
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-32" }),
|
|
22
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-20" })
|
|
23
|
+
] }) }),
|
|
24
|
+
Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b p-4 last:border-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-4", children: [
|
|
25
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-24" }),
|
|
26
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-48" }),
|
|
27
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-32" }),
|
|
28
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: "h-4 w-20" })
|
|
29
|
+
] }) }, i))
|
|
30
|
+
] })
|
|
31
|
+
] }) });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.SubmissionsSkeleton = SubmissionsSkeleton;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { Skeleton } from '../../../ui/src/components/skeleton.mjs';
|
|
4
|
+
import { PageWrapper } from '../shared/page-wrapper.mjs';
|
|
5
|
+
|
|
6
|
+
function SubmissionsSkeleton() {
|
|
7
|
+
return /* @__PURE__ */ jsx(PageWrapper, { testId: "submissions-skeleton", children: /* @__PURE__ */ jsxs("div", { className: "w-full max-w-5xl space-y-6", children: [
|
|
8
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
9
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
10
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-48" }),
|
|
11
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-64" })
|
|
12
|
+
] }),
|
|
13
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-32" })
|
|
14
|
+
] }),
|
|
15
|
+
/* @__PURE__ */ jsxs("div", { className: "rounded-lg border", children: [
|
|
16
|
+
/* @__PURE__ */ jsx("div", { className: "border-b p-4", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-4", children: [
|
|
17
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" }),
|
|
18
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-48" }),
|
|
19
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-32" }),
|
|
20
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-20" })
|
|
21
|
+
] }) }),
|
|
22
|
+
Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ jsx("div", { className: "border-b p-4 last:border-0", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-4", children: [
|
|
23
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" }),
|
|
24
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-48" }),
|
|
25
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-32" }),
|
|
26
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-20" })
|
|
27
|
+
] }) }, i))
|
|
28
|
+
] })
|
|
29
|
+
] }) });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { SubmissionsSkeleton };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const button = require('../../../ui/src/components/button.cjs');
|
|
6
|
+
const context = require('@btst/stack/context');
|
|
7
|
+
const constants = require('../../constants.cjs');
|
|
8
|
+
|
|
9
|
+
function NotFoundPage() {
|
|
10
|
+
const t = context.useTranslate();
|
|
11
|
+
const { localization } = context.usePluginOverrides(
|
|
12
|
+
constants.FORM_BUILDER_PLUGIN_ID
|
|
13
|
+
);
|
|
14
|
+
const { Link: LinkComponent, resolve } = context.usePluginSiteNavigation(
|
|
15
|
+
constants.FORM_BUILDER_PLUGIN_ID
|
|
16
|
+
);
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center py-12 px-4 text-center", children: [
|
|
18
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-6xl font-bold text-muted-foreground mb-4", children: "404" }),
|
|
19
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-xl font-medium text-foreground mb-2", children: localization?.FORM_BUILDER_404_TITLE ?? t("formBuilder.common.404Title", "Page not found") }),
|
|
20
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground mb-6 max-w-sm", children: localization?.FORM_BUILDER_404_DESCRIPTION ?? t(
|
|
21
|
+
"formBuilder.common.404Description",
|
|
22
|
+
"The page you're looking for doesn't exist or has been moved."
|
|
23
|
+
) }),
|
|
24
|
+
/* @__PURE__ */ jsxRuntime.jsx(button.Button, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(LinkComponent, { href: resolve("forms").href, children: localization?.FORM_BUILDER_404_BACK ?? t("formBuilder.common.404Back", "Back to Forms") }) })
|
|
25
|
+
] });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.NotFoundPage = NotFoundPage;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Button } from '../../../ui/src/components/button.mjs';
|
|
4
|
+
import { useTranslate, usePluginOverrides, usePluginSiteNavigation } from '@btst/stack/context';
|
|
5
|
+
import { FORM_BUILDER_PLUGIN_ID } from '../../constants.mjs';
|
|
6
|
+
|
|
7
|
+
function NotFoundPage() {
|
|
8
|
+
const t = useTranslate();
|
|
9
|
+
const { localization } = usePluginOverrides(
|
|
10
|
+
FORM_BUILDER_PLUGIN_ID
|
|
11
|
+
);
|
|
12
|
+
const { Link: LinkComponent, resolve } = usePluginSiteNavigation(
|
|
13
|
+
FORM_BUILDER_PLUGIN_ID
|
|
14
|
+
);
|
|
15
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center py-12 px-4 text-center", children: [
|
|
16
|
+
/* @__PURE__ */ jsx("h1", { className: "text-6xl font-bold text-muted-foreground mb-4", children: "404" }),
|
|
17
|
+
/* @__PURE__ */ jsx("h2", { className: "text-xl font-medium text-foreground mb-2", children: localization?.FORM_BUILDER_404_TITLE ?? t("formBuilder.common.404Title", "Page not found") }),
|
|
18
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mb-6 max-w-sm", children: localization?.FORM_BUILDER_404_DESCRIPTION ?? t(
|
|
19
|
+
"formBuilder.common.404Description",
|
|
20
|
+
"The page you're looking for doesn't exist or has been moved."
|
|
21
|
+
) }),
|
|
22
|
+
/* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsx(LinkComponent, { href: resolve("forms").href, children: localization?.FORM_BUILDER_404_BACK ?? t("formBuilder.common.404Back", "Back to Forms") }) })
|
|
23
|
+
] });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { NotFoundPage };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const React = require('react');
|
|
6
|
+
const context = require('@btst/stack/context');
|
|
7
|
+
const components = require('@btst/stack/client/components');
|
|
8
|
+
const defaultError = require('../shared/default-error.cjs');
|
|
9
|
+
const formBuilderSkeleton = require('../loading/form-builder-skeleton.cjs');
|
|
10
|
+
const _404Page = require('./404-page.cjs');
|
|
11
|
+
const permissions = require('../../../permissions.cjs');
|
|
12
|
+
const constants = require('../../constants.cjs');
|
|
13
|
+
const formBuilderHooks = require('../../hooks/form-builder-hooks.cjs');
|
|
14
|
+
|
|
15
|
+
const FormBuilderPage = React.lazy(
|
|
16
|
+
() => import('./form-builder-page.internal.cjs').then((m) => ({
|
|
17
|
+
default: m.FormBuilderPage
|
|
18
|
+
}))
|
|
19
|
+
);
|
|
20
|
+
function FormBuilderPageComponent({ id }) {
|
|
21
|
+
const { onRouteError } = context.usePluginOverrides(
|
|
22
|
+
constants.FORM_BUILDER_PLUGIN_ID
|
|
23
|
+
);
|
|
24
|
+
const isNew = !id;
|
|
25
|
+
const path = isNew ? "/forms/new" : `/forms/${id}/edit`;
|
|
26
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
27
|
+
components.ComposedRoute,
|
|
28
|
+
{
|
|
29
|
+
path,
|
|
30
|
+
PageComponent: AuthorizedFormBuilderPage,
|
|
31
|
+
ErrorComponent: defaultError.DefaultError,
|
|
32
|
+
LoadingComponent: formBuilderSkeleton.FormBuilderSkeleton,
|
|
33
|
+
NotFoundComponent: _404Page.NotFoundPage,
|
|
34
|
+
props: { id },
|
|
35
|
+
onError: (error) => {
|
|
36
|
+
if (onRouteError) {
|
|
37
|
+
onRouteError("formBuilder", error, {
|
|
38
|
+
path,
|
|
39
|
+
params: id ? { id } : {},
|
|
40
|
+
isSSR: typeof window === "undefined"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function AuthorizedFormBuilderPage({ id }) {
|
|
48
|
+
if (!id) {
|
|
49
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
50
|
+
components.PermissionRouteAccess,
|
|
51
|
+
{
|
|
52
|
+
permission: permissions.formBuilderPermissions.form.create(),
|
|
53
|
+
LoadingComponent: formBuilderSkeleton.FormBuilderSkeleton,
|
|
54
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(FormBuilderPage, {})
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AuthorizedExistingFormBuilderPage, { id });
|
|
59
|
+
}
|
|
60
|
+
function AuthorizedExistingFormBuilderPage({ id }) {
|
|
61
|
+
const { form } = formBuilderHooks.useSuspenseFormForUpdate(id);
|
|
62
|
+
if (!form) return /* @__PURE__ */ jsxRuntime.jsx(_404Page.NotFoundPage, {});
|
|
63
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
64
|
+
components.PermissionRouteAccess,
|
|
65
|
+
{
|
|
66
|
+
permission: permissions.formBuilderPermissions.form.update({
|
|
67
|
+
formId: form.id,
|
|
68
|
+
...form.createdBy ? { ownerId: form.createdBy } : {},
|
|
69
|
+
status: form.status
|
|
70
|
+
}),
|
|
71
|
+
LoadingComponent: formBuilderSkeleton.FormBuilderSkeleton,
|
|
72
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(FormBuilderPage, { id })
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.FormBuilderPageComponent = FormBuilderPageComponent;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const React = require('react');
|
|
6
|
+
const context = require('@btst/stack/context');
|
|
7
|
+
const button = require('../../../ui/src/components/button.cjs');
|
|
8
|
+
const input = require('../../../ui/src/components/input.cjs');
|
|
9
|
+
const label = require('../../../ui/src/components/label.cjs');
|
|
10
|
+
const select = require('../../../ui/src/components/select.cjs');
|
|
11
|
+
const lucideReact = require('lucide-react');
|
|
12
|
+
const index = require('../../../ui/src/components/form-builder/index.cjs');
|
|
13
|
+
const utils = require('../../../utils.cjs');
|
|
14
|
+
const permissions = require('../../../permissions.cjs');
|
|
15
|
+
const _404Page = require('./404-page.cjs');
|
|
16
|
+
const constants = require('../../constants.cjs');
|
|
17
|
+
const formBuilderHooks = require('../../hooks/form-builder-hooks.cjs');
|
|
18
|
+
|
|
19
|
+
function FormBuilderPage({ id }) {
|
|
20
|
+
if (id) {
|
|
21
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EditFormBuilderPage, { id });
|
|
22
|
+
}
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CreateFormBuilderPage, {});
|
|
24
|
+
}
|
|
25
|
+
function EditFormBuilderPage({ id }) {
|
|
26
|
+
const { form: existingForm } = formBuilderHooks.useSuspenseFormForUpdate(id);
|
|
27
|
+
if (!existingForm) return /* @__PURE__ */ jsxRuntime.jsx(_404Page.NotFoundPage, {});
|
|
28
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormBuilderPageContent, { id, existingForm });
|
|
29
|
+
}
|
|
30
|
+
function CreateFormBuilderPage() {
|
|
31
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormBuilderPageContent, {});
|
|
32
|
+
}
|
|
33
|
+
function FormBuilderPageContent({
|
|
34
|
+
id,
|
|
35
|
+
existingForm
|
|
36
|
+
}) {
|
|
37
|
+
const t = context.useTranslate();
|
|
38
|
+
const notify = context.useNotify();
|
|
39
|
+
const { localization } = context.usePluginOverrides(
|
|
40
|
+
constants.FORM_BUILDER_PLUGIN_ID
|
|
41
|
+
);
|
|
42
|
+
const {
|
|
43
|
+
Link: LinkComponent,
|
|
44
|
+
navigate,
|
|
45
|
+
resolve
|
|
46
|
+
} = context.usePluginSiteNavigation(constants.FORM_BUILDER_PLUGIN_ID);
|
|
47
|
+
const [name, setName] = React.useState(existingForm?.name || "");
|
|
48
|
+
const [slug, setSlug] = React.useState(existingForm?.slug || "");
|
|
49
|
+
const [status, setStatus] = React.useState(
|
|
50
|
+
existingForm?.status || "active"
|
|
51
|
+
);
|
|
52
|
+
const [schema, setSchema] = React.useState(() => {
|
|
53
|
+
if (existingForm?.schema) {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(existingForm.schema);
|
|
56
|
+
} catch {
|
|
57
|
+
return void 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
});
|
|
62
|
+
const [autoSlug, setAutoSlug] = React.useState(!id);
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
if (autoSlug && name) {
|
|
65
|
+
setSlug(utils.slugify(name));
|
|
66
|
+
}
|
|
67
|
+
}, [name, autoSlug]);
|
|
68
|
+
const handleSchemaChange = React.useCallback((newSchema) => {
|
|
69
|
+
setSchema(newSchema);
|
|
70
|
+
}, []);
|
|
71
|
+
const resourceForm = formBuilderHooks.useFormBuilderForm({
|
|
72
|
+
action: id ? "edit" : "create",
|
|
73
|
+
record: id ? existingForm ?? null : null,
|
|
74
|
+
successMessage: (_result, action) => action === "create" ? localization?.FORM_BUILDER_TOAST_CREATE_SUCCESS ?? t("formBuilder.toasts.createSuccess", "Form created successfully") : localization?.FORM_BUILDER_TOAST_UPDATE_SUCCESS ?? t("formBuilder.toasts.updateSuccess", "Form updated successfully"),
|
|
75
|
+
errorMessage: (error) => error.statusCode === 409 ? localization?.FORM_BUILDER_TOAST_DUPLICATE_SLUG ?? t(
|
|
76
|
+
"formBuilder.toasts.duplicateSlug",
|
|
77
|
+
"A form with this slug already exists"
|
|
78
|
+
) : localization?.FORM_BUILDER_TOAST_ERROR ?? t(
|
|
79
|
+
"formBuilder.toasts.error",
|
|
80
|
+
"An error occurred. Please try again."
|
|
81
|
+
),
|
|
82
|
+
toCreateVars: (values) => values,
|
|
83
|
+
toUpdateVars: (values) => ({
|
|
84
|
+
id: id ?? "",
|
|
85
|
+
data: {
|
|
86
|
+
name: values.name,
|
|
87
|
+
schema: values.schema,
|
|
88
|
+
status: values.status
|
|
89
|
+
}
|
|
90
|
+
}),
|
|
91
|
+
onSuccess: (result) => {
|
|
92
|
+
if (!id && result) return navigate("forms", result.id, "edit");
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const handleSave = async () => {
|
|
96
|
+
if (!name.trim()) {
|
|
97
|
+
notify.error(
|
|
98
|
+
localization?.FORM_BUILDER_TOAST_NAME_REQUIRED ?? t("formBuilder.toasts.nameRequired", "Name is required")
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!slug.trim()) {
|
|
103
|
+
notify.error(
|
|
104
|
+
localization?.FORM_BUILDER_TOAST_SLUG_REQUIRED ?? t("formBuilder.toasts.slugRequired", "Slug is required")
|
|
105
|
+
);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!schema) {
|
|
109
|
+
notify.error(
|
|
110
|
+
localization?.FORM_BUILDER_TOAST_SCHEMA_REQUIRED ?? t(
|
|
111
|
+
"formBuilder.toasts.schemaRequired",
|
|
112
|
+
"Please add at least one field to the form"
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
await resourceForm.submit({
|
|
118
|
+
name,
|
|
119
|
+
slug,
|
|
120
|
+
status,
|
|
121
|
+
schema: JSON.stringify(schema)
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const isSaving = resourceForm.isSubmitting;
|
|
125
|
+
const fieldError = (field) => {
|
|
126
|
+
const error = resourceForm.fieldErrors[field];
|
|
127
|
+
if (!error) return void 0;
|
|
128
|
+
return Array.isArray(error) ? error[0] : error;
|
|
129
|
+
};
|
|
130
|
+
const saveButton = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ml-auto", children: /* @__PURE__ */ jsxRuntime.jsxs(button.Button, { onClick: handleSave, disabled: isSaving, children: [
|
|
131
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "mr-2 h-4 w-4" }),
|
|
132
|
+
isSaving ? localization?.FORM_BUILDER_STATUS_SAVING ?? t("formBuilder.common.statusSaving", "Saving...") : id ? localization?.FORM_BUILDER_BUTTON_SAVE ?? t("formBuilder.common.buttonSave", "Save") : localization?.FORM_BUILDER_BUTTON_CREATE ?? t("formBuilder.common.buttonCreate", "Create")
|
|
133
|
+
] }) });
|
|
134
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col", "data-testid": "form-builder-page", children: [
|
|
135
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4 border-b p-4", children: [
|
|
136
|
+
/* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(LinkComponent, { href: resolve("forms").href, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowLeft, { className: "h-4 w-4" }) }) }),
|
|
137
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
138
|
+
/* @__PURE__ */ jsxRuntime.jsx(label.Label, { htmlFor: "form-name", className: "text-xs text-muted-foreground", children: localization?.FORM_BUILDER_LABEL_NAME ?? t("formBuilder.common.labelName", "Name") }),
|
|
139
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
140
|
+
input.Input,
|
|
141
|
+
{
|
|
142
|
+
id: "form-name",
|
|
143
|
+
value: name,
|
|
144
|
+
onChange: (e) => setName(e.target.value),
|
|
145
|
+
placeholder: localization?.FORM_BUILDER_EDITOR_NAME_PLACEHOLDER ?? t("formBuilder.editor.namePlaceholder", "Enter form name"),
|
|
146
|
+
className: "h-8 w-48"
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
fieldError("name") && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-destructive", children: fieldError("name") })
|
|
150
|
+
] }),
|
|
151
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
152
|
+
/* @__PURE__ */ jsxRuntime.jsx(label.Label, { htmlFor: "form-slug", className: "text-xs text-muted-foreground", children: localization?.FORM_BUILDER_LABEL_SLUG ?? t("formBuilder.common.labelSlug", "Slug") }),
|
|
153
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
154
|
+
input.Input,
|
|
155
|
+
{
|
|
156
|
+
id: "form-slug",
|
|
157
|
+
value: slug,
|
|
158
|
+
onChange: (e) => {
|
|
159
|
+
setSlug(e.target.value);
|
|
160
|
+
setAutoSlug(false);
|
|
161
|
+
},
|
|
162
|
+
placeholder: localization?.FORM_BUILDER_EDITOR_SLUG_PLACEHOLDER ?? t("formBuilder.editor.slugPlaceholder", "enter-form-slug"),
|
|
163
|
+
className: "h-8 w-48 font-mono text-sm",
|
|
164
|
+
disabled: !!id
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
fieldError("slug") && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-destructive", children: fieldError("slug") })
|
|
168
|
+
] }),
|
|
169
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
170
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
171
|
+
label.Label,
|
|
172
|
+
{
|
|
173
|
+
htmlFor: "form-status",
|
|
174
|
+
className: "text-xs text-muted-foreground",
|
|
175
|
+
children: localization?.FORM_BUILDER_LABEL_STATUS ?? t("formBuilder.common.labelStatus", "Status")
|
|
176
|
+
}
|
|
177
|
+
),
|
|
178
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
179
|
+
select.Select,
|
|
180
|
+
{
|
|
181
|
+
value: status,
|
|
182
|
+
onValueChange: (v) => setStatus(v),
|
|
183
|
+
children: [
|
|
184
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectTrigger, { className: "h-8 w-28", children: /* @__PURE__ */ jsxRuntime.jsx(select.SelectValue, {}) }),
|
|
185
|
+
/* @__PURE__ */ jsxRuntime.jsxs(select.SelectContent, { children: [
|
|
186
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectItem, { value: "active", children: localization?.FORM_BUILDER_STATUS_ACTIVE ?? t("formBuilder.common.statusActive", "Active") }),
|
|
187
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectItem, { value: "inactive", children: localization?.FORM_BUILDER_STATUS_INACTIVE ?? t("formBuilder.common.statusInactive", "Inactive") }),
|
|
188
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectItem, { value: "archived", children: localization?.FORM_BUILDER_STATUS_ARCHIVED ?? t("formBuilder.common.statusArchived", "Archived") })
|
|
189
|
+
] })
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
] }),
|
|
194
|
+
id && existingForm ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
195
|
+
context.PermissionAccess,
|
|
196
|
+
{
|
|
197
|
+
permission: permissions.formBuilderPermissions.form.update({
|
|
198
|
+
formId: existingForm.id,
|
|
199
|
+
...existingForm.createdBy ? { ownerId: existingForm.createdBy } : {},
|
|
200
|
+
status: existingForm.status
|
|
201
|
+
}),
|
|
202
|
+
children: saveButton
|
|
203
|
+
}
|
|
204
|
+
) : !id ? /* @__PURE__ */ jsxRuntime.jsx(context.PermissionAccess, { permission: permissions.formBuilderPermissions.form.create(), children: saveButton }) : null
|
|
205
|
+
] }),
|
|
206
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
207
|
+
index.FormBuilder,
|
|
208
|
+
{
|
|
209
|
+
value: schema,
|
|
210
|
+
onChange: handleSchemaChange,
|
|
211
|
+
className: "flex-1"
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
] });
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
exports.FormBuilderPage = FormBuilderPage;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import { useTranslate, useNotify, usePluginOverrides, usePluginSiteNavigation, PermissionAccess } from '@btst/stack/context';
|
|
5
|
+
import { Button } from '../../../ui/src/components/button.mjs';
|
|
6
|
+
import { Input } from '../../../ui/src/components/input.mjs';
|
|
7
|
+
import { Label } from '../../../ui/src/components/label.mjs';
|
|
8
|
+
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../../../ui/src/components/select.mjs';
|
|
9
|
+
import { Save, ArrowLeft } from 'lucide-react';
|
|
10
|
+
import { FormBuilder } from '../../../ui/src/components/form-builder/index.mjs';
|
|
11
|
+
import { slugify } from '../../../utils.mjs';
|
|
12
|
+
import { formBuilderPermissions } from '../../../permissions.mjs';
|
|
13
|
+
import { NotFoundPage } from './404-page.mjs';
|
|
14
|
+
import { FORM_BUILDER_PLUGIN_ID } from '../../constants.mjs';
|
|
15
|
+
import { useSuspenseFormForUpdate, useFormBuilderForm } from '../../hooks/form-builder-hooks.mjs';
|
|
16
|
+
|
|
17
|
+
function FormBuilderPage({ id }) {
|
|
18
|
+
if (id) {
|
|
19
|
+
return /* @__PURE__ */ jsx(EditFormBuilderPage, { id });
|
|
20
|
+
}
|
|
21
|
+
return /* @__PURE__ */ jsx(CreateFormBuilderPage, {});
|
|
22
|
+
}
|
|
23
|
+
function EditFormBuilderPage({ id }) {
|
|
24
|
+
const { form: existingForm } = useSuspenseFormForUpdate(id);
|
|
25
|
+
if (!existingForm) return /* @__PURE__ */ jsx(NotFoundPage, {});
|
|
26
|
+
return /* @__PURE__ */ jsx(FormBuilderPageContent, { id, existingForm });
|
|
27
|
+
}
|
|
28
|
+
function CreateFormBuilderPage() {
|
|
29
|
+
return /* @__PURE__ */ jsx(FormBuilderPageContent, {});
|
|
30
|
+
}
|
|
31
|
+
function FormBuilderPageContent({
|
|
32
|
+
id,
|
|
33
|
+
existingForm
|
|
34
|
+
}) {
|
|
35
|
+
const t = useTranslate();
|
|
36
|
+
const notify = useNotify();
|
|
37
|
+
const { localization } = usePluginOverrides(
|
|
38
|
+
FORM_BUILDER_PLUGIN_ID
|
|
39
|
+
);
|
|
40
|
+
const {
|
|
41
|
+
Link: LinkComponent,
|
|
42
|
+
navigate,
|
|
43
|
+
resolve
|
|
44
|
+
} = usePluginSiteNavigation(FORM_BUILDER_PLUGIN_ID);
|
|
45
|
+
const [name, setName] = useState(existingForm?.name || "");
|
|
46
|
+
const [slug, setSlug] = useState(existingForm?.slug || "");
|
|
47
|
+
const [status, setStatus] = useState(
|
|
48
|
+
existingForm?.status || "active"
|
|
49
|
+
);
|
|
50
|
+
const [schema, setSchema] = useState(() => {
|
|
51
|
+
if (existingForm?.schema) {
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(existingForm.schema);
|
|
54
|
+
} catch {
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return void 0;
|
|
59
|
+
});
|
|
60
|
+
const [autoSlug, setAutoSlug] = useState(!id);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (autoSlug && name) {
|
|
63
|
+
setSlug(slugify(name));
|
|
64
|
+
}
|
|
65
|
+
}, [name, autoSlug]);
|
|
66
|
+
const handleSchemaChange = useCallback((newSchema) => {
|
|
67
|
+
setSchema(newSchema);
|
|
68
|
+
}, []);
|
|
69
|
+
const resourceForm = useFormBuilderForm({
|
|
70
|
+
action: id ? "edit" : "create",
|
|
71
|
+
record: id ? existingForm ?? null : null,
|
|
72
|
+
successMessage: (_result, action) => action === "create" ? localization?.FORM_BUILDER_TOAST_CREATE_SUCCESS ?? t("formBuilder.toasts.createSuccess", "Form created successfully") : localization?.FORM_BUILDER_TOAST_UPDATE_SUCCESS ?? t("formBuilder.toasts.updateSuccess", "Form updated successfully"),
|
|
73
|
+
errorMessage: (error) => error.statusCode === 409 ? localization?.FORM_BUILDER_TOAST_DUPLICATE_SLUG ?? t(
|
|
74
|
+
"formBuilder.toasts.duplicateSlug",
|
|
75
|
+
"A form with this slug already exists"
|
|
76
|
+
) : localization?.FORM_BUILDER_TOAST_ERROR ?? t(
|
|
77
|
+
"formBuilder.toasts.error",
|
|
78
|
+
"An error occurred. Please try again."
|
|
79
|
+
),
|
|
80
|
+
toCreateVars: (values) => values,
|
|
81
|
+
toUpdateVars: (values) => ({
|
|
82
|
+
id: id ?? "",
|
|
83
|
+
data: {
|
|
84
|
+
name: values.name,
|
|
85
|
+
schema: values.schema,
|
|
86
|
+
status: values.status
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
onSuccess: (result) => {
|
|
90
|
+
if (!id && result) return navigate("forms", result.id, "edit");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const handleSave = async () => {
|
|
94
|
+
if (!name.trim()) {
|
|
95
|
+
notify.error(
|
|
96
|
+
localization?.FORM_BUILDER_TOAST_NAME_REQUIRED ?? t("formBuilder.toasts.nameRequired", "Name is required")
|
|
97
|
+
);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!slug.trim()) {
|
|
101
|
+
notify.error(
|
|
102
|
+
localization?.FORM_BUILDER_TOAST_SLUG_REQUIRED ?? t("formBuilder.toasts.slugRequired", "Slug is required")
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (!schema) {
|
|
107
|
+
notify.error(
|
|
108
|
+
localization?.FORM_BUILDER_TOAST_SCHEMA_REQUIRED ?? t(
|
|
109
|
+
"formBuilder.toasts.schemaRequired",
|
|
110
|
+
"Please add at least one field to the form"
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
await resourceForm.submit({
|
|
116
|
+
name,
|
|
117
|
+
slug,
|
|
118
|
+
status,
|
|
119
|
+
schema: JSON.stringify(schema)
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const isSaving = resourceForm.isSubmitting;
|
|
123
|
+
const fieldError = (field) => {
|
|
124
|
+
const error = resourceForm.fieldErrors[field];
|
|
125
|
+
if (!error) return void 0;
|
|
126
|
+
return Array.isArray(error) ? error[0] : error;
|
|
127
|
+
};
|
|
128
|
+
const saveButton = /* @__PURE__ */ jsx("div", { className: "ml-auto", children: /* @__PURE__ */ jsxs(Button, { onClick: handleSave, disabled: isSaving, children: [
|
|
129
|
+
/* @__PURE__ */ jsx(Save, { className: "mr-2 h-4 w-4" }),
|
|
130
|
+
isSaving ? localization?.FORM_BUILDER_STATUS_SAVING ?? t("formBuilder.common.statusSaving", "Saving...") : id ? localization?.FORM_BUILDER_BUTTON_SAVE ?? t("formBuilder.common.buttonSave", "Save") : localization?.FORM_BUILDER_BUTTON_CREATE ?? t("formBuilder.common.buttonCreate", "Create")
|
|
131
|
+
] }) });
|
|
132
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col", "data-testid": "form-builder-page", children: [
|
|
133
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 border-b p-4", children: [
|
|
134
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", asChild: true, children: /* @__PURE__ */ jsx(LinkComponent, { href: resolve("forms").href, children: /* @__PURE__ */ jsx(ArrowLeft, { className: "h-4 w-4" }) }) }),
|
|
135
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
136
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "form-name", className: "text-xs text-muted-foreground", children: localization?.FORM_BUILDER_LABEL_NAME ?? t("formBuilder.common.labelName", "Name") }),
|
|
137
|
+
/* @__PURE__ */ jsx(
|
|
138
|
+
Input,
|
|
139
|
+
{
|
|
140
|
+
id: "form-name",
|
|
141
|
+
value: name,
|
|
142
|
+
onChange: (e) => setName(e.target.value),
|
|
143
|
+
placeholder: localization?.FORM_BUILDER_EDITOR_NAME_PLACEHOLDER ?? t("formBuilder.editor.namePlaceholder", "Enter form name"),
|
|
144
|
+
className: "h-8 w-48"
|
|
145
|
+
}
|
|
146
|
+
),
|
|
147
|
+
fieldError("name") && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: fieldError("name") })
|
|
148
|
+
] }),
|
|
149
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
150
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "form-slug", className: "text-xs text-muted-foreground", children: localization?.FORM_BUILDER_LABEL_SLUG ?? t("formBuilder.common.labelSlug", "Slug") }),
|
|
151
|
+
/* @__PURE__ */ jsx(
|
|
152
|
+
Input,
|
|
153
|
+
{
|
|
154
|
+
id: "form-slug",
|
|
155
|
+
value: slug,
|
|
156
|
+
onChange: (e) => {
|
|
157
|
+
setSlug(e.target.value);
|
|
158
|
+
setAutoSlug(false);
|
|
159
|
+
},
|
|
160
|
+
placeholder: localization?.FORM_BUILDER_EDITOR_SLUG_PLACEHOLDER ?? t("formBuilder.editor.slugPlaceholder", "enter-form-slug"),
|
|
161
|
+
className: "h-8 w-48 font-mono text-sm",
|
|
162
|
+
disabled: !!id
|
|
163
|
+
}
|
|
164
|
+
),
|
|
165
|
+
fieldError("slug") && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: fieldError("slug") })
|
|
166
|
+
] }),
|
|
167
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
168
|
+
/* @__PURE__ */ jsx(
|
|
169
|
+
Label,
|
|
170
|
+
{
|
|
171
|
+
htmlFor: "form-status",
|
|
172
|
+
className: "text-xs text-muted-foreground",
|
|
173
|
+
children: localization?.FORM_BUILDER_LABEL_STATUS ?? t("formBuilder.common.labelStatus", "Status")
|
|
174
|
+
}
|
|
175
|
+
),
|
|
176
|
+
/* @__PURE__ */ jsxs(
|
|
177
|
+
Select,
|
|
178
|
+
{
|
|
179
|
+
value: status,
|
|
180
|
+
onValueChange: (v) => setStatus(v),
|
|
181
|
+
children: [
|
|
182
|
+
/* @__PURE__ */ jsx(SelectTrigger, { className: "h-8 w-28", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
|
|
183
|
+
/* @__PURE__ */ jsxs(SelectContent, { children: [
|
|
184
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "active", children: localization?.FORM_BUILDER_STATUS_ACTIVE ?? t("formBuilder.common.statusActive", "Active") }),
|
|
185
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "inactive", children: localization?.FORM_BUILDER_STATUS_INACTIVE ?? t("formBuilder.common.statusInactive", "Inactive") }),
|
|
186
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "archived", children: localization?.FORM_BUILDER_STATUS_ARCHIVED ?? t("formBuilder.common.statusArchived", "Archived") })
|
|
187
|
+
] })
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
] }),
|
|
192
|
+
id && existingForm ? /* @__PURE__ */ jsx(
|
|
193
|
+
PermissionAccess,
|
|
194
|
+
{
|
|
195
|
+
permission: formBuilderPermissions.form.update({
|
|
196
|
+
formId: existingForm.id,
|
|
197
|
+
...existingForm.createdBy ? { ownerId: existingForm.createdBy } : {},
|
|
198
|
+
status: existingForm.status
|
|
199
|
+
}),
|
|
200
|
+
children: saveButton
|
|
201
|
+
}
|
|
202
|
+
) : !id ? /* @__PURE__ */ jsx(PermissionAccess, { permission: formBuilderPermissions.form.create(), children: saveButton }) : null
|
|
203
|
+
] }),
|
|
204
|
+
/* @__PURE__ */ jsx(
|
|
205
|
+
FormBuilder,
|
|
206
|
+
{
|
|
207
|
+
value: schema,
|
|
208
|
+
onChange: handleSchemaChange,
|
|
209
|
+
className: "flex-1"
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
] });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export { FormBuilderPage };
|