muffin-admin 2.5.2 → 2.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -15,9 +15,7 @@ import { buildIcon, findBuilder } from "../utils"
15
15
  export function BulkActionButton({ label, icon, title, action }) {
16
16
  const resource = useResourceContext()
17
17
  const { selectedIds } = useListContext()
18
- const [payload, setPayload] = useState(null)
19
18
  const [payloadActive, setPayloadActive] = useState(false)
20
- const actionData = { payload, ids: selectedIds }
21
19
 
22
20
  const PayloadBuilder = findBuilder(["action", "payload", action])
23
21
 
@@ -27,27 +25,30 @@ export function BulkActionButton({ label, icon, title, action }) {
27
25
 
28
26
  const { mutate, isLoading } = useAction(action)
29
27
 
30
- const process = () =>
31
- mutate(actionData, {
32
- onSuccess: ({ data }) => {
33
- if (data && data.message) notify(data.message, { type: "success" })
34
- if (data && data.redirectTo) window.location = data.redirectTo
35
- else {
36
- unselectAll()
37
- refresh()
38
- }
39
- },
40
- onError: (err) => {
41
- notify(typeof err === "string" ? err : err.message, { type: "error" })
42
- },
43
- })
28
+ const process = (payload?) =>
29
+ mutate(
30
+ { ids: selectedIds, payload },
31
+ {
32
+ onSuccess: ({ data }) => {
33
+ if (data && data.message) notify(data.message, { type: "success" })
34
+ if (data && data.redirectTo) window.location = data.redirectTo
35
+ else {
36
+ unselectAll()
37
+ refresh()
38
+ }
39
+ },
40
+ onError: (err) => {
41
+ notify(typeof err === "string" ? err : err.message, { type: "error" })
42
+ },
43
+ }
44
+ )
44
45
 
45
46
  return (
46
47
  <>
47
48
  <Button
48
49
  label={label}
49
50
  title={title}
50
- onClick={PayloadBuilder ? () => setPayloadActive(true) : process}
51
+ onClick={() => (PayloadBuilder ? setPayloadActive(true) : process())}
51
52
  disabled={isLoading}
52
53
  >
53
54
  {buildIcon(icon)}
@@ -55,11 +56,7 @@ export function BulkActionButton({ label, icon, title, action }) {
55
56
  {PayloadBuilder && (
56
57
  <PayloadBuilder
57
58
  active={payloadActive}
58
- onChange={(payload) => {
59
- setPayloadActive(false)
60
- setPayload(payload)
61
- process()
62
- }}
59
+ onHandle={(payload) => process(payload)}
63
60
  onClose={() => setPayloadActive(false)}
64
61
  />
65
62
  )}
@@ -68,11 +65,9 @@ export function BulkActionButton({ label, icon, title, action }) {
68
65
  }
69
66
 
70
67
  export function ActionButton({ icon, label, title, action }) {
71
- const [payload, setPayload] = useState(null)
72
68
  const [payloadActive, setPayloadActive] = useState(false)
73
69
 
74
70
  const record = useRecordContext()
75
- const actionData = { record, payload }
76
71
  const { mutate, isLoading } = useAction(action)
77
72
 
78
73
  const PayloadBuilder = findBuilder(["action", "payload", action])
@@ -80,24 +75,27 @@ export function ActionButton({ icon, label, title, action }) {
80
75
  const refresh = useRefresh(),
81
76
  notify = useNotify()
82
77
 
83
- const process = () =>
84
- mutate(actionData, {
85
- onSuccess: ({ data }) => {
86
- if (data && data.message) notify(data.message, { type: "success" })
87
- if (data && data.redirectTo) window.location = data.redirectTo
88
- else refresh()
89
- },
90
- onError: (err) => {
91
- notify(typeof err === "string" ? err : err.message, { type: "error" })
92
- },
93
- })
78
+ const process = (payload?) =>
79
+ mutate(
80
+ { record, payload },
81
+ {
82
+ onSuccess: ({ data }) => {
83
+ if (data && data.message) notify(data.message, { type: "success" })
84
+ if (data && data.redirectTo) window.location = data.redirectTo
85
+ else refresh()
86
+ },
87
+ onError: (err) => {
88
+ notify(typeof err === "string" ? err : err.message, { type: "error" })
89
+ },
90
+ }
91
+ )
94
92
 
95
93
  return (
96
94
  <>
97
95
  <Button
98
96
  label={label}
99
97
  title={title}
100
- onClick={PayloadBuilder ? () => setPayloadActive(true) : process}
98
+ onClick={() => (PayloadBuilder ? setPayloadActive(true) : process())}
101
99
  disabled={isLoading}
102
100
  >
103
101
  {buildIcon(icon)}
@@ -105,11 +103,7 @@ export function ActionButton({ icon, label, title, action }) {
105
103
  {PayloadBuilder && (
106
104
  <PayloadBuilder
107
105
  active={payloadActive}
108
- onChange={(payload) => {
109
- setPayloadActive(false)
110
- setPayload(payload)
111
- process()
112
- }}
106
+ onHandle={(payload) => process(payload)}
113
107
  onClose={() => setPayloadActive(false)}
114
108
  />
115
109
  )}