@compill/admin 1.0.101 → 1.0.103

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 (169) hide show
  1. package/dist/index.js +50 -0
  2. package/{src → dist}/lib/SectionTitle.d.ts +0 -1
  3. package/dist/lib/SectionTitle.js +4 -0
  4. package/{src → dist}/lib/breadcrumbs/BreadCrumbs.d.ts +0 -1
  5. package/dist/lib/breadcrumbs/BreadCrumbs.js +29 -0
  6. package/dist/lib/buttons/DialogButton.js +15 -0
  7. package/{src → dist}/lib/buttons/InvalidateButton.d.ts +0 -1
  8. package/dist/lib/buttons/InvalidateButton.js +11 -0
  9. package/{src → dist}/lib/buttons/NavigateButton.d.ts +0 -1
  10. package/dist/lib/buttons/NavigateButton.js +12 -0
  11. package/{src → dist}/lib/buttons/PublishButton.d.ts +0 -1
  12. package/dist/lib/buttons/PublishButton.js +17 -0
  13. package/{src → dist}/lib/buttons/UpdateButton.d.ts +0 -1
  14. package/dist/lib/buttons/UpdateButton.js +11 -0
  15. package/{src → dist}/lib/buttons/ViewButton.d.ts +1 -2
  16. package/dist/lib/buttons/ViewButton.js +13 -0
  17. package/{src → dist}/lib/cells/OrderCell.d.ts +0 -1
  18. package/dist/lib/cells/OrderCell.js +26 -0
  19. package/{src → dist}/lib/json/DetailsView.d.ts +0 -1
  20. package/dist/lib/json/DetailsView.js +69 -0
  21. package/{src → dist}/lib/json/EditItemView.d.ts +0 -1
  22. package/dist/lib/json/EditItemView.js +6 -0
  23. package/{src → dist}/lib/json/MultiQueryWrapper.d.ts +0 -1
  24. package/dist/lib/json/MultiQueryWrapper.js +61 -0
  25. package/{src → dist}/lib/json/QueryWrapper.d.ts +0 -1
  26. package/dist/lib/json/QueryWrapper.js +29 -0
  27. package/{src → dist}/lib/json/ScreenRenderer.d.ts +0 -1
  28. package/dist/lib/json/ScreenRenderer.js +19 -0
  29. package/{src → dist}/lib/json/ScreenTopBar.d.ts +0 -1
  30. package/dist/lib/json/ScreenTopBar.js +18 -0
  31. package/{src → dist}/lib/json/TabbedView.d.ts +0 -1
  32. package/dist/lib/json/TabbedView.js +21 -0
  33. package/{src → dist}/lib/json/buttons/ActionButton.d.ts +0 -1
  34. package/dist/lib/json/buttons/ActionButton.js +11 -0
  35. package/{src → dist}/lib/json/buttons/ConfirmationActionButton.d.ts +0 -1
  36. package/dist/lib/json/buttons/ConfirmationActionButton.js +20 -0
  37. package/{src → dist}/lib/json/dialog/DialogRenderer.d.ts +0 -1
  38. package/dist/lib/json/dialog/DialogRenderer.js +14 -0
  39. package/dist/lib/json/dialog/ItemDeleteDialog.js +14 -0
  40. package/dist/lib/json/dialog/ItemEditDialog.js +77 -0
  41. package/{src → dist}/lib/json/dialog/MultiQueryWrapperDialog.d.ts +0 -1
  42. package/dist/lib/json/dialog/MultiQueryWrapperDialog.js +23 -0
  43. package/{src → dist}/lib/json/dialog/QueryWrapperDialog.d.ts +0 -1
  44. package/dist/lib/json/dialog/QueryWrapperDialog.js +20 -0
  45. package/{src → dist}/lib/json/table/RefreshButton.d.ts +0 -1
  46. package/dist/lib/json/table/RefreshButton.js +11 -0
  47. package/{src → dist}/lib/json/table/TableRowActionsView.d.ts +0 -1
  48. package/dist/lib/json/table/TableRowActionsView.js +36 -0
  49. package/{src → dist}/lib/json/table/TableRowPublishPostButton.d.ts +0 -1
  50. package/dist/lib/json/table/TableRowPublishPostButton.js +20 -0
  51. package/{src → dist}/lib/json/table/TableView.d.ts +0 -1
  52. package/dist/lib/json/table/TableView.js +65 -0
  53. package/dist/lib/json/table/TableViewContext.js +58 -0
  54. package/dist/lib/json/table/useTableProps.js +57 -0
  55. package/{src → dist}/lib/json/types/DetailsView.d.ts +0 -1
  56. package/dist/lib/json/types/DetailsView.js +1 -0
  57. package/dist/lib/json/types/EditItemDialog.js +1 -0
  58. package/dist/lib/json/types/MultiQueryWrapper.js +1 -0
  59. package/dist/lib/json/types/MultiQueryWrapperDialog.js +1 -0
  60. package/dist/lib/json/types/QueryWrapper.js +1 -0
  61. package/dist/lib/json/types/QueryWrapperDialog.js +1 -0
  62. package/dist/lib/json/types/ScreenConfig.js +1 -0
  63. package/{src → dist}/lib/json/types/TabbedView.d.ts +0 -1
  64. package/dist/lib/json/types/TabbedView.js +1 -0
  65. package/{src → dist}/lib/json/types/TableView.d.ts +0 -1
  66. package/dist/lib/json/types/TableView.js +1 -0
  67. package/{src → dist}/lib/layout/AdminLayout.d.ts +0 -1
  68. package/dist/lib/layout/AdminLayout.js +15 -0
  69. package/{src → dist}/lib/layout/ButtonBar.d.ts +1 -1
  70. package/dist/lib/layout/ButtonBar.js +19 -0
  71. package/{src → dist}/lib/layout/Content.d.ts +0 -1
  72. package/dist/lib/layout/Content.js +9 -0
  73. package/{src → dist}/lib/layout/PageTitleBar.d.ts +0 -1
  74. package/dist/lib/layout/PageTitleBar.js +4 -0
  75. package/{src → dist}/lib/layout/Sidebar.d.ts +0 -1
  76. package/dist/lib/layout/Sidebar.js +12 -0
  77. package/{src → dist}/lib/layout/menu/Menu.d.ts +0 -1
  78. package/dist/lib/layout/menu/Menu.js +23 -0
  79. package/{src → dist}/lib/layout/menu/MenuButton.d.ts +0 -1
  80. package/dist/lib/layout/menu/MenuButton.js +5 -0
  81. package/dist/lib/layout/menu/MenuConfig.js +1 -0
  82. package/{src → dist}/lib/layout/menu/MenuItem.d.ts +0 -1
  83. package/dist/lib/layout/menu/MenuItem.js +11 -0
  84. package/{src → dist}/lib/layout/menu/NextMenuItem.d.ts +0 -1
  85. package/dist/lib/layout/menu/NextMenuItem.js +11 -0
  86. package/{src → dist}/lib/layout/menu/SelectedIndicator.d.ts +0 -1
  87. package/dist/lib/layout/menu/SelectedIndicator.js +4 -0
  88. package/{src → dist}/lib/layout/menu/UserBlock.d.ts +1 -2
  89. package/dist/lib/layout/menu/UserBlock.js +34 -0
  90. package/{src → dist}/lib/modal/AttachDialog.d.ts +0 -1
  91. package/dist/lib/modal/AttachDialog.js +73 -0
  92. package/dist/lib/modal/FormActionDialog.js +20 -0
  93. package/{src → dist}/lib/page/PageContainer.d.ts +0 -1
  94. package/dist/lib/page/PageContainer.js +5 -0
  95. package/{src → dist}/lib/page/PageContentEditor.d.ts +0 -1
  96. package/dist/lib/page/PageContentEditor.js +10 -0
  97. package/{src → dist}/lib/page/PageMain.d.ts +0 -1
  98. package/dist/lib/page/PageMain.js +5 -0
  99. package/dist/lib/page/PageQueryStateContainer.js +16 -0
  100. package/{src → dist}/lib/page/PageSectionTitle.d.ts +0 -1
  101. package/dist/lib/page/PageSectionTitle.js +4 -0
  102. package/{src → dist}/lib/page/PageSidebar.d.ts +0 -1
  103. package/dist/lib/page/PageSidebar.js +4 -0
  104. package/{src → dist}/lib/page/PageSidebarSection.d.ts +0 -1
  105. package/dist/lib/page/PageSidebarSection.js +5 -0
  106. package/dist/lib/page/PageStateContainer.js +7 -0
  107. package/{src → dist}/lib/page/PageSubSectionTitle.d.ts +0 -1
  108. package/dist/lib/page/PageSubSectionTitle.js +4 -0
  109. package/{src → dist}/lib/page/PageTitle.d.ts +0 -1
  110. package/dist/lib/page/PageTitle.js +4 -0
  111. package/dist/lib/page/PageTopBar.js +78 -0
  112. package/{src → dist}/lib/status/StatusBadge.d.ts +0 -1
  113. package/dist/lib/status/StatusBadge.js +21 -0
  114. package/dist/lib/table/TableColumnButton.d.ts +1 -0
  115. package/dist/lib/table/TableColumnButton.js +53 -0
  116. package/{src → dist}/lib/table/TableContainer.d.ts +0 -1
  117. package/dist/lib/table/TableContainer.js +6 -0
  118. package/dist/lib/table/TableContainerContext.js +40 -0
  119. package/{src → dist}/lib/table/TableCreateButton.d.ts +0 -1
  120. package/dist/lib/table/TableCreateButton.js +7 -0
  121. package/{src → dist}/lib/table/TableFilterButton.d.ts +0 -1
  122. package/dist/lib/table/TableFilterButton.js +8 -0
  123. package/{src → dist}/lib/table/TableFilters.d.ts +0 -1
  124. package/dist/lib/table/TableFilters.js +27 -0
  125. package/{src → dist}/lib/table/TableMassActions.d.ts +0 -1
  126. package/dist/lib/table/TableMassActions.js +9 -0
  127. package/{src → dist}/lib/table/TableRowActionBar.d.ts +0 -1
  128. package/dist/lib/table/TableRowActionBar.js +8 -0
  129. package/{src → dist}/lib/table/TableRowActionButton.d.ts +0 -1
  130. package/dist/lib/table/TableRowActionButton.js +5 -0
  131. package/{src → dist}/lib/table/TableRowActionDialogButton.d.ts +1 -2
  132. package/dist/lib/table/TableRowActionDialogButton.js +6 -0
  133. package/{src → dist}/lib/table/TableRowDeleteButton.d.ts +0 -1
  134. package/dist/lib/table/TableRowDeleteButton.js +6 -0
  135. package/{src → dist}/lib/table/TableRowEditButton.d.ts +0 -1
  136. package/dist/lib/table/TableRowEditButton.js +6 -0
  137. package/{src → dist}/lib/table/TableRowNavigateButton.d.ts +0 -1
  138. package/dist/lib/table/TableRowNavigateButton.js +14 -0
  139. package/{src → dist}/lib/table/TableRowPublishPostButton.d.ts +0 -1
  140. package/dist/lib/table/TableRowPublishPostButton.js +19 -0
  141. package/{src → dist}/lib/table/TableRowViewButton.d.ts +0 -1
  142. package/dist/lib/table/TableRowViewButton.js +13 -0
  143. package/{src → dist}/lib/table/TableTopBar.d.ts +1 -2
  144. package/dist/lib/table/TableTopBar.js +5 -0
  145. package/package.json +60 -4
  146. package/README.md +0 -7
  147. package/index.cjs.d.ts +0 -1
  148. package/index.cjs.js +0 -3710
  149. package/index.esm.d.ts +0 -1
  150. package/index.esm.js +0 -3662
  151. package/src/lib/table/TableColumnButton.d.ts +0 -0
  152. /package/{src → dist}/index.d.ts +0 -0
  153. /package/{src → dist}/lib/buttons/DialogButton.d.ts +0 -0
  154. /package/{src → dist}/lib/json/dialog/ItemDeleteDialog.d.ts +0 -0
  155. /package/{src → dist}/lib/json/dialog/ItemEditDialog.d.ts +0 -0
  156. /package/{src → dist}/lib/json/table/TableViewContext.d.ts +0 -0
  157. /package/{src → dist}/lib/json/table/useTableProps.d.ts +0 -0
  158. /package/{src → dist}/lib/json/types/EditItemDialog.d.ts +0 -0
  159. /package/{src → dist}/lib/json/types/MultiQueryWrapper.d.ts +0 -0
  160. /package/{src → dist}/lib/json/types/MultiQueryWrapperDialog.d.ts +0 -0
  161. /package/{src → dist}/lib/json/types/QueryWrapper.d.ts +0 -0
  162. /package/{src → dist}/lib/json/types/QueryWrapperDialog.d.ts +0 -0
  163. /package/{src → dist}/lib/json/types/ScreenConfig.d.ts +0 -0
  164. /package/{src → dist}/lib/layout/menu/MenuConfig.d.ts +0 -0
  165. /package/{src → dist}/lib/modal/FormActionDialog.d.ts +0 -0
  166. /package/{src → dist}/lib/page/PageQueryStateContainer.d.ts +0 -0
  167. /package/{src → dist}/lib/page/PageStateContainer.d.ts +0 -0
  168. /package/{src → dist}/lib/page/PageTopBar.d.ts +0 -0
  169. /package/{src → dist}/lib/table/TableContainerContext.d.ts +0 -0
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ export * from "./lib/SectionTitle";
2
+ export * from "./lib/breadcrumbs/BreadCrumbs";
3
+ export * from "./lib/buttons/DialogButton";
4
+ export * from "./lib/buttons/InvalidateButton";
5
+ export * from "./lib/buttons/NavigateButton";
6
+ export * from "./lib/buttons/PublishButton";
7
+ export * from "./lib/buttons/UpdateButton";
8
+ export * from "./lib/buttons/ViewButton";
9
+ export * from "./lib/cells/OrderCell";
10
+ export * from "./lib/json/ScreenRenderer";
11
+ export * from "./lib/json/dialog/ItemEditDialog";
12
+ export * from "./lib/json/dialog/ItemDeleteDialog";
13
+ export * from "./lib/json/types/DetailsView";
14
+ export * from "./lib/json/types/EditItemDialog";
15
+ export * from "./lib/json/types/MultiQueryWrapper";
16
+ export * from "./lib/json/types/QueryWrapper";
17
+ export * from "./lib/json/types/QueryWrapperDialog";
18
+ export * from "./lib/json/types/ScreenConfig";
19
+ export * from "./lib/json/types/TabbedView";
20
+ export * from "./lib/json/types/TableView";
21
+ export * from "./lib/layout/AdminLayout";
22
+ export * from "./lib/layout/ButtonBar";
23
+ export * from "./lib/layout/menu/Menu";
24
+ export * from "./lib/layout/menu/MenuConfig";
25
+ export * from "./lib/modal/AttachDialog";
26
+ export * from "./lib/modal/FormActionDialog";
27
+ export * from "./lib/page/PageContainer";
28
+ export * from "./lib/page/PageContentEditor";
29
+ export * from "./lib/page/PageMain";
30
+ export * from "./lib/page/PageQueryStateContainer";
31
+ export * from "./lib/page/PageSectionTitle";
32
+ export * from "./lib/page/PageSidebar";
33
+ export * from "./lib/page/PageSidebarSection";
34
+ export * from "./lib/page/PageStateContainer";
35
+ export * from "./lib/page/PageSubSectionTitle";
36
+ export * from "./lib/page/PageTitle";
37
+ export * from "./lib/page/PageTopBar";
38
+ export * from "./lib/status/StatusBadge";
39
+ export * from "./lib/table/TableContainer";
40
+ export * from "./lib/table/TableCreateButton";
41
+ export * from "./lib/table/TableFilterButton";
42
+ export * from "./lib/table/TableRowActionBar";
43
+ export * from "./lib/table/TableRowActionButton";
44
+ export * from "./lib/table/TableRowActionDialogButton";
45
+ export * from "./lib/table/TableRowDeleteButton";
46
+ export * from "./lib/table/TableRowEditButton";
47
+ export * from "./lib/table/TableRowNavigateButton";
48
+ export * from "./lib/table/TableRowPublishPostButton";
49
+ export * from "./lib/table/TableRowViewButton";
50
+ export * from "./lib/table/TableTopBar";
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import { ParentComponent, SoperioComponent } from "@soperio/react";
3
2
  export declare function SectionTitle({ children, ...props }: SoperioComponent & ParentComponent): JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ export function SectionTitle({ children, ...props }) {
3
+ return _jsx("h2", { textSize: "xl", fontWeight: "600", textColor: "slate-800", ...props, children: children });
4
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { SoperioComponent } from "@soperio/react";
3
2
  export interface Breadcrumb {
4
3
  label: string;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@soperio/jsx-runtime";
2
+ import { useApiQuery } from "@compill/api";
3
+ import { Shimmer } from "@compill/components";
4
+ import { mdiCircleSmall } from "@mdi/js";
5
+ import { Icon } from "@valerya/ui";
6
+ import { isArray } from "es-toolkit/compat";
7
+ import Link from "next/link";
8
+ import { useParams } from "react-router-dom";
9
+ export function Breadcrumbs({ breadcrumbs, ...props }) {
10
+ if (isArray(breadcrumbs)) {
11
+ return (_jsx("div", { dflex: true, alignItems: "center", trait: "typo.h5", ...props, children: breadcrumbs.map((b, index) => _jsx(BreadcrumbItem, { breadcrumb: b, showSeparator: index > 0 }, index)) }));
12
+ }
13
+ return _jsx(QueryBreadcrumbs, { queryFn: breadcrumbs.queryFn, queryField: breadcrumbs.queryField, generate: breadcrumbs.generate });
14
+ }
15
+ function QueryBreadcrumbs({ queryFn, queryField, generate, ...props }) {
16
+ const params = useParams();
17
+ const id = queryField ? params[queryField] : undefined;
18
+ const { data, isLoading, isError } = useApiQuery([""], queryFn, id);
19
+ if (isLoading || isError) {
20
+ return (_jsxs("div", { dflex: true, alignItems: "center", children: [_jsx(Shimmer, { h: "8", w: "24" }), _jsx(Icon, { path: mdiCircleSmall, mx: "1" }), _jsx(Shimmer, { h: "8", w: "20" })] }));
21
+ }
22
+ const breadcrumbs = generate(data);
23
+ return (_jsx("div", { dflex: true, alignItems: "center", trait: "typo.h5", ...props, children: breadcrumbs.map((b, index) => _jsx(BreadcrumbItem, { breadcrumb: b, showSeparator: index > 0 }, index)) }));
24
+ }
25
+ function BreadcrumbItem({ breadcrumb, showSeparator }) {
26
+ return (_jsxs(_Fragment, { children: [showSeparator && _jsx(Icon, { path: mdiCircleSmall, mx: "1" }), _jsx(Link, { href: `/${breadcrumb.path || "#"}`, children: _jsx("span", {
27
+ // onClick={breadcrumb.path ? handleClick : undefined}
28
+ hover_textDecoration: breadcrumb.path ? "underline" : undefined, cursor: breadcrumb.path ? "pointer" : undefined, children: breadcrumb.label }) })] }));
29
+ }
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { Button } from "@valerya/ui";
3
+ import React from "react";
4
+ export function DialogButton({ buildDialog, ...props }) {
5
+ const [showDialog, setShowDialog] = React.useState(false);
6
+ const onShowDialog = React.useCallback((event) => {
7
+ event?.preventDefault();
8
+ event?.stopPropagation();
9
+ setShowDialog(true);
10
+ }, [setShowDialog]);
11
+ const onCloseDialog = React.useCallback(() => {
12
+ setShowDialog(false);
13
+ }, [setShowDialog]);
14
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: onShowDialog, ...props }), showDialog && buildDialog(onCloseDialog)] }));
15
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ButtonBarButtonProps } from "../layout/ButtonBar";
3
2
  interface InvalidateButtonProps extends ButtonBarButtonProps {
4
3
  pathOrPermalink: string;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { INVALIDATE_API } from "@compill/admin-api";
3
+ import { useApiMutation, useMutate } from "@compill/api";
4
+ import { mdiDatabaseRefreshOutline } from "@mdi/js";
5
+ import { ButtonBarButton } from "../layout/ButtonBar";
6
+ export function InvalidateButton({ pathOrPermalink, ...props }) {
7
+ const api = INVALIDATE_API.new(pathOrPermalink);
8
+ const mutation = useApiMutation(api.invalidate, api.queryKey);
9
+ const invalidate = useMutate(mutation, { successMsg: "Page successfully invalidated" });
10
+ return (_jsx(ButtonBarButton, { title: "Regenerate", disabled: mutation.isLoading, onClick: invalidate, icon: mdiDatabaseRefreshOutline, ...props }));
11
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ButtonProps } from "@valerya/ui";
3
2
  export declare function NavigateButton({ path, ...props }: {
4
3
  path: string;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { mdiPost } from "@mdi/js";
3
+ import { Button, Icon } from "@valerya/ui";
4
+ import React from "react";
5
+ import { useNavigate } from "react-router-dom";
6
+ export function NavigateButton({ path, ...props }) {
7
+ const navigate = useNavigate();
8
+ const handleClick = React.useCallback(() => {
9
+ navigate(path);
10
+ }, [navigate, path]);
11
+ return (_jsx(Button, { type: "submit", scheme: "dark", variant: "glass", corners: "pill", w: "10", h: "10", onClick: handleClick, ...props, children: _jsx(Icon, { path: mdiPost }) }));
12
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { API } from "@compill/admin-api";
3
2
  import { ButtonProps } from "@valerya/ui";
4
3
  interface PublishButtonProps extends ButtonProps {
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { useInvalidateMutation } from "@compill/api";
3
+ import { mdiEye, mdiEyeOff } from "@mdi/js";
4
+ import React from "react";
5
+ import { toast } from "react-toastify";
6
+ import { ButtonBarButton } from "../layout/ButtonBar";
7
+ export function PublishButton({ status, queryId, api, ...props }) {
8
+ const isDraft = status == "draft";
9
+ const mutation = useInvalidateMutation(isDraft ? api.publish : api.unpublish, api.queryKey, queryId, { networkMode: "always" });
10
+ const publish = React.useCallback(() => {
11
+ mutation.reset();
12
+ mutation.mutateAsync(queryId)
13
+ .then(() => toast.success(isDraft ? "Published!" : "Unpublished!"))
14
+ .catch(error => toast.error(`Error: ${error}`));
15
+ }, [mutation, queryId]);
16
+ return (_jsx(ButtonBarButton, { disabled: mutation.isLoading, onClick: publish, icon: isDraft ? mdiEye : mdiEyeOff, ...props, children: isDraft ? "Publish" : "Switch to draft" }));
17
+ }
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import { ButtonProps } from "@valerya/ui";
3
2
  export declare function UpdateButton({ ...props }: ButtonProps): JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { mdiCloudUpload } from "@mdi/js";
3
+ import { useFormikContext } from "formik";
4
+ import { useHotkeys } from "react-hotkeys-hook";
5
+ import { ButtonBarSubmitButton } from "../layout/ButtonBar";
6
+ export function UpdateButton({ ...props }) {
7
+ const { dirty, handleSubmit } = useFormikContext() ?? { dirty: false, handleSubmit: undefined, values: {} };
8
+ useHotkeys('ctrl+s', () => { if (dirty && !props.disabled)
9
+ handleSubmit(); }, { preventDefault: true }, [dirty, props, handleSubmit]);
10
+ return (_jsx(ButtonBarSubmitButton, { icon: mdiCloudUpload, ...props, children: "Update" }));
11
+ }
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
- import { ButtonBarButtonProps } from "@compill/admin";
1
+ import { ButtonBarButtonProps } from "../layout/ButtonBar";
3
2
  export declare function ViewButton({ label, path, icon, ...props }: ButtonBarButtonProps & {
4
3
  label?: string;
5
4
  path: string;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { mdiOpenInNew } from "@mdi/js";
3
+ import React from "react";
4
+ import { ButtonBarButton } from "../layout/ButtonBar";
5
+ export function ViewButton({ label, path, icon, ...props }) {
6
+ const openPage = React.useCallback(() => {
7
+ window.open(path, '_blank');
8
+ }, [path]);
9
+ return (_jsx(ButtonBarButton, { onClick: openPage, dflex: true, alignItems: "center", gap: "2", icon: icon || mdiOpenInNew, ...props, children: label }));
10
+ // return (
11
+ // <IconButton icon={icon ? icon : mdiOpenInNew} type="submit" scheme="dark" variant="glass" size="md" onClick={openPage} {...props}/>
12
+ // )
13
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  interface OrderApi {
3
2
  moveUp: (id: string) => Promise<any>;
4
3
  moveDown: (id: string) => Promise<any>;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { FlexCenter } from "@compill/components";
3
+ import { useInvalidateMutation } from "@compill/api";
4
+ import { mdiArrowDownBoldBox, mdiArrowUpBoldBox } from "@mdi/js";
5
+ import { Button, Icon } from "@valerya/ui";
6
+ import React from "react";
7
+ import { toast } from "react-toastify";
8
+ export function OrderCell({ api, postId, order }) {
9
+ const mutationDown = useInvalidateMutation(api.moveDown, api.queryKey);
10
+ const mutationUp = useInvalidateMutation(api.moveUp, api.queryKey);
11
+ const moveDown = React.useCallback((e) => {
12
+ e.stopPropagation();
13
+ mutationDown.mutateAsync(postId)
14
+ .catch(error => {
15
+ toast.error(`Error: ${error}`);
16
+ });
17
+ }, [mutationDown, postId]);
18
+ const moveUp = React.useCallback((e) => {
19
+ e.stopPropagation();
20
+ mutationUp.mutateAsync(postId)
21
+ .catch(error => {
22
+ toast.error(`Error: ${error}`);
23
+ });
24
+ }, [mutationUp, postId]);
25
+ return (_jsxs(FlexCenter, { placeContent: "start", numericFontVariant: "tabular-nums", children: [order, _jsx(Button, { ms: "3", variant: "borderless", scheme: "dark", onClick: moveUp, children: _jsx(Icon, { path: mdiArrowUpBoldBox }) }), _jsx(Button, { variant: "borderless", scheme: "dark", onClick: moveDown, children: _jsx(Icon, { path: mdiArrowDownBoldBox }) })] }));
26
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { SoperioComponent } from "@soperio/react";
3
2
  import { DetailsViewConfig } from "./types/DetailsView";
4
3
  export declare function DetailsView({ queryField, api, useNextRouter, processInput, screen, tabbed, ...props }: DetailsViewConfig & {
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { useInvalidateParentMutation, useMutate } from "@compill/api";
3
+ import { FormProvider, FormRenderer, TextArea } from "@compill/form";
4
+ import { runIfFn } from "@soperio/react";
5
+ import React from "react";
6
+ import { useParams } from "react-router-dom";
7
+ import { PageContainer } from "../page/PageContainer";
8
+ import { PageContentEditor } from "../page/PageContentEditor";
9
+ import { PageQueryStateContainer } from "../page/PageQueryStateContainer";
10
+ import { PageSidebar } from "../page/PageSidebar";
11
+ import { PageSidebarSection } from "../page/PageSidebarSection";
12
+ import { ScreenTopBar } from "./ScreenTopBar";
13
+ import { useRouter } from "next/router";
14
+ import { useInvalidatePage } from "@compill/admin-api";
15
+ function useQueryField(queryField, useNextRouter) {
16
+ if (useNextRouter) {
17
+ const router = useRouter();
18
+ return router.query[queryField];
19
+ }
20
+ const { [queryField]: id } = useParams();
21
+ return id;
22
+ }
23
+ export function DetailsView({ queryField, api, useNextRouter, processInput, screen, tabbed, ...props }) {
24
+ const id = useQueryField(queryField, useNextRouter);
25
+ const ref = React.useRef(null);
26
+ return (_jsx(PageQueryStateContainer, { api: api, apiFn: "get", queryId: id, ref: ref, p: "5", ...props, children: (item) => _jsx(Internal, { item: item, screen: screen, api: api, tabbed: tabbed, processInput: processInput, containerRef: ref }) }));
27
+ }
28
+ function Internal({ item, screen, api, processInput, tabbed, containerRef }) {
29
+ const pScreen = runIfFn(screen, item);
30
+ const { breadcrumbs, schema, initialValues, header, sections, buttonBar, type, invalidateParentQueryKey, invalidatePage } = pScreen;
31
+ const mutation = useInvalidateParentMutation((api.update), invalidateParentQueryKey ?? api.queryKey, { networkMode: "always" });
32
+ const invalidatePageFn = useInvalidatePage(invalidatePage || "");
33
+ const save = useMutate(mutation, {
34
+ processInput,
35
+ successMsg: (item, values) => `${item.title || item.name} updated.`,
36
+ errorMsg: (error, item) => `Error updating ${item.title || item.name}: ${error}`,
37
+ onSuccess: () => {
38
+ if (invalidatePage)
39
+ invalidatePageFn();
40
+ }
41
+ });
42
+ let editorMaxW = undefined;
43
+ if (!type || type == "post")
44
+ editorMaxW = "calc(1280px - 28rem)";
45
+ else if (type == "section")
46
+ editorMaxW = "calc(1280px - 22rem)";
47
+ return (_jsxs(FormProvider, { initialValues: runIfFn(initialValues, item), validationSchema: schema, onSubmit: save, enableReinitialize: true, children: [_jsx(ScreenTopBar, { tabbed: tabbed, api: api, breadcrumbs: breadcrumbs, buttonBar: buttonBar, item: item, isLoading: mutation.isLoading, trackingRef: containerRef?.current }), type == "form" && sections?.map((section, index) => (_jsx(Section, { section: section, item: item }, index))), (pScreen.type == "post" || pScreen.type == "section") &&
48
+ (_jsx("div", { p: "5", bgColor: "slate-100", rounded: "lg", children: _jsxs(PageContainer, { w: editorMaxW ? "auto" : "full", size: "x2", id: "pagecontainer", children: [header, _jsxs("div", { dflex: true, gap: "5", children: [_jsxs("div", { dflex: true, flexCol: true, gap: "8", flexGrow: true, children: [pScreen.editor?.type != "textarea" &&
49
+ (
50
+ // TODO Find a way to make this editor shrink in width when resizing the window...
51
+ _jsx(PageContentEditor, { name: "content", maxW: editorMaxW, minW: "144", shadow: true, rounded: "lg" })), pScreen.editor?.type == "textarea" &&
52
+ (_jsx(TextArea, { name: pScreen.editor?.name, maxW: editorMaxW, minW: editorMaxW, w: editorMaxW, minH: "128", rows: 25, bgColor: "white", border: "0", shadow: true, p: "5", textColor: "slate-800" })), pScreen.editorFooter] }), _jsx(PageSidebar, { children: sections?.map((section, index) => (_jsx(Section, { section: section, item: item, cardStyle: true }, index))) })] })] }) }))] }));
53
+ }
54
+ function Section({ section, item, cardStyle }) {
55
+ if (section.type === "section") {
56
+ const style = cardStyle ?
57
+ {
58
+ bgColor: "white",
59
+ rounded: "lg",
60
+ p: "5",
61
+ textSize: "sm",
62
+ shadow: true
63
+ } : {};
64
+ return (_jsx(PageSidebarSection, { title: section.title, ...style, children: _jsx(FormRenderer, { form: runIfFn(section.form, item) }) }));
65
+ }
66
+ if (section.type === "custom")
67
+ return runIfFn(section.component, item);
68
+ return null;
69
+ }
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import { ItemEditDialogProps } from "./dialog/ItemEditDialog";
3
2
  export declare function EditItemView({ initialValues, ...props }: Omit<ItemEditDialogProps, "show">): JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { runIfFn } from "@soperio/react";
3
+ import { ItemEditDialog } from "./dialog/ItemEditDialog";
4
+ export function EditItemView({ initialValues, ...props }) {
5
+ return (_jsx(ItemEditDialog, { ...props, initialValues: runIfFn(initialValues, null), show: true }));
6
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { MultiQueryWrapperConfig } from "./types/MultiQueryWrapper";
3
2
  import { SoperioComponent } from "@soperio/react";
4
3
  export declare function MultiQueryWrapper({ queries, config, tabbed, ...props }: Omit<MultiQueryWrapperConfig, "type"> & {
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { useApiQueries } from "@compill/api";
3
+ import { useQueryClient } from "@tanstack/react-query";
4
+ import React from "react";
5
+ import { useParams } from "react-router-dom";
6
+ import { ScreenRenderer } from "./ScreenRenderer";
7
+ import { isFunction, runIfFn } from "@soperio/react";
8
+ import { QueryLoadingState, RetryOnError } from "@compill/components";
9
+ function useQueries(queries) {
10
+ const params = useParams();
11
+ const { data, isFetching, isError } = useApiQueries(queries.map(q => {
12
+ if (!q.queryField) {
13
+ const api = runIfFn(q.api);
14
+ return {
15
+ queryKey: api.queryKey,
16
+ queryFn: q.fn == "get" ? api.get : api.getAll,
17
+ queryParam: q.params
18
+ };
19
+ }
20
+ const id = params[q.queryField];
21
+ const api = runIfFn(q.api, id);
22
+ return {
23
+ queryKey: api.queryKey,
24
+ queryFn: q.fn == "get" ? api.get : api.getAll,
25
+ queryParam: q.fn == "getAll" ? q.params : isFunction(q.api) ? undefined : id
26
+ };
27
+ }));
28
+ let transformedData = undefined;
29
+ if (!isFetching && !isError) {
30
+ transformedData = data?.map((d, index) => queries[index].transformFn ? queries[index].transformFn?.(d) : d);
31
+ }
32
+ return { data: transformedData, isFetching, isError };
33
+ }
34
+ function useInvalidate(queries) {
35
+ const queryClient = useQueryClient();
36
+ const params = useParams();
37
+ const invalidate = React.useCallback(() => {
38
+ const queryKeys = [];
39
+ queries.forEach(q => {
40
+ if (!q.queryField || !isFunction(q.api)) {
41
+ queryKeys.push(q.api.queryKey);
42
+ }
43
+ else {
44
+ const id = params[q.queryField];
45
+ const api = runIfFn(q.api, id);
46
+ queryKeys.push(api.queryKey);
47
+ }
48
+ });
49
+ queryClient.invalidateQueries({ predicate: (query) => queryKeys.includes(query.queryKey), });
50
+ }, [queries, queryClient, params]);
51
+ return invalidate;
52
+ }
53
+ export function MultiQueryWrapper({ queries, config, tabbed, ...props }) {
54
+ const { data, isFetching, isError } = useQueries(queries);
55
+ const invalidate = useInvalidate(queries);
56
+ if (isFetching)
57
+ return _jsx(QueryLoadingState, { w: "full", h: "100vh" });
58
+ if (isError || !data)
59
+ return _jsx(RetryOnError, { p: "0", w: "full", h: "100vh", onClick: invalidate });
60
+ return _jsx(ScreenRenderer, { config: config(...data), tabbed: tabbed, ...props });
61
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { QueryWrapperConfig } from "./types/QueryWrapper";
3
2
  import { SoperioComponent } from "@soperio/react";
4
3
  import { CRUD_MODEL } from "@compill/api";
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import React from "react";
3
+ import { ScreenRenderer } from "./ScreenRenderer";
4
+ import { isFunction, runIfFn } from "@soperio/react";
5
+ import { useParams } from "react-router-dom";
6
+ import { useApiQuery } from "@compill/api";
7
+ function useApi(api, queryField) {
8
+ const params = useParams();
9
+ if (queryField === undefined)
10
+ return { id: undefined, api: api };
11
+ const { [queryField]: id } = params;
12
+ return { id, api: runIfFn(api, id) };
13
+ }
14
+ export function QueryWrapper({ api, queryField, fn, transformFn, config, tabbed, ...props }) {
15
+ const { id, api: mApi } = useApi(api, queryField);
16
+ const { data } = useApiQuery(mApi.queryKey, fn === "get" || fn === "getTransformed" ? mApi.get : mApi.getAll, isFunction(api) ? undefined : id);
17
+ const transformedData = React.useMemo(() => {
18
+ if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
19
+ if (!transformFn)
20
+ console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
21
+ return transformFn?.(data);
22
+ }
23
+ return data;
24
+ }, [data]);
25
+ // TODO states
26
+ if (!data)
27
+ return null;
28
+ return _jsx(ScreenRenderer, { config: config(transformedData), tabbed: tabbed, ...props });
29
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ScreenConfig } from "./types/ScreenConfig";
3
2
  import { SoperioComponent } from "@soperio/react";
4
3
  export declare function ScreenRenderer({ config, tabbed, ...props }: {
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "@soperio/jsx-runtime";
2
+ import { DetailsView } from "./DetailsView";
3
+ import { QueryWrapper } from "./QueryWrapper";
4
+ import { TabbedView } from "./TabbedView";
5
+ import { TableView } from "./table/TableView";
6
+ import { MultiQueryWrapper } from "./MultiQueryWrapper";
7
+ export function ScreenRenderer({ config, tabbed, ...props }) {
8
+ if (config.type === "table")
9
+ return _jsx(TableView, { ...config, ...props });
10
+ if (config.type === "tabbed")
11
+ return _jsx(TabbedView, { ...config, ...props });
12
+ if (config.type === "details")
13
+ return _jsx(DetailsView, { ...config, tabbed: tabbed, ...props });
14
+ if (config.type === "query")
15
+ return _jsx(QueryWrapper, { ...config, tabbed: tabbed, ...props });
16
+ if (config.type === "multiQuery")
17
+ return _jsx(MultiQueryWrapper, { ...config, tabbed: tabbed, ...props });
18
+ return _jsx(_Fragment, {});
19
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { API } from "@compill/admin-api";
3
2
  import { Breadcrumb } from "../breadcrumbs/BreadCrumbs";
4
3
  import { DetailViewButton } from "./types/DetailsView";
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { API } from "@compill/admin-api";
3
+ import { InvalidateButton } from "../buttons/InvalidateButton";
4
+ import { PublishButton } from "../buttons/PublishButton";
5
+ import { UpdateButton } from "../buttons/UpdateButton";
6
+ import { ViewButton } from "../buttons/ViewButton";
7
+ import { PageTopBar, PageTopBarToolbar } from "../page/PageTopBar";
8
+ import React from "react";
9
+ import { ButtonBar } from "../layout/ButtonBar";
10
+ export function ScreenTopBar({ tabbed, breadcrumbs, api, item, isLoading, buttonBar, trackingRef }) {
11
+ return (_jsxs(_Fragment, { children: [tabbed &&
12
+ (_jsx(PageTopBarToolbar, { trackingRef: trackingRef, children: _jsx(Buttons, { api: api, item: item, isLoading: isLoading, buttonBar: buttonBar }) })), !tabbed &&
13
+ (_jsx(PageTopBar, { breadcrumbs: breadcrumbs, children: _jsx(Buttons, { api: api, item: item, isLoading: isLoading, buttonBar: buttonBar }) }))] }));
14
+ }
15
+ function Buttons({ api, item, isLoading, buttonBar }) {
16
+ return (_jsxs(_Fragment, { children: [buttonBar && buttonBar.length > 0 &&
17
+ (_jsx(ButtonBar, { children: buttonBar.map((button, index) => (_jsxs(React.Fragment, { children: [button.type === "link" && _jsx(ViewButton, { label: button.label, path: button.path, icon: button.icon }), button.type === "invalidate" && _jsx(InvalidateButton, { pathOrPermalink: button.pathOrPermalink }), button.type == "custom" && button.render(item)] }, index))) })), _jsxs(ButtonBar, { children: [api instanceof API && _jsx(PublishButton, { api: api, queryId: item.id, status: item.status, disabled: isLoading }), _jsx(UpdateButton, { disabled: isLoading })] })] }));
18
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { TabbedViewConfig } from "./types/TabbedView";
3
2
  import { SoperioComponent } from "@soperio/react";
4
3
  export declare function TabbedView({ queryField, api, screen, ...props }: TabbedViewConfig & SoperioComponent): JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { useParams } from "react-router-dom";
3
+ import { PageQueryStateContainer } from "../page/PageQueryStateContainer";
4
+ import { PageTabbedTopBar, PageTabbedTopBarProvider } from "../page/PageTopBar";
5
+ import { TabContainer } from "@compill/components";
6
+ import { runIfFn } from "@soperio/react";
7
+ import { ScreenRenderer } from "./ScreenRenderer";
8
+ export function TabbedView({ queryField, api, screen, ...props }) {
9
+ const { [queryField]: id } = useParams();
10
+ return (_jsx(PageQueryStateContainer, { queryId: id, api: api, apiFn: "get", p: "5", children: (city) => {
11
+ const { breadcrumbs, tabs } = runIfFn(screen, city);
12
+ return (_jsxs(PageTabbedTopBarProvider, { children: [_jsx(PageTabbedTopBar, { breadcrumbs: breadcrumbs, mb: "-3" }), _jsx(TabContainer, { tabs: tabs.map(tab => tab.label), saveKey: `tab-${id}`, mt: "-3", mb: "3", id: "fff", children: tabs.map((tab, index) => _jsx(TabView, { tab: tab }, index)) })] }));
13
+ } }));
14
+ }
15
+ function TabView({ tab }) {
16
+ if (!tab.component && !tab.config)
17
+ throw new Error(`Screen config for tabbed view: one of your tabs does not have a component or config declared: ${tab.label}`);
18
+ if (tab.component)
19
+ return tab.component();
20
+ return _jsx(ScreenRenderer, { config: tab.config, tabbed: true, p: "0" });
21
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { MutationQueryFn, MutationQueryKey } from "@compill/api";
3
2
  import { ButtonProps } from "@valerya/ui";
4
3
  interface ActionButtonProps {
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { useApiMutation, useInvalidateParentMutation, useMutate } from "@compill/api";
3
+ import { Button, Icon } from "@valerya/ui";
4
+ export function ActionButton({ label, buttonProps, icon, queryKey, queryFn, successMsg, errorMsg, invalidateParent }) {
5
+ const mutation = invalidateParent ? useInvalidateParentMutation(queryFn, queryKey) : useApiMutation(queryFn, queryKey);
6
+ const mutate = useMutate(mutation, {
7
+ successMsg,
8
+ errorMsg
9
+ });
10
+ return (_jsxs(Button, { display: "flex", alignItems: "center", gap: "3", ...buttonProps, onClick: mutate, disabled: mutation.isLoading, children: [icon && _jsx(Icon, { path: icon }), label] }));
11
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { MutationQueryFn, MutationQueryKey } from "@compill/api";
3
2
  import { ButtonProps, ModalProps } from "@valerya/ui";
4
3
  interface ConfirmationActionButtonProps {
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { useApiMutation, useInvalidateParentMutation, useMutate } from "@compill/api";
3
+ import { ModalLoadingOverlay } from "@compill/components";
4
+ import { Button, Icon, Modal, ModalBody, ModalFooter, ModalHeader } from "@valerya/ui";
5
+ export function ConfirmationActionButton({ label, buttonProps, icon, queryKey, queryFn, successMsg, errorMsg, invalidateParent }) {
6
+ const mutation = invalidateParent ? useInvalidateParentMutation(queryFn, queryKey) : useApiMutation(queryFn, queryKey);
7
+ const mutate = useMutate(mutation, {
8
+ successMsg,
9
+ errorMsg
10
+ });
11
+ return (_jsxs(Button, { display: "flex", alignItems: "center", gap: "3", ...buttonProps, onClick: mutate, disabled: mutation.isLoading, children: [icon && _jsx(Icon, { path: icon }), label] }));
12
+ }
13
+ export function ConfirmationDialog({ title, text, positiveButtonLabel, negativeButtonLabel, queryKey, queryFn, successMsg, errorMsg, invalidateParent, show, onClose }) {
14
+ const mutation = invalidateParent ? useInvalidateParentMutation(queryFn, queryKey) : useApiMutation(queryFn, queryKey);
15
+ const mutate = useMutate(mutation, {
16
+ successMsg,
17
+ errorMsg
18
+ });
19
+ return (_jsxs(Modal, { show: show, onClose: onClose, children: [_jsx(ModalHeader, { children: _jsx("div", { textSize: "xl", fontWeight: "600", children: title }) }), _jsx(ModalBody, { children: text }), _jsxs(ModalFooter, { dflex: true, gap: "3", alignItems: "center", placeContent: "end", children: [_jsx(Button, { children: negativeButtonLabel || "Cancel" }), _jsx(Button, { onClick: mutate, children: positiveButtonLabel || "OK" })] }), mutation.isLoading && _jsx(ModalLoadingOverlay, {})] }));
20
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { EditItemDialogConfig } from "../types/EditItemDialog";
3
2
  import { QueryWrapperDialogConfig } from "../types/QueryWrapperDialog";
4
3
  import { MultiQueryWrapperDialogConfig } from "../types/MultiQueryWrapperDialog";
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "@soperio/jsx-runtime";
2
+ import { ItemEditDialog } from "./ItemEditDialog";
3
+ import { QueryWrapperDialog } from "./QueryWrapperDialog";
4
+ import { MultiQueryWrapperDialog } from "./MultiQueryWrapperDialog";
5
+ export function DialogRenderer({ config, onClose, invalidateQueryKey, queryId }) {
6
+ const { type, ...props } = config;
7
+ if (config.type === "dialog")
8
+ return _jsx(ItemEditDialog, { ...props, queryId: queryId, invalidateQueryKey: invalidateQueryKey, show: true, onClose: onClose });
9
+ if (config.type === "query")
10
+ return _jsx(QueryWrapperDialog, { ...props, queryId: queryId, invalidateQueryKey: invalidateQueryKey, onClose: onClose });
11
+ if (config.type === "multiQuery")
12
+ return _jsx(MultiQueryWrapperDialog, { ...props, queryId: queryId, invalidateQueryKey: invalidateQueryKey, onClose: onClose });
13
+ return null;
14
+ }
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@soperio/jsx-runtime";
2
+ import { useApiMutation, useInvalidateParentMutation, useMutate } from "@compill/api";
3
+ import { ModalLoadingOverlay } from "@compill/components";
4
+ import { runIfFn } from "@soperio/react";
5
+ import { Button, Modal } from "@valerya/ui";
6
+ import React from "react";
7
+ export function ItemDeleteDialog({ title, actionButtonLabel, closeActionButtonLabel = "Cancel", itemLabel, queryId = "", api, apiFn, invalidateQueriesOnSuccess = true, invalidateQueryKey, size = "lg", md_boxSizing, msg, show, onClose, onSuccess, ...props }) {
8
+ const fn = apiFn ? api[apiFn] : api.delete;
9
+ const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(fn, invalidateQueryKey ?? api.queryKey)
10
+ : useApiMutation(fn, api.queryKey);
11
+ const mutate = useMutate(mutation, { onSuccess: () => { onClose?.(); onSuccess?.(); } });
12
+ const handleDelete = React.useCallback(() => mutate(queryId), [mutate, queryId]);
13
+ return (_jsxs(Modal, { size: size, show: show, onClose: onClose, scheme: "danger", variant: "glass", transition: true, ...props, children: [_jsx(Modal.Header, { children: title || `Delete ${itemLabel}` }), _jsxs(Modal.Body, { pb: "6", children: [!msg && `Do you really want to delete ${itemLabel}?`, msg && runIfFn(msg, itemLabel)] }), _jsxs(Modal.Footer, { dflex: true, placeContent: "end", spaceX: "3", children: [_jsx(Button, { disabled: mutation.isPending, onClick: onClose, variant: "borderless", scheme: "dark", me: "2", children: closeActionButtonLabel }), _jsx(Button, { scheme: "danger", disabled: mutation.isPending, onClick: handleDelete, children: actionButtonLabel || "Delete" })] }), mutation.isPending && _jsx(ModalLoadingOverlay, {})] }));
14
+ }