muffin-admin 2.5.1 → 2.5.3

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.
@@ -4,4 +4,9 @@ export declare function BulkActionButton({ label, icon, title, action }: {
4
4
  title: any;
5
5
  action: any;
6
6
  }): import("react/jsx-runtime").JSX.Element;
7
- export declare function ActionButton(props: any): import("react/jsx-runtime").JSX.Element;
7
+ export declare function ActionButton({ icon, label, title, action }: {
8
+ icon: any;
9
+ label: any;
10
+ title: any;
11
+ action: any;
12
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,4 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import * as icons from "@mui/icons-material";
3
2
  import { Button, useListContext, useNotify, useRecordContext, useRefresh, useResourceContext, useUnselectAll, } from "react-admin";
4
3
  import { useState } from "react";
5
4
  import { useAction } from "../hooks/useAction";
@@ -7,36 +6,34 @@ import { buildIcon, findBuilder } from "../utils";
7
6
  export function BulkActionButton({ label, icon, title, action }) {
8
7
  const resource = useResourceContext();
9
8
  const { selectedIds } = useListContext();
9
+ const [payloadActive, setPayloadActive] = useState(false);
10
+ const PayloadBuilder = findBuilder(["action", "payload", action]);
10
11
  const refresh = useRefresh(), unselectAll = useUnselectAll(resource), notify = useNotify();
11
12
  const { mutate, isLoading } = useAction(action);
12
- const onClick = () => {
13
- mutate({
14
- action,
15
- ids: selectedIds,
16
- }, {
17
- onSuccess: ({ data }) => {
18
- if (data && data.message)
19
- notify(data.message, { type: "success" });
20
- refresh();
13
+ const process = (payload) => mutate({ ids: selectedIds, payload }, {
14
+ onSuccess: ({ data }) => {
15
+ if (data && data.message)
16
+ notify(data.message, { type: "success" });
17
+ if (data && data.redirectTo)
18
+ window.location = data.redirectTo;
19
+ else {
21
20
  unselectAll();
22
- },
23
- onError: (err) => {
24
- notify(typeof err === "string" ? err : err.message, { type: "error" });
25
- },
26
- });
27
- };
28
- return (_jsx(Button, { label: label, title: title, onClick: onClick, disabled: isLoading, children: buildIcon(icon) }));
21
+ refresh();
22
+ }
23
+ },
24
+ onError: (err) => {
25
+ notify(typeof err === "string" ? err : err.message, { type: "error" });
26
+ },
27
+ });
28
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: PayloadBuilder ? () => setPayloadActive(true) : process, disabled: isLoading, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => process(payload), onClose: () => setPayloadActive(false) }))] }));
29
29
  }
30
- export function ActionButton(props) {
31
- const { icon, label, title, action } = props;
32
- const [payload, setPayload] = useState(null);
30
+ export function ActionButton({ icon, label, title, action }) {
33
31
  const [payloadActive, setPayloadActive] = useState(false);
34
32
  const record = useRecordContext();
35
- const actionData = { record, payload };
36
33
  const { mutate, isLoading } = useAction(action);
37
34
  const PayloadBuilder = findBuilder(["action", "payload", action]);
38
- const refresh = useRefresh(), notify = useNotify(), Icon = icons[icon];
39
- const process = () => mutate(actionData, {
35
+ const refresh = useRefresh(), notify = useNotify();
36
+ const process = (payload) => mutate({ record, payload }, {
40
37
  onSuccess: ({ data }) => {
41
38
  if (data && data.message)
42
39
  notify(data.message, { type: "success" });
@@ -49,9 +46,5 @@ export function ActionButton(props) {
49
46
  notify(typeof err === "string" ? err : err.message, { type: "error" });
50
47
  },
51
48
  });
52
- return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: PayloadBuilder ? () => setPayloadActive(true) : process, disabled: isLoading, children: Icon && _jsx(Icon, {}) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onChange: (payload) => {
53
- setPayloadActive(false);
54
- setPayload(payload);
55
- process();
56
- }, onClose: () => setPayloadActive(false) }))] }));
49
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: PayloadBuilder ? () => setPayloadActive(true) : process, disabled: isLoading, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => process(payload), onClose: () => setPayloadActive(false) }))] }));
57
50
  }