@btst/stack 1.5.2 → 1.6.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/dist/node_modules/.pnpm/@dnd-kit_accessibility@3.1.1_react@19.2.0/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.cjs +68 -0
- package/dist/node_modules/.pnpm/@dnd-kit_accessibility@3.1.1_react@19.2.0/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.mjs +60 -0
- package/dist/node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.cjs +3937 -0
- package/dist/node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.mjs +3907 -0
- package/dist/node_modules/.pnpm/@dnd-kit_modifiers@9.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/modifiers/dist/modifiers.esm.cjs +30 -0
- package/dist/node_modules/.pnpm/@dnd-kit_modifiers@9.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/modifiers/dist/modifiers.esm.mjs +28 -0
- package/dist/node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.cjs +675 -0
- package/dist/node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.mjs +661 -0
- package/dist/node_modules/.pnpm/@dnd-kit_utilities@3.2.2_react@19.2.0/node_modules/@dnd-kit/utilities/dist/utilities.esm.cjs +358 -0
- package/dist/node_modules/.pnpm/@dnd-kit_utilities@3.2.2_react@19.2.0/node_modules/@dnd-kit/utilities/dist/utilities.esm.mjs +332 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-tabs@1.1.13_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_865f042350eb43f3338b0fffb33f6246/node_modules/@radix-ui/react-tabs/dist/index.cjs +211 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-tabs@1.1.13_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_865f042350eb43f3338b0fffb33f6246/node_modules/@radix-ui/react-tabs/dist/index.mjs +188 -0
- package/dist/packages/better-stack/src/plugins/cms/api/plugin.cjs +3 -2
- package/dist/packages/better-stack/src/plugins/cms/api/plugin.mjs +3 -2
- package/dist/packages/better-stack/src/plugins/cms/client/components/forms/content-form.cjs +15 -15
- package/dist/packages/better-stack/src/plugins/cms/client/components/forms/content-form.mjs +16 -16
- package/dist/packages/better-stack/src/plugins/form-builder/api/plugin.cjs +588 -0
- package/dist/packages/better-stack/src/plugins/form-builder/api/plugin.mjs +586 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/forms/form-renderer.cjs +131 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/forms/form-renderer.mjs +129 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-builder-skeleton.cjs +32 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-builder-skeleton.mjs +30 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-list-skeleton.cjs +21 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-list-skeleton.mjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/submissions-skeleton.cjs +34 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/submissions-skeleton.mjs +32 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/404-page.cjs +20 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/404-page.mjs +18 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.cjs +186 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.mjs +184 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.cjs +165 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.mjs +163 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +177 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +175 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/default-error.cjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/default-error.mjs +15 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/empty-state.cjs +16 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/empty-state.mjs +14 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/page-wrapper.cjs +27 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/page-wrapper.mjs +25 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.cjs +39 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.mjs +37 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/hooks/form-builder-hooks.cjs +551 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/hooks/form-builder-hooks.mjs +537 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-common.cjs +36 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-common.mjs +34 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-editor.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-editor.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-list.cjs +21 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-list.mjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-submissions.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-submissions.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-toasts.cjs +14 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-toasts.mjs +12 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/index.cjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/index.mjs +15 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/plugin.cjs +278 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/plugin.mjs +276 -0
- package/dist/packages/better-stack/src/plugins/form-builder/db.cjs +99 -0
- package/dist/packages/better-stack/src/plugins/form-builder/db.mjs +97 -0
- package/dist/packages/better-stack/src/plugins/form-builder/schemas.cjs +82 -0
- package/dist/packages/better-stack/src/plugins/form-builder/schemas.mjs +74 -0
- package/dist/packages/better-stack/src/plugins/form-builder/utils.cjs +37 -0
- package/dist/packages/better-stack/src/plugins/form-builder/utils.mjs +29 -0
- package/dist/packages/ui/src/components/auto-form/index.cjs +2 -12
- package/dist/packages/ui/src/components/auto-form/index.mjs +2 -9
- package/dist/packages/ui/src/components/auto-form/stepped-auto-form.cjs +377 -0
- package/dist/packages/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
- package/dist/packages/ui/src/components/auto-form/utils.cjs +1 -56
- package/dist/packages/ui/src/components/auto-form/utils.mjs +2 -56
- package/dist/packages/ui/src/components/form-builder/canvas.cjs +111 -0
- package/dist/packages/ui/src/components/form-builder/canvas.mjs +109 -0
- package/dist/packages/ui/src/components/form-builder/components/index.cjs +570 -0
- package/dist/packages/ui/src/components/form-builder/components/index.mjs +553 -0
- package/dist/packages/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
- package/dist/packages/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
- package/dist/packages/ui/src/components/form-builder/form-preview.cjs +73 -0
- package/dist/packages/ui/src/components/form-builder/form-preview.mjs +71 -0
- package/dist/packages/ui/src/components/form-builder/index.cjs +353 -0
- package/dist/packages/ui/src/components/form-builder/index.mjs +344 -0
- package/dist/packages/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
- package/dist/packages/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
- package/dist/packages/ui/src/components/form-builder/palette.cjs +52 -0
- package/dist/packages/ui/src/components/form-builder/palette.mjs +49 -0
- package/dist/packages/ui/src/components/form-builder/schema-utils.cjs +120 -0
- package/dist/packages/ui/src/components/form-builder/schema-utils.mjs +114 -0
- package/dist/packages/ui/src/components/form-builder/sortable-field.cjs +151 -0
- package/dist/packages/ui/src/components/form-builder/sortable-field.mjs +148 -0
- package/dist/packages/ui/src/components/form-builder/step-tabs.cjs +180 -0
- package/dist/packages/ui/src/components/form-builder/step-tabs.mjs +178 -0
- package/dist/packages/ui/src/components/form-builder/types.cjs +7 -0
- package/dist/packages/ui/src/components/form-builder/types.mjs +5 -0
- package/dist/packages/ui/src/components/form-builder/validation-schemas.cjs +67 -0
- package/dist/packages/ui/src/components/form-builder/validation-schemas.mjs +56 -0
- package/dist/packages/ui/src/components/tabs.cjs +70 -0
- package/dist/packages/ui/src/components/tabs.mjs +65 -0
- package/dist/packages/ui/src/lib/schema-converter.cjs +130 -0
- package/dist/packages/ui/src/lib/schema-converter.mjs +124 -0
- package/dist/plugins/blog/api/index.d.cts +1 -1
- package/dist/plugins/blog/api/index.d.mts +1 -1
- package/dist/plugins/blog/api/index.d.ts +1 -1
- package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
- package/dist/plugins/blog/client/index.d.cts +1 -1
- package/dist/plugins/blog/client/index.d.mts +1 -1
- package/dist/plugins/blog/client/index.d.ts +1 -1
- package/dist/plugins/blog/query-keys.d.cts +2 -2
- package/dist/plugins/blog/query-keys.d.mts +2 -2
- package/dist/plugins/blog/query-keys.d.ts +2 -2
- package/dist/plugins/cms/client/index.cjs +6 -0
- package/dist/plugins/cms/client/index.d.cts +6 -113
- package/dist/plugins/cms/client/index.d.mts +6 -113
- package/dist/plugins/cms/client/index.d.ts +6 -113
- package/dist/plugins/cms/client/index.mjs +1 -0
- package/dist/plugins/form-builder/api/index.cjs +7 -0
- package/dist/plugins/form-builder/api/index.d.cts +141 -0
- package/dist/plugins/form-builder/api/index.d.mts +141 -0
- package/dist/plugins/form-builder/api/index.d.ts +141 -0
- package/dist/plugins/form-builder/api/index.mjs +1 -0
- package/dist/plugins/form-builder/client/components/index.cjs +29 -0
- package/dist/plugins/form-builder/client/components/index.d.cts +93 -0
- package/dist/plugins/form-builder/client/components/index.d.mts +93 -0
- package/dist/plugins/form-builder/client/components/index.d.ts +93 -0
- package/dist/plugins/form-builder/client/components/index.mjs +18 -0
- package/dist/plugins/form-builder/client/hooks/index.cjs +19 -0
- package/dist/plugins/form-builder/client/hooks/index.d.cts +154 -0
- package/dist/plugins/form-builder/client/hooks/index.d.mts +154 -0
- package/dist/plugins/form-builder/client/hooks/index.d.ts +154 -0
- package/dist/plugins/form-builder/client/hooks/index.mjs +1 -0
- package/dist/plugins/form-builder/client/index.cjs +13 -0
- package/dist/plugins/form-builder/client/index.d.cts +381 -0
- package/dist/plugins/form-builder/client/index.d.mts +381 -0
- package/dist/plugins/form-builder/client/index.d.ts +381 -0
- package/dist/plugins/form-builder/client/index.mjs +2 -0
- package/dist/plugins/form-builder/client.css +3 -0
- package/dist/plugins/form-builder/query-keys.cjs +143 -0
- package/dist/plugins/form-builder/query-keys.d.cts +74 -0
- package/dist/plugins/form-builder/query-keys.d.mts +74 -0
- package/dist/plugins/form-builder/query-keys.d.ts +74 -0
- package/dist/plugins/form-builder/query-keys.mjs +141 -0
- package/dist/plugins/form-builder/style.css +19 -0
- package/dist/shared/stack.AX5nZ6A3.d.cts +86 -0
- package/dist/shared/stack.AX5nZ6A3.d.mts +86 -0
- package/dist/shared/stack.AX5nZ6A3.d.ts +86 -0
- package/dist/shared/stack.BIh2AXaW.d.cts +123 -0
- package/dist/shared/stack.BIh2AXaW.d.mts +123 -0
- package/dist/shared/stack.BIh2AXaW.d.ts +123 -0
- package/dist/shared/stack.DzH_wcvr.d.cts +195 -0
- package/dist/shared/stack.DzH_wcvr.d.mts +195 -0
- package/dist/shared/stack.DzH_wcvr.d.ts +195 -0
- package/package.json +54 -1
- package/src/plugins/cms/api/plugin.ts +9 -4
- package/src/plugins/cms/client/components/forms/content-form.tsx +23 -25
- package/src/plugins/cms/client/index.ts +11 -0
- package/src/plugins/form-builder/api/index.ts +1 -0
- package/src/plugins/form-builder/api/plugin.ts +776 -0
- package/src/plugins/form-builder/client/components/forms/form-renderer.tsx +253 -0
- package/src/plugins/form-builder/client/components/index.tsx +24 -0
- package/src/plugins/form-builder/client/components/loading/form-builder-skeleton.tsx +42 -0
- package/src/plugins/form-builder/client/components/loading/form-list-skeleton.tsx +25 -0
- package/src/plugins/form-builder/client/components/loading/index.tsx +3 -0
- package/src/plugins/form-builder/client/components/loading/submissions-skeleton.tsx +40 -0
- package/src/plugins/form-builder/client/components/pages/404-page.tsx +28 -0
- package/src/plugins/form-builder/client/components/pages/form-builder-page.internal.tsx +253 -0
- package/src/plugins/form-builder/client/components/pages/form-builder-page.tsx +26 -0
- package/src/plugins/form-builder/client/components/pages/form-list-page.internal.tsx +231 -0
- package/src/plugins/form-builder/client/components/pages/form-list-page.tsx +22 -0
- package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +268 -0
- package/src/plugins/form-builder/client/components/pages/submissions-page.tsx +26 -0
- package/src/plugins/form-builder/client/components/shared/default-error.tsx +30 -0
- package/src/plugins/form-builder/client/components/shared/empty-state.tsx +26 -0
- package/src/plugins/form-builder/client/components/shared/page-wrapper.tsx +32 -0
- package/src/plugins/form-builder/client/components/shared/pagination.tsx +52 -0
- package/src/plugins/form-builder/client/hooks/form-builder-hooks.tsx +799 -0
- package/src/plugins/form-builder/client/hooks/index.tsx +1 -0
- package/src/plugins/form-builder/client/index.ts +22 -0
- package/src/plugins/form-builder/client/localization/form-builder-common.ts +36 -0
- package/src/plugins/form-builder/client/localization/form-builder-editor.ts +18 -0
- package/src/plugins/form-builder/client/localization/form-builder-list.ts +17 -0
- package/src/plugins/form-builder/client/localization/form-builder-submissions.ts +17 -0
- package/src/plugins/form-builder/client/localization/form-builder-toasts.ts +10 -0
- package/src/plugins/form-builder/client/localization/index.ts +15 -0
- package/src/plugins/form-builder/client/overrides.ts +146 -0
- package/src/plugins/form-builder/client/plugin.tsx +488 -0
- package/src/plugins/form-builder/client.css +3 -0
- package/src/plugins/form-builder/db.ts +99 -0
- package/src/plugins/form-builder/query-keys.ts +198 -0
- package/src/plugins/form-builder/schemas.ts +122 -0
- package/src/plugins/form-builder/style.css +19 -0
- package/src/plugins/form-builder/types.ts +317 -0
- package/src/plugins/form-builder/utils.ts +63 -0
- package/dist/shared/{stack.DLhzx1-D.d.cts → stack.CcI4sYJP.d.cts} +1 -1
- package/dist/shared/{stack.DLhzx1-D.d.mts → stack.CcI4sYJP.d.mts} +1 -1
- package/dist/shared/{stack.DLhzx1-D.d.ts → stack.CcI4sYJP.d.ts} +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const context = require('@btst/stack/context');
|
|
6
|
+
const pageWrapper = require('../../../../../../../ui/src/components/page-wrapper.cjs');
|
|
7
|
+
|
|
8
|
+
function PageWrapper({
|
|
9
|
+
children,
|
|
10
|
+
className,
|
|
11
|
+
testId
|
|
12
|
+
}) {
|
|
13
|
+
const { showAttribution } = context.usePluginOverrides("form-builder", {
|
|
14
|
+
showAttribution: true
|
|
15
|
+
});
|
|
16
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
17
|
+
pageWrapper.PageWrapper,
|
|
18
|
+
{
|
|
19
|
+
className,
|
|
20
|
+
testId,
|
|
21
|
+
showAttribution,
|
|
22
|
+
children
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.PageWrapper = PageWrapper;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { usePluginOverrides } from '@btst/stack/context';
|
|
4
|
+
import { PageWrapper as PageWrapper$1 } from '../../../../../../../ui/src/components/page-wrapper.mjs';
|
|
5
|
+
|
|
6
|
+
function PageWrapper({
|
|
7
|
+
children,
|
|
8
|
+
className,
|
|
9
|
+
testId
|
|
10
|
+
}) {
|
|
11
|
+
const { showAttribution } = usePluginOverrides("form-builder", {
|
|
12
|
+
showAttribution: true
|
|
13
|
+
});
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
PageWrapper$1,
|
|
16
|
+
{
|
|
17
|
+
className,
|
|
18
|
+
testId,
|
|
19
|
+
showAttribution,
|
|
20
|
+
children
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { PageWrapper };
|
package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.cjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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 lucideReact = require('lucide-react');
|
|
7
|
+
|
|
8
|
+
function Pagination({
|
|
9
|
+
total,
|
|
10
|
+
showing,
|
|
11
|
+
hasMore,
|
|
12
|
+
isLoadingMore,
|
|
13
|
+
onLoadMore,
|
|
14
|
+
labels = {}
|
|
15
|
+
}) {
|
|
16
|
+
const {
|
|
17
|
+
showing: showingLabel = "Showing {count} of {total}",
|
|
18
|
+
next = "Load More"
|
|
19
|
+
} = labels;
|
|
20
|
+
const showingText = showingLabel.replace("{count}", String(showing)).replace("{total}", String(total));
|
|
21
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between py-4", children: [
|
|
22
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: showingText }),
|
|
23
|
+
hasMore && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
24
|
+
button.Button,
|
|
25
|
+
{
|
|
26
|
+
variant: "outline",
|
|
27
|
+
size: "sm",
|
|
28
|
+
onClick: onLoadMore,
|
|
29
|
+
disabled: isLoadingMore,
|
|
30
|
+
children: [
|
|
31
|
+
isLoadingMore ? "Loading..." : next,
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "ml-2 h-4 w-4" })
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
] });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.Pagination = Pagination;
|
package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Button } from '../../../../../../../ui/src/components/button.mjs';
|
|
4
|
+
import { ChevronRight } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
function Pagination({
|
|
7
|
+
total,
|
|
8
|
+
showing,
|
|
9
|
+
hasMore,
|
|
10
|
+
isLoadingMore,
|
|
11
|
+
onLoadMore,
|
|
12
|
+
labels = {}
|
|
13
|
+
}) {
|
|
14
|
+
const {
|
|
15
|
+
showing: showingLabel = "Showing {count} of {total}",
|
|
16
|
+
next = "Load More"
|
|
17
|
+
} = labels;
|
|
18
|
+
const showingText = showingLabel.replace("{count}", String(showing)).replace("{total}", String(total));
|
|
19
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between py-4", children: [
|
|
20
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: showingText }),
|
|
21
|
+
hasMore && /* @__PURE__ */ jsxs(
|
|
22
|
+
Button,
|
|
23
|
+
{
|
|
24
|
+
variant: "outline",
|
|
25
|
+
size: "sm",
|
|
26
|
+
onClick: onLoadMore,
|
|
27
|
+
disabled: isLoadingMore,
|
|
28
|
+
children: [
|
|
29
|
+
isLoadingMore ? "Loading..." : next,
|
|
30
|
+
/* @__PURE__ */ jsx(ChevronRight, { className: "ml-2 h-4 w-4" })
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
] });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { Pagination };
|
package/dist/packages/better-stack/src/plugins/form-builder/client/hooks/form-builder-hooks.cjs
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const reactQuery = require('@tanstack/react-query');
|
|
5
|
+
const client = require('@btst/stack/plugins/client');
|
|
6
|
+
const context = require('@btst/stack/context');
|
|
7
|
+
const plugins_formBuilder_queryKeys = require('../../../../../../../plugins/form-builder/query-keys.cjs');
|
|
8
|
+
|
|
9
|
+
function isErrorResponse(response) {
|
|
10
|
+
if (typeof response !== "object" || response === null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const obj = response;
|
|
14
|
+
return "error" in obj && obj.error !== null && obj.error !== void 0;
|
|
15
|
+
}
|
|
16
|
+
function toError(error) {
|
|
17
|
+
if (error instanceof Error) {
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
if (typeof error === "object" && error !== null) {
|
|
21
|
+
const errorObj = error;
|
|
22
|
+
const message = (typeof errorObj.message === "string" ? errorObj.message : null) || (typeof errorObj.error === "string" ? errorObj.error : null) || JSON.stringify(error);
|
|
23
|
+
const err = new Error(message);
|
|
24
|
+
Object.assign(err, error);
|
|
25
|
+
return err;
|
|
26
|
+
}
|
|
27
|
+
return new Error(String(error));
|
|
28
|
+
}
|
|
29
|
+
const SHARED_QUERY_CONFIG = {
|
|
30
|
+
retry: false,
|
|
31
|
+
refetchOnWindowFocus: false,
|
|
32
|
+
refetchOnMount: false,
|
|
33
|
+
refetchOnReconnect: false,
|
|
34
|
+
staleTime: 1e3 * 60 * 5,
|
|
35
|
+
// 5 minutes
|
|
36
|
+
gcTime: 1e3 * 60 * 10
|
|
37
|
+
// 10 minutes
|
|
38
|
+
};
|
|
39
|
+
function useForms(options = {}) {
|
|
40
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
41
|
+
const client$1 = client.createApiClient({
|
|
42
|
+
baseURL: apiBaseURL,
|
|
43
|
+
basePath: apiBasePath
|
|
44
|
+
});
|
|
45
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
46
|
+
const { status, limit = 20, enabled = true } = options;
|
|
47
|
+
const baseQuery = queries.forms.list({ status, limit, offset: 0 });
|
|
48
|
+
const {
|
|
49
|
+
data,
|
|
50
|
+
isLoading,
|
|
51
|
+
error,
|
|
52
|
+
fetchNextPage,
|
|
53
|
+
hasNextPage,
|
|
54
|
+
isFetchingNextPage,
|
|
55
|
+
refetch
|
|
56
|
+
} = reactQuery.useInfiniteQuery({
|
|
57
|
+
queryKey: baseQuery.queryKey,
|
|
58
|
+
queryFn: async ({ pageParam = 0 }) => {
|
|
59
|
+
const response = await client$1("/forms", {
|
|
60
|
+
method: "GET",
|
|
61
|
+
query: { status, limit, offset: pageParam },
|
|
62
|
+
headers
|
|
63
|
+
});
|
|
64
|
+
if (isErrorResponse(response)) {
|
|
65
|
+
throw toError(response.error);
|
|
66
|
+
}
|
|
67
|
+
return response.data;
|
|
68
|
+
},
|
|
69
|
+
...SHARED_QUERY_CONFIG,
|
|
70
|
+
initialPageParam: 0,
|
|
71
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
72
|
+
if (!lastPage || typeof lastPage !== "object") return void 0;
|
|
73
|
+
const items = lastPage?.items;
|
|
74
|
+
if (!Array.isArray(items) || items.length < limit) return void 0;
|
|
75
|
+
const loadedCount = (allPages || []).reduce(
|
|
76
|
+
(sum, page) => sum + (Array.isArray(page?.items) ? page.items.length : 0),
|
|
77
|
+
0
|
|
78
|
+
);
|
|
79
|
+
const total2 = lastPage?.total ?? 0;
|
|
80
|
+
if (loadedCount >= total2) return void 0;
|
|
81
|
+
return loadedCount;
|
|
82
|
+
},
|
|
83
|
+
enabled
|
|
84
|
+
});
|
|
85
|
+
const pages = data?.pages;
|
|
86
|
+
const forms = pages?.flatMap(
|
|
87
|
+
(page) => Array.isArray(page?.items) ? page.items : []
|
|
88
|
+
) ?? [];
|
|
89
|
+
const total = pages?.[0]?.total ?? 0;
|
|
90
|
+
return {
|
|
91
|
+
forms,
|
|
92
|
+
total,
|
|
93
|
+
isLoading,
|
|
94
|
+
error,
|
|
95
|
+
loadMore: fetchNextPage,
|
|
96
|
+
hasMore: !!hasNextPage,
|
|
97
|
+
isLoadingMore: isFetchingNextPage,
|
|
98
|
+
refetch
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function useSuspenseForms(options = {}) {
|
|
102
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
103
|
+
const client$1 = client.createApiClient({
|
|
104
|
+
baseURL: apiBaseURL,
|
|
105
|
+
basePath: apiBasePath
|
|
106
|
+
});
|
|
107
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
108
|
+
const { status, limit = 20 } = options;
|
|
109
|
+
const baseQuery = queries.forms.list({ status, limit, offset: 0 });
|
|
110
|
+
const {
|
|
111
|
+
data,
|
|
112
|
+
fetchNextPage,
|
|
113
|
+
hasNextPage,
|
|
114
|
+
isFetchingNextPage,
|
|
115
|
+
refetch,
|
|
116
|
+
error,
|
|
117
|
+
isFetching
|
|
118
|
+
} = reactQuery.useSuspenseInfiniteQuery({
|
|
119
|
+
queryKey: baseQuery.queryKey,
|
|
120
|
+
queryFn: async ({ pageParam = 0 }) => {
|
|
121
|
+
const response = await client$1("/forms", {
|
|
122
|
+
method: "GET",
|
|
123
|
+
query: { status, limit, offset: pageParam },
|
|
124
|
+
headers
|
|
125
|
+
});
|
|
126
|
+
if (isErrorResponse(response)) {
|
|
127
|
+
throw toError(response.error);
|
|
128
|
+
}
|
|
129
|
+
return response.data;
|
|
130
|
+
},
|
|
131
|
+
...SHARED_QUERY_CONFIG,
|
|
132
|
+
initialPageParam: 0,
|
|
133
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
134
|
+
if (!lastPage || typeof lastPage !== "object") return void 0;
|
|
135
|
+
const items = lastPage?.items;
|
|
136
|
+
if (!Array.isArray(items) || items.length < limit) return void 0;
|
|
137
|
+
const loadedCount = (allPages || []).reduce(
|
|
138
|
+
(sum, page) => sum + (Array.isArray(page?.items) ? page.items.length : 0),
|
|
139
|
+
0
|
|
140
|
+
);
|
|
141
|
+
const total2 = lastPage?.total ?? 0;
|
|
142
|
+
if (loadedCount >= total2) return void 0;
|
|
143
|
+
return loadedCount;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
if (error && !isFetching) {
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
const pages = data.pages;
|
|
150
|
+
const forms = pages?.flatMap(
|
|
151
|
+
(page) => Array.isArray(page?.items) ? page.items : []
|
|
152
|
+
) ?? [];
|
|
153
|
+
const total = pages?.[0]?.total ?? 0;
|
|
154
|
+
return {
|
|
155
|
+
forms,
|
|
156
|
+
total,
|
|
157
|
+
loadMore: fetchNextPage,
|
|
158
|
+
hasMore: !!hasNextPage,
|
|
159
|
+
isLoadingMore: isFetchingNextPage,
|
|
160
|
+
refetch
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function useFormById(id) {
|
|
164
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
165
|
+
const client$1 = client.createApiClient({
|
|
166
|
+
baseURL: apiBaseURL,
|
|
167
|
+
basePath: apiBasePath
|
|
168
|
+
});
|
|
169
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
170
|
+
const baseQuery = queries.forms.byId(id);
|
|
171
|
+
const { data, isLoading, error, refetch } = reactQuery.useQuery({
|
|
172
|
+
...baseQuery,
|
|
173
|
+
...SHARED_QUERY_CONFIG,
|
|
174
|
+
enabled: !!id
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
form: data ?? null,
|
|
178
|
+
isLoading,
|
|
179
|
+
error,
|
|
180
|
+
refetch
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function useSuspenseFormById(id) {
|
|
184
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
185
|
+
const client$1 = client.createApiClient({
|
|
186
|
+
baseURL: apiBaseURL,
|
|
187
|
+
basePath: apiBasePath
|
|
188
|
+
});
|
|
189
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
190
|
+
const baseQuery = queries.forms.byId(id);
|
|
191
|
+
const { data, refetch, error, isFetching } = reactQuery.useSuspenseQuery({
|
|
192
|
+
...baseQuery,
|
|
193
|
+
...SHARED_QUERY_CONFIG
|
|
194
|
+
});
|
|
195
|
+
if (error && !isFetching) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
form: data ?? null,
|
|
200
|
+
refetch
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function useFormBySlug(slug) {
|
|
204
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
205
|
+
const client$1 = client.createApiClient({
|
|
206
|
+
baseURL: apiBaseURL,
|
|
207
|
+
basePath: apiBasePath
|
|
208
|
+
});
|
|
209
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
210
|
+
const baseQuery = queries.forms.bySlug(slug);
|
|
211
|
+
const { data, isLoading, error, refetch } = reactQuery.useQuery({
|
|
212
|
+
...baseQuery,
|
|
213
|
+
...SHARED_QUERY_CONFIG,
|
|
214
|
+
enabled: !!slug
|
|
215
|
+
});
|
|
216
|
+
return {
|
|
217
|
+
form: data ?? null,
|
|
218
|
+
isLoading,
|
|
219
|
+
error,
|
|
220
|
+
refetch
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function useSuspenseFormBySlug(slug) {
|
|
224
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
225
|
+
const client$1 = client.createApiClient({
|
|
226
|
+
baseURL: apiBaseURL,
|
|
227
|
+
basePath: apiBasePath
|
|
228
|
+
});
|
|
229
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
230
|
+
const baseQuery = queries.forms.bySlug(slug);
|
|
231
|
+
const { data, refetch, error, isFetching } = reactQuery.useSuspenseQuery({
|
|
232
|
+
...baseQuery,
|
|
233
|
+
...SHARED_QUERY_CONFIG
|
|
234
|
+
});
|
|
235
|
+
if (error && !isFetching) {
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
form: data ?? null,
|
|
240
|
+
refetch
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function useCreateForm() {
|
|
244
|
+
const { refresh, apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
245
|
+
const client$1 = client.createApiClient({
|
|
246
|
+
baseURL: apiBaseURL,
|
|
247
|
+
basePath: apiBasePath
|
|
248
|
+
});
|
|
249
|
+
const queryClient = reactQuery.useQueryClient();
|
|
250
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
251
|
+
return reactQuery.useMutation({
|
|
252
|
+
mutationKey: [...queries.forms._def, "create"],
|
|
253
|
+
mutationFn: async (data) => {
|
|
254
|
+
const response = await client$1("@post/forms", {
|
|
255
|
+
method: "POST",
|
|
256
|
+
body: data,
|
|
257
|
+
headers
|
|
258
|
+
});
|
|
259
|
+
if (isErrorResponse(response)) {
|
|
260
|
+
throw toError(response.error);
|
|
261
|
+
}
|
|
262
|
+
return response.data;
|
|
263
|
+
},
|
|
264
|
+
onSuccess: async () => {
|
|
265
|
+
await queryClient.invalidateQueries({
|
|
266
|
+
queryKey: queries.forms._def
|
|
267
|
+
});
|
|
268
|
+
if (refresh) {
|
|
269
|
+
await refresh();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function useUpdateForm() {
|
|
275
|
+
const { refresh, apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
276
|
+
const client$1 = client.createApiClient({
|
|
277
|
+
baseURL: apiBaseURL,
|
|
278
|
+
basePath: apiBasePath
|
|
279
|
+
});
|
|
280
|
+
const queryClient = reactQuery.useQueryClient();
|
|
281
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
282
|
+
return reactQuery.useMutation({
|
|
283
|
+
mutationKey: [...queries.forms._def, "update"],
|
|
284
|
+
mutationFn: async ({ id, data }) => {
|
|
285
|
+
const response = await client$1("@put/forms/:id", {
|
|
286
|
+
method: "PUT",
|
|
287
|
+
params: { id },
|
|
288
|
+
body: data,
|
|
289
|
+
headers
|
|
290
|
+
});
|
|
291
|
+
if (isErrorResponse(response)) {
|
|
292
|
+
throw toError(response.error);
|
|
293
|
+
}
|
|
294
|
+
return response.data;
|
|
295
|
+
},
|
|
296
|
+
onSuccess: async (updated) => {
|
|
297
|
+
if (updated) {
|
|
298
|
+
queryClient.setQueryData(
|
|
299
|
+
queries.forms.byId(updated.id).queryKey,
|
|
300
|
+
updated
|
|
301
|
+
);
|
|
302
|
+
queryClient.setQueryData(
|
|
303
|
+
queries.forms.bySlug(updated.slug).queryKey,
|
|
304
|
+
updated
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
await queryClient.invalidateQueries({
|
|
308
|
+
queryKey: queries.forms._def
|
|
309
|
+
});
|
|
310
|
+
if (refresh) {
|
|
311
|
+
await refresh();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
function useDeleteForm() {
|
|
317
|
+
const { refresh, apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
318
|
+
const client$1 = client.createApiClient({
|
|
319
|
+
baseURL: apiBaseURL,
|
|
320
|
+
basePath: apiBasePath
|
|
321
|
+
});
|
|
322
|
+
const queryClient = reactQuery.useQueryClient();
|
|
323
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
324
|
+
return reactQuery.useMutation({
|
|
325
|
+
mutationKey: [...queries.forms._def, "delete"],
|
|
326
|
+
mutationFn: async (id) => {
|
|
327
|
+
const response = await client$1("@delete/forms/:id", {
|
|
328
|
+
method: "DELETE",
|
|
329
|
+
params: { id },
|
|
330
|
+
headers
|
|
331
|
+
});
|
|
332
|
+
if (isErrorResponse(response)) {
|
|
333
|
+
throw toError(response.error);
|
|
334
|
+
}
|
|
335
|
+
return response.data;
|
|
336
|
+
},
|
|
337
|
+
onSuccess: async () => {
|
|
338
|
+
await queryClient.invalidateQueries({
|
|
339
|
+
queryKey: queries.forms._def
|
|
340
|
+
});
|
|
341
|
+
if (refresh) {
|
|
342
|
+
await refresh();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
function useSubmitForm(slug) {
|
|
348
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
349
|
+
const client$1 = client.createApiClient({
|
|
350
|
+
baseURL: apiBaseURL,
|
|
351
|
+
basePath: apiBasePath
|
|
352
|
+
});
|
|
353
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
354
|
+
return reactQuery.useMutation({
|
|
355
|
+
mutationKey: [...queries.forms._def, slug, "submit"],
|
|
356
|
+
mutationFn: async ({ data }) => {
|
|
357
|
+
const response = await client$1("@post/forms/:slug/submit", {
|
|
358
|
+
method: "POST",
|
|
359
|
+
params: { slug },
|
|
360
|
+
body: { data },
|
|
361
|
+
headers
|
|
362
|
+
});
|
|
363
|
+
if (isErrorResponse(response)) {
|
|
364
|
+
throw toError(response.error);
|
|
365
|
+
}
|
|
366
|
+
return response.data;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function useSubmissions(formId, options = {}) {
|
|
371
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
372
|
+
const client$1 = client.createApiClient({
|
|
373
|
+
baseURL: apiBaseURL,
|
|
374
|
+
basePath: apiBasePath
|
|
375
|
+
});
|
|
376
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
377
|
+
const { limit = 20, enabled = true } = options;
|
|
378
|
+
const baseQuery = queries.formSubmissions.list({
|
|
379
|
+
formId,
|
|
380
|
+
limit,
|
|
381
|
+
offset: 0
|
|
382
|
+
});
|
|
383
|
+
const {
|
|
384
|
+
data,
|
|
385
|
+
isLoading,
|
|
386
|
+
error,
|
|
387
|
+
fetchNextPage,
|
|
388
|
+
hasNextPage,
|
|
389
|
+
isFetchingNextPage,
|
|
390
|
+
refetch
|
|
391
|
+
} = reactQuery.useInfiniteQuery({
|
|
392
|
+
queryKey: baseQuery.queryKey,
|
|
393
|
+
queryFn: async ({ pageParam = 0 }) => {
|
|
394
|
+
const response = await client$1("/forms/:formId/submissions", {
|
|
395
|
+
method: "GET",
|
|
396
|
+
params: { formId },
|
|
397
|
+
query: { limit, offset: pageParam },
|
|
398
|
+
headers
|
|
399
|
+
});
|
|
400
|
+
if (isErrorResponse(response)) {
|
|
401
|
+
throw toError(response.error);
|
|
402
|
+
}
|
|
403
|
+
return response.data;
|
|
404
|
+
},
|
|
405
|
+
...SHARED_QUERY_CONFIG,
|
|
406
|
+
initialPageParam: 0,
|
|
407
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
408
|
+
if (!lastPage || typeof lastPage !== "object") return void 0;
|
|
409
|
+
const items = lastPage?.items;
|
|
410
|
+
if (!Array.isArray(items) || items.length < limit) return void 0;
|
|
411
|
+
const loadedCount = (allPages || []).reduce(
|
|
412
|
+
(sum, page) => sum + (Array.isArray(page?.items) ? page.items.length : 0),
|
|
413
|
+
0
|
|
414
|
+
);
|
|
415
|
+
const total2 = lastPage?.total ?? 0;
|
|
416
|
+
if (loadedCount >= total2) return void 0;
|
|
417
|
+
return loadedCount;
|
|
418
|
+
},
|
|
419
|
+
enabled: enabled && !!formId
|
|
420
|
+
});
|
|
421
|
+
const pages = data?.pages;
|
|
422
|
+
const submissions = pages?.flatMap(
|
|
423
|
+
(page) => Array.isArray(page?.items) ? page.items : []
|
|
424
|
+
) ?? [];
|
|
425
|
+
const total = pages?.[0]?.total ?? 0;
|
|
426
|
+
return {
|
|
427
|
+
submissions,
|
|
428
|
+
total,
|
|
429
|
+
isLoading,
|
|
430
|
+
error,
|
|
431
|
+
loadMore: fetchNextPage,
|
|
432
|
+
hasMore: !!hasNextPage,
|
|
433
|
+
isLoadingMore: isFetchingNextPage,
|
|
434
|
+
refetch
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function useSuspenseSubmissions(formId, options = {}) {
|
|
438
|
+
const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
439
|
+
const client$1 = client.createApiClient({
|
|
440
|
+
baseURL: apiBaseURL,
|
|
441
|
+
basePath: apiBasePath
|
|
442
|
+
});
|
|
443
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
444
|
+
const { limit = 20 } = options;
|
|
445
|
+
const baseQuery = queries.formSubmissions.list({
|
|
446
|
+
formId,
|
|
447
|
+
limit,
|
|
448
|
+
offset: 0
|
|
449
|
+
});
|
|
450
|
+
const {
|
|
451
|
+
data,
|
|
452
|
+
fetchNextPage,
|
|
453
|
+
hasNextPage,
|
|
454
|
+
isFetchingNextPage,
|
|
455
|
+
refetch,
|
|
456
|
+
error,
|
|
457
|
+
isFetching
|
|
458
|
+
} = reactQuery.useSuspenseInfiniteQuery({
|
|
459
|
+
queryKey: baseQuery.queryKey,
|
|
460
|
+
queryFn: async ({ pageParam = 0 }) => {
|
|
461
|
+
const response = await client$1("/forms/:formId/submissions", {
|
|
462
|
+
method: "GET",
|
|
463
|
+
params: { formId },
|
|
464
|
+
query: { limit, offset: pageParam },
|
|
465
|
+
headers
|
|
466
|
+
});
|
|
467
|
+
if (isErrorResponse(response)) {
|
|
468
|
+
throw toError(response.error);
|
|
469
|
+
}
|
|
470
|
+
return response.data;
|
|
471
|
+
},
|
|
472
|
+
...SHARED_QUERY_CONFIG,
|
|
473
|
+
initialPageParam: 0,
|
|
474
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
475
|
+
if (!lastPage || typeof lastPage !== "object") return void 0;
|
|
476
|
+
const items = lastPage?.items;
|
|
477
|
+
if (!Array.isArray(items) || items.length < limit) return void 0;
|
|
478
|
+
const loadedCount = (allPages || []).reduce(
|
|
479
|
+
(sum, page) => sum + (Array.isArray(page?.items) ? page.items.length : 0),
|
|
480
|
+
0
|
|
481
|
+
);
|
|
482
|
+
const total2 = lastPage?.total ?? 0;
|
|
483
|
+
if (loadedCount >= total2) return void 0;
|
|
484
|
+
return loadedCount;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
if (error && !isFetching) {
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
const pages = data.pages;
|
|
491
|
+
const submissions = pages?.flatMap(
|
|
492
|
+
(page) => Array.isArray(page?.items) ? page.items : []
|
|
493
|
+
) ?? [];
|
|
494
|
+
const total = pages?.[0]?.total ?? 0;
|
|
495
|
+
return {
|
|
496
|
+
submissions,
|
|
497
|
+
total,
|
|
498
|
+
loadMore: fetchNextPage,
|
|
499
|
+
hasMore: !!hasNextPage,
|
|
500
|
+
isLoadingMore: isFetchingNextPage,
|
|
501
|
+
refetch
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function useDeleteSubmission(formId) {
|
|
505
|
+
const { refresh, apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("form-builder");
|
|
506
|
+
const client$1 = client.createApiClient({
|
|
507
|
+
baseURL: apiBaseURL,
|
|
508
|
+
basePath: apiBasePath
|
|
509
|
+
});
|
|
510
|
+
const queryClient = reactQuery.useQueryClient();
|
|
511
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
512
|
+
return reactQuery.useMutation({
|
|
513
|
+
mutationKey: [...queries.formSubmissions._def, formId, "delete"],
|
|
514
|
+
mutationFn: async (subId) => {
|
|
515
|
+
const response = await client$1(
|
|
516
|
+
"@delete/forms/:formId/submissions/:subId",
|
|
517
|
+
{
|
|
518
|
+
method: "DELETE",
|
|
519
|
+
params: { formId, subId },
|
|
520
|
+
headers
|
|
521
|
+
}
|
|
522
|
+
);
|
|
523
|
+
if (isErrorResponse(response)) {
|
|
524
|
+
throw toError(response.error);
|
|
525
|
+
}
|
|
526
|
+
return response.data;
|
|
527
|
+
},
|
|
528
|
+
onSuccess: async () => {
|
|
529
|
+
await queryClient.invalidateQueries({
|
|
530
|
+
queryKey: queries.formSubmissions._def
|
|
531
|
+
});
|
|
532
|
+
if (refresh) {
|
|
533
|
+
await refresh();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
exports.useCreateForm = useCreateForm;
|
|
540
|
+
exports.useDeleteForm = useDeleteForm;
|
|
541
|
+
exports.useDeleteSubmission = useDeleteSubmission;
|
|
542
|
+
exports.useFormById = useFormById;
|
|
543
|
+
exports.useFormBySlug = useFormBySlug;
|
|
544
|
+
exports.useForms = useForms;
|
|
545
|
+
exports.useSubmissions = useSubmissions;
|
|
546
|
+
exports.useSubmitForm = useSubmitForm;
|
|
547
|
+
exports.useSuspenseFormById = useSuspenseFormById;
|
|
548
|
+
exports.useSuspenseFormBySlug = useSuspenseFormBySlug;
|
|
549
|
+
exports.useSuspenseForms = useSuspenseForms;
|
|
550
|
+
exports.useSuspenseSubmissions = useSuspenseSubmissions;
|
|
551
|
+
exports.useUpdateForm = useUpdateForm;
|