@strapi/review-workflows 0.0.0-experimental.d954d57341a6623992a0d211daaec8e245c3517d → 0.0.0-experimental.da32ec023171430e0b0185c39f3cdd0f22d36928

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.
Files changed (121) hide show
  1. package/LICENSE +12 -17
  2. package/dist/admin/chunks/Layout-COWXwu3C.js +290 -0
  3. package/dist/admin/chunks/Layout-COWXwu3C.js.map +1 -0
  4. package/dist/admin/chunks/Layout-CsShRydy.mjs +265 -0
  5. package/dist/admin/chunks/Layout-CsShRydy.mjs.map +1 -0
  6. package/dist/admin/chunks/en-BNGiWajd.js +20 -0
  7. package/dist/admin/chunks/en-BNGiWajd.js.map +1 -0
  8. package/dist/admin/chunks/en-BrZXFtVv.mjs +18 -0
  9. package/dist/admin/chunks/en-BrZXFtVv.mjs.map +1 -0
  10. package/dist/admin/chunks/id-D8zbh_Y8.js +1442 -0
  11. package/dist/admin/chunks/id-D8zbh_Y8.js.map +1 -0
  12. package/dist/admin/chunks/id-afdVynVx.mjs +1420 -0
  13. package/dist/admin/chunks/id-afdVynVx.mjs.map +1 -0
  14. package/dist/admin/chunks/index-2VGAYchq.mjs +1081 -0
  15. package/dist/admin/chunks/index-2VGAYchq.mjs.map +1 -0
  16. package/dist/admin/chunks/index-7Tk-SHLf.js +293 -0
  17. package/dist/admin/chunks/index-7Tk-SHLf.js.map +1 -0
  18. package/dist/admin/chunks/index-BXlkcM4s.mjs +271 -0
  19. package/dist/admin/chunks/index-BXlkcM4s.mjs.map +1 -0
  20. package/dist/admin/chunks/index-CEABZUwQ.js +1115 -0
  21. package/dist/admin/chunks/index-CEABZUwQ.js.map +1 -0
  22. package/dist/admin/chunks/purchase-review-workflows-BJkm1_Dd.mjs +180 -0
  23. package/dist/admin/chunks/purchase-review-workflows-BJkm1_Dd.mjs.map +1 -0
  24. package/dist/admin/chunks/purchase-review-workflows-BQL0PbmB.js +182 -0
  25. package/dist/admin/chunks/purchase-review-workflows-BQL0PbmB.js.map +1 -0
  26. package/dist/admin/chunks/router-Cc8VcSCc.js +30 -0
  27. package/dist/admin/chunks/router-Cc8VcSCc.js.map +1 -0
  28. package/dist/admin/chunks/router-JyFAzv9_.mjs +28 -0
  29. package/dist/admin/chunks/router-JyFAzv9_.mjs.map +1 -0
  30. package/dist/admin/chunks/uk-CbRUr1I7.js +16 -0
  31. package/dist/admin/chunks/uk-CbRUr1I7.js.map +1 -0
  32. package/dist/admin/chunks/uk-DLlzEBUF.mjs +14 -0
  33. package/dist/admin/chunks/uk-DLlzEBUF.mjs.map +1 -0
  34. package/dist/admin/index.js +17 -2
  35. package/dist/admin/index.js.map +1 -1
  36. package/dist/admin/index.mjs +12 -4
  37. package/dist/admin/index.mjs.map +1 -1
  38. package/dist/admin/src/routes/content-manager/model/id/components/AssigneeSelect.d.ts +4 -0
  39. package/dist/admin/src/routes/content-manager/model/id/components/Header.d.ts +5 -0
  40. package/dist/admin/src/routes/content-manager/model/id/components/StageSelect.d.ts +3 -0
  41. package/dist/admin/src/services/admin.d.ts +1 -1
  42. package/dist/admin/src/services/api.d.ts +1 -1
  43. package/dist/admin/src/services/content-manager.d.ts +4 -4
  44. package/dist/admin/src/services/settings.d.ts +1739 -9
  45. package/dist/server/index.js +2110 -8013
  46. package/dist/server/index.js.map +1 -1
  47. package/dist/server/index.mjs +2116 -8022
  48. package/dist/server/index.mjs.map +1 -1
  49. package/dist/server/src/bootstrap.d.ts.map +1 -1
  50. package/dist/server/src/constants/workflows.d.ts +1 -0
  51. package/dist/server/src/constants/workflows.d.ts.map +1 -1
  52. package/dist/server/src/content-types/index.d.ts +6 -0
  53. package/dist/server/src/content-types/index.d.ts.map +1 -1
  54. package/dist/server/src/content-types/workflow/index.d.ts +6 -0
  55. package/dist/server/src/content-types/workflow/index.d.ts.map +1 -1
  56. package/dist/server/src/controllers/assignees.d.ts.map +1 -1
  57. package/dist/server/src/controllers/index.d.ts +0 -1
  58. package/dist/server/src/controllers/index.d.ts.map +1 -1
  59. package/dist/server/src/controllers/stages.d.ts.map +1 -1
  60. package/dist/server/src/controllers/workflows.d.ts +0 -7
  61. package/dist/server/src/controllers/workflows.d.ts.map +1 -1
  62. package/dist/server/src/index.d.ts +28 -7
  63. package/dist/server/src/index.d.ts.map +1 -1
  64. package/dist/server/src/register.d.ts.map +1 -1
  65. package/dist/server/src/routes/review-workflows.d.ts.map +1 -1
  66. package/dist/server/src/services/assignees.d.ts +8 -4
  67. package/dist/server/src/services/assignees.d.ts.map +1 -1
  68. package/dist/server/src/services/document-service-middleware.d.ts +2 -1
  69. package/dist/server/src/services/document-service-middleware.d.ts.map +1 -1
  70. package/dist/server/src/services/index.d.ts +16 -6
  71. package/dist/server/src/services/index.d.ts.map +1 -1
  72. package/dist/server/src/services/metrics/index.d.ts +4 -4
  73. package/dist/server/src/services/metrics/index.d.ts.map +1 -1
  74. package/dist/server/src/services/metrics/weekly-metrics.d.ts.map +1 -1
  75. package/dist/server/src/services/stages.d.ts +7 -7
  76. package/dist/server/src/services/stages.d.ts.map +1 -1
  77. package/dist/server/src/services/workflows.d.ts.map +1 -1
  78. package/dist/server/src/validation/review-workflows.d.ts +4 -0
  79. package/dist/server/src/validation/review-workflows.d.ts.map +1 -1
  80. package/dist/shared/contracts/review-workflows.d.ts +9 -18
  81. package/dist/shared/contracts/review-workflows.d.ts.map +1 -1
  82. package/package.json +17 -16
  83. package/dist/_chunks/Layout-BDKzgDbH.mjs +0 -234
  84. package/dist/_chunks/Layout-BDKzgDbH.mjs.map +0 -1
  85. package/dist/_chunks/Layout-y4m6QHjX.js +0 -252
  86. package/dist/_chunks/Layout-y4m6QHjX.js.map +0 -1
  87. package/dist/_chunks/_id-CB3lqKgb.js +0 -1274
  88. package/dist/_chunks/_id-CB3lqKgb.js.map +0 -1
  89. package/dist/_chunks/_id-yOfUu1Rs.mjs +0 -1254
  90. package/dist/_chunks/_id-yOfUu1Rs.mjs.map +0 -1
  91. package/dist/_chunks/en-D9ZrQAV6.mjs +0 -12
  92. package/dist/_chunks/en-D9ZrQAV6.mjs.map +0 -1
  93. package/dist/_chunks/en-xcewH2pC.js +0 -12
  94. package/dist/_chunks/en-xcewH2pC.js.map +0 -1
  95. package/dist/_chunks/index--7HYUi67.mjs +0 -234
  96. package/dist/_chunks/index--7HYUi67.mjs.map +0 -1
  97. package/dist/_chunks/index-Bj7gelY1.js +0 -819
  98. package/dist/_chunks/index-Bj7gelY1.js.map +0 -1
  99. package/dist/_chunks/index-Bx0Y1GZR.mjs +0 -801
  100. package/dist/_chunks/index-Bx0Y1GZR.mjs.map +0 -1
  101. package/dist/_chunks/index-CNKQvAnM.js +0 -253
  102. package/dist/_chunks/index-CNKQvAnM.js.map +0 -1
  103. package/dist/_chunks/purchase-review-workflows-BN-5Ube7.mjs +0 -52
  104. package/dist/_chunks/purchase-review-workflows-BN-5Ube7.mjs.map +0 -1
  105. package/dist/_chunks/purchase-review-workflows-DlCDg0fD.js +0 -52
  106. package/dist/_chunks/purchase-review-workflows-DlCDg0fD.js.map +0 -1
  107. package/dist/_chunks/router-LZ2xbb95.js +0 -24
  108. package/dist/_chunks/router-LZ2xbb95.js.map +0 -1
  109. package/dist/_chunks/router-t6Nj4F0T.mjs +0 -24
  110. package/dist/_chunks/router-t6Nj4F0T.mjs.map +0 -1
  111. package/dist/admin/src/routes/content-manager/[model]/[id]/components/AssigneeSelect.d.ts +0 -2
  112. package/dist/admin/src/routes/content-manager/[model]/[id]/components/StageSelect.d.ts +0 -1
  113. package/strapi-server.js +0 -3
  114. /package/dist/admin/src/routes/content-manager/{[model] → model}/components/AssigneeFilter.d.ts +0 -0
  115. /package/dist/admin/src/routes/content-manager/{[model] → model}/components/StageFilter.d.ts +0 -0
  116. /package/dist/admin/src/routes/content-manager/{[model] → model}/components/TableColumns.d.ts +0 -0
  117. /package/dist/admin/src/routes/content-manager/{[model] → model}/configure/constants.d.ts +0 -0
  118. /package/dist/admin/src/routes/content-manager/{[model] → model}/constants.d.ts +0 -0
  119. /package/dist/admin/src/routes/content-manager/{[model]/[id] → model/id}/components/Panel.d.ts +0 -0
  120. /package/dist/admin/src/routes/content-manager/{[model]/[id] → model/id}/components/constants.d.ts +0 -0
  121. /package/dist/admin/src/routes/settings/{:id.d.ts → id.d.ts} +0 -0
@@ -1,1254 +0,0 @@
1
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { useTracking, useForm, useField, InputRenderer as InputRenderer$1, useNotification, ConfirmDialog, Page, useAPIErrorHandler, useRBAC, Form, BackButton } from "@strapi/admin/strapi-admin";
4
- import { useLicenseLimits } from "@strapi/admin/strapi-admin/ee";
5
- import { Box, Typography, Flex, Accordion, MenuItem, Menu, MultiSelectOption, useComposedRefs, VisuallyHidden, IconButton, Grid, Field, SingleSelect, SingleSelectOption, TextInput, MultiSelect, MultiSelectGroup, Dialog, useCollator, Button } from "@strapi/design-system";
6
- import { PlusCircle, More, Drag, EyeStriked, Duplicate, Check } from "@strapi/icons";
7
- import { generateNKeysBetween } from "fractional-indexing";
8
- import { useIntl } from "react-intl";
9
- import { useDispatch } from "react-redux";
10
- import { useParams, useNavigate } from "react-router-dom";
11
- import * as yup from "yup";
12
- import { r as reviewWorkflowsApi, A as AVAILABLE_COLORS, g as getStageColorByHex, u as useGetContentTypesQuery, a as useTypedSelector, C as CHARGEBEE_WORKFLOW_ENTITLEMENT_NAME, b as CHARGEBEE_STAGES_PER_WORKFLOW_ENTITLEMENT_NAME, L as LimitsModal, i as isBaseQueryError } from "./index-Bx0Y1GZR.mjs";
13
- import { D as DRAG_DROP_TYPES, u as useReviewWorkflows, a as DragLayerRendered, H as Header, R as Root } from "./Layout-BDKzgDbH.mjs";
14
- import { getEmptyImage } from "react-dnd-html5-backend";
15
- import { styled } from "styled-components";
16
- import { useDrop, useDrag } from "react-dnd";
17
- const adminApi = reviewWorkflowsApi.injectEndpoints({
18
- endpoints(builder) {
19
- return {
20
- getAdminRoles: builder.query({
21
- query: () => ({
22
- url: `/admin/roles`,
23
- method: "GET"
24
- }),
25
- transformResponse: (res) => {
26
- return res.data;
27
- }
28
- })
29
- };
30
- }
31
- });
32
- const { useGetAdminRolesQuery } = adminApi;
33
- const useKeyboardDragAndDrop = (active, index, { onCancel, onDropItem, onGrabItem, onMoveItem }) => {
34
- const [isSelected, setIsSelected] = React.useState(false);
35
- const handleMove = (movement) => {
36
- if (!isSelected) {
37
- return;
38
- }
39
- if (typeof index === "number" && onMoveItem) {
40
- if (movement === "UP") {
41
- onMoveItem(index - 1, index);
42
- } else if (movement === "DOWN") {
43
- onMoveItem(index + 1, index);
44
- }
45
- }
46
- };
47
- const handleDragClick = () => {
48
- if (isSelected) {
49
- if (onDropItem) {
50
- onDropItem(index);
51
- }
52
- setIsSelected(false);
53
- } else {
54
- if (onGrabItem) {
55
- onGrabItem(index);
56
- }
57
- setIsSelected(true);
58
- }
59
- };
60
- const handleCancel = () => {
61
- if (isSelected) {
62
- setIsSelected(false);
63
- if (onCancel) {
64
- onCancel(index);
65
- }
66
- }
67
- };
68
- const handleKeyDown = (e) => {
69
- if (!active) {
70
- return;
71
- }
72
- if (e.key === "Tab" && !isSelected) {
73
- return;
74
- }
75
- e.preventDefault();
76
- switch (e.key) {
77
- case " ":
78
- case "Enter":
79
- handleDragClick();
80
- break;
81
- case "Escape":
82
- handleCancel();
83
- break;
84
- case "ArrowDown":
85
- case "ArrowRight":
86
- handleMove("DOWN");
87
- break;
88
- case "ArrowUp":
89
- case "ArrowLeft":
90
- handleMove("UP");
91
- break;
92
- }
93
- };
94
- return handleKeyDown;
95
- };
96
- const DIRECTIONS = {
97
- UPWARD: "upward",
98
- DOWNWARD: "downward"
99
- };
100
- const DROP_SENSITIVITY = {
101
- REGULAR: "regular",
102
- IMMEDIATE: "immediate"
103
- };
104
- const useDragAndDrop = (active, {
105
- type = "STRAPI_DND",
106
- index,
107
- item,
108
- onStart,
109
- onEnd,
110
- onGrabItem,
111
- onDropItem,
112
- onCancel,
113
- onMoveItem,
114
- dropSensitivity = DROP_SENSITIVITY.REGULAR
115
- }) => {
116
- const objectRef = React.useRef(null);
117
- const [{ handlerId, isOver }, dropRef] = useDrop({
118
- accept: type,
119
- collect(monitor) {
120
- return {
121
- handlerId: monitor.getHandlerId(),
122
- isOver: monitor.isOver({ shallow: true })
123
- };
124
- },
125
- drop(item2) {
126
- const draggedIndex = item2.index;
127
- const newIndex = index;
128
- if (isOver && onDropItem) {
129
- onDropItem(draggedIndex, newIndex);
130
- }
131
- },
132
- hover(item2, monitor) {
133
- if (!objectRef.current || !onMoveItem) {
134
- return;
135
- }
136
- const dragIndex = item2.index;
137
- const newIndex = index;
138
- const hoverBoundingRect = objectRef.current?.getBoundingClientRect();
139
- const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
140
- const clientOffset = monitor.getClientOffset();
141
- if (!clientOffset)
142
- return;
143
- const hoverClientY = clientOffset && clientOffset.y - hoverBoundingRect.top;
144
- if (typeof dragIndex === "number" && typeof newIndex === "number") {
145
- if (dragIndex === newIndex) {
146
- return;
147
- }
148
- if (dropSensitivity === DROP_SENSITIVITY.REGULAR) {
149
- if (dragIndex < newIndex && hoverClientY < hoverMiddleY) {
150
- return;
151
- }
152
- if (dragIndex > newIndex && hoverClientY > hoverMiddleY) {
153
- return;
154
- }
155
- }
156
- onMoveItem(newIndex, dragIndex);
157
- item2.index = newIndex;
158
- } else {
159
- if (Array.isArray(dragIndex) && Array.isArray(newIndex)) {
160
- const minLength = Math.min(dragIndex.length, newIndex.length);
161
- let areEqual = true;
162
- let isLessThan = false;
163
- let isGreaterThan = false;
164
- for (let i = 0; i < minLength; i++) {
165
- if (dragIndex[i] < newIndex[i]) {
166
- isLessThan = true;
167
- areEqual = false;
168
- break;
169
- } else if (dragIndex[i] > newIndex[i]) {
170
- isGreaterThan = true;
171
- areEqual = false;
172
- break;
173
- }
174
- }
175
- if (areEqual && dragIndex.length === newIndex.length) {
176
- return;
177
- }
178
- if (dropSensitivity === DROP_SENSITIVITY.REGULAR) {
179
- if (isLessThan && !isGreaterThan && hoverClientY < hoverMiddleY) {
180
- return;
181
- }
182
- if (isGreaterThan && !isLessThan && hoverClientY > hoverMiddleY) {
183
- return;
184
- }
185
- }
186
- }
187
- onMoveItem(newIndex, dragIndex);
188
- item2.index = newIndex;
189
- }
190
- }
191
- });
192
- const getDragDirection = (monitor) => {
193
- if (monitor && monitor.isDragging() && !monitor.didDrop() && monitor.getInitialClientOffset() && monitor.getClientOffset()) {
194
- const deltaY = monitor.getInitialClientOffset().y - monitor.getClientOffset().y;
195
- if (deltaY > 0)
196
- return DIRECTIONS.UPWARD;
197
- if (deltaY < 0)
198
- return DIRECTIONS.DOWNWARD;
199
- return null;
200
- }
201
- return null;
202
- };
203
- const [{ isDragging, direction }, dragRef, dragPreviewRef] = useDrag({
204
- type,
205
- item() {
206
- if (onStart) {
207
- onStart();
208
- }
209
- const { width } = objectRef.current?.getBoundingClientRect() ?? {};
210
- return { index, width, ...item };
211
- },
212
- end() {
213
- if (onEnd) {
214
- onEnd();
215
- }
216
- },
217
- canDrag: active,
218
- /**
219
- * This is useful when the item is in a virtualized list.
220
- * However, if we don't have an ID then we want the libraries
221
- * defaults to take care of this.
222
- */
223
- isDragging: item?.id ? (monitor) => {
224
- return item.id === monitor.getItem().id;
225
- } : void 0,
226
- collect: (monitor) => ({
227
- isDragging: monitor.isDragging(),
228
- initialOffset: monitor.getInitialClientOffset(),
229
- currentOffset: monitor.getClientOffset(),
230
- direction: getDragDirection(monitor)
231
- })
232
- });
233
- const handleKeyDown = useKeyboardDragAndDrop(active, index, {
234
- onGrabItem,
235
- onDropItem,
236
- onCancel,
237
- onMoveItem
238
- });
239
- return [
240
- { handlerId, isDragging, handleKeyDown, isOverDropTarget: isOver, direction },
241
- objectRef,
242
- dropRef,
243
- dragRef,
244
- dragPreviewRef
245
- ];
246
- };
247
- const AddStage = ({ children, ...props }) => {
248
- return /* @__PURE__ */ jsx(
249
- StyledButton,
250
- {
251
- tag: "button",
252
- background: "neutral0",
253
- borderColor: "neutral150",
254
- paddingBottom: 3,
255
- paddingLeft: 4,
256
- paddingRight: 4,
257
- paddingTop: 3,
258
- shadow: "filterShadow",
259
- ...props,
260
- children: /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", children: /* @__PURE__ */ jsxs(Flex, { tag: "span", gap: 2, children: [
261
- /* @__PURE__ */ jsx(PlusCircle, { width: "2.4rem", height: "2.4rem", "aria-hidden": true }),
262
- children
263
- ] }) })
264
- }
265
- );
266
- };
267
- const StyledButton = styled(Box)`
268
- border-radius: 26px;
269
- color: ${({ theme }) => theme.colors.neutral500};
270
-
271
- &:hover {
272
- color: ${({ theme }) => theme.colors.primary600};
273
- }
274
-
275
- &:active {
276
- color: ${({ theme }) => theme.colors.primary600};
277
- }
278
- `;
279
- const Stages = ({ canDelete = true, canUpdate = true, isCreating }) => {
280
- const { formatMessage } = useIntl();
281
- const { trackUsage } = useTracking();
282
- const addFieldRow = useForm("Stages", (state) => state.addFieldRow);
283
- const { value: stages = [] } = useField("stages");
284
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 6, width: "100%", children: [
285
- /* @__PURE__ */ jsxs(Box, { position: "relative", width: "100%", children: [
286
- /* @__PURE__ */ jsx(
287
- Background,
288
- {
289
- background: "neutral200",
290
- height: "100%",
291
- left: "50%",
292
- position: "absolute",
293
- top: "0",
294
- width: 2,
295
- zIndex: 1
296
- }
297
- ),
298
- /* @__PURE__ */ jsx(
299
- Flex,
300
- {
301
- direction: "column",
302
- alignItems: "stretch",
303
- gap: 6,
304
- zIndex: 2,
305
- position: "relative",
306
- tag: "ol",
307
- children: stages.map((stage, index) => {
308
- return /* @__PURE__ */ jsx(Box, { tag: "li", children: /* @__PURE__ */ jsx(
309
- Stage,
310
- {
311
- index,
312
- canDelete: stages.length > 1 && canDelete,
313
- canReorder: stages.length > 1,
314
- canUpdate,
315
- stagesCount: stages.length,
316
- defaultOpen: isCreating,
317
- ...stage
318
- }
319
- ) }, stage.__temp_key__);
320
- })
321
- }
322
- )
323
- ] }),
324
- canUpdate && /* @__PURE__ */ jsx(
325
- AddStage,
326
- {
327
- type: "button",
328
- onClick: () => {
329
- addFieldRow("stages", { name: "" });
330
- trackUsage("willCreateStage");
331
- },
332
- children: formatMessage({
333
- id: "Settings.review-workflows.stage.add",
334
- defaultMessage: "Add new stage"
335
- })
336
- }
337
- )
338
- ] });
339
- };
340
- const Background = styled(Box)`
341
- transform: translateX(-50%);
342
- `;
343
- const Stage = ({
344
- index,
345
- canDelete = false,
346
- canReorder = false,
347
- canUpdate = false,
348
- stagesCount,
349
- name,
350
- permissions,
351
- color,
352
- defaultOpen
353
- }) => {
354
- const [liveText, setLiveText] = React.useState();
355
- const { formatMessage } = useIntl();
356
- const { trackUsage } = useTracking();
357
- const stageErrors = useForm("Stages", (state) => state.errors.stages);
358
- const error = stageErrors?.[index];
359
- const addFieldRow = useForm("Stage", (state) => state.addFieldRow);
360
- const moveFieldRow = useForm("Stage", (state) => state.moveFieldRow);
361
- const removeFieldRow = useForm("Stage", (state) => state.removeFieldRow);
362
- const getItemPos = (index2) => `${index2 + 1} of ${stagesCount}`;
363
- const handleGrabStage = (index2) => {
364
- setLiveText(
365
- formatMessage(
366
- {
367
- id: "dnd.grab-item",
368
- defaultMessage: `{item}, grabbed. Current position in list: {position}. Press up and down arrow to change position, Spacebar to drop, Escape to cancel.`
369
- },
370
- {
371
- item: name,
372
- position: getItemPos(index2)
373
- }
374
- )
375
- );
376
- };
377
- const handleDropStage = (index2) => {
378
- setLiveText(
379
- formatMessage(
380
- {
381
- id: "dnd.drop-item",
382
- defaultMessage: `{item}, dropped. Final position in list: {position}.`
383
- },
384
- {
385
- item: name,
386
- position: getItemPos(index2)
387
- }
388
- )
389
- );
390
- };
391
- const handleCancelDragStage = () => {
392
- setLiveText(
393
- formatMessage(
394
- {
395
- id: "dnd.cancel-item",
396
- defaultMessage: "{item}, dropped. Re-order cancelled."
397
- },
398
- {
399
- item: name
400
- }
401
- )
402
- );
403
- };
404
- const handleMoveStage = (newIndex, oldIndex) => {
405
- setLiveText(
406
- formatMessage(
407
- {
408
- id: "dnd.reorder",
409
- defaultMessage: "{item}, moved. New position in list: {position}."
410
- },
411
- {
412
- item: name,
413
- position: getItemPos(newIndex)
414
- }
415
- )
416
- );
417
- moveFieldRow("stages", oldIndex, newIndex);
418
- };
419
- const [{ handlerId, isDragging, handleKeyDown }, stageRef, dropRef, dragRef, dragPreviewRef] = useDragAndDrop(canReorder, {
420
- index,
421
- item: {
422
- index,
423
- name
424
- },
425
- onGrabItem: handleGrabStage,
426
- onDropItem: handleDropStage,
427
- onMoveItem: handleMoveStage,
428
- onCancel: handleCancelDragStage,
429
- type: DRAG_DROP_TYPES.STAGE
430
- });
431
- const composedRef = useComposedRefs(stageRef, dropRef);
432
- React.useEffect(() => {
433
- dragPreviewRef(getEmptyImage(), { captureDraggingState: false });
434
- }, [dragPreviewRef, index]);
435
- const handleCloneClick = () => {
436
- addFieldRow("stages", { name, color, permissions });
437
- };
438
- const id = React.useId();
439
- return /* @__PURE__ */ jsxs(Box, { ref: composedRef, children: [
440
- liveText && /* @__PURE__ */ jsx(VisuallyHidden, { "aria-live": "assertive", children: liveText }),
441
- isDragging ? /* @__PURE__ */ jsx(
442
- Box,
443
- {
444
- background: "primary100",
445
- borderStyle: "dashed",
446
- borderColor: "primary600",
447
- borderWidth: "1px",
448
- display: "block",
449
- hasRadius: true,
450
- padding: 6
451
- }
452
- ) : /* @__PURE__ */ jsx(
453
- AccordionRoot,
454
- {
455
- onValueChange: (value) => {
456
- if (value) {
457
- trackUsage("willEditStage");
458
- }
459
- },
460
- defaultValue: defaultOpen ? id : void 0,
461
- $error: Object.values(error ?? {}).length > 0,
462
- children: /* @__PURE__ */ jsxs(Accordion.Item, { value: id, children: [
463
- /* @__PURE__ */ jsxs(Accordion.Header, { children: [
464
- /* @__PURE__ */ jsx(Accordion.Trigger, { children: name }),
465
- /* @__PURE__ */ jsx(Accordion.Actions, { children: canDelete || canUpdate ? /* @__PURE__ */ jsxs(Fragment, { children: [
466
- /* @__PURE__ */ jsxs(Menu.Root, { children: [
467
- /* @__PURE__ */ jsxs(ContextMenuTrigger, { size: "S", endIcon: null, paddingLeft: 2, paddingRight: 2, children: [
468
- /* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
469
- /* @__PURE__ */ jsx(VisuallyHidden, { tag: "span", children: formatMessage({
470
- id: "[tbdb].components.DynamicZone.more-actions",
471
- defaultMessage: "More actions"
472
- }) })
473
- ] }),
474
- /* @__PURE__ */ jsx(Menu.Content, { popoverPlacement: "bottom-end", zIndex: 2, children: /* @__PURE__ */ jsxs(Menu.SubRoot, { children: [
475
- canUpdate && /* @__PURE__ */ jsx(MenuItem, { onClick: handleCloneClick, children: formatMessage({
476
- id: "Settings.review-workflows.stage.delete",
477
- defaultMessage: "Duplicate stage"
478
- }) }),
479
- canDelete && /* @__PURE__ */ jsx(DeleteMenuItem, { onClick: () => removeFieldRow("stages", index), children: formatMessage({
480
- id: "Settings.review-workflows.stage.delete",
481
- defaultMessage: "Delete"
482
- }) })
483
- ] }) })
484
- ] }),
485
- canUpdate && /* @__PURE__ */ jsx(
486
- IconButton,
487
- {
488
- background: "transparent",
489
- hasRadius: true,
490
- borderWidth: 0,
491
- "data-handler-id": handlerId,
492
- ref: dragRef,
493
- label: formatMessage({
494
- id: "Settings.review-workflows.stage.drag",
495
- defaultMessage: "Drag"
496
- }),
497
- onClick: (e) => e.stopPropagation(),
498
- onKeyDown: handleKeyDown,
499
- children: /* @__PURE__ */ jsx(Drag, {})
500
- }
501
- )
502
- ] }) : null })
503
- ] }),
504
- /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Grid.Root, { gap: 4, padding: 6, children: [
505
- {
506
- disabled: !canUpdate,
507
- label: formatMessage({
508
- id: "Settings.review-workflows.stage.name.label",
509
- defaultMessage: "Stage name"
510
- }),
511
- name: `stages.${index}.name`,
512
- required: true,
513
- size: 6,
514
- type: "string"
515
- },
516
- {
517
- disabled: !canUpdate,
518
- label: formatMessage({
519
- id: "content-manager.reviewWorkflows.stage.color",
520
- defaultMessage: "Color"
521
- }),
522
- name: `stages.${index}.color`,
523
- required: true,
524
- size: 6,
525
- type: "color"
526
- },
527
- {
528
- disabled: !canUpdate,
529
- label: formatMessage({
530
- id: "Settings.review-workflows.stage.permissions.label",
531
- defaultMessage: "Roles that can change this stage"
532
- }),
533
- name: `stages.${index}.permissions`,
534
- placeholder: formatMessage({
535
- id: "Settings.review-workflows.stage.permissions.placeholder",
536
- defaultMessage: "Select a role"
537
- }),
538
- required: true,
539
- size: 6,
540
- type: "permissions"
541
- }
542
- ].map(({ size, ...field }) => /* @__PURE__ */ jsx(Grid.Item, { col: size, children: /* @__PURE__ */ jsx(InputRenderer, { ...field }) }, field.name)) }) })
543
- ] })
544
- }
545
- )
546
- ] });
547
- };
548
- const AccordionRoot = styled(Accordion.Root)`
549
- border: 1px solid
550
- ${({ theme, $error }) => $error ? theme.colors.danger600 : theme.colors.neutral200};
551
- `;
552
- const DeleteMenuItem = styled(MenuItem)`
553
- color: ${({ theme }) => theme.colors.danger600};
554
- `;
555
- const ContextMenuTrigger = styled(Menu.Trigger)`
556
- :hover,
557
- :focus {
558
- background-color: ${({ theme }) => theme.colors.neutral100};
559
- }
560
-
561
- > span {
562
- font-size: 0;
563
- }
564
- `;
565
- const InputRenderer = (props) => {
566
- switch (props.type) {
567
- case "color":
568
- return /* @__PURE__ */ jsx(ColorSelector, { ...props });
569
- case "permissions":
570
- return /* @__PURE__ */ jsx(PermissionsField, { ...props });
571
- default:
572
- return /* @__PURE__ */ jsx(InputRenderer$1, { ...props });
573
- }
574
- };
575
- const ColorSelector = ({ disabled, label, name, required }) => {
576
- const { formatMessage } = useIntl();
577
- const { value, error, onChange } = useField(name);
578
- const colorOptions = AVAILABLE_COLORS.map(({ hex, name: name2 }) => ({
579
- value: hex,
580
- label: formatMessage(
581
- {
582
- id: "Settings.review-workflows.stage.color.name",
583
- defaultMessage: "{name}"
584
- },
585
- { name: name2 }
586
- ),
587
- color: hex
588
- }));
589
- const { themeColorName } = getStageColorByHex(value) ?? {};
590
- return /* @__PURE__ */ jsxs(Field.Root, { error, name, required, children: [
591
- /* @__PURE__ */ jsx(Field.Label, { children: label }),
592
- /* @__PURE__ */ jsx(
593
- SingleSelect,
594
- {
595
- disabled,
596
- onChange: (v) => {
597
- onChange(name, v.toString());
598
- },
599
- value: value?.toUpperCase(),
600
- startIcon: /* @__PURE__ */ jsx(
601
- Flex,
602
- {
603
- tag: "span",
604
- height: 2,
605
- background: value,
606
- borderColor: themeColorName === "neutral0" ? "neutral150" : "transparent",
607
- hasRadius: true,
608
- shrink: 0,
609
- width: 2
610
- }
611
- ),
612
- children: colorOptions.map(({ value: value2, label: label2, color }) => {
613
- const { themeColorName: themeColorName2 } = getStageColorByHex(color) || {};
614
- return /* @__PURE__ */ jsx(
615
- SingleSelectOption,
616
- {
617
- value: value2,
618
- startIcon: /* @__PURE__ */ jsx(
619
- Flex,
620
- {
621
- tag: "span",
622
- height: 2,
623
- background: color,
624
- borderColor: themeColorName2 === "neutral0" ? "neutral150" : "transparent",
625
- hasRadius: true,
626
- shrink: 0,
627
- width: 2
628
- }
629
- ),
630
- children: label2
631
- },
632
- value2
633
- );
634
- })
635
- }
636
- ),
637
- /* @__PURE__ */ jsx(Field.Error, {})
638
- ] });
639
- };
640
- const PermissionsField = ({ disabled, name, placeholder, required }) => {
641
- const { formatMessage } = useIntl();
642
- const { toggleNotification } = useNotification();
643
- const [isApplyAllConfirmationOpen, setIsApplyAllConfirmationOpen] = React.useState(false);
644
- const { value = [], error, onChange } = useField(name);
645
- const allStages = useForm("PermissionsField", (state) => state.values.stages);
646
- const onFormValueChange = useForm("PermissionsField", (state) => state.onChange);
647
- const { data: roles = [], isLoading } = useGetAdminRolesQuery();
648
- const filteredRoles = roles?.filter((role) => role.code !== "strapi-super-admin") ?? [];
649
- React.useEffect(() => {
650
- if (!isLoading && roles.length === 0) {
651
- toggleNotification({
652
- blockTransition: true,
653
- type: "danger",
654
- message: formatMessage({
655
- id: "review-workflows.stage.permissions.noPermissions.description",
656
- defaultMessage: "You don’t have the permission to see roles"
657
- })
658
- });
659
- }
660
- }, [formatMessage, isLoading, roles, toggleNotification]);
661
- if (!isLoading && filteredRoles.length === 0) {
662
- return /* @__PURE__ */ jsxs(
663
- Field.Root,
664
- {
665
- name,
666
- hint: formatMessage({
667
- id: "Settings.review-workflows.stage.permissions.noPermissions.description",
668
- defaultMessage: "You don’t have the permission to see roles"
669
- }),
670
- required,
671
- children: [
672
- /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
673
- id: "Settings.review-workflows.stage.permissions.label",
674
- defaultMessage: "Roles that can change this stage"
675
- }) }),
676
- /* @__PURE__ */ jsx(
677
- TextInput,
678
- {
679
- disabled: true,
680
- placeholder: formatMessage({
681
- id: "components.NotAllowedInput.text",
682
- defaultMessage: "No permissions to see this field"
683
- }),
684
- startAction: /* @__PURE__ */ jsx(EyeStriked, { fill: "neutral600" }),
685
- type: "text",
686
- value: ""
687
- }
688
- ),
689
- /* @__PURE__ */ jsx(Field.Hint, {})
690
- ]
691
- }
692
- );
693
- }
694
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Flex, { alignItems: "flex-end", gap: 3, children: [
695
- /* @__PURE__ */ jsx(PermissionWrapper, { grow: 1, children: /* @__PURE__ */ jsxs(Field.Root, { error, name, required: true, children: [
696
- /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
697
- id: "Settings.review-workflows.stage.permissions.label",
698
- defaultMessage: "Roles that can change this stage"
699
- }) }),
700
- /* @__PURE__ */ jsx(
701
- MultiSelect,
702
- {
703
- disabled,
704
- onChange: (values) => {
705
- const permissions = values.map((value2) => ({
706
- role: parseInt(value2, 10),
707
- action: "admin::review-workflows.stage.transition"
708
- }));
709
- onChange(name, permissions);
710
- },
711
- placeholder,
712
- value: value.map((permission) => `${permission.role}`),
713
- withTags: true,
714
- children: /* @__PURE__ */ jsx(
715
- MultiSelectGroup,
716
- {
717
- label: formatMessage({
718
- id: "Settings.review-workflows.stage.permissions.allRoles.label",
719
- defaultMessage: "All roles"
720
- }),
721
- values: filteredRoles.map((r) => `${r.id}`),
722
- children: filteredRoles.map((role) => {
723
- return /* @__PURE__ */ jsx(NestedOption$1, { value: `${role.id}`, children: role.name }, role.id);
724
- })
725
- }
726
- )
727
- }
728
- ),
729
- /* @__PURE__ */ jsx(Field.Error, {})
730
- ] }) }),
731
- /* @__PURE__ */ jsxs(Dialog.Root, { open: isApplyAllConfirmationOpen, onOpenChange: setIsApplyAllConfirmationOpen, children: [
732
- /* @__PURE__ */ jsx(Dialog.Trigger, { children: /* @__PURE__ */ jsx(
733
- IconButton,
734
- {
735
- disabled,
736
- label: formatMessage({
737
- id: "Settings.review-workflows.stage.permissions.apply.label",
738
- defaultMessage: "Apply to all stages"
739
- }),
740
- size: "L",
741
- variant: "secondary",
742
- children: /* @__PURE__ */ jsx(Duplicate, {})
743
- }
744
- ) }),
745
- /* @__PURE__ */ jsx(
746
- ConfirmDialog,
747
- {
748
- onConfirm: () => {
749
- onFormValueChange(
750
- "stages",
751
- allStages.map((stage) => ({
752
- ...stage,
753
- permissions: value
754
- }))
755
- );
756
- setIsApplyAllConfirmationOpen(false);
757
- toggleNotification({
758
- type: "success",
759
- message: formatMessage({
760
- id: "Settings.review-workflows.page.edit.confirm.stages.permissions.copy.success",
761
- defaultMessage: "Applied roles to all other stages of the workflow"
762
- })
763
- });
764
- },
765
- variant: "default",
766
- children: formatMessage({
767
- id: "Settings.review-workflows.page.edit.confirm.stages.permissions.copy",
768
- defaultMessage: "Roles that can change that stage will be applied to all the other stages."
769
- })
770
- }
771
- )
772
- ] })
773
- ] }) });
774
- };
775
- const NestedOption$1 = styled(MultiSelectOption)`
776
- padding-left: ${({ theme }) => theme.spaces[7]};
777
- `;
778
- const PermissionWrapper = styled(Flex)`
779
- > * {
780
- flex-grow: 1;
781
- }
782
- `;
783
- const WorkflowAttributes = ({ canUpdate = true }) => {
784
- const { formatMessage } = useIntl();
785
- return /* @__PURE__ */ jsxs(Grid.Root, { background: "neutral0", hasRadius: true, gap: 4, padding: 6, shadow: "tableShadow", children: [
786
- /* @__PURE__ */ jsx(Grid.Item, { col: 6, children: /* @__PURE__ */ jsx(
787
- InputRenderer$1,
788
- {
789
- disabled: !canUpdate,
790
- label: formatMessage({
791
- id: "Settings.review-workflows.workflow.name.label",
792
- defaultMessage: "Workflow Name"
793
- }),
794
- name: "name",
795
- required: true,
796
- type: "string"
797
- }
798
- ) }),
799
- /* @__PURE__ */ jsx(Grid.Item, { col: 6, children: /* @__PURE__ */ jsx(ContentTypesSelector, { disabled: !canUpdate }) })
800
- ] });
801
- };
802
- const ContentTypesSelector = ({ disabled }) => {
803
- const { formatMessage, locale } = useIntl();
804
- const { data: contentTypes, isLoading } = useGetContentTypesQuery();
805
- const { workflows } = useReviewWorkflows();
806
- const currentWorkflow = useForm("ContentTypesSelector", (state) => state.values);
807
- const { error, value, onChange } = useField("contentTypes");
808
- const formatter = useCollator(locale, {
809
- sensitivity: "base"
810
- });
811
- const isDisabled = disabled || isLoading || !contentTypes || contentTypes.collectionType.length === 0 && contentTypes.singleType.length === 0;
812
- const collectionTypes = (contentTypes?.collectionType ?? []).toSorted((a, b) => formatter.compare(a.info.displayName, b.info.displayName)).map((contentType) => ({
813
- label: contentType.info.displayName,
814
- value: contentType.uid
815
- }));
816
- const singleTypes = (contentTypes?.singleType ?? []).map((contentType) => ({
817
- label: contentType.info.displayName,
818
- value: contentType.uid
819
- }));
820
- return /* @__PURE__ */ jsxs(Field.Root, { error, name: "contentTypes", children: [
821
- /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
822
- id: "Settings.review-workflows.workflow.contentTypes.label",
823
- defaultMessage: "Associated to"
824
- }) }),
825
- /* @__PURE__ */ jsx(
826
- MultiSelect,
827
- {
828
- customizeContent: (value2) => formatMessage(
829
- {
830
- id: "Settings.review-workflows.workflow.contentTypes.displayValue",
831
- defaultMessage: "{count} {count, plural, one {content type} other {content types}} selected"
832
- },
833
- { count: value2?.length }
834
- ),
835
- disabled: isDisabled,
836
- onChange: (values) => {
837
- onChange("contentTypes", values);
838
- },
839
- value,
840
- placeholder: formatMessage({
841
- id: "Settings.review-workflows.workflow.contentTypes.placeholder",
842
- defaultMessage: "Select"
843
- }),
844
- children: [
845
- ...collectionTypes.length > 0 ? [
846
- {
847
- label: formatMessage({
848
- id: "Settings.review-workflows.workflow.contentTypes.collectionTypes.label",
849
- defaultMessage: "Collection Types"
850
- }),
851
- children: collectionTypes
852
- }
853
- ] : [],
854
- ...singleTypes.length > 0 ? [
855
- {
856
- label: formatMessage({
857
- id: "Settings.review-workflows.workflow.contentTypes.singleTypes.label",
858
- defaultMessage: "Single Types"
859
- }),
860
- children: singleTypes
861
- }
862
- ] : []
863
- ].map((opt) => {
864
- return /* @__PURE__ */ jsx(
865
- MultiSelectGroup,
866
- {
867
- label: opt.label,
868
- values: opt.children.map((child) => child.value.toString()),
869
- children: opt.children.map((child) => {
870
- const { name: assignedWorkflowName } = workflows?.find(
871
- (workflow) => (currentWorkflow && workflow.id !== currentWorkflow.id || !currentWorkflow) && workflow.contentTypes.includes(child.value)
872
- ) ?? {};
873
- return /* @__PURE__ */ jsx(NestedOption, { value: child.value, children: /* @__PURE__ */ jsx(Typography, {
874
- // @ts-expect-error - formatMessage options doesn't expect to be a React component but that's what we need actually for the <i> and <em> components
875
- children: formatMessage(
876
- {
877
- id: "Settings.review-workflows.workflow.contentTypes.assigned.notice",
878
- defaultMessage: "{label} {name, select, undefined {} other {<i>(assigned to <em>{name}</em> workflow)</i>}}"
879
- },
880
- {
881
- label: child.label,
882
- name: assignedWorkflowName,
883
- em: (...children) => /* @__PURE__ */ jsx(Typography, { tag: "em", fontWeight: "bold", children }),
884
- i: (...children) => /* @__PURE__ */ jsx(ContentTypeTakeNotice, { children })
885
- }
886
- )
887
- }) }, child.value);
888
- })
889
- },
890
- opt.label
891
- );
892
- })
893
- }
894
- )
895
- ] });
896
- };
897
- const NestedOption = styled(MultiSelectOption)`
898
- padding-left: ${({ theme }) => theme.spaces[7]};
899
- `;
900
- const ContentTypeTakeNotice = styled(Typography)`
901
- font-style: italic;
902
- `;
903
- const WORKFLOW_SCHEMA = yup.object({
904
- contentTypes: yup.array().of(yup.string()),
905
- name: yup.string().max(255, {
906
- id: "review-workflows.validation.name.max-length",
907
- defaultMessage: "Name can not be longer than 255 characters"
908
- }).required(),
909
- stages: yup.array().of(
910
- yup.object().shape({
911
- name: yup.string().required({
912
- id: "review-workflows.validation.stage.name",
913
- defaultMessage: "Name is required"
914
- }).max(255, {
915
- id: "review-workflows.validation.stage.max-length",
916
- defaultMessage: "Name can not be longer than 255 characters"
917
- }).test(
918
- "unique-name",
919
- {
920
- id: "review-workflows.validation.stage.duplicate",
921
- defaultMessage: "Stage name must be unique"
922
- },
923
- (stageName, context) => {
924
- const { stages } = context.from[1].value;
925
- return stages.filter((stage) => stage.name === stageName).length === 1;
926
- }
927
- ),
928
- color: yup.string().required({
929
- id: "review-workflows.validation.stage.color",
930
- defaultMessage: "Color is required"
931
- }).matches(/^#(?:[0-9a-fA-F]{3}){1,2}$/i),
932
- permissions: yup.array(
933
- yup.object({
934
- role: yup.number().strict().typeError({
935
- id: "review-workflows.validation.stage.permissions.role.number",
936
- defaultMessage: "Role must be of type number"
937
- }).required(),
938
- action: yup.string().required({
939
- id: "review-workflows.validation.stage.permissions.action.required",
940
- defaultMessage: "Action is a required argument"
941
- })
942
- })
943
- ).strict()
944
- })
945
- ).min(1)
946
- });
947
- const EditPage = () => {
948
- const { id = "" } = useParams();
949
- const isCreatingWorkflow = id === "create";
950
- const { formatMessage } = useIntl();
951
- const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
952
- const navigate = useNavigate();
953
- const { toggleNotification } = useNotification();
954
- const dispatch = useDispatch();
955
- const {
956
- isLoading: isLoadingWorkflow,
957
- meta,
958
- workflows,
959
- error,
960
- update,
961
- create
962
- } = useReviewWorkflows({ id: isCreatingWorkflow ? void 0 : id });
963
- const permissions = useTypedSelector(
964
- (state) => state.admin_app.permissions["settings"]?.["review-workflows"]
965
- );
966
- const {
967
- allowedActions: { canDelete, canUpdate, canCreate }
968
- } = useRBAC(permissions);
969
- const [savePrompts, setSavePrompts] = React.useState({});
970
- const { getFeature, isLoading: isLicenseLoading } = useLicenseLimits();
971
- const [showLimitModal, setShowLimitModal] = React.useState(null);
972
- const currentWorkflow = workflows?.find((workflow) => workflow.id === parseInt(id, 10));
973
- const contentTypesFromOtherWorkflows = workflows?.filter((workflow) => workflow.id !== parseInt(id, 10)).flatMap((workflow) => workflow.contentTypes);
974
- const limits = getFeature("review-workflows");
975
- const numberOfWorkflows = limits?.[CHARGEBEE_WORKFLOW_ENTITLEMENT_NAME];
976
- const stagesPerWorkflow = limits?.[CHARGEBEE_STAGES_PER_WORKFLOW_ENTITLEMENT_NAME];
977
- const submitForm = async (data, helpers) => {
978
- try {
979
- if (!isCreatingWorkflow) {
980
- const res = await update(id, {
981
- ...data,
982
- // compare permissions of stages and only submit them if at least one has
983
- // changed; this enables partial updates e.g. for users who don't have
984
- // permissions to see roles
985
- stages: data.stages.map((stage) => {
986
- let hasUpdatedPermissions = true;
987
- const serverStage = currentWorkflow?.stages?.find(
988
- (serverStage2) => serverStage2.id === stage?.id
989
- );
990
- if (serverStage) {
991
- hasUpdatedPermissions = serverStage.permissions?.length !== stage.permissions?.length || !serverStage.permissions?.every(
992
- (serverPermission) => !!stage.permissions?.find(
993
- (permission) => permission.role === serverPermission.role
994
- )
995
- );
996
- }
997
- return {
998
- ...stage,
999
- permissions: hasUpdatedPermissions ? stage.permissions : void 0
1000
- };
1001
- })
1002
- });
1003
- if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1004
- helpers.setErrors(formatValidationErrors(res.error));
1005
- } else if ("data" in res) {
1006
- for (const uid of res.data.contentTypes) {
1007
- dispatch({
1008
- type: "contentManagerApi/invalidateTags",
1009
- payload: [
1010
- {
1011
- type: "ContentTypesConfiguration",
1012
- id: uid
1013
- }
1014
- ]
1015
- });
1016
- }
1017
- }
1018
- } else {
1019
- const res = await create(data);
1020
- if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1021
- helpers.setErrors(formatValidationErrors(res.error));
1022
- } else if ("data" in res) {
1023
- for (const uid of res.data.contentTypes) {
1024
- dispatch({
1025
- type: "contentManagerApi/invalidateTags",
1026
- payload: [
1027
- {
1028
- type: "ContentTypesConfiguration",
1029
- id: uid
1030
- }
1031
- ]
1032
- });
1033
- }
1034
- navigate(`../${res.data.id}`);
1035
- }
1036
- }
1037
- } catch (error2) {
1038
- toggleNotification({
1039
- type: "danger",
1040
- message: formatMessage({
1041
- id: "notification.error",
1042
- defaultMessage: "An error occurred"
1043
- })
1044
- });
1045
- }
1046
- setSavePrompts({});
1047
- };
1048
- const handleConfirmDeleteDialog = (data, helpers) => async () => {
1049
- await submitForm(data, helpers);
1050
- };
1051
- const handleConfirmClose = () => {
1052
- setSavePrompts({});
1053
- };
1054
- const handleSubmit = async (data, helpers) => {
1055
- const isContentTypeReassignment = data.contentTypes.some(
1056
- (contentType) => contentTypesFromOtherWorkflows?.includes(contentType)
1057
- );
1058
- const hasDeletedServerStages = !isCreatingWorkflow && !currentWorkflow?.stages.every(
1059
- (stage) => data.stages.some((newStage) => newStage.id === stage.id)
1060
- );
1061
- if (meta && numberOfWorkflows && meta?.workflowCount > parseInt(numberOfWorkflows, 10)) {
1062
- setShowLimitModal("workflow");
1063
- } else if (data.stages && stagesPerWorkflow && data.stages.length > parseInt(stagesPerWorkflow, 10)) {
1064
- setShowLimitModal("stage");
1065
- } else if (hasDeletedServerStages || isContentTypeReassignment) {
1066
- if (hasDeletedServerStages) {
1067
- setSavePrompts((prev) => ({ ...prev, hasDeletedServerStages: true }));
1068
- }
1069
- if (isContentTypeReassignment) {
1070
- setSavePrompts((prev) => ({ ...prev, hasReassignedContentTypes: true }));
1071
- }
1072
- } else {
1073
- await submitForm(data, helpers);
1074
- }
1075
- };
1076
- React.useEffect(() => {
1077
- if (!isLoadingWorkflow && !isLicenseLoading) {
1078
- if (meta && numberOfWorkflows && meta?.workflowCount > parseInt(numberOfWorkflows, 10)) {
1079
- setShowLimitModal("workflow");
1080
- } else if (currentWorkflow && currentWorkflow.stages && stagesPerWorkflow && currentWorkflow.stages.length > parseInt(stagesPerWorkflow, 10)) {
1081
- setShowLimitModal("stage");
1082
- }
1083
- }
1084
- }, [
1085
- currentWorkflow,
1086
- isLicenseLoading,
1087
- isLoadingWorkflow,
1088
- limits,
1089
- meta,
1090
- numberOfWorkflows,
1091
- stagesPerWorkflow
1092
- ]);
1093
- const initialValues = React.useMemo(() => {
1094
- if (isCreatingWorkflow || !currentWorkflow) {
1095
- return {
1096
- name: "",
1097
- stages: [],
1098
- contentTypes: []
1099
- };
1100
- } else {
1101
- return {
1102
- name: currentWorkflow.name,
1103
- stages: addTmpKeysToStages(currentWorkflow.stages),
1104
- contentTypes: currentWorkflow.contentTypes
1105
- };
1106
- }
1107
- }, [currentWorkflow, isCreatingWorkflow]);
1108
- if (isLoadingWorkflow) {
1109
- return /* @__PURE__ */ jsx(Page.Loading, {});
1110
- }
1111
- if (error) {
1112
- return /* @__PURE__ */ jsx(Page.Error, {});
1113
- }
1114
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1115
- /* @__PURE__ */ jsx(DragLayerRendered, {}),
1116
- /* @__PURE__ */ jsx(
1117
- Form,
1118
- {
1119
- method: isCreatingWorkflow ? "POST" : "PUT",
1120
- initialValues,
1121
- validationSchema: WORKFLOW_SCHEMA,
1122
- onSubmit: handleSubmit,
1123
- children: ({ modified, isSubmitting, values, setErrors }) => /* @__PURE__ */ jsxs(Fragment, { children: [
1124
- /* @__PURE__ */ jsx(
1125
- Header,
1126
- {
1127
- navigationAction: /* @__PURE__ */ jsx(BackButton, {}),
1128
- primaryAction: canUpdate || canCreate ? /* @__PURE__ */ jsx(
1129
- Button,
1130
- {
1131
- startIcon: /* @__PURE__ */ jsx(Check, {}),
1132
- type: "submit",
1133
- size: "M",
1134
- disabled: !modified || isSubmitting || values.stages.length === 0,
1135
- loading: !Boolean(Object.keys(savePrompts).length > 0) && isSubmitting,
1136
- children: formatMessage({
1137
- id: "global.save",
1138
- defaultMessage: "Save"
1139
- })
1140
- }
1141
- ) : null,
1142
- subtitle: formatMessage(
1143
- {
1144
- id: "review-workflows.page.subtitle",
1145
- defaultMessage: "{count, plural, one {# stage} other {# stages}}"
1146
- },
1147
- { count: currentWorkflow?.stages?.length ?? 0 }
1148
- ),
1149
- title: currentWorkflow?.name || formatMessage({
1150
- id: "Settings.review-workflows.create.page.title",
1151
- defaultMessage: "Create Review Workflow"
1152
- })
1153
- }
1154
- ),
1155
- /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsxs(Flex, { alignItems: "stretch", direction: "column", gap: 7, children: [
1156
- /* @__PURE__ */ jsx(WorkflowAttributes, { canUpdate }),
1157
- /* @__PURE__ */ jsx(
1158
- Stages,
1159
- {
1160
- canDelete,
1161
- canUpdate,
1162
- isCreating: isCreatingWorkflow
1163
- }
1164
- )
1165
- ] }) }),
1166
- /* @__PURE__ */ jsx(
1167
- Dialog.Root,
1168
- {
1169
- open: Object.keys(savePrompts).length > 0,
1170
- onOpenChange: handleConfirmClose,
1171
- children: /* @__PURE__ */ jsx(ConfirmDialog, { onConfirm: handleConfirmDeleteDialog(values, { setErrors }), children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 5, children: [
1172
- savePrompts.hasDeletedServerStages && /* @__PURE__ */ jsx(Typography, { textAlign: "center", variant: "omega", children: formatMessage({
1173
- id: "review-workflows.page.delete.confirm.stages.body",
1174
- defaultMessage: "All entries assigned to deleted stages will be moved to the previous stage."
1175
- }) }),
1176
- savePrompts.hasReassignedContentTypes && /* @__PURE__ */ jsx(Typography, { textAlign: "center", variant: "omega", children: formatMessage(
1177
- {
1178
- id: "review-workflows.page.delete.confirm.contentType.body",
1179
- defaultMessage: "{count} {count, plural, one {content-type} other {content-types}} {count, plural, one {is} other {are}} already mapped to {count, plural, one {another workflow} other {other workflows}}. If you save changes, {count, plural, one {this} other {these}} {count, plural, one {content-type} other {{count} content-types}} will no more be mapped to the {count, plural, one {another workflow} other {other workflows}} and all corresponding information will be removed."
1180
- },
1181
- {
1182
- count: contentTypesFromOtherWorkflows?.filter(
1183
- (contentType) => currentWorkflow?.contentTypes?.includes(contentType)
1184
- ).length ?? 0
1185
- }
1186
- ) }),
1187
- /* @__PURE__ */ jsx(Typography, { textAlign: "center", variant: "omega", children: formatMessage({
1188
- id: "review-workflows.page.delete.confirm.confirm",
1189
- defaultMessage: "Are you sure you want to save?"
1190
- }) })
1191
- ] }) })
1192
- }
1193
- )
1194
- ] })
1195
- }
1196
- ),
1197
- /* @__PURE__ */ jsxs(
1198
- LimitsModal.Root,
1199
- {
1200
- open: showLimitModal === "workflow",
1201
- onOpenChange: () => setShowLimitModal(null),
1202
- children: [
1203
- /* @__PURE__ */ jsx(LimitsModal.Title, { children: formatMessage({
1204
- id: "review-workflows.edit.page.workflows.limit.title",
1205
- defaultMessage: "You’ve reached the limit of workflows in your plan"
1206
- }) }),
1207
- /* @__PURE__ */ jsx(LimitsModal.Body, { children: formatMessage({
1208
- id: "review-workflows.edit.page.workflows.limit.body",
1209
- defaultMessage: "Delete a workflow or contact Sales to enable more workflows."
1210
- }) })
1211
- ]
1212
- }
1213
- ),
1214
- /* @__PURE__ */ jsxs(
1215
- LimitsModal.Root,
1216
- {
1217
- open: showLimitModal === "stage",
1218
- onOpenChange: () => setShowLimitModal(null),
1219
- children: [
1220
- /* @__PURE__ */ jsx(LimitsModal.Title, { children: formatMessage({
1221
- id: "review-workflows.edit.page.stages.limit.title",
1222
- defaultMessage: "You have reached the limit of stages for this workflow in your plan"
1223
- }) }),
1224
- /* @__PURE__ */ jsx(LimitsModal.Body, { children: formatMessage({
1225
- id: "review-workflows.edit.page.stages.limit.body",
1226
- defaultMessage: "Try deleting some stages or contact Sales to enable more stages."
1227
- }) })
1228
- ]
1229
- }
1230
- )
1231
- ] });
1232
- };
1233
- const addTmpKeysToStages = (data) => {
1234
- const keys = generateNKeysBetween(void 0, void 0, data.length);
1235
- return data.map((datum, index) => ({
1236
- ...datum,
1237
- __temp_key__: keys[index]
1238
- }));
1239
- };
1240
- const ProtectedEditPage = () => {
1241
- const permissions = useTypedSelector((state) => {
1242
- const {
1243
- create = [],
1244
- update = [],
1245
- read = []
1246
- } = state.admin_app.permissions.settings?.["review-workflows"] ?? {};
1247
- return [...create, ...update, ...read];
1248
- });
1249
- return /* @__PURE__ */ jsx(Page.Protect, { permissions, children: /* @__PURE__ */ jsx(EditPage, {}) });
1250
- };
1251
- export {
1252
- ProtectedEditPage
1253
- };
1254
- //# sourceMappingURL=_id-yOfUu1Rs.mjs.map