@commercetools-frontend-extensions/unpublish-products-modal 0.0.0-canary-20250528102549 → 0.0.0-canary-20251209161906

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.
@@ -2,50 +2,1265 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_commercetoolsFrontendExtensionsUnpublishProductsModal = require('./index-405961f5.cjs.prod.js');
6
- require('@babel/runtime-corejs3/core-js-stable/object/keys');
7
- require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
8
- require('@babel/runtime-corejs3/core-js-stable/instance/filter');
9
- require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
10
- require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
11
- require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
12
- require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
13
- require('@babel/runtime-corejs3/core-js-stable/object/define-property');
14
- require('@babel/runtime-corejs3/helpers/defineProperty');
15
- require('react-intl');
16
- require('@commercetools-frontend/application-shell-connectors');
17
- require('@babel/runtime-corejs3/helpers/slicedToArray');
18
- require('react');
19
- require('@commercetools-frontend/sdk');
20
- require('@babel/runtime-corejs3/core-js-stable/json/stringify');
21
- require('@commercetools-frontend/constants');
22
- require('@babel/runtime-corejs3/core-js-stable/instance/every');
23
- require('@babel/runtime-corejs3/core-js-stable/promise');
24
- require('@babel/runtime-corejs3/core-js-stable/array/is-array');
25
- require('@babel/runtime-corejs3/core-js-stable/instance/find');
26
- require('@babel/runtime-corejs3/core-js-stable/instance/map');
27
- require('papaparse');
28
- require('@emotion/react/jsx-runtime');
29
- require('@commercetools-frontend/application-components');
30
- require('@commercetools-frontend/fullstory');
31
- require('@commercetools-frontend/ui-kit');
32
- require('@babel/runtime-corejs3/core-js-stable/instance/some');
33
- require('react-dropzone');
34
- require('@commercetools-frontend/actions-global');
35
- require('@emotion/styled/base');
5
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
6
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
7
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
8
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
9
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
10
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
11
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
12
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
13
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
14
+ var reactIntl = require('react-intl');
15
+ var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
16
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
17
+ var React = require('react');
18
+ var operations = require('@commercetools-frontend-extensions/operations');
19
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
20
+ var applicationComponents = require('@commercetools-frontend/application-components');
21
+ var fullstory = require('@commercetools-frontend/fullstory');
22
+ var uiKit = require('@commercetools-frontend/ui-kit');
23
+ var actionsGlobal = require('@commercetools-frontend/actions-global');
24
+ var constants = require('@commercetools-frontend/constants');
25
+ var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
26
+ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
27
+ var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
28
+ var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
29
+ var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
30
+ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
31
+ var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
32
+ var applicationShell = require('@commercetools-frontend/application-shell');
33
+ var sentry = require('@commercetools-frontend/sentry');
34
+ var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
36
35
  require('@emotion/react');
37
- require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
38
- require('@babel/runtime-corejs3/helpers/createClass');
39
- require('@babel/runtime-corejs3/helpers/classCallCheck');
40
- require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
41
- require('@babel/runtime-corejs3/helpers/getPrototypeOf');
42
- require('@babel/runtime-corejs3/helpers/inherits');
43
- require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
44
- require('@commercetools-frontend/sentry');
45
- require('@commercetools-frontend/application-shell');
46
- require('@babel/runtime-corejs3/core-js-stable/instance/slice');
47
- require('@commercetools-frontend/i18n');
36
+ var i18n = require('@commercetools-frontend/i18n');
48
37
 
38
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
49
39
 
40
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
41
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
42
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
43
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
44
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
45
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
46
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
47
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
48
+ var React__default = /*#__PURE__*/_interopDefault(React);
49
+ var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
50
+ var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
50
51
 
51
- exports["default"] = dist_commercetoolsFrontendExtensionsUnpublishProductsModal.UnpublishProductsModal;
52
+ function ownKeys$7(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
53
+ function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$7(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$7(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
54
+ function reducer(state, action) {
55
+ if (action.type === 'setCurrentStep') return _objectSpread$7(_objectSpread$7({}, state), {}, {
56
+ currentStep: action.currentStep,
57
+ progress: 0
58
+ });
59
+ if (action.type === 'setContainerKey') return _objectSpread$7(_objectSpread$7({}, state), {}, {
60
+ containerKey: action.containerKey
61
+ });
62
+ if (action.type === 'cancelImport') return _objectSpread$7(_objectSpread$7({}, state), {}, {
63
+ currentStep: 'upload',
64
+ containerKey: undefined,
65
+ droppedFile: undefined,
66
+ dropAreaState: 'ready-for-drop',
67
+ progress: 0,
68
+ jobId: undefined,
69
+ totalResourceCount: undefined,
70
+ validationProcessed: undefined,
71
+ isValidating: false
72
+ });
73
+ if (action.type === 'uploadNewFile') return _objectSpread$7(_objectSpread$7({}, state), {}, {
74
+ currentStep: 'upload',
75
+ containerKey: undefined,
76
+ droppedFile: undefined,
77
+ dropAreaState: 'ready-for-drop',
78
+ progress: 0,
79
+ jobId: undefined,
80
+ totalResourceCount: undefined,
81
+ validationProcessed: undefined,
82
+ isValidating: false
83
+ });
84
+ if (action.type === 'setDroppedFile') {
85
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
86
+ droppedFile: action.droppedFile
87
+ });
88
+ }
89
+ if (action.type === 'setAbortController') {
90
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
91
+ abortController: action.abortController
92
+ });
93
+ }
94
+ if (action.type === 'setProgress') {
95
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
96
+ progress: action.progress
97
+ });
98
+ }
99
+ if (action.type === 'setUploadFileResponse') {
100
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
101
+ uploadFileResponse: action.uploadFileResponse
102
+ });
103
+ }
104
+ if (action.type === 'setFileUploadErrors') {
105
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
106
+ fileUploadErrors: action.fileUploadErrors
107
+ });
108
+ }
109
+ if (action.type === 'setJobId') {
110
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
111
+ jobId: action.jobId
112
+ });
113
+ }
114
+ if (action.type === 'setTotalResourceCount') {
115
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
116
+ totalResourceCount: action.totalResourceCount
117
+ });
118
+ }
119
+ if (action.type === 'setValidationProgress') {
120
+ return _objectSpread$7(_objectSpread$7({}, state), {}, {
121
+ validationProcessed: action.processed,
122
+ isValidating: action.isValidating
123
+ });
124
+ }
125
+ throw new Error(getUnknownActionError(action));
126
+ }
127
+ function getUnknownActionError(actionType) {
128
+ return `Unkown type: ${actionType}`;
129
+ }
130
+ const initialState = {
131
+ currentStep: 'upload',
132
+ abortController: new AbortController(),
133
+ dropAreaState: 'ready-for-drop',
134
+ containerKey: undefined,
135
+ progress: 0,
136
+ uploadFileResponse: undefined,
137
+ fileUploadErrors: []
138
+ };
139
+ const initialActions = {
140
+ setCurrentStep(_currentStep) {
141
+ /**/
142
+ },
143
+ cancelImport() {
144
+ /**/
145
+ },
146
+ uploadNewFile() {
147
+ /**/
148
+ },
149
+ setDroppedFile(_nextDroppedFile) {
150
+ /**/
151
+ },
152
+ setUploadFileResponse(_uploadFileResponse) {
153
+ /**/
154
+ },
155
+ setFileUploadErrors(_fileUploadErrors) {
156
+ /**/
157
+ },
158
+ setContainerKey(_containerKey) {
159
+ /**/
160
+ },
161
+ setAbortController(_abortController) {
162
+ /**/
163
+ },
164
+ setProgress(_progress) {
165
+ /**/
166
+ },
167
+ setJobId(_jobId) {
168
+ /**/
169
+ },
170
+ setTotalResourceCount(_totalResourceCount) {
171
+ /**/
172
+ },
173
+ setValidationProgress(_params) {
174
+ /**/
175
+ }
176
+ };
177
+
178
+ const UnpublishProductsContext = /*#__PURE__*/React__default["default"].createContext({
179
+ state: initialState,
180
+ actions: initialActions,
181
+ onClose: () => {}
182
+ });
183
+ const UnpublishProductsProvider = props => {
184
+ const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
185
+ projectKey: context.project?.key
186
+ })),
187
+ projectKey = _useApplicationContex.projectKey;
188
+ const _React$useReducer = React__default["default"].useReducer(reducer, initialState),
189
+ _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
190
+ state = _React$useReducer2[0],
191
+ dispatch = _React$useReducer2[1];
192
+ const setCurrentStep = currentStep => dispatch({
193
+ type: 'setCurrentStep',
194
+ currentStep
195
+ });
196
+ const setContainerKey = containerKey => dispatch({
197
+ type: 'setContainerKey',
198
+ containerKey
199
+ });
200
+ const cancelImport = () => dispatch({
201
+ type: 'cancelImport'
202
+ });
203
+ const uploadNewFile = () => dispatch({
204
+ type: 'uploadNewFile'
205
+ });
206
+ const setDroppedFile = droppedFile => dispatch({
207
+ type: 'setDroppedFile',
208
+ droppedFile: droppedFile
209
+ });
210
+ const setFileUploadErrors = fileUploadErrors => {
211
+ dispatch({
212
+ type: 'setFileUploadErrors',
213
+ fileUploadErrors
214
+ });
215
+ };
216
+ const setAbortController = abortController => dispatch({
217
+ type: 'setAbortController',
218
+ abortController: abortController
219
+ });
220
+ const setProgress = progress => dispatch({
221
+ type: 'setProgress',
222
+ progress
223
+ });
224
+ const setUploadFileResponse = uploadFileResponse => {
225
+ dispatch({
226
+ type: 'setUploadFileResponse',
227
+ uploadFileResponse
228
+ });
229
+ };
230
+ const setJobId = jobId => dispatch({
231
+ type: 'setJobId',
232
+ jobId
233
+ });
234
+ const setTotalResourceCount = totalResourceCount => dispatch({
235
+ type: 'setTotalResourceCount',
236
+ totalResourceCount
237
+ });
238
+ const setValidationProgress = _ref => {
239
+ let processed = _ref.processed,
240
+ isValidating = _ref.isValidating;
241
+ return dispatch({
242
+ type: 'setValidationProgress',
243
+ processed,
244
+ isValidating
245
+ });
246
+ };
247
+ const actions = {
248
+ setCurrentStep,
249
+ cancelImport,
250
+ uploadNewFile,
251
+ setDroppedFile,
252
+ setUploadFileResponse,
253
+ setFileUploadErrors,
254
+ setContainerKey,
255
+ setAbortController,
256
+ setProgress,
257
+ setJobId,
258
+ setTotalResourceCount,
259
+ setValidationProgress
260
+ };
261
+ const handleClose = function () {
262
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
263
+ if (state.abortController) state.abortController.abort();
264
+ if (typeof props.onClose === 'function') props.onClose();
265
+ // Removes the associated import container when the import is closed
266
+ if (options.shouldDeleteImportContainer && projectKey && state.containerKey) operations.deleteImportContainer({
267
+ projectKey,
268
+ importContainerKey: state.containerKey
269
+ });
270
+ };
271
+ return jsxRuntime.jsx(UnpublishProductsContext.Provider, {
272
+ value: {
273
+ state,
274
+ onClose: handleClose,
275
+ actions
276
+ },
277
+ children: props.children
278
+ });
279
+ };
280
+
281
+ function getDropArea(_ref) {
282
+ let dropAreaState = _ref.dropAreaState,
283
+ isFileDropped = _ref.isFileDropped,
284
+ fileName = _ref.fileName,
285
+ messages = _ref.messages;
286
+ if (dropAreaState === 'ready-for-drop') {
287
+ return jsxRuntime.jsx(operations.EnabledDropArea, {
288
+ dragAndDropText: messages.dragAndDropCSV,
289
+ orText: messages.or,
290
+ browseFileText: messages.browseButton
291
+ });
292
+ }
293
+ if (dropAreaState === 'file-dropped') {
294
+ return jsxRuntime.jsx(operations.FileDroppedArea, {
295
+ fileName: fileName,
296
+ chooseFileLabel: messages.chooseFile
297
+ });
298
+ }
299
+ if (dropAreaState === 'active-drag') {
300
+ return jsxRuntime.jsx(operations.ActiveDragDropArea, {
301
+ isFileDropped: isFileDropped,
302
+ fileName: fileName,
303
+ chooseFileLabel: messages.chooseFile,
304
+ dragAndDropText: messages.dragAndDropCSV,
305
+ orText: messages.or,
306
+ browseFileText: messages.browseButton
307
+ });
308
+ }
309
+ return fallbackDropArea(dropAreaState, fileName, messages);
310
+ }
311
+ function fallbackDropArea(_dropAreaState, fileName, messages) {
312
+ return jsxRuntime.jsx(operations.FileDroppedArea, {
313
+ fileName: fileName,
314
+ chooseFileLabel: messages.chooseFile
315
+ });
316
+ }
317
+ function getDropAreaState(flags) {
318
+ if (flags.isDragActive) {
319
+ return 'active-drag';
320
+ }
321
+ if (flags.isReady) {
322
+ return 'file-dropped';
323
+ }
324
+ return 'ready-for-drop';
325
+ }
326
+
327
+ var messages$5 = reactIntl.defineMessages({
328
+ dragAndDropCSV: {
329
+ id: 'UnpublishProductsModal.dragAndDropCSV',
330
+ description: 'The message telling the user to drag and drop CSV file in the file drop area',
331
+ defaultMessage: 'Drag and drop CSV'
332
+ },
333
+ or: {
334
+ id: 'UnpublishProductsModal.or',
335
+ description: 'The word "or" in the drag and drop message',
336
+ defaultMessage: 'or'
337
+ },
338
+ browseButton: {
339
+ id: 'UnpublishProductsModal.browseFile',
340
+ defaultMessage: 'Browse file'
341
+ },
342
+ uploadAndPreview: {
343
+ id: 'UnpublishProductsModal.uploadAndPreview',
344
+ description: 'Label for the button that uploads the file and shows the preview',
345
+ defaultMessage: 'Upload and preview'
346
+ },
347
+ chooseFile: {
348
+ id: 'UnpublishProductsModal.chooseFile',
349
+ description: 'Label for a button on the file upload page, shown on ready to upload state',
350
+ defaultMessage: 'Choose file'
351
+ },
352
+ fileUploadFailed: {
353
+ id: 'UnpublishProductsModal.fileUploadFailed',
354
+ description: 'A title on the file upload page, shown on file upload error state',
355
+ defaultMessage: 'File upload failed'
356
+ },
357
+ fileFormatNotSupported: {
358
+ id: 'UnpublishProductsModal.fileFormatNotSupported',
359
+ description: 'Error message displayed when a user drags and drops a non-CSV file',
360
+ defaultMessage: 'Invalid file format: The file is not in CSV format and cannot be processed.'
361
+ },
362
+ tooManyFilesError: {
363
+ id: 'UnpublishProductsModal.tooManyFilesError',
364
+ description: 'Error message displayed when a user drags and drops multiple files at once',
365
+ defaultMessage: 'Multiple files detected: You can only drag and drop one file at a time.'
366
+ },
367
+ genericError: {
368
+ id: 'UnpublishProductsModal.genericError',
369
+ description: 'Default error message for unexpected file upload issues (for unhandled cases)',
370
+ defaultMessage: 'Error occurred: Please try uploading the file again or contact our support team for assistance.'
371
+ },
372
+ dataType: {
373
+ id: 'UnpublishProductsModal.dataType',
374
+ description: 'Label for the data type selection dropdown',
375
+ defaultMessage: 'Data type'
376
+ },
377
+ instructions: {
378
+ id: 'UnpublishProductsModal.instructions',
379
+ description: 'Label for the instructions section',
380
+ defaultMessage: 'Instructions'
381
+ }
382
+ });
383
+
384
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
385
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
386
+ let MissingUnpublishProductsProviderError = /*#__PURE__*/function (_Error) {
387
+ function MissingUnpublishProductsProviderError() {
388
+ var _this;
389
+ _classCallCheck(this, MissingUnpublishProductsProviderError);
390
+ _this = _callSuper(this, MissingUnpublishProductsProviderError, ['useUnpublishProductsProviderError must be used within MissingUnpublishProductsProviderError']);
391
+ _this.name = 'MissingUnpublishProductsProviderError';
392
+ return _this;
393
+ }
394
+ _inherits(MissingUnpublishProductsProviderError, _Error);
395
+ return _createClass(MissingUnpublishProductsProviderError);
396
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
397
+
398
+ const useUnpublishProductsContext = () => {
399
+ const context = React.useContext(UnpublishProductsContext);
400
+ if (!context) {
401
+ throw new MissingUnpublishProductsProviderError();
402
+ }
403
+ return context;
404
+ };
405
+
406
+ var messages$4 = reactIntl.defineMessages({
407
+ fileSizeExceededTitle: {
408
+ id: 'UnpublishProductsModal.sizeExceededTitle',
409
+ defaultMessage: 'File size exceeded'
410
+ },
411
+ fileSizeExceededDescription: {
412
+ id: 'UnpublishProductsModal.sizeExceededDescription',
413
+ description: 'Error description when the file size exceeds the allowable limit',
414
+ defaultMessage: 'The file exceeds the maximum allowed size of {fileSizeLimit} MB'
415
+ },
416
+ rowLimitExceededTitle: {
417
+ id: 'UnpublishProductsModal.rowLimitExceededTitle',
418
+ defaultMessage: 'Row limit exceeded'
419
+ },
420
+ rowLimitExceededDescription: {
421
+ id: 'UnpublishProductsModal.rowLimitExceededDescription',
422
+ description: 'Error description when the file contains more rows than the allowable maximum',
423
+ defaultMessage: 'The file contains more than the allowable maximum of {rowLimit} rows'
424
+ },
425
+ dropAreaNotEnoughRowsTitle: {
426
+ id: 'UnpublishProductsModal.dropAreaNotEnoughRowsTitle',
427
+ description: 'Error title shown when the uploaded CSV file does not contain a header and at least one row of data',
428
+ defaultMessage: 'Invalid CSV file'
429
+ },
430
+ dropAreaNotEnoughRowsDescription: {
431
+ id: 'UnpublishProductsModal.dropAreaNotEnoughRowsDescription',
432
+ description: 'Error description shown when the uploaded CSV file does not contain a header and at least one row of data',
433
+ defaultMessage: 'Make sure the file contains a header and at least one row of data'
434
+ },
435
+ unexpectedError: {
436
+ id: 'UnpublishProductsModal.unexpectedError',
437
+ description: 'Generic notification message when file upload fails',
438
+ defaultMessage: 'An unexpected error occurred during the file upload. Please try again, or contact support if this error occurs again.'
439
+ },
440
+ missingRequiredField: {
441
+ id: 'UnpublishProductsModal.missingRequiredField',
442
+ description: 'Error message displayed when a required field is missing',
443
+ defaultMessage: 'Missing required field'
444
+ },
445
+ missingKeyError: {
446
+ id: 'UnpublishProductsModal.missingKeyError',
447
+ description: 'Error message displayed when the uploaded file is missing the key field',
448
+ defaultMessage: "The 'key' field is missing or incomplete in some rows. Please ensure every row has a 'key' value."
449
+ },
450
+ csvFormatErrorTitle: {
451
+ id: 'UnpublishProductsModal.csvFormatErrorTitle',
452
+ description: 'Error title shown when the uploaded CSV file is not formatted correctly',
453
+ defaultMessage: 'Invalid CSV file'
454
+ },
455
+ csvFormatErrorDescription: {
456
+ id: 'UnpublishProductsModal.csvFormatErrorDescription',
457
+ description: 'Error message displayed when the CSV file is not formatted correctly',
458
+ defaultMessage: "Your CSV file is not formatted correctly. Make sure the file contains only one column named 'key', which includes the product keys"
459
+ }
460
+ });
461
+
462
+ function ownKeys$6(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
463
+ function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$6(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$6(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
464
+ const FILE_IMPORT_JOB_FLOW = 'fileImportJobFlow';
465
+ const DEFAULT_SHORT_LIVED_FLAGS = {
466
+ [FILE_IMPORT_JOB_FLOW]: false
467
+ };
468
+ const DEFAULT_LONG_LIVED_FLAGS = {};
469
+ _objectSpread$6(_objectSpread$6({}, DEFAULT_SHORT_LIVED_FLAGS), DEFAULT_LONG_LIVED_FLAGS);
470
+
471
+ const DOCUMENTATION_LINK = 'https://docs.commercetools.com/merchant-center/product-list#bulk-unpublish-via-csv-import';
472
+ const TEMPLATE_DOWNLOAD_LINK = 'https://docs.commercetools.com/merchant-center/downloads/product_unpublish_import_template.csv';
473
+
474
+ const useUpload = () => {
475
+ const intl = reactIntl.useIntl();
476
+ const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
477
+ projectKey: context.project?.key
478
+ })),
479
+ projectKey = _useApplicationContex.projectKey;
480
+ const _useUnpublishProducts = useUnpublishProductsContext(),
481
+ state = _useUnpublishProducts.state,
482
+ actions = _useUnpublishProducts.actions;
483
+ const showNotification = actionsGlobal.useShowNotification();
484
+ const isFileImportJobFlowEnabled = applicationShell.useFeatureToggle(FILE_IMPORT_JOB_FLOW);
485
+ const _useFileUpload = operations.useFileUpload({
486
+ projectKey: projectKey,
487
+ useJobBasedFlow: isFileImportJobFlowEnabled
488
+ }),
489
+ upload = _useFileUpload.upload;
490
+ const isFileValid = async file => {
491
+ const errors = [];
492
+ const maxFileSizeMB = isFileImportJobFlowEnabled ? operations.IMPORT_MAX_FILE_SIZE_MB : operations.IMPORT_LEGACY_MAX_FILE_SIZE_MB;
493
+ const maxItemCount = isFileImportJobFlowEnabled ? operations.IMPORT_MAX_ITEM_COUNT : operations.IMPORT_LEGACY_MAX_ROW_COUNT;
494
+ const rowCount = await operations.getRowCount(file);
495
+ if (rowCount < 1) errors.push({
496
+ title: intl.formatMessage(messages$4.dropAreaNotEnoughRowsTitle),
497
+ description: intl.formatMessage(messages$4.dropAreaNotEnoughRowsDescription)
498
+ });
499
+ if (file.size > operations.toBytes(maxFileSizeMB)) errors.push({
500
+ title: intl.formatMessage(messages$4.fileSizeExceededTitle),
501
+ description: intl.formatMessage(messages$4.fileSizeExceededDescription, {
502
+ fileSizeLimit: intl.formatNumber(maxFileSizeMB)
503
+ })
504
+ });
505
+ if (!(await operations.hasSingleKeyColumn(file))) {
506
+ errors.push({
507
+ title: intl.formatMessage(messages$4.csvFormatErrorTitle),
508
+ description: intl.formatMessage(messages$4.csvFormatErrorDescription)
509
+ });
510
+ }
511
+ if (rowCount > maxItemCount) errors.push({
512
+ title: intl.formatMessage(messages$4.rowLimitExceededTitle),
513
+ description: intl.formatMessage(messages$4.rowLimitExceededDescription, {
514
+ rowLimit: intl.formatNumber(maxItemCount)
515
+ })
516
+ });
517
+ if (errors.length > 0) {
518
+ actions.setFileUploadErrors(errors);
519
+ actions.setCurrentStep('upload-error');
520
+ return false;
521
+ }
522
+ if (isFileImportJobFlowEnabled) {
523
+ const resourceCount = await operations.countUniqueResourcesInCsv(file);
524
+ actions.setTotalResourceCount(resourceCount);
525
+ }
526
+ return true;
527
+ };
528
+ const handleUploadError = error => {
529
+ if (operations.isAbortError(error)) {
530
+ actions.cancelImport();
531
+ return;
532
+ }
533
+ if (error instanceof operations.HttpError) {
534
+ actions.setValidationProgress({
535
+ processed: 0,
536
+ isValidating: false
537
+ });
538
+ if (error.errorData?.code === 'MISSING_KEY_ERROR') {
539
+ actions.setFileUploadErrors([{
540
+ title: intl.formatMessage(messages$4.missingRequiredField),
541
+ description: intl.formatMessage(messages$4.missingKeyError)
542
+ }]);
543
+ actions.setCurrentStep('upload-error');
544
+ } else if (error.errorData?.invalid > 0) {
545
+ actions.setUploadFileResponse(error.errorData);
546
+ actions.setCurrentStep('upload-error');
547
+ } else {
548
+ actions.cancelImport();
549
+ showNotification({
550
+ kind: 'error',
551
+ domain: constants.DOMAINS.PAGE,
552
+ text: intl.formatMessage(messages$4.unexpectedError)
553
+ });
554
+ }
555
+ } else {
556
+ actions.cancelImport();
557
+ showNotification({
558
+ kind: 'error',
559
+ domain: constants.DOMAINS.PAGE,
560
+ text: String(error)
561
+ });
562
+ sentry.reportErrorToSentry(new Error('Upload File Error: An unexpected issue occurred while uploading the file'), {
563
+ extra: {
564
+ error,
565
+ fileSizeInBytes: state.droppedFile?.size
566
+ }
567
+ });
568
+ }
569
+ };
570
+ const handleUploadAndValidation = async () => {
571
+ if (!state.droppedFile) return;
572
+ const canUpload = await isFileValid(state.droppedFile);
573
+ if (!canUpload) return;
574
+ const abortController = new AbortController();
575
+ actions.setAbortController(abortController);
576
+ actions.setCurrentStep('uploading');
577
+ await upload({
578
+ file: state.droppedFile,
579
+ resourceType: 'product',
580
+ settings: {
581
+ format: 'CSV',
582
+ options: {
583
+ unpublishAllChanges: true
584
+ }
585
+ },
586
+ abortSignal: abortController.signal,
587
+ onSuccess: result => {
588
+ actions.setValidationProgress({
589
+ processed: 0,
590
+ isValidating: false
591
+ });
592
+ actions.setContainerKey(result.containerKey);
593
+ if (result.jobId) {
594
+ actions.setJobId(result.jobId);
595
+ }
596
+ const fileUploadResponse = {
597
+ results: result.summary.results,
598
+ invalid: result.summary.invalid,
599
+ valid: result.summary.valid,
600
+ fileName: state.droppedFile?.name || '',
601
+ itemsCount: result.summary.total,
602
+ rowsCount: result.summary.total,
603
+ columnsCount: result.summary.fieldsCount,
604
+ fields: result.summary.fields,
605
+ ignoredFields: result.summary.ignoredFields
606
+ };
607
+ actions.setUploadFileResponse(fileUploadResponse);
608
+ actions.setCurrentStep('upload-preview');
609
+ },
610
+ onProgress: progress => {
611
+ actions.setProgress(progress);
612
+ },
613
+ onValidationProgress: job => {
614
+ const processed = job.summary?.total ?? 0;
615
+ actions.setValidationProgress({
616
+ processed,
617
+ isValidating: true
618
+ });
619
+ },
620
+ onError: handleUploadError
621
+ });
622
+ };
623
+ return {
624
+ handleUploadAndValidation
625
+ };
626
+ };
627
+
628
+ const FileDropArea = () => {
629
+ const intl = reactIntl.useIntl();
630
+ const _useUnpublishProducts = useUnpublishProductsContext(),
631
+ state = _useUnpublishProducts.state,
632
+ actions = _useUnpublishProducts.actions;
633
+ const showNotification = actionsGlobal.useShowNotification();
634
+ const onDrop = React__default["default"].useCallback(_ref => {
635
+ let _ref2 = _slicedToArray(_ref, 1),
636
+ file = _ref2[0];
637
+ if (!file) return;
638
+ actions.setDroppedFile(file);
639
+ }, [actions]);
640
+ const handleDropRejected = React__default["default"].useCallback(errorType => {
641
+ const errorMessageMap = {
642
+ 'too-many-files': messages$5.tooManyFilesError,
643
+ 'invalid-type': messages$5.fileFormatNotSupported,
644
+ generic: messages$5.genericError
645
+ };
646
+ showNotification({
647
+ kind: 'error',
648
+ domain: constants.DOMAINS.PAGE,
649
+ text: intl.formatMessage(errorMessageMap[errorType])
650
+ });
651
+ }, [intl, showNotification]);
652
+ const getState = React__default["default"].useCallback(isDragActive => getDropAreaState({
653
+ isReady: Boolean(state.droppedFile),
654
+ isDragActive
655
+ }), [state.droppedFile]);
656
+ return jsxRuntime.jsx(operations.FileDropArea, {
657
+ onDrop: onDrop,
658
+ onDropRejected: handleDropRejected,
659
+ accept: {
660
+ 'text/csv': ['.csv']
661
+ },
662
+ getDropAreaState: getState,
663
+ children: dropAreaState => getDropArea({
664
+ dropAreaState,
665
+ isFileDropped: Boolean(state.droppedFile),
666
+ fileName: state.droppedFile?.name,
667
+ messages: {
668
+ dragAndDropCSV: intl.formatMessage(messages$5.dragAndDropCSV),
669
+ or: intl.formatMessage(messages$5.or),
670
+ browseButton: intl.formatMessage(messages$5.browseButton),
671
+ chooseFile: intl.formatMessage(messages$5.chooseFile)
672
+ }
673
+ })
674
+ });
675
+ };
676
+
677
+ var sharedMessages = reactIntl.defineMessages({
678
+ unpublishModalTitle: {
679
+ id: 'UnpublishProductsModal.unpublishModalTitle',
680
+ description: 'The title of the modal',
681
+ defaultMessage: 'Bulk unpublish via CSV'
682
+ },
683
+ startBulkUnpublish: {
684
+ id: 'UnpublishProductsModal.startBulkUnpublish',
685
+ description: 'Start bulk unpublish button',
686
+ defaultMessage: 'Start bulk unpublish'
687
+ },
688
+ cancel: {
689
+ id: 'UnpublishProductsModal.cancel',
690
+ description: 'The label for the cancel button',
691
+ defaultMessage: 'Cancel'
692
+ },
693
+ products: {
694
+ id: 'UnpublishProductsModal.products',
695
+ description: 'Products resource type label',
696
+ defaultMessage: 'Products'
697
+ }
698
+ });
699
+
700
+ var messages$3 = reactIntl.defineMessages({
701
+ fileUploadInstructions: {
702
+ id: 'UnpublishProductsModal.fileUploadInstructions',
703
+ description: 'Instructions for uploading a CSV file with product keys to unpublish',
704
+ defaultMessage: "The CSV file must contain the product keys to be unpublished under the header 'key'. Maximum file size is {maxFileSize} MB with a limit of {maxRowCount} rows. Download <csvTemplateLink>the CSV template</csvTemplateLink> or refer to <documentationLink>the documentation</documentationLink>."
705
+ }
706
+ });
707
+
708
+ function ownKeys$5(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
709
+ function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$5(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$5(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
710
+ const Instructions = () => {
711
+ const intl = reactIntl.useIntl();
712
+ const isFileImportJobFlowEnabled = applicationShell.useFeatureToggle(FILE_IMPORT_JOB_FLOW);
713
+ const maxFileSizeMB = isFileImportJobFlowEnabled ? operations.IMPORT_MAX_FILE_SIZE_MB : operations.IMPORT_LEGACY_MAX_FILE_SIZE_MB;
714
+ const maxItemCount = isFileImportJobFlowEnabled ? operations.IMPORT_MAX_ITEM_COUNT : operations.IMPORT_LEGACY_MAX_ROW_COUNT;
715
+ return jsxRuntime.jsx(uiKit.Text.Body, {
716
+ intlMessage: _objectSpread$5(_objectSpread$5({}, messages$3.fileUploadInstructions), {}, {
717
+ values: {
718
+ maxFileSize: intl.formatNumber(maxFileSizeMB),
719
+ maxRowCount: intl.formatNumber(maxItemCount),
720
+ csvTemplateLink: msg => jsxRuntime.jsx(uiKit.Link, {
721
+ tone: "secondary",
722
+ isExternal: true,
723
+ to: TEMPLATE_DOWNLOAD_LINK,
724
+ children: msg
725
+ }, "csvTemplateLink"),
726
+ documentationLink: msg => jsxRuntime.jsx(uiKit.Link, {
727
+ tone: "secondary",
728
+ isExternal: true,
729
+ to: DOCUMENTATION_LINK,
730
+ children: msg
731
+ }, "documentationLink")
732
+ }
733
+ })
734
+ });
735
+ };
736
+
737
+ const Upload = () => {
738
+ const _useUnpublishProducts = useUnpublishProductsContext(),
739
+ state = _useUnpublishProducts.state,
740
+ onClose = _useUnpublishProducts.onClose;
741
+ const intl = reactIntl.useIntl();
742
+ const _useUpload = useUpload(),
743
+ handleUploadAndValidation = _useUpload.handleUploadAndValidation;
744
+ return jsxRuntime.jsx(applicationComponents.FormDialog, {
745
+ size: 16,
746
+ isOpen: true,
747
+ title: intl.formatMessage(sharedMessages.unpublishModalTitle),
748
+ labelPrimary: intl.formatMessage(messages$5.uploadAndPreview),
749
+ onPrimaryButtonClick: handleUploadAndValidation,
750
+ isPrimaryButtonDisabled: !Boolean(state.droppedFile),
751
+ onSecondaryButtonClick: () => onClose({
752
+ shouldDeleteImportContainer: true
753
+ }),
754
+ onClose: () => onClose({
755
+ shouldDeleteImportContainer: true
756
+ }),
757
+ children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
758
+ children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
759
+ scale: "m",
760
+ children: [jsxRuntime.jsx(Instructions, {}), jsxRuntime.jsx(FileDropArea, {})]
761
+ })
762
+ })
763
+ });
764
+ };
765
+
766
+ var messages$2 = reactIntl.defineMessages({
767
+ validatingResources: {
768
+ id: 'UnpublishProductsModal.Uploading.validatingResources',
769
+ defaultMessage: 'Validating {processed} / {total} {resourceType}'
770
+ }
771
+ });
772
+
773
+ const Uploading = () => {
774
+ const intl = reactIntl.useIntl();
775
+ const _useUnpublishProducts = useUnpublishProductsContext(),
776
+ state = _useUnpublishProducts.state,
777
+ actions = _useUnpublishProducts.actions,
778
+ onClose = _useUnpublishProducts.onClose;
779
+ if (!state.droppedFile?.name) return null;
780
+ const showValidationProgress = state.isValidating && state.totalResourceCount && (state.validationProcessed ?? 0) > 0;
781
+ const statusMessage = showValidationProgress ? intl.formatMessage(messages$2.validatingResources, {
782
+ processed: intl.formatNumber(state.validationProcessed ?? 0),
783
+ total: intl.formatNumber(state.totalResourceCount ?? 0),
784
+ resourceType: intl.formatMessage(sharedMessages.products)
785
+ }) : undefined;
786
+ return jsxRuntime.jsx(operations.UploadingModal, {
787
+ isOpen: true,
788
+ title: intl.formatMessage(sharedMessages.unpublishModalTitle),
789
+ fileName: state.droppedFile.name,
790
+ fileSize: state.droppedFile.size,
791
+ progress: state.progress,
792
+ statusMessage: statusMessage,
793
+ cancelLabel: intl.formatMessage(sharedMessages.cancel),
794
+ onCancel: () => {
795
+ actions.setCurrentStep('upload');
796
+ state.abortController.abort();
797
+ },
798
+ onClose: () => onClose({
799
+ shouldDeleteImportContainer: true
800
+ })
801
+ });
802
+ };
803
+
804
+ var messages$1 = reactIntl.defineMessages({
805
+ uploadNewFile: {
806
+ id: 'UnpublishProductsModal.uploadNewFile',
807
+ defaultMessage: 'Upload new file'
808
+ },
809
+ uploadErrorDescription: {
810
+ id: 'UnpublishProductsModal.uploadError',
811
+ description: 'Title when errors detected while uploading file',
812
+ defaultMessage: 'There {errorsCount, plural, one {is <b>1</b> error} other {are <b>{errorsCount}</b> errors}} detected while uploading the file "{fileName}".'
813
+ },
814
+ errorType: {
815
+ id: 'UnpublishProductsModal.errorType',
816
+ description: 'Error type" column',
817
+ defaultMessage: 'Error type'
818
+ },
819
+ details: {
820
+ id: 'UnpublishProductsModal.details',
821
+ description: '"Details" column',
822
+ defaultMessage: 'Details'
823
+ }
824
+ });
825
+
826
+ function ownKeys$4(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
827
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$4(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$4(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
828
+ const getColumns = () => [{
829
+ key: 'errorType',
830
+ label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$4({}, messages$1.errorType)),
831
+ width: 'max-content'
832
+ }, {
833
+ key: 'details',
834
+ label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$4({}, messages$1.details))
835
+ }];
836
+ const UploadErrorTable = props => {
837
+ var _context;
838
+ const pagination = uiKit.usePaginationState({
839
+ perPage: 10
840
+ });
841
+ const startIndex = (pagination.page.value - 1) * pagination.perPage.value;
842
+ const endIndex = startIndex + pagination.perPage.value;
843
+ const currentPageRows = _sliceInstanceProperty__default["default"](_context = props.rows).call(_context, startIndex, endIndex);
844
+ const shouldShowPagination = props.rows.length > pagination.perPage.value;
845
+ return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
846
+ scale: "l",
847
+ children: [jsxRuntime.jsx(uiKit.DataTable, {
848
+ verticalCellAlignment: "center",
849
+ isCondensed: true,
850
+ rows: currentPageRows,
851
+ columns: getColumns(),
852
+ itemRenderer: itemRenderer
853
+ }), shouldShowPagination && jsxRuntime.jsx(uiKit.PageNavigator, {
854
+ onPageChange: pagination.page.onChange,
855
+ page: pagination.page.value,
856
+ totalPages: Math.ceil(props.rows.length / pagination.perPage.value)
857
+ })]
858
+ });
859
+ };
860
+ function itemRenderer(item, column) {
861
+ switch (column.key) {
862
+ case 'errorType':
863
+ return jsxRuntime.jsx(uiKit.Stamp, {
864
+ isCondensed: true,
865
+ label: item.title,
866
+ tone: "critical"
867
+ });
868
+ case 'details':
869
+ return jsxRuntime.jsx(uiKit.Text.Body, {
870
+ children: item.description
871
+ });
872
+ default:
873
+ return null;
874
+ }
875
+ }
876
+
877
+ function ownKeys$3(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
878
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$3(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$3(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
879
+ const UploadErrorsModal = () => {
880
+ const intl = reactIntl.useIntl();
881
+ const _useUnpublishProducts = useUnpublishProductsContext(),
882
+ state = _useUnpublishProducts.state,
883
+ actions = _useUnpublishProducts.actions,
884
+ onClose = _useUnpublishProducts.onClose;
885
+ const errorsCount = state.fileUploadErrors?.length ?? 0;
886
+ return jsxRuntime.jsx(applicationComponents.InfoDialog, {
887
+ size: 16,
888
+ isOpen: true,
889
+ title: intl.formatMessage(sharedMessages.unpublishModalTitle),
890
+ onClose: () => onClose(),
891
+ children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
892
+ children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
893
+ scale: "l",
894
+ children: [jsxRuntime.jsx(fullstory.Masking.Mask, {
895
+ children: jsxRuntime.jsx(uiKit.Text.Body, {
896
+ intlMessage: _objectSpread$3(_objectSpread$3({}, messages$1.uploadErrorDescription), {}, {
897
+ values: {
898
+ fileName: state.droppedFile?.name,
899
+ errorsCount: intl.formatNumber(errorsCount),
900
+ b: getBold$2
901
+ }
902
+ })
903
+ })
904
+ }), jsxRuntime.jsx(UploadErrorTable, {
905
+ rows: operations.mapFileUploadErrorsToUploadFileErrorRows(state.fileUploadErrors ?? [])
906
+ }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
907
+ scale: "m",
908
+ justifyContent: "flex-end",
909
+ children: [jsxRuntime.jsx(uiKit.SecondaryButton, {
910
+ label: intl.formatMessage(sharedMessages.cancel),
911
+ onClick: () => onClose()
912
+ }), jsxRuntime.jsx(uiKit.PrimaryButton, {
913
+ iconLeft: jsxRuntime.jsx(uiKit.ImportIcon, {}),
914
+ label: intl.formatMessage(messages$1.uploadNewFile),
915
+ onClick: () => actions.uploadNewFile()
916
+ })]
917
+ })]
918
+ })
919
+ })
920
+ });
921
+ };
922
+ function getBold$2(msg) {
923
+ return jsxRuntime.jsx(uiKit.Text.Body, {
924
+ as: "span",
925
+ isBold: true,
926
+ children: msg
927
+ }, crypto.randomUUID());
928
+ }
929
+
930
+ var messages = reactIntl.defineMessages({
931
+ continue: {
932
+ id: 'UnpublishProductsModal.continue',
933
+ description: 'Continue button',
934
+ defaultMessage: 'Continue'
935
+ },
936
+ heresAPreview: {
937
+ id: 'UnpublishProductsModal.heresAPreview',
938
+ description: 'Here is a preview',
939
+ defaultMessage: "Here's a preview:"
940
+ },
941
+ productsToBeUnpublished: {
942
+ id: 'UnpublishProductsModal.productsToBeUnpublished',
943
+ description: 'Products to be unpublished',
944
+ defaultMessage: '{count, plural, one {<b>{count}</b> product to be unpublished} other {<b>{count}</b> products to be unpublished}}'
945
+ },
946
+ confirmationQuestion: {
947
+ id: 'UnpublishProductsModal.confirmationQuestion',
948
+ description: 'Confirmation question',
949
+ defaultMessage: 'Are you sure you want to unpublish the products? '
950
+ },
951
+ confirmationText: {
952
+ id: 'UnpublishProductsModal.confirmationText',
953
+ description: 'Confirmation text',
954
+ defaultMessage: '{count, plural, one {You are about to unpublish <b>{count}</b> product in the project: <b>{projectName}</b>.} other {You are about to unpublish <b>{count}</b> products in the project: <b>{projectName}</b>.}}'
955
+ },
956
+ importStarted: {
957
+ id: 'UnpublishProductsModal.importStarted',
958
+ description: 'Import started',
959
+ defaultMessage: '<b>Your import for bulk unpublish has started.</b><newline></newline>Go to <logsLink>Import logs</logsLink> to view the progress.'
960
+ },
961
+ preparingImport: {
962
+ id: 'UnpublishProductsModal.preparingImport',
963
+ description: 'Preparing import',
964
+ defaultMessage: '<b>Prepare bulk unpublish.</b><newline></newline>Once preparation is complete, you can track the progress <logsLink>in the Import logs</logsLink>. The data will be unpublished after the import is finalized.'
965
+ }
966
+ });
967
+
968
+ function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
969
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
970
+ const getNewLine = () => jsxRuntime.jsx("br", {}, "break");
971
+ const getImportLogsLink = (msg, projectKey) => jsxRuntime.jsx(uiKit.Link, {
972
+ to: `/${projectKey}/operations/import/logs`,
973
+ children: msg
974
+ }, "link");
975
+ var _ref2 = {
976
+ name: "1vs9i7r",
977
+ styles: "width:360px"
978
+ } ;
979
+ const ImportRunningTextNotification = props => jsxRuntime.jsx("div", {
980
+ css: _ref2,
981
+ children: jsxRuntime.jsx(uiKit.Text.Body, {
982
+ intlMessage: _objectSpread$2(_objectSpread$2({}, messages.importStarted), {}, {
983
+ values: {
984
+ newline: getNewLine,
985
+ logsLink: msg => getImportLogsLink(msg, props.projectKey),
986
+ b: getBold$1
987
+ }
988
+ })
989
+ })
990
+ });
991
+ var _ref = {
992
+ name: "1vs9i7r",
993
+ styles: "width:360px"
994
+ } ;
995
+ const ImportPreparingTextNotification = props => jsxRuntime.jsx("div", {
996
+ css: _ref,
997
+ children: jsxRuntime.jsx(uiKit.Text.Body, {
998
+ intlMessage: _objectSpread$2(_objectSpread$2({}, messages.preparingImport), {}, {
999
+ values: {
1000
+ newline: getNewLine,
1001
+ logsLink: msg => getImportLogsLink(msg, props.projectKey),
1002
+ b: getBold$1
1003
+ }
1004
+ })
1005
+ })
1006
+ });
1007
+ const UnpublishProductsConfirmationModal = () => {
1008
+ const intl = reactIntl.useIntl();
1009
+ const _useUnpublishProducts = useUnpublishProductsContext(),
1010
+ state = _useUnpublishProducts.state,
1011
+ onClose = _useUnpublishProducts.onClose;
1012
+ const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
1013
+ projectKey: context.project?.key,
1014
+ projectName: context.project?.name
1015
+ })),
1016
+ projectKey = _useApplicationContex.projectKey,
1017
+ projectName = _useApplicationContex.projectName;
1018
+ const showNotification = actionsGlobal.useShowNotification();
1019
+ return jsxRuntime.jsx(applicationComponents.ConfirmationDialog, {
1020
+ title: intl.formatMessage(sharedMessages.unpublishModalTitle),
1021
+ labelPrimary: intl.formatMessage(sharedMessages.startBulkUnpublish),
1022
+ isOpen: true,
1023
+ onClose: () => onClose({
1024
+ shouldDeleteImportContainer: true
1025
+ }),
1026
+ onCancel: () => onClose({
1027
+ shouldDeleteImportContainer: true
1028
+ }),
1029
+ dataAttributesPrimaryButton: {
1030
+ 'data-test-id': 'confirmation-dialog-confirm'
1031
+ },
1032
+ dataAttributesSecondaryButton: {
1033
+ 'data-test-id': 'confirmation-dialog-cancel'
1034
+ },
1035
+ onConfirm: async () => {
1036
+ try {
1037
+ const canConfirm = projectKey && state.containerKey && state.droppedFile?.name;
1038
+ if (!canConfirm) return;
1039
+ onClose();
1040
+ showNotification({
1041
+ kind: 'info',
1042
+ domain: constants.DOMAINS.SIDE,
1043
+ // @ts-ignore
1044
+ text: jsxRuntime.jsx(ImportPreparingTextNotification, {
1045
+ projectKey: projectKey
1046
+ })
1047
+ }, {
1048
+ dismissAfter: 5000
1049
+ });
1050
+ if (state.jobId) {
1051
+ await operations.processFileImportJob({
1052
+ projectKey,
1053
+ importContainerKey: state.containerKey,
1054
+ jobId: state.jobId,
1055
+ resourceType: 'product'
1056
+ });
1057
+ } else {
1058
+ await operations.processUploadedFile({
1059
+ projectKey,
1060
+ resourceType: 'product',
1061
+ importContainerKey: state.containerKey
1062
+ });
1063
+ }
1064
+ showNotification({
1065
+ kind: 'info',
1066
+ domain: constants.DOMAINS.SIDE,
1067
+ // @ts-ignore
1068
+ text: jsxRuntime.jsx(ImportRunningTextNotification, {
1069
+ projectKey: projectKey
1070
+ })
1071
+ }, {
1072
+ dismissAfter: 5000
1073
+ });
1074
+ } catch (error) {
1075
+ onClose({
1076
+ shouldDeleteImportContainer: true
1077
+ });
1078
+ showNotification({
1079
+ kind: 'error',
1080
+ domain: constants.DOMAINS.PAGE,
1081
+ text: String(error)
1082
+ });
1083
+ }
1084
+ },
1085
+ size: 16,
1086
+ children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
1087
+ children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1088
+ scale: "xl",
1089
+ children: [jsxRuntime.jsx(uiKit.Text.Body, {
1090
+ intlMessage: _objectSpread$2(_objectSpread$2({}, messages.confirmationText), {}, {
1091
+ values: {
1092
+ projectName: projectName,
1093
+ // TODO: Replace with actual count
1094
+ count: intl.formatNumber(state.uploadFileResponse?.rowsCount ?? 0),
1095
+ b: getBold$1
1096
+ }
1097
+ })
1098
+ }), jsxRuntime.jsx(uiKit.Text.Body, {
1099
+ intlMessage: messages.confirmationQuestion
1100
+ })]
1101
+ })
1102
+ })
1103
+ });
1104
+ };
1105
+ function getBold$1(msg) {
1106
+ return jsxRuntime.jsx(uiKit.Text.Body, {
1107
+ as: "span",
1108
+ isBold: true,
1109
+ children: msg
1110
+ }, crypto.randomUUID());
1111
+ }
1112
+
1113
+ function ownKeys$1(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
1114
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1115
+ function UploadPreviewModal() {
1116
+ const _useUnpublishProducts = useUnpublishProductsContext(),
1117
+ state = _useUnpublishProducts.state,
1118
+ onClose = _useUnpublishProducts.onClose,
1119
+ actions = _useUnpublishProducts.actions;
1120
+ const intl = reactIntl.useIntl();
1121
+ return jsxRuntime.jsx(applicationComponents.FormDialog, {
1122
+ size: 16,
1123
+ isOpen: true,
1124
+ title: intl.formatMessage(sharedMessages.unpublishModalTitle),
1125
+ labelPrimary: intl.formatMessage(messages.continue),
1126
+ onSecondaryButtonClick: () => onClose({
1127
+ shouldDeleteImportContainer: true
1128
+ }),
1129
+ onPrimaryButtonClick: () => {
1130
+ actions.setCurrentStep('unpublish-confirmation');
1131
+ },
1132
+ onClose: () => onClose({
1133
+ shouldDeleteImportContainer: true
1134
+ }),
1135
+ children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1136
+ scale: "m",
1137
+ children: [jsxRuntime.jsx(uiKit.Text.Body, {
1138
+ intlMessage: messages.heresAPreview
1139
+ }), jsxRuntime.jsx(uiKit.Card, {
1140
+ insetScale: "xl",
1141
+ children: jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1142
+ scale: "m",
1143
+ alignItems: "center",
1144
+ children: [jsxRuntime.jsx(uiKit.CloseBoldIcon, {
1145
+ size: "40",
1146
+ color: "neutral60"
1147
+ }), jsxRuntime.jsx(uiKit.Text.Body, {
1148
+ intlMessage: _objectSpread$1(_objectSpread$1({}, messages.productsToBeUnpublished), {}, {
1149
+ values: {
1150
+ count: intl.formatNumber(state.uploadFileResponse?.rowsCount ?? 0),
1151
+ b: getBold
1152
+ }
1153
+ })
1154
+ })]
1155
+ })
1156
+ })]
1157
+ })
1158
+ });
1159
+ }
1160
+ function getBold(msg) {
1161
+ return jsxRuntime.jsx(uiKit.Text.Body, {
1162
+ as: "span",
1163
+ isBold: true,
1164
+ children: msg
1165
+ }, crypto.randomUUID());
1166
+ }
1167
+
1168
+ const steps = {
1169
+ upload: jsxRuntime.jsx(Upload, {}),
1170
+ uploading: jsxRuntime.jsx(Uploading, {}),
1171
+ 'upload-preview': jsxRuntime.jsx(UploadPreviewModal, {}),
1172
+ 'upload-error': jsxRuntime.jsx(UploadErrorsModal, {}),
1173
+ 'unpublish-confirmation': jsxRuntime.jsx(UnpublishProductsConfirmationModal, {})
1174
+ };
1175
+ const CurrentStep = () => {
1176
+ const _useUnpublishProducts = useUnpublishProductsContext(),
1177
+ state = _useUnpublishProducts.state;
1178
+ return steps[state.currentStep] || null;
1179
+ };
1180
+
1181
+ const getChunkImport = locale => {
1182
+ const intlLocale = i18n.mapLocaleToIntlLocale(locale);
1183
+ switch (intlLocale) {
1184
+ case 'de':
1185
+ return Promise.resolve().then(function () { return require('./de-003f2859.cjs.prod.js'); });
1186
+ case 'es':
1187
+ return Promise.resolve().then(function () { return require('./es-040a89ab.cjs.prod.js'); });
1188
+ case 'fr-FR':
1189
+ return Promise.resolve().then(function () { return require('./fr-FR-9ed02ab8.cjs.prod.js'); });
1190
+ case 'ja':
1191
+ return Promise.resolve().then(function () { return require('./ja-37632763.cjs.prod.js'); });
1192
+ case 'pt-BR':
1193
+ return Promise.resolve().then(function () { return require('./pt-BR-46c4eaae.cjs.prod.js'); });
1194
+ default:
1195
+ return Promise.resolve().then(function () { return require('./en-da1bb187.cjs.prod.js'); });
1196
+ }
1197
+ };
1198
+ const loadMessages = async locale => {
1199
+ try {
1200
+ const chunkImport = await getChunkImport(locale);
1201
+ return i18n.parseChunkImport(chunkImport);
1202
+ } catch (error) {
1203
+ // eslint-disable-next-line no-console
1204
+ console.warn(`Something went wrong while loading the unpublish-products-modal messages for ${locale}`, error);
1205
+ sentry.reportErrorToSentry(new Error(`Something went wrong while loading the unpublish-products-modal messages for ${locale}`), {
1206
+ extra: error
1207
+ });
1208
+ return {};
1209
+ }
1210
+ };
1211
+
1212
+ const useAsyncIntlMessages = (locale, loader) => {
1213
+ const _useState = React.useState({
1214
+ isLoading: true,
1215
+ messages: undefined,
1216
+ error: undefined
1217
+ }),
1218
+ _useState2 = _slicedToArray(_useState, 2),
1219
+ state = _useState2[0],
1220
+ setState = _useState2[1];
1221
+ React.useEffect(() => {
1222
+ let _isUnmounting = false;
1223
+ async function load() {
1224
+ try {
1225
+ if (!_isUnmounting) {
1226
+ const messages = await loader(locale);
1227
+ setState({
1228
+ isLoading: false,
1229
+ messages
1230
+ });
1231
+ }
1232
+ } catch (error) {
1233
+ setState({
1234
+ isLoading: false,
1235
+ error
1236
+ });
1237
+ }
1238
+ }
1239
+ if (locale) load();
1240
+ return () => {
1241
+ _isUnmounting = true;
1242
+ };
1243
+ }, [locale, loader]);
1244
+ return state;
1245
+ };
1246
+
1247
+ function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
1248
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1249
+ const UnpublishProductsModal = props => {
1250
+ const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
1251
+ locale: context.user && context.user.locale
1252
+ })),
1253
+ locale = _useApplicationContex.locale;
1254
+ const messages = useAsyncIntlMessages(locale, loadMessages);
1255
+ if (!props.isOpen || messages.isLoading) return null;
1256
+ return jsxRuntime.jsx(reactIntl.IntlProvider, {
1257
+ locale: locale,
1258
+ messages: messages.messages,
1259
+ children: jsxRuntime.jsx(UnpublishProductsProvider, _objectSpread(_objectSpread({}, props), {}, {
1260
+ children: jsxRuntime.jsx(CurrentStep, {})
1261
+ }))
1262
+ });
1263
+ };
1264
+ UnpublishProductsModal.displayName = 'UnpublishProductsModal';
1265
+
1266
+ exports["default"] = UnpublishProductsModal;