@primershop/strapi-plugin-status-manager 0.0.16 → 0.0.18
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/_chunks/HomePage-CYpSKXVE.mjs +2115 -0
- package/dist/_chunks/HomePage-D9xj2-y8.js +2115 -0
- package/dist/_chunks/index-BXToWkDF.js +227 -0
- package/dist/_chunks/index-CzxwE0pe.mjs +226 -0
- package/dist/admin/index.js +2 -11
- package/dist/admin/index.mjs +4 -6
- package/dist/server/index.js +601 -703
- package/dist/server/index.mjs +603 -702
- package/package.json +13 -14
- package/dist/admin/HomePage-Bez9ZXv-.js +0 -412
- package/dist/admin/HomePage-Dx9N0awm.mjs +0 -410
- package/dist/admin/index-BVybZ6IA.mjs +0 -280
- package/dist/admin/index-mATo7IeG.js +0 -283
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var icons = require('@strapi/icons');
|
|
6
|
-
var designSystem = require('@strapi/design-system');
|
|
7
|
-
var admin = require('@strapi/strapi/admin');
|
|
8
|
-
|
|
9
|
-
const PLUGIN_ID = "primershop-status-manager";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {import('react').FC<{ setPlugin: (id: string) => void }>}
|
|
13
|
-
*/ const Initializer = ({ setPlugin })=>{
|
|
14
|
-
const ref = React.useRef(setPlugin);
|
|
15
|
-
React.useEffect(()=>{
|
|
16
|
-
ref.current(PLUGIN_ID);
|
|
17
|
-
}, []);
|
|
18
|
-
return null;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const PluginIcon = ()=>/*#__PURE__*/ jsxRuntime.jsx(icons.CheckCircle, {});
|
|
22
|
-
|
|
23
|
-
const ProductStatusField = ()=>{
|
|
24
|
-
const { contentType, id } = admin.unstable_useContentManagerContext();
|
|
25
|
-
const [statuses, setStatuses] = React.useState([]);
|
|
26
|
-
const [currentStatus, setCurrentStatus] = React.useState("");
|
|
27
|
-
const [message, setMessage] = React.useState("");
|
|
28
|
-
const { get, put } = admin.useFetchClient();
|
|
29
|
-
const handleStatusChange = React.useCallback(async (newStatus)=>{
|
|
30
|
-
if (!id) {
|
|
31
|
-
setMessage("Save the product first and then change the status");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
await put(`primershop-status-manager/content-status`, {
|
|
36
|
-
contentTypeUid: "api::product.product",
|
|
37
|
-
contentDocumentId: id,
|
|
38
|
-
statusId: statuses.find((status)=>status.name === newStatus)?.documentId
|
|
39
|
-
});
|
|
40
|
-
setMessage(`Status updated ${currentStatus ? `from ${currentStatus}` : ""} to ${newStatus}`);
|
|
41
|
-
setCurrentStatus(newStatus || "");
|
|
42
|
-
} catch (error) {
|
|
43
|
-
setMessage("Error updating status");
|
|
44
|
-
console.error("Error updating status:", error);
|
|
45
|
-
}
|
|
46
|
-
}, [
|
|
47
|
-
id,
|
|
48
|
-
statuses,
|
|
49
|
-
currentStatus,
|
|
50
|
-
put
|
|
51
|
-
]);
|
|
52
|
-
React.useEffect(()=>{
|
|
53
|
-
async function fetchCurrentStatus() {
|
|
54
|
-
try {
|
|
55
|
-
const { data: productData } = await get(`primershop-status-manager/content-status?contentDocumentId=${id}&contentTypeUid=api::product.product`);
|
|
56
|
-
const status = productData?.status;
|
|
57
|
-
if (status && status.name) return setCurrentStatus(status.name);
|
|
58
|
-
if (statuses.length) return handleStatusChange(statuses[0].name);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error("Error fetching product status:", error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (id && !currentStatus.length) fetchCurrentStatus();
|
|
64
|
-
if (!id && statuses.length) setCurrentStatus(statuses[0].name);
|
|
65
|
-
}, [
|
|
66
|
-
id,
|
|
67
|
-
statuses,
|
|
68
|
-
get
|
|
69
|
-
]);
|
|
70
|
-
React.useEffect(()=>{
|
|
71
|
-
async function fetchStatuses() {
|
|
72
|
-
try {
|
|
73
|
-
const { data } = await get("primershop-status-manager/statuses");
|
|
74
|
-
setStatuses(data);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error("Error fetching statuses:", error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
fetchStatuses();
|
|
80
|
-
}, [
|
|
81
|
-
get
|
|
82
|
-
]);
|
|
83
|
-
return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
|
84
|
-
direction: "column",
|
|
85
|
-
justifyContent: "center",
|
|
86
|
-
alignItems: "stretch",
|
|
87
|
-
width: "100%",
|
|
88
|
-
children: [
|
|
89
|
-
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
|
90
|
-
padding: 2,
|
|
91
|
-
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Typography, {
|
|
92
|
-
variant: "sigma",
|
|
93
|
-
children: [
|
|
94
|
-
contentType?.info.displayName,
|
|
95
|
-
" status"
|
|
96
|
-
]
|
|
97
|
-
})
|
|
98
|
-
}),
|
|
99
|
-
/*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelect, {
|
|
100
|
-
placeholder: currentStatus,
|
|
101
|
-
onChange: handleStatusChange,
|
|
102
|
-
children: statuses.map((status)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelectOption, {
|
|
103
|
-
value: status.name,
|
|
104
|
-
children: status.name
|
|
105
|
-
}, status.documentId))
|
|
106
|
-
}),
|
|
107
|
-
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
|
108
|
-
padding: 2,
|
|
109
|
-
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
|
110
|
-
variant: "sigma",
|
|
111
|
-
children: message
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
]
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const StatusCell = ({ row })=>{
|
|
119
|
-
const [status, setStatus] = React.useState(null);
|
|
120
|
-
React.useEffect(()=>{
|
|
121
|
-
setStatus(row.statusField);
|
|
122
|
-
}, [
|
|
123
|
-
row
|
|
124
|
-
]);
|
|
125
|
-
if (!status) return null;
|
|
126
|
-
return /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
127
|
-
style: {
|
|
128
|
-
padding: "4px 8px",
|
|
129
|
-
borderRadius: 4,
|
|
130
|
-
background: status.published ? "#eafbe7" : "#f0f0ff",
|
|
131
|
-
color: status.published ? "#2f6846" : "#271fe0",
|
|
132
|
-
border: `1px solid ${status.published ? "#2f6846" : "#271fe0"}`,
|
|
133
|
-
fontSize: 14
|
|
134
|
-
},
|
|
135
|
-
children: status.name
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const addStatusColumnHook = ({ displayedHeaders, layout })=>{
|
|
140
|
-
const statusHeader = {
|
|
141
|
-
attribute: {
|
|
142
|
-
type: "custom"
|
|
143
|
-
},
|
|
144
|
-
name: "statusLabel",
|
|
145
|
-
label: {
|
|
146
|
-
id: "primershop-status-manager.status",
|
|
147
|
-
defaultMessage: "Status"
|
|
148
|
-
},
|
|
149
|
-
searchable: false,
|
|
150
|
-
sortable: false,
|
|
151
|
-
cellFormatter: (row)=>{
|
|
152
|
-
return React.createElement(StatusCell, {
|
|
153
|
-
row
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
displayedHeaders: [
|
|
159
|
-
...displayedHeaders,
|
|
160
|
-
statusHeader
|
|
161
|
-
],
|
|
162
|
-
layout
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Admin permission actions for use in addMenuLink, Page.Protect, and useRBAC.
|
|
168
|
-
* Action IDs must match uids registered in server bootstrap (registerMany).
|
|
169
|
-
*/ const pluginPermissions = {
|
|
170
|
-
accessStatusManager: [
|
|
171
|
-
{
|
|
172
|
-
action: "plugin::primershop-status-manager.main",
|
|
173
|
-
subject: null
|
|
174
|
-
}
|
|
175
|
-
]
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const StatusFilter = ()=>{
|
|
179
|
-
const { contentType } = admin.unstable_useContentManagerContext();
|
|
180
|
-
const [statuses, setStatuses] = React.useState([]);
|
|
181
|
-
const [selected, setSelected] = React.useState("");
|
|
182
|
-
const { get } = admin.useFetchClient();
|
|
183
|
-
const [{ query }, setQuery] = admin.useQueryParams();
|
|
184
|
-
const handleStatusChange = React.useCallback((name)=>{
|
|
185
|
-
setQuery({
|
|
186
|
-
page: 1,
|
|
187
|
-
plugins: {
|
|
188
|
-
...query.plugins,
|
|
189
|
-
"primershop-status-manager": {
|
|
190
|
-
statusName: name.toLowerCase()
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}, "push", true);
|
|
194
|
-
}, [
|
|
195
|
-
query.plugins,
|
|
196
|
-
setQuery
|
|
197
|
-
]);
|
|
198
|
-
React.useEffect(()=>{
|
|
199
|
-
const selectedStatusName = query.plugins?.["primershop-status-manager"]?.statusName;
|
|
200
|
-
if (!selectedStatusName) return;
|
|
201
|
-
const status = statuses.find((status)=>status.name.toLowerCase() === selectedStatusName);
|
|
202
|
-
if (status) {
|
|
203
|
-
setSelected(status.name);
|
|
204
|
-
}
|
|
205
|
-
}, [
|
|
206
|
-
query,
|
|
207
|
-
statuses
|
|
208
|
-
]);
|
|
209
|
-
React.useEffect(()=>{
|
|
210
|
-
async function fetchStatuses() {
|
|
211
|
-
try {
|
|
212
|
-
const { data } = await get("primershop-status-manager/statuses");
|
|
213
|
-
const allStatusesObject = {
|
|
214
|
-
documentId: "all",
|
|
215
|
-
name: "All"
|
|
216
|
-
};
|
|
217
|
-
setStatuses([
|
|
218
|
-
allStatusesObject,
|
|
219
|
-
...data
|
|
220
|
-
]);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error("Error fetching statuses:", error);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
fetchStatuses();
|
|
226
|
-
}, [
|
|
227
|
-
get
|
|
228
|
-
]);
|
|
229
|
-
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
|
|
230
|
-
direction: "column",
|
|
231
|
-
justifyContent: "center",
|
|
232
|
-
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelect, {
|
|
233
|
-
size: "S",
|
|
234
|
-
placeholder: `${contentType?.info.displayName} status`,
|
|
235
|
-
value: selected,
|
|
236
|
-
onChange: handleStatusChange,
|
|
237
|
-
children: statuses.map((status)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelectOption, {
|
|
238
|
-
value: status.name,
|
|
239
|
-
children: status.name
|
|
240
|
-
}, status.documentId))
|
|
241
|
-
})
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
const plugin = {
|
|
246
|
-
register (app) {
|
|
247
|
-
app.registerPlugin({
|
|
248
|
-
id: PLUGIN_ID,
|
|
249
|
-
initializer: Initializer,
|
|
250
|
-
isReady: true,
|
|
251
|
-
name: PLUGIN_ID
|
|
252
|
-
});
|
|
253
|
-
app.addMenuLink({
|
|
254
|
-
to: `plugins/${PLUGIN_ID}`,
|
|
255
|
-
icon: PluginIcon,
|
|
256
|
-
intlLabel: {
|
|
257
|
-
id: `${PLUGIN_ID}.plugin.name`,
|
|
258
|
-
defaultMessage: "Status manager"
|
|
259
|
-
},
|
|
260
|
-
permissions: [
|
|
261
|
-
pluginPermissions.accessStatusManager[0]
|
|
262
|
-
],
|
|
263
|
-
Component: ()=>Promise.resolve().then(function () { return require('./HomePage-Bez9ZXv-.js'); }).then((module)=>({
|
|
264
|
-
default: module.HomePage
|
|
265
|
-
}))
|
|
266
|
-
});
|
|
267
|
-
},
|
|
268
|
-
bootstrap (app) {
|
|
269
|
-
app.getPlugin("content-manager").injectComponent("editView", "right-links", {
|
|
270
|
-
name: "Status",
|
|
271
|
-
Component: ProductStatusField
|
|
272
|
-
});
|
|
273
|
-
app.registerHook('Admin/CM/pages/ListView/inject-column-in-table', addStatusColumnHook);
|
|
274
|
-
const contentManager = app.getPlugin('content-manager');
|
|
275
|
-
contentManager.injectComponent('listView', 'actions', {
|
|
276
|
-
name: 'status-filter',
|
|
277
|
-
Component: StatusFilter
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
exports.plugin = plugin;
|
|
283
|
-
exports.pluginPermissions = pluginPermissions;
|