@primershop/strapi-plugin-product-actions 0.0.10 → 0.0.11

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.
@@ -1,276 +1,23 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
- var jsxRuntime = require('react/jsx-runtime');
5
- var designSystem = require('@strapi/design-system');
6
- var admin = require('@strapi/strapi/admin');
7
-
8
- const PLUGIN_ID = "primershop-product-actions";
9
-
10
- /**
11
- * @type {import('react').FC<{ setPlugin: (id: string) => void }>}
12
- */ const Initializer = ({ setPlugin })=>{
13
- const ref = react.useRef(setPlugin);
14
- react.useEffect(()=>{
15
- ref.current(PLUGIN_ID);
16
- }, []);
17
- return null;
18
- };
19
-
20
- const en = {
21
- "plugin.name": "Product Series",
22
- "plugin.description": "Manage product series and their products",
23
- "product-series.actions.label": "Product Actions",
24
- "product-series.actions.createProducts": "Create Products",
25
- "product-series.actions.updateProducts": "Update Products",
26
- "product-series.actions.createDialogTitle": "Create Products from Series",
27
- "product-series.actions.updateDialogTitle": "Update All Products in Series",
28
- "product-series.actions.updateDialogDescription": "This will update all products in the series with the selected fields. Make sure to save the series first before updating the products.",
29
- "product-series.actions.productCount": "Number of Products",
30
- "product-series.actions.create": "Create",
31
- "product-series.actions.update": "Update",
32
- "product-series.actions.cancel": "Cancel",
33
- "product-series.actions.createSuccess": "Products created successfully",
34
- "product-series.actions.createError": "Failed to create products",
35
- "product-series.actions.updateSuccess": "Products updated successfully",
36
- "product-series.actions.updateError": "Failed to update products",
37
- "product-series.actions.selectFields": "Select fields to update",
38
- "product-series.actions.noDocumentId": "Save the series first before creating products"
39
- };
40
-
41
- const formatMessage = (arg)=>{
42
- return en[arg.id];
43
- };
44
- const valuesToUpdate = [
45
- "description",
46
- "shortDescription",
47
- "media",
48
- "coverImage",
49
- "seo",
50
- "totalCost",
51
- "wholesalePrice",
52
- "retailPrice",
53
- "category",
54
- "creator"
55
- ];
56
- const SeriesProductActions = ({ document })=>{
57
- const { model } = admin.unstable_useContentManagerContext();
58
- const documentId = document?.documentId;
59
- const [productCount, setProductCount] = react.useState(1);
60
- const [isLoading, setIsLoading] = react.useState(false);
61
- const [fieldsToUpdate, setFieldsToUpdate] = react.useState([]);
62
- const { post, put } = admin.useFetchClient();
63
- if (model !== "api::product-series.product-series") return null;
64
- const handleCreateProducts = async ()=>{
65
- try {
66
- setIsLoading(true);
67
- const response = await post(`primershop-product-actions/create-products`, {
68
- count: productCount,
69
- id: documentId
70
- });
71
- if (!response.data) {
72
- throw new Error("Failed to create products");
73
- }
74
- setProductCount(1);
75
- } catch (error) {
76
- console.error("Error creating products:", error);
77
- } finally{
78
- setIsLoading(false);
79
- }
80
- };
81
- const handleUpdateProducts = async ()=>{
82
- try {
83
- setIsLoading(true);
84
- const response = await put(`/primershop-product-actions/update-products`, {
85
- seriesId: documentId,
86
- fieldsToUpdate
87
- });
88
- if (!response.data) {
89
- throw new Error("Failed to update products");
90
- }
91
- } catch (error) {
92
- console.error("Error updating products:", error);
93
- } finally{
94
- setIsLoading(false);
95
- }
96
- };
97
- return {
98
- title: "Series Product Actions",
99
- content: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
100
- children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Box, {
101
- children: [
102
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
103
- variant: "delta",
104
- fontWeight: "bold",
105
- children: formatMessage({
106
- id: "product-series.actions.label"
107
- })
108
- }),
109
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
110
- wrap: "wrap",
111
- children: [
112
- !documentId && /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
113
- display: "block",
114
- marginTop: 2,
115
- marginBottom: 2,
116
- width: "100%",
117
- color: "red",
118
- children: formatMessage({
119
- id: "product-series.actions.noDocumentId"
120
- })
121
- }),
122
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Root, {
123
- children: [
124
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Trigger, {
125
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
126
- variant: "secondary",
127
- disabled: isLoading || !documentId,
128
- children: formatMessage({
129
- id: "product-series.actions.createProducts"
130
- })
131
- })
132
- }),
133
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Content, {
134
- children: [
135
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Body, {
136
- children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Box, {
137
- children: [
138
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
139
- children: formatMessage({
140
- id: "product-series.actions.createDialogTitle"
141
- })
142
- }),
143
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.NumberInput, {
144
- value: productCount,
145
- onValueChange: (value)=>setProductCount(value || 1),
146
- min: 1,
147
- max: 100
148
- })
149
- ]
150
- })
151
- }),
152
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Footer, {
153
- children: [
154
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Cancel, {
155
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
156
- fullWidth: true,
157
- variant: "tertiary",
158
- children: "Cancel"
159
- })
160
- }),
161
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Action, {
162
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
163
- onClick: handleCreateProducts,
164
- variant: "default",
165
- loading: isLoading,
166
- children: formatMessage({
167
- id: "product-series.actions.create"
168
- })
169
- })
170
- })
171
- ]
172
- })
173
- ]
174
- })
175
- ]
176
- }),
177
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Root, {
178
- children: [
179
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Trigger, {
180
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
181
- marginLeft: 2,
182
- variant: "secondary",
183
- disabled: isLoading || !documentId,
184
- children: formatMessage({
185
- id: "product-series.actions.updateProducts"
186
- })
187
- })
188
- }),
189
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Content, {
190
- children: [
191
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Body, {
192
- display: "flex",
193
- direction: "column",
194
- gap: 2,
195
- justifyContent: "center",
196
- alignItems: "center",
197
- width: "100%",
198
- children: [
199
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
200
- variant: "delta",
201
- fontWeight: "bold",
202
- children: formatMessage({
203
- id: "product-series.actions.updateDialogTitle"
204
- })
205
- }),
206
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
207
- children: formatMessage({
208
- id: "product-series.actions.updateDialogDescription"
209
- })
210
- }),
211
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.MultiSelect, {
212
- withTags: true,
213
- value: fieldsToUpdate,
214
- onClear: ()=>setFieldsToUpdate([]),
215
- onChange: (value)=>setFieldsToUpdate(value),
216
- required: true,
217
- placeholder: formatMessage({
218
- id: "product-series.actions.selectFields"
219
- }),
220
- children: valuesToUpdate.map((field)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.MultiSelectOption, {
221
- value: field,
222
- children: field
223
- }, field))
224
- })
225
- ]
226
- }),
227
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Footer, {
228
- children: [
229
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Cancel, {
230
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
231
- fullWidth: true,
232
- variant: "tertiary",
233
- children: "Cancel"
234
- })
235
- }),
236
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Action, {
237
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
238
- onClick: handleUpdateProducts,
239
- variant: "default",
240
- loading: isLoading,
241
- children: formatMessage({
242
- id: "product-series.actions.update"
243
- })
244
- })
245
- })
246
- ]
247
- })
248
- ]
249
- })
250
- ]
251
- })
252
- ]
253
- })
254
- ]
255
- })
256
- })
257
- };
258
- };
3
+ var index$1 = require('./components/Initializer/index.js');
4
+ var index = require('./components/SeriesProductActions/index.js');
5
+ var pluginId = require('./pluginId.js');
259
6
 
260
7
  const plugin = {
261
8
  register (app) {
262
9
  app.registerPlugin({
263
- id: PLUGIN_ID,
264
- initializer: Initializer,
10
+ id: pluginId.PLUGIN_ID,
11
+ initializer: index$1.Initializer,
265
12
  isReady: false,
266
- name: PLUGIN_ID
13
+ name: pluginId.PLUGIN_ID
267
14
  });
268
15
  },
269
16
  bootstrap (app) {
270
17
  app.getPlugin("content-manager").apis.addEditViewSidePanel((panels)=>{
271
18
  return [
272
19
  ...panels,
273
- SeriesProductActions
20
+ index.SeriesProductActions
274
21
  ];
275
22
  });
276
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../admin/src/pluginId.ts","../../admin/src/components/Initializer/index.tsx","../../admin/src/translations/en.ts","../../admin/src/components/SeriesProductActions/index.tsx","../../admin/src/index.ts"],"sourcesContent":["export const PLUGIN_ID = \"primershop-product-actions\";\r\n","import { useEffect, useRef } from \"react\";\r\n\r\nimport { PLUGIN_ID } from \"../../pluginId\";\r\n\r\n/**\r\n * @type {import('react').FC<{ setPlugin: (id: string) => void }>}\r\n */\r\nconst Initializer = ({ setPlugin }: { setPlugin: (id: string) => void }) => {\r\n const ref = useRef(setPlugin);\r\n\r\n useEffect(() => {\r\n ref.current(PLUGIN_ID);\r\n }, []);\r\n\r\n return null;\r\n};\r\n\r\nexport { Initializer };\r\n","const en: Record<string, string> = {\r\n \"plugin.name\": \"Product Series\",\r\n \"plugin.description\": \"Manage product series and their products\",\r\n \"product-series.actions.label\": \"Product Actions\",\r\n \"product-series.actions.createProducts\": \"Create Products\",\r\n \"product-series.actions.updateProducts\": \"Update Products\",\r\n \"product-series.actions.createDialogTitle\": \"Create Products from Series\",\r\n \"product-series.actions.updateDialogTitle\": \"Update All Products in Series\",\r\n \"product-series.actions.updateDialogDescription\":\r\n \"This will update all products in the series with the selected fields. Make sure to save the series first before updating the products.\",\r\n \"product-series.actions.productCount\": \"Number of Products\",\r\n \"product-series.actions.create\": \"Create\",\r\n \"product-series.actions.update\": \"Update\",\r\n \"product-series.actions.cancel\": \"Cancel\",\r\n \"product-series.actions.createSuccess\": \"Products created successfully\",\r\n \"product-series.actions.createError\": \"Failed to create products\",\r\n \"product-series.actions.updateSuccess\": \"Products updated successfully\",\r\n \"product-series.actions.updateError\": \"Failed to update products\",\r\n \"product-series.actions.selectFields\": \"Select fields to update\",\r\n \"product-series.actions.noDocumentId\":\r\n \"Save the series first before creating products\",\r\n};\r\n\r\nexport { en };\r\n","import React, { useState } from \"react\";\r\n\r\nimport {\r\n Box,\r\n Button,\r\n Typography,\r\n Dialog,\r\n NumberInput,\r\n Flex,\r\n MultiSelect,\r\n MultiSelectOption,\r\n} from \"@strapi/design-system\";\r\nimport {\r\n useFetchClient,\r\n unstable_useContentManagerContext as useContentManagerContext,\r\n} from \"@strapi/strapi/admin\";\r\n\r\nimport { en } from \"../../translations\";\r\n\r\nconst formatMessage = (arg: { id: string }): string => {\r\n return en[arg.id];\r\n};\r\n\r\nconst valuesToUpdate = [\r\n \"description\",\r\n \"shortDescription\",\r\n \"media\",\r\n \"coverImage\",\r\n \"seo\",\r\n \"totalCost\",\r\n \"wholesalePrice\",\r\n \"retailPrice\",\r\n \"category\",\r\n \"creator\",\r\n];\r\n\r\ninterface Document {\r\n documentId?: string;\r\n}\r\n\r\nconst SeriesProductActions = ({ document }: { document: Document }) => {\r\n const { model } = useContentManagerContext();\r\n const documentId = document?.documentId;\r\n const [productCount, setProductCount] = useState(1);\r\n const [isLoading, setIsLoading] = useState(false);\r\n const [fieldsToUpdate, setFieldsToUpdate] = useState<string[]>([]);\r\n const { post, put } = useFetchClient();\r\n\r\n if (model !== \"api::product-series.product-series\") return null;\r\n\r\n const handleCreateProducts = async () => {\r\n try {\r\n setIsLoading(true);\r\n const response = await post(\r\n `primershop-product-actions/create-products`,\r\n {\r\n count: productCount,\r\n id: documentId,\r\n }\r\n );\r\n\r\n if (!response.data) {\r\n throw new Error(\"Failed to create products\");\r\n }\r\n\r\n setProductCount(1);\r\n } catch (error) {\r\n console.error(\"Error creating products:\", error);\r\n } finally {\r\n setIsLoading(false);\r\n }\r\n };\r\n\r\n const handleUpdateProducts = async () => {\r\n try {\r\n setIsLoading(true);\r\n const response = await put(\r\n `/primershop-product-actions/update-products`,\r\n {\r\n seriesId: documentId,\r\n fieldsToUpdate,\r\n }\r\n );\r\n\r\n if (!response.data) {\r\n throw new Error(\"Failed to update products\");\r\n }\r\n } catch (error) {\r\n console.error(\"Error updating products:\", error);\r\n } finally {\r\n setIsLoading(false);\r\n }\r\n };\r\n return {\r\n title: \"Series Product Actions\",\r\n content: (\r\n <Box>\r\n <Box>\r\n <Typography variant=\"delta\" fontWeight=\"bold\">\r\n {formatMessage({ id: \"product-series.actions.label\" })}\r\n </Typography>\r\n <Flex wrap={\"wrap\"}>\r\n {!documentId && (\r\n <Typography\r\n display={\"block\"}\r\n marginTop={2}\r\n marginBottom={2}\r\n width=\"100%\"\r\n color=\"red\"\r\n >\r\n {formatMessage({ id: \"product-series.actions.noDocumentId\" })}\r\n </Typography>\r\n )}\r\n\r\n <Dialog.Root>\r\n <Dialog.Trigger>\r\n <Button variant=\"secondary\" disabled={isLoading || !documentId}>\r\n {formatMessage({\r\n id: \"product-series.actions.createProducts\",\r\n })}\r\n </Button>\r\n </Dialog.Trigger>\r\n <Dialog.Content>\r\n <Dialog.Body>\r\n <Box>\r\n <Typography>\r\n {formatMessage({\r\n id: \"product-series.actions.createDialogTitle\",\r\n })}\r\n </Typography>\r\n <NumberInput\r\n value={productCount}\r\n onValueChange={(value) => setProductCount(value || 1)}\r\n min={1}\r\n max={100}\r\n ></NumberInput>\r\n </Box>\r\n </Dialog.Body>\r\n <Dialog.Footer>\r\n <Dialog.Cancel>\r\n <Button fullWidth variant=\"tertiary\">\r\n Cancel\r\n </Button>\r\n </Dialog.Cancel>\r\n <Dialog.Action>\r\n <Button\r\n onClick={handleCreateProducts}\r\n variant=\"default\"\r\n loading={isLoading}\r\n >\r\n {formatMessage({ id: \"product-series.actions.create\" })}\r\n </Button>\r\n </Dialog.Action>\r\n </Dialog.Footer>\r\n </Dialog.Content>\r\n </Dialog.Root>\r\n\r\n {/* Update Products Dialog */}\r\n <Dialog.Root>\r\n <Dialog.Trigger>\r\n <Button\r\n marginLeft={2}\r\n variant=\"secondary\"\r\n disabled={isLoading || !documentId}\r\n >\r\n {formatMessage({\r\n id: \"product-series.actions.updateProducts\",\r\n })}\r\n </Button>\r\n </Dialog.Trigger>\r\n <Dialog.Content>\r\n <Dialog.Body\r\n display={\"flex\"}\r\n direction={\"column\"}\r\n gap={2}\r\n justifyContent={\"center\"}\r\n alignItems={\"center\"}\r\n width={\"100%\"}\r\n >\r\n <Typography variant=\"delta\" fontWeight=\"bold\">\r\n {formatMessage({\r\n id: \"product-series.actions.updateDialogTitle\",\r\n })}\r\n </Typography>\r\n <Typography>\r\n {formatMessage({\r\n id: \"product-series.actions.updateDialogDescription\",\r\n })}\r\n </Typography>\r\n <MultiSelect\r\n withTags={true}\r\n value={fieldsToUpdate}\r\n onClear={() => setFieldsToUpdate([])}\r\n onChange={(value: string[]) => setFieldsToUpdate(value)}\r\n required={true}\r\n placeholder={formatMessage({\r\n id: \"product-series.actions.selectFields\",\r\n })}\r\n >\r\n {valuesToUpdate.map((field) => (\r\n <MultiSelectOption key={field} value={field}>\r\n {field}\r\n </MultiSelectOption>\r\n ))}\r\n </MultiSelect>\r\n </Dialog.Body>\r\n <Dialog.Footer>\r\n <Dialog.Cancel>\r\n <Button fullWidth variant=\"tertiary\">\r\n Cancel\r\n </Button>\r\n </Dialog.Cancel>\r\n <Dialog.Action>\r\n <Button\r\n onClick={handleUpdateProducts}\r\n variant=\"default\"\r\n loading={isLoading}\r\n >\r\n {formatMessage({ id: \"product-series.actions.update\" })}\r\n </Button>\r\n </Dialog.Action>\r\n </Dialog.Footer>\r\n </Dialog.Content>\r\n </Dialog.Root>\r\n </Flex>\r\n </Box>\r\n </Box>\r\n ),\r\n };\r\n};\r\n\r\nexport { SeriesProductActions };\r\n","import { Initializer } from \"./components/Initializer\";\r\nimport { SeriesProductActions } from \"./components/SeriesProductActions\";\r\nimport { PLUGIN_ID } from \"./pluginId\";\r\n\r\nimport type { PanelComponent } from \"@strapi/content-manager/strapi-admin\";\r\n\r\nconst plugin = {\r\n register(app: any) {\r\n app.registerPlugin({\r\n id: PLUGIN_ID,\r\n initializer: Initializer,\r\n isReady: false,\r\n name: PLUGIN_ID,\r\n });\r\n },\r\n\r\n bootstrap(app: any) {\r\n app\r\n .getPlugin(\"content-manager\")\r\n .apis.addEditViewSidePanel((panels: any): PanelComponent[] => {\r\n return [...panels, SeriesProductActions];\r\n });\r\n },\r\n};\r\n\r\nexport default plugin;\r\n"],"names":["PLUGIN_ID","Initializer","setPlugin","ref","useRef","useEffect","current","en","formatMessage","arg","id","valuesToUpdate","SeriesProductActions","document","model","useContentManagerContext","documentId","productCount","setProductCount","useState","isLoading","setIsLoading","fieldsToUpdate","setFieldsToUpdate","post","put","useFetchClient","handleCreateProducts","response","count","data","Error","error","console","handleUpdateProducts","seriesId","title","content","_jsx","Box","_jsxs","Typography","variant","fontWeight","Flex","wrap","display","marginTop","marginBottom","width","color","Dialog","Root","Trigger","Button","disabled","Content","Body","NumberInput","value","onValueChange","min","max","Footer","Cancel","fullWidth","Action","onClick","loading","marginLeft","direction","gap","justifyContent","alignItems","MultiSelect","withTags","onClear","onChange","required","placeholder","map","field","MultiSelectOption","plugin","register","app","registerPlugin","initializer","isReady","name","bootstrap","getPlugin","apis","addEditViewSidePanel","panels"],"mappings":";;;;;;;AAAO,MAAMA,YAAY,4BAAA;;ACIzB;;AAEC,IACD,MAAMC,WAAAA,GAAc,CAAC,EAAEC,SAAS,EAAuC,GAAA;AACrE,IAAA,MAAMC,MAAMC,YAAAA,CAA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gB,mBAAAA,EAAAA;4DACCa,OAAAA,EAASjC,oBAAAA;4DACTQ,OAAAA,EAAQ,SAAA;4DACR0B,OAAAA,EAAShD,SAAAA;sEAERZ,aAAAA,CAAc;gEAAEE,EAAAA,EAAI;AAAgC,6DAAA;;;;;;;;;;;;;;AAUzE,KAAA;AACF,CAAA;;AC/NA,MAAMyE,MAAAA,GAAS;AACbC,IAAAA,QAAAA,CAAAA,CAASC,GAAQ,EAAA;AACfA,QAAAA,GAAAA,CAAIC,cAAc,CAAC;YACjB5E,EAAAA,EAAIV,SAAAA;YACJuF,WAAAA,EAAatF,WAAAA;YACbuF,OAAAA,EAAS,KAAA;YACTC,IAAAA,EAAMzF;AACR,SAAA,CAAA;AACF,IAAA,CAAA;AAEA0F,IAAAA,SAAAA,CAAAA,CAAUL,GAAQ,EAAA;AAChBA,QAAAA,GAAAA,CACGM,SAAS,CAAC,iBAAA,CAAA,CACVC,IAAI,CAACC,oBAAoB,CAAC,CAACC,MAAAA,GAAAA;YAC1B,OAAO;AAAIA,gBAAAA,GAAAA,MAAAA;AAAQlF,gBAAAA;AAAqB,aAAA;AAC1C,QAAA,CAAA,CAAA;AACJ,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../admin/src/index.ts"],"sourcesContent":["import { Initializer } from \"./components/Initializer\";\r\nimport { SeriesProductActions } from \"./components/SeriesProductActions\";\r\nimport { PLUGIN_ID } from \"./pluginId\";\r\n\r\nimport type { PanelComponent } from \"@strapi/content-manager/strapi-admin\";\r\n\r\nconst plugin = {\r\n register(app: any) {\r\n app.registerPlugin({\r\n id: PLUGIN_ID,\r\n initializer: Initializer,\r\n isReady: false,\r\n name: PLUGIN_ID,\r\n });\r\n },\r\n\r\n bootstrap(app: any) {\r\n app\r\n .getPlugin(\"content-manager\")\r\n .apis.addEditViewSidePanel((panels: any): PanelComponent[] => {\r\n return [...panels, SeriesProductActions];\r\n });\r\n },\r\n};\r\n\r\nexport default plugin;\r\n"],"names":["plugin","register","app","registerPlugin","id","PLUGIN_ID","initializer","Initializer","isReady","name","bootstrap","getPlugin","apis","addEditViewSidePanel","panels","SeriesProductActions"],"mappings":";;;;;;AAMA,MAAMA,MAAAA,GAAS;AACbC,IAAAA,QAAAA,CAAAA,CAASC,GAAQ,EAAA;AACfA,QAAAA,GAAAA,CAAIC,cAAc,CAAC;YACjBC,EAAAA,EAAIC,kBAAAA;YACJC,WAAAA,EAAaC,mBAAAA;YACbC,OAAAA,EAAS,KAAA;YACTC,IAAAA,EAAMJ;AACR,SAAA,CAAA;AACF,IAAA,CAAA;AAEAK,IAAAA,SAAAA,CAAAA,CAAUR,GAAQ,EAAA;AAChBA,QAAAA,GAAAA,CACGS,SAAS,CAAC,iBAAA,CAAA,CACVC,IAAI,CAACC,oBAAoB,CAAC,CAACC,MAAAA,GAAAA;YAC1B,OAAO;AAAIA,gBAAAA,GAAAA,MAAAA;AAAQC,gBAAAA;AAAqB,aAAA;AAC1C,QAAA,CAAA,CAAA;AACJ,IAAA;AACF;;;;"}
@@ -1,259 +1,6 @@
1
- import { useRef, useEffect, useState } from 'react';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { Box, Typography, Flex, Dialog, Button, NumberInput, MultiSelect, MultiSelectOption } from '@strapi/design-system';
4
- import { unstable_useContentManagerContext, useFetchClient } from '@strapi/strapi/admin';
5
-
6
- const PLUGIN_ID = "primershop-product-actions";
7
-
8
- /**
9
- * @type {import('react').FC<{ setPlugin: (id: string) => void }>}
10
- */ const Initializer = ({ setPlugin })=>{
11
- const ref = useRef(setPlugin);
12
- useEffect(()=>{
13
- ref.current(PLUGIN_ID);
14
- }, []);
15
- return null;
16
- };
17
-
18
- const en = {
19
- "plugin.name": "Product Series",
20
- "plugin.description": "Manage product series and their products",
21
- "product-series.actions.label": "Product Actions",
22
- "product-series.actions.createProducts": "Create Products",
23
- "product-series.actions.updateProducts": "Update Products",
24
- "product-series.actions.createDialogTitle": "Create Products from Series",
25
- "product-series.actions.updateDialogTitle": "Update All Products in Series",
26
- "product-series.actions.updateDialogDescription": "This will update all products in the series with the selected fields. Make sure to save the series first before updating the products.",
27
- "product-series.actions.productCount": "Number of Products",
28
- "product-series.actions.create": "Create",
29
- "product-series.actions.update": "Update",
30
- "product-series.actions.cancel": "Cancel",
31
- "product-series.actions.createSuccess": "Products created successfully",
32
- "product-series.actions.createError": "Failed to create products",
33
- "product-series.actions.updateSuccess": "Products updated successfully",
34
- "product-series.actions.updateError": "Failed to update products",
35
- "product-series.actions.selectFields": "Select fields to update",
36
- "product-series.actions.noDocumentId": "Save the series first before creating products"
37
- };
38
-
39
- const formatMessage = (arg)=>{
40
- return en[arg.id];
41
- };
42
- const valuesToUpdate = [
43
- "description",
44
- "shortDescription",
45
- "media",
46
- "coverImage",
47
- "seo",
48
- "totalCost",
49
- "wholesalePrice",
50
- "retailPrice",
51
- "category",
52
- "creator"
53
- ];
54
- const SeriesProductActions = ({ document })=>{
55
- const { model } = unstable_useContentManagerContext();
56
- const documentId = document?.documentId;
57
- const [productCount, setProductCount] = useState(1);
58
- const [isLoading, setIsLoading] = useState(false);
59
- const [fieldsToUpdate, setFieldsToUpdate] = useState([]);
60
- const { post, put } = useFetchClient();
61
- if (model !== "api::product-series.product-series") return null;
62
- const handleCreateProducts = async ()=>{
63
- try {
64
- setIsLoading(true);
65
- const response = await post(`primershop-product-actions/create-products`, {
66
- count: productCount,
67
- id: documentId
68
- });
69
- if (!response.data) {
70
- throw new Error("Failed to create products");
71
- }
72
- setProductCount(1);
73
- } catch (error) {
74
- console.error("Error creating products:", error);
75
- } finally{
76
- setIsLoading(false);
77
- }
78
- };
79
- const handleUpdateProducts = async ()=>{
80
- try {
81
- setIsLoading(true);
82
- const response = await put(`/primershop-product-actions/update-products`, {
83
- seriesId: documentId,
84
- fieldsToUpdate
85
- });
86
- if (!response.data) {
87
- throw new Error("Failed to update products");
88
- }
89
- } catch (error) {
90
- console.error("Error updating products:", error);
91
- } finally{
92
- setIsLoading(false);
93
- }
94
- };
95
- return {
96
- title: "Series Product Actions",
97
- content: /*#__PURE__*/ jsx(Box, {
98
- children: /*#__PURE__*/ jsxs(Box, {
99
- children: [
100
- /*#__PURE__*/ jsx(Typography, {
101
- variant: "delta",
102
- fontWeight: "bold",
103
- children: formatMessage({
104
- id: "product-series.actions.label"
105
- })
106
- }),
107
- /*#__PURE__*/ jsxs(Flex, {
108
- wrap: "wrap",
109
- children: [
110
- !documentId && /*#__PURE__*/ jsx(Typography, {
111
- display: "block",
112
- marginTop: 2,
113
- marginBottom: 2,
114
- width: "100%",
115
- color: "red",
116
- children: formatMessage({
117
- id: "product-series.actions.noDocumentId"
118
- })
119
- }),
120
- /*#__PURE__*/ jsxs(Dialog.Root, {
121
- children: [
122
- /*#__PURE__*/ jsx(Dialog.Trigger, {
123
- children: /*#__PURE__*/ jsx(Button, {
124
- variant: "secondary",
125
- disabled: isLoading || !documentId,
126
- children: formatMessage({
127
- id: "product-series.actions.createProducts"
128
- })
129
- })
130
- }),
131
- /*#__PURE__*/ jsxs(Dialog.Content, {
132
- children: [
133
- /*#__PURE__*/ jsx(Dialog.Body, {
134
- children: /*#__PURE__*/ jsxs(Box, {
135
- children: [
136
- /*#__PURE__*/ jsx(Typography, {
137
- children: formatMessage({
138
- id: "product-series.actions.createDialogTitle"
139
- })
140
- }),
141
- /*#__PURE__*/ jsx(NumberInput, {
142
- value: productCount,
143
- onValueChange: (value)=>setProductCount(value || 1),
144
- min: 1,
145
- max: 100
146
- })
147
- ]
148
- })
149
- }),
150
- /*#__PURE__*/ jsxs(Dialog.Footer, {
151
- children: [
152
- /*#__PURE__*/ jsx(Dialog.Cancel, {
153
- children: /*#__PURE__*/ jsx(Button, {
154
- fullWidth: true,
155
- variant: "tertiary",
156
- children: "Cancel"
157
- })
158
- }),
159
- /*#__PURE__*/ jsx(Dialog.Action, {
160
- children: /*#__PURE__*/ jsx(Button, {
161
- onClick: handleCreateProducts,
162
- variant: "default",
163
- loading: isLoading,
164
- children: formatMessage({
165
- id: "product-series.actions.create"
166
- })
167
- })
168
- })
169
- ]
170
- })
171
- ]
172
- })
173
- ]
174
- }),
175
- /*#__PURE__*/ jsxs(Dialog.Root, {
176
- children: [
177
- /*#__PURE__*/ jsx(Dialog.Trigger, {
178
- children: /*#__PURE__*/ jsx(Button, {
179
- marginLeft: 2,
180
- variant: "secondary",
181
- disabled: isLoading || !documentId,
182
- children: formatMessage({
183
- id: "product-series.actions.updateProducts"
184
- })
185
- })
186
- }),
187
- /*#__PURE__*/ jsxs(Dialog.Content, {
188
- children: [
189
- /*#__PURE__*/ jsxs(Dialog.Body, {
190
- display: "flex",
191
- direction: "column",
192
- gap: 2,
193
- justifyContent: "center",
194
- alignItems: "center",
195
- width: "100%",
196
- children: [
197
- /*#__PURE__*/ jsx(Typography, {
198
- variant: "delta",
199
- fontWeight: "bold",
200
- children: formatMessage({
201
- id: "product-series.actions.updateDialogTitle"
202
- })
203
- }),
204
- /*#__PURE__*/ jsx(Typography, {
205
- children: formatMessage({
206
- id: "product-series.actions.updateDialogDescription"
207
- })
208
- }),
209
- /*#__PURE__*/ jsx(MultiSelect, {
210
- withTags: true,
211
- value: fieldsToUpdate,
212
- onClear: ()=>setFieldsToUpdate([]),
213
- onChange: (value)=>setFieldsToUpdate(value),
214
- required: true,
215
- placeholder: formatMessage({
216
- id: "product-series.actions.selectFields"
217
- }),
218
- children: valuesToUpdate.map((field)=>/*#__PURE__*/ jsx(MultiSelectOption, {
219
- value: field,
220
- children: field
221
- }, field))
222
- })
223
- ]
224
- }),
225
- /*#__PURE__*/ jsxs(Dialog.Footer, {
226
- children: [
227
- /*#__PURE__*/ jsx(Dialog.Cancel, {
228
- children: /*#__PURE__*/ jsx(Button, {
229
- fullWidth: true,
230
- variant: "tertiary",
231
- children: "Cancel"
232
- })
233
- }),
234
- /*#__PURE__*/ jsx(Dialog.Action, {
235
- children: /*#__PURE__*/ jsx(Button, {
236
- onClick: handleUpdateProducts,
237
- variant: "default",
238
- loading: isLoading,
239
- children: formatMessage({
240
- id: "product-series.actions.update"
241
- })
242
- })
243
- })
244
- ]
245
- })
246
- ]
247
- })
248
- ]
249
- })
250
- ]
251
- })
252
- ]
253
- })
254
- })
255
- };
256
- };
1
+ import { Initializer } from './components/Initializer/index.mjs';
2
+ import { SeriesProductActions } from './components/SeriesProductActions/index.mjs';
3
+ import { PLUGIN_ID } from './pluginId.mjs';
257
4
 
258
5
  const plugin = {
259
6
  register (app) {