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