muffin-admin 2.5.0 → 2.5.2
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,5 +1,3 @@
|
|
|
1
|
-
import * as icons from "@mui/icons-material"
|
|
2
|
-
import { Box, Modal } from "@mui/material"
|
|
3
1
|
import {
|
|
4
2
|
Button,
|
|
5
3
|
useListContext,
|
|
@@ -12,46 +10,64 @@ import {
|
|
|
12
10
|
|
|
13
11
|
import { useState } from "react"
|
|
14
12
|
import { useAction } from "../hooks/useAction"
|
|
15
|
-
import { buildIcon, findBuilder
|
|
13
|
+
import { buildIcon, findBuilder } from "../utils"
|
|
16
14
|
|
|
17
15
|
export function BulkActionButton({ label, icon, title, action }) {
|
|
18
16
|
const resource = useResourceContext()
|
|
19
17
|
const { selectedIds } = useListContext()
|
|
18
|
+
const [payload, setPayload] = useState(null)
|
|
19
|
+
const [payloadActive, setPayloadActive] = useState(false)
|
|
20
|
+
const actionData = { payload, ids: selectedIds }
|
|
21
|
+
|
|
22
|
+
const PayloadBuilder = findBuilder(["action", "payload", action])
|
|
23
|
+
|
|
20
24
|
const refresh = useRefresh(),
|
|
21
25
|
unselectAll = useUnselectAll(resource),
|
|
22
26
|
notify = useNotify()
|
|
23
27
|
|
|
24
28
|
const { mutate, isLoading } = useAction(action)
|
|
25
29
|
|
|
26
|
-
const
|
|
27
|
-
mutate(
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
onSuccess: ({ data }) => {
|
|
34
|
-
if (data && data.message) notify(data.message, { type: "success" })
|
|
35
|
-
refresh()
|
|
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
36
|
unselectAll()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
refresh()
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
onError: (err) => {
|
|
41
|
+
notify(typeof err === "string" ? err : err.message, { type: "error" })
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
44
|
|
|
45
45
|
return (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
<>
|
|
47
|
+
<Button
|
|
48
|
+
label={label}
|
|
49
|
+
title={title}
|
|
50
|
+
onClick={PayloadBuilder ? () => setPayloadActive(true) : process}
|
|
51
|
+
disabled={isLoading}
|
|
52
|
+
>
|
|
53
|
+
{buildIcon(icon)}
|
|
54
|
+
</Button>
|
|
55
|
+
{PayloadBuilder && (
|
|
56
|
+
<PayloadBuilder
|
|
57
|
+
active={payloadActive}
|
|
58
|
+
onChange={(payload) => {
|
|
59
|
+
setPayloadActive(false)
|
|
60
|
+
setPayload(payload)
|
|
61
|
+
process()
|
|
62
|
+
}}
|
|
63
|
+
onClose={() => setPayloadActive(false)}
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
</>
|
|
49
67
|
)
|
|
50
68
|
}
|
|
51
69
|
|
|
52
|
-
export function ActionButton(
|
|
53
|
-
const { icon, label, title, action } = props
|
|
54
|
-
|
|
70
|
+
export function ActionButton({ icon, label, title, action }) {
|
|
55
71
|
const [payload, setPayload] = useState(null)
|
|
56
72
|
const [payloadActive, setPayloadActive] = useState(false)
|
|
57
73
|
|
|
@@ -62,8 +78,7 @@ export function ActionButton(props) {
|
|
|
62
78
|
const PayloadBuilder = findBuilder(["action", "payload", action])
|
|
63
79
|
|
|
64
80
|
const refresh = useRefresh(),
|
|
65
|
-
notify = useNotify()
|
|
66
|
-
Icon = icons[icon]
|
|
81
|
+
notify = useNotify()
|
|
67
82
|
|
|
68
83
|
const process = () =>
|
|
69
84
|
mutate(actionData, {
|
|
@@ -85,15 +100,17 @@ export function ActionButton(props) {
|
|
|
85
100
|
onClick={PayloadBuilder ? () => setPayloadActive(true) : process}
|
|
86
101
|
disabled={isLoading}
|
|
87
102
|
>
|
|
88
|
-
{
|
|
103
|
+
{buildIcon(icon)}
|
|
89
104
|
</Button>
|
|
90
105
|
{PayloadBuilder && (
|
|
91
106
|
<PayloadBuilder
|
|
107
|
+
active={payloadActive}
|
|
92
108
|
onChange={(payload) => {
|
|
109
|
+
setPayloadActive(false)
|
|
93
110
|
setPayload(payload)
|
|
94
111
|
process()
|
|
95
112
|
}}
|
|
96
|
-
|
|
113
|
+
onClose={() => setPayloadActive(false)}
|
|
97
114
|
/>
|
|
98
115
|
)}
|
|
99
116
|
</>
|