@unimaze/billing 0.21.64 → 0.21.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,74 @@
1
- import { FormInstance } from "antd";
2
1
  import { WrappedComponentProps } from "react-intl";
3
2
  import React from "react";
3
+ import { SubmittingStatus } from "./AttachmentUploadStatus";
4
+ import { AttachmentProps } from "../../../create-invoice";
4
5
  interface Props extends WrappedComponentProps {
5
- numberOfSuccessfulCalls: number;
6
- totalNumberOfCalls: number;
7
- form: FormInstance;
6
+ numberOfAttemptedCalls: number;
7
+ retryUploadingFailedAttachments(_failedAttemptsIndexes: AttachmentProps[]): void;
8
+ retrySubmittingInvoice(): void;
9
+ alreadyRetried: boolean;
10
+ invoiceSubmittingStatus: SubmittingStatus;
11
+ allAttachments: any[];
12
+ allAttachmentsWithStatuses: AttachmentProps[];
8
13
  }
14
+ export declare const translationMessages: {
15
+ submitConfirmation_title: {
16
+ id: string;
17
+ defaultMessage: string;
18
+ };
19
+ submitConfirmation_text: {
20
+ id: string;
21
+ defaultMessage: string;
22
+ };
23
+ submitConfirmation_footer_text: {
24
+ id: string;
25
+ defaultMessage: string;
26
+ };
27
+ submitConfirmation_successfullyCreatedInvoice: {
28
+ id: string;
29
+ defaultMessage: string;
30
+ };
31
+ submitConfirmation_SuccessfullyUploadedAttachment: {
32
+ id: string;
33
+ defaultMessage: string;
34
+ };
35
+ submitConfirmation_retryFailedAttachments: {
36
+ id: string;
37
+ defaultMessage: string;
38
+ };
39
+ submitConfirmation_retryButton: {
40
+ id: string;
41
+ defaultMessage: string;
42
+ };
43
+ submitConfirmation_submitWithFailedAttachmentsInfoMessage: {
44
+ id: string;
45
+ defaultMessage: string;
46
+ };
47
+ submitConfirmation_attachmentFailedToUpload: {
48
+ id: string;
49
+ defaultMessage: string;
50
+ };
51
+ submitConfirmation_successfullyUploadedAttachment: {
52
+ id: string;
53
+ defaultMessage: string;
54
+ };
55
+ submitConfirmation_submittingAttachment: {
56
+ id: string;
57
+ defaultMessage: string;
58
+ };
59
+ submitConfirmation_submittingInvoiceFailed: {
60
+ id: string;
61
+ defaultMessage: string;
62
+ };
63
+ submitConfirmation_submittingInvoiceSuccessful: {
64
+ id: string;
65
+ defaultMessage: string;
66
+ };
67
+ submitConfirmation_submittingInvoice: {
68
+ id: string;
69
+ defaultMessage: string;
70
+ };
71
+ };
9
72
  declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omit<Props, "intl"> & {
10
73
  forwardedRef?: React.Ref<any>;
11
74
  } & React.RefAttributes<any>> & {
@@ -26,12 +26,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.translationMessages = void 0;
29
30
  var antd_1 = require("antd");
30
31
  var react_intl_1 = require("react-intl");
31
32
  var react_1 = __importStar(require("react"));
32
33
  var SubmitConfirmationSVG_1 = __importDefault(require("./SubmitConfirmationSVG"));
33
- var icons_1 = require("@ant-design/icons");
34
- var translationMessages = (0, react_intl_1.defineMessages)({
34
+ var AttachmentUploadStatus_1 = __importStar(require("./AttachmentUploadStatus"));
35
+ var AttachmentsUtility_1 = require("../../../utils/AttachmentsUtility");
36
+ var SubmitConfirmationUtility_1 = require("../../../utils/SubmitConfirmationUtility");
37
+ exports.translationMessages = (0, react_intl_1.defineMessages)({
35
38
  submitConfirmation_title: {
36
39
  id: "submitConfirmation_title",
37
40
  defaultMessage: "Invoice sent",
@@ -52,28 +55,73 @@ var translationMessages = (0, react_intl_1.defineMessages)({
52
55
  id: "submitConfirmation_SuccessfullyUploadedAttachment",
53
56
  defaultMessage: "Successfully uploaded attachment:",
54
57
  },
58
+ submitConfirmation_retryFailedAttachments: {
59
+ id: "submitConfirmation_retryFailedAttachments",
60
+ defaultMessage: "Retry failed attachments",
61
+ },
62
+ submitConfirmation_retryButton: {
63
+ id: "submitConfirmation_retryButton",
64
+ defaultMessage: "Retry",
65
+ },
66
+ submitConfirmation_submitWithFailedAttachmentsInfoMessage: {
67
+ id: "submitConfirmation_submitWithFailedAttachmentsInfoMessage",
68
+ defaultMessage: "Invoice will be delivered without failed attachments within 24 hours.",
69
+ },
70
+ submitConfirmation_attachmentFailedToUpload: {
71
+ id: "submitConfirmation_attachmentFailedToUpload",
72
+ defaultMessage: "Attachment failed to upload:",
73
+ },
74
+ submitConfirmation_successfullyUploadedAttachment: {
75
+ id: "submitConfirmation_successfullyUploadedAttachment",
76
+ defaultMessage: "Successfully uploaded attachment:",
77
+ },
78
+ submitConfirmation_submittingAttachment: {
79
+ id: "submitConfirmation_submittingAttachment",
80
+ defaultMessage: "Submitting attachment:",
81
+ },
82
+ submitConfirmation_submittingInvoiceFailed: {
83
+ id: "submitConfirmation_submittingInvoiceFailed",
84
+ defaultMessage: "Submitting invoice failed",
85
+ },
86
+ submitConfirmation_submittingInvoiceSuccessful: {
87
+ id: "submitConfirmation_submittingInvoiceSuccessful",
88
+ defaultMessage: "Successfully submitted invoice",
89
+ },
90
+ submitConfirmation_submittingInvoice: {
91
+ id: "submitConfirmation_submittingInvoice",
92
+ defaultMessage: "Submitting invoice...",
93
+ },
55
94
  });
56
95
  var SubmitConfirmation = function (props) {
57
- var numberOfSuccessfulCalls = props.numberOfSuccessfulCalls, totalNumberOfCalls = props.totalNumberOfCalls, form = props.form;
58
- var _a = (0, react_1.useState)([]), attachmentsNames = _a[0], setAttachmentsNames = _a[1];
96
+ var numberOfAttemptedCalls = props.numberOfAttemptedCalls, retryUploadingFailedAttachments = props.retryUploadingFailedAttachments, retrySubmittingInvoice = props.retrySubmittingInvoice, alreadyRetried = props.alreadyRetried, invoiceSubmittingStatus = props.invoiceSubmittingStatus, allAttachments = props.allAttachments, allAttachmentsWithStatuses = props.allAttachmentsWithStatuses;
97
+ var _a = (0, react_1.useState)(''), progressBarColor = _a[0], setProgressBarColor = _a[1];
98
+ var _b = (0, react_1.useState)(false), retryButtonVisible = _b[0], setRetryButtonVisible = _b[1];
99
+ var _c = (0, react_1.useState)(false), allAttachmentsUploadedSuccessfully = _c[0], setAllAttachmentsUploadedSuccessfully = _c[1];
59
100
  var token = antd_1.theme.useToken().token;
60
- var percentUnit = 100 / totalNumberOfCalls;
101
+ var percentUnit = 100 / (allAttachments.length + 1);
61
102
  (0, react_1.useEffect)(function () {
62
- var _a, _b, _c, _d, _e;
63
- var attachments = form.getFieldValue(['attachments']);
64
- if (((_a = attachments === null || attachments === void 0 ? void 0 : attachments.file1) === null || _a === void 0 ? void 0 : _a.description) || ((_b = attachments === null || attachments === void 0 ? void 0 : attachments.file2) === null || _b === void 0 ? void 0 : _b.description) || ((_c = attachments === null || attachments === void 0 ? void 0 : attachments.file3) === null || _c === void 0 ? void 0 : _c.description)) {
65
- setAttachmentsNames([attachments.file1.description, (_d = attachments === null || attachments === void 0 ? void 0 : attachments.file2) === null || _d === void 0 ? void 0 : _d.description, (_e = attachments === null || attachments === void 0 ? void 0 : attachments.file3) === null || _e === void 0 ? void 0 : _e.description]);
103
+ if (invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Failed) {
104
+ setProgressBarColor('red');
66
105
  }
67
- }, [form]);
68
- var getAttachmentUploadMessage = function (attachmentName) {
69
- return react_1.default.createElement(antd_1.Typography.Text, { style: { margin: 5 } },
70
- react_1.default.createElement(icons_1.CheckCircleTwoTone, { twoToneColor: "green", style: { marginRight: 5 } }), "".concat(props.intl.formatMessage(translationMessages.submitConfirmation_SuccessfullyUploadedAttachment)).concat(attachmentName));
71
- };
72
- var getCreatedInvoiceMessage = function () {
73
- return react_1.default.createElement(antd_1.Typography.Text, { style: { margin: 5 } },
74
- react_1.default.createElement(icons_1.CheckCircleTwoTone, { twoToneColor: "green", style: { marginRight: 5 } }),
75
- props.intl.formatMessage(translationMessages.submitConfirmation_successfullyCreatedInvoice));
76
- };
106
+ else {
107
+ var numberOfSuccessfulAttachmentUploads = (0, SubmitConfirmationUtility_1.getNumberOfUploadedAttachments)(allAttachmentsWithStatuses);
108
+ var numberOfFailedAttachmentUploads = (0, SubmitConfirmationUtility_1.getNumberOfFailedAttachments)(allAttachmentsWithStatuses);
109
+ if (numberOfAttemptedCalls === (allAttachments.length + 1) && ((numberOfSuccessfulAttachmentUploads + numberOfFailedAttachmentUploads) === allAttachments.length)) {
110
+ if (numberOfFailedAttachmentUploads > 0) {
111
+ setProgressBarColor('red');
112
+ }
113
+ }
114
+ }
115
+ }, [numberOfAttemptedCalls, allAttachments, allAttachmentsWithStatuses, invoiceSubmittingStatus]);
116
+ (0, react_1.useEffect)(function () {
117
+ var numberOfSuccessfulAttachmentUploads = (0, SubmitConfirmationUtility_1.getNumberOfUploadedAttachments)(allAttachmentsWithStatuses);
118
+ var numberOfFailedAttachmentUploads = (0, SubmitConfirmationUtility_1.getNumberOfFailedAttachments)(allAttachmentsWithStatuses);
119
+ var isRetryBtnVisible = (0, AttachmentsUtility_1.isRetryButtonVisible)(numberOfAttemptedCalls, allAttachments.length, numberOfSuccessfulAttachmentUploads, numberOfFailedAttachmentUploads, alreadyRetried, invoiceSubmittingStatus);
120
+ setRetryButtonVisible(isRetryBtnVisible);
121
+ if (allAttachments.length === numberOfSuccessfulAttachmentUploads && invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Done) {
122
+ setAllAttachmentsUploadedSuccessfully(true);
123
+ }
124
+ }, [numberOfAttemptedCalls, allAttachments, allAttachmentsWithStatuses, alreadyRetried, invoiceSubmittingStatus]);
77
125
  var cardStyle = {
78
126
  width: "auto",
79
127
  backgroundColor: "whitesmoke",
@@ -81,22 +129,43 @@ var SubmitConfirmation = function (props) {
81
129
  display: "flex",
82
130
  justifyContent: "center"
83
131
  };
132
+ var getSinnerStatus = function (_invoiceSubmittingStatus, _allAttachments, _allAttachmentsWithStatuses) {
133
+ if (_invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Failed || _invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Done)
134
+ return false;
135
+ return _allAttachments.length !== ((0, SubmitConfirmationUtility_1.getNumberOfUploadedAttachments)(_allAttachmentsWithStatuses) + (0, SubmitConfirmationUtility_1.getNumberOfFailedAttachments)(_allAttachmentsWithStatuses));
136
+ };
84
137
  return (react_1.default.createElement(antd_1.Flex, { justify: "center", style: { padding: "45px" } },
85
138
  react_1.default.createElement(antd_1.Flex, { vertical: true, justify: "center", align: "center", style: { width: "100%", maxWidth: "900px" }, gap: "small" },
86
139
  react_1.default.createElement(SubmitConfirmationSVG_1.default, null),
87
140
  " ",
88
141
  react_1.default.createElement(antd_1.Flex, { justify: "center", align: "center", style: { width: "100%", maxWidth: "900px" }, gap: "small" },
89
- react_1.default.createElement(antd_1.Progress, { showInfo: false, percent: (numberOfSuccessfulCalls + 1) * percentUnit, success: { percent: numberOfSuccessfulCalls * percentUnit } }),
90
- react_1.default.createElement(antd_1.Spin, { size: "small", spinning: totalNumberOfCalls !== numberOfSuccessfulCalls })),
91
- numberOfSuccessfulCalls >= 1 && react_1.default.createElement(antd_1.Card, { size: "small", style: cardStyle },
142
+ react_1.default.createElement(antd_1.Progress, { showInfo: false, percent: (0, SubmitConfirmationUtility_1.getProgressPercent)((0, SubmitConfirmationUtility_1.getNumberOfUploadedAttachments)(allAttachmentsWithStatuses), (0, SubmitConfirmationUtility_1.getNumberOfFailedAttachments)(allAttachmentsWithStatuses), allAttachments.length, percentUnit, invoiceSubmittingStatus, numberOfAttemptedCalls), success: { percent: (0, SubmitConfirmationUtility_1.getSuccessPercent)(allAttachmentsWithStatuses, percentUnit, invoiceSubmittingStatus) }, trailColor: progressBarColor }),
143
+ react_1.default.createElement(antd_1.Spin, { size: "small", spinning: getSinnerStatus(invoiceSubmittingStatus, allAttachments, allAttachmentsWithStatuses) })),
144
+ react_1.default.createElement(antd_1.Card, { size: "small", style: cardStyle },
92
145
  react_1.default.createElement("ul", { style: { listStyleType: 'none', paddingLeft: 0, margin: 0 } },
93
- react_1.default.createElement("li", null, numberOfSuccessfulCalls >= 1 && getCreatedInvoiceMessage()),
94
- react_1.default.createElement("li", null, numberOfSuccessfulCalls >= 2 && getAttachmentUploadMessage(attachmentsNames[0])),
95
- react_1.default.createElement("li", null, numberOfSuccessfulCalls >= 3 && getAttachmentUploadMessage(attachmentsNames[1])),
96
- react_1.default.createElement("li", null, numberOfSuccessfulCalls >= 4 && getAttachmentUploadMessage(attachmentsNames[2])))),
97
- totalNumberOfCalls === numberOfSuccessfulCalls &&
98
- react_1.default.createElement(antd_1.Flex, { vertical: true, align: "center", style: { paddingTop: "20px" } },
99
- react_1.default.createElement(antd_1.Typography.Title, { level: 2 }, props.intl.formatMessage(translationMessages.submitConfirmation_title)),
100
- react_1.default.createElement(antd_1.Typography.Text, { style: { fontSize: token.fontSizeHeading4, textAlign: "center" } }, props.intl.formatMessage(translationMessages.submitConfirmation_text))))));
146
+ react_1.default.createElement("li", null,
147
+ react_1.default.createElement(AttachmentUploadStatus_1.default, { name: (0, SubmitConfirmationUtility_1.getInvoiceText)(invoiceSubmittingStatus, props.intl), status: invoiceSubmittingStatus })), allAttachments === null || allAttachments === void 0 ? void 0 :
148
+ allAttachments.map(function (attachment) {
149
+ var attachmentStatus = (0, SubmitConfirmationUtility_1.getStatusOfAttachment)(allAttachmentsWithStatuses, attachment.description);
150
+ var name = (0, SubmitConfirmationUtility_1.getAttachmentsText)(attachmentStatus, attachment.description, props.intl);
151
+ return react_1.default.createElement("li", { key: attachment.description },
152
+ react_1.default.createElement(AttachmentUploadStatus_1.default, { name: name, status: invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Failed ? invoiceSubmittingStatus : attachmentStatus }));
153
+ })),
154
+ retryButtonVisible &&
155
+ react_1.default.createElement(antd_1.Flex, { justify: 'center' },
156
+ react_1.default.createElement(antd_1.Button, { size: 'small', style: { marginTop: "10px" }, onClick: function () {
157
+ if (invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Failed) {
158
+ retrySubmittingInvoice();
159
+ }
160
+ else {
161
+ retryUploadingFailedAttachments(allAttachmentsWithStatuses.filter(function (att) { return att.status === AttachmentUploadStatus_1.SubmittingStatus.Failed; }));
162
+ }
163
+ } }, invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Failed ? props.intl.formatMessage(exports.translationMessages.submitConfirmation_retryButton) : props.intl.formatMessage(exports.translationMessages.submitConfirmation_retryFailedAttachments)))),
164
+ react_1.default.createElement(antd_1.Flex, { vertical: true, align: "center", style: { paddingTop: "20px" } }, (0, SubmitConfirmationUtility_1.getNumberOfFailedAttachments)(allAttachmentsWithStatuses) > 0
165
+ ? react_1.default.createElement(antd_1.Typography.Title, { level: 2 }, props.intl.formatMessage(exports.translationMessages.submitConfirmation_submitWithFailedAttachmentsInfoMessage))
166
+ : react_1.default.createElement(react_1.default.Fragment, null, allAttachmentsUploadedSuccessfully &&
167
+ react_1.default.createElement(react_1.default.Fragment, null,
168
+ react_1.default.createElement(antd_1.Typography.Title, { level: 2 }, props.intl.formatMessage(exports.translationMessages.submitConfirmation_title)),
169
+ react_1.default.createElement(antd_1.Typography.Text, { style: { fontSize: token.fontSizeHeading4, textAlign: "center" } }, props.intl.formatMessage(exports.translationMessages.submitConfirmation_text))))))));
101
170
  };
102
171
  exports.default = (0, react_intl_1.injectIntl)(SubmitConfirmation);
@@ -1,8 +1,10 @@
1
1
  import React from "react";
2
2
  import { WrappedComponentProps } from "react-intl";
3
3
  import { CommonProps } from "../common/types/CommonProps";
4
+ import { UploadFile } from "antd/es/upload/interface";
4
5
  import "../common/style/index.css";
5
6
  import { PortalConfigurationCustomer } from "@unimaze/api-clients/lib/rapi";
7
+ import { SubmittingStatus } from "../common/components/submit-confirmation/AttachmentUploadStatus";
6
8
  export declare const translationMessages: {
7
9
  createInvoice_addDocumentLineMsg: {
8
10
  id: string;
@@ -73,6 +75,11 @@ export declare const translationMessages: {
73
75
  defaultMessage: string;
74
76
  };
75
77
  };
78
+ export interface AttachmentProps {
79
+ description: string;
80
+ file: UploadFile;
81
+ status: SubmittingStatus;
82
+ }
76
83
  interface Props extends CommonProps, WrappedComponentProps {
77
84
  customers: PortalConfigurationCustomer[];
78
85
  referenceIdentifiersHelpText?: string;
@@ -82,6 +82,8 @@ var ReferenceIdentifierUtility_1 = require("../utils/ReferenceIdentifierUtility"
82
82
  var RequirementsUtility_1 = require("../utils/RequirementsUtility");
83
83
  var CommonTranslations_1 = require("../common/components/CommonTranslations");
84
84
  var LocalStorageUtility_1 = require("../utils/LocalStorageUtility");
85
+ var AttachmentUploadStatus_1 = require("../common/components/submit-confirmation/AttachmentUploadStatus");
86
+ var SubmitConfirmationUtility_1 = require("../utils/SubmitConfirmationUtility");
85
87
  exports.translationMessages = (0, react_intl_1.defineMessages)({
86
88
  createInvoice_addDocumentLineMsg: {
87
89
  id: "createInvoice_addDocumentLineMsg",
@@ -191,10 +193,17 @@ var CreateInvoiceConstructor = function (props) {
191
193
  var _y = (0, react_1.useState)({}), removedInvoiceLine = _y[0], setRemovedInvoiceLine = _y[1];
192
194
  var _z = (0, react_1.useState)(undefined), missingRequiredDataTooltip = _z[0], setMissingRequiredDataTooltip = _z[1];
193
195
  var _0 = (0, react_1.useState)(false), newLineSaved = _0[0], setNewLineSaved = _0[1];
196
+ var _1 = (0, react_1.useState)(0), numberOfAttemptedCalls = _1[0], setNumberOfAttemptedCalls = _1[1];
197
+ var _2 = (0, react_1.useState)(''), messageIdForRetryAttachments = _2[0], setMessageIdForRetryAttachments = _2[1];
198
+ var _3 = (0, react_1.useState)(''), tokenForRetryAttachments = _3[0], setTokenForRetryAttachments = _3[1];
199
+ var _4 = (0, react_1.useState)([]), allAttachments = _4[0], setAllAttachments = _4[1];
200
+ var _5 = (0, react_1.useState)(false), alreadyRetried = _5[0], setAlreadyRetried = _5[1];
201
+ var _6 = (0, react_1.useState)(AttachmentUploadStatus_1.SubmittingStatus.Pending), invoiceSubmittingStatus = _6[0], setInvoiceSubmittingStatus = _6[1];
202
+ var _7 = (0, react_1.useState)([]), allAttachmentsWithStatuses = _7[0], setAllAttachmentsWithStatuses = _7[1];
194
203
  var getDefaultPaymentType = function (defaultPaymentType) {
195
204
  return defaultPaymentType || mapi_1.PaymentMeansType.DomesticClaim;
196
205
  };
197
- var _1 = (0, react_1.useState)({
206
+ var _8 = (0, react_1.useState)({
198
207
  invoice: {
199
208
  supplier: {
200
209
  address: {
@@ -220,7 +229,7 @@ var CreateInvoiceConstructor = function (props) {
220
229
  },
221
230
  issueDate: (0, dayjs_1.default)(),
222
231
  },
223
- }), formData = _1[0], setFormData = _1[1];
232
+ }), formData = _8[0], setFormData = _8[1];
224
233
  var values = antd_1.Form.useWatch([], form);
225
234
  var validateBillingLinesAndRefIdentifierField = function (isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty) {
226
235
  var validationErrors = (0, ValidationUtility_1.validateInvoiceFieldsWithoutRules)(form, isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty, setIsNextStepDisabled, referenceIdentifierIsMandatory, referenceIdentifierValidateStatus, intl);
@@ -404,9 +413,18 @@ var CreateInvoiceConstructor = function (props) {
404
413
  // setSendCopyDisabled(true);
405
414
  // }
406
415
  // }, [supplierEmail]);
407
- var _2 = (0, react_1.useState)(0), totalNumberOfCalls = _2[0], setTotalNumberOfCalls = _2[1];
408
- var _3 = (0, react_1.useState)(0), numberOfSuccessfulCalls = _3[0], setNumberOfSuccessfulCalls = _3[1];
409
- var handleSubmit = function (_values) {
416
+ var retryUploadingFailedAttachments = function (_failedAttachments) {
417
+ var failed = (0, SubmitConfirmationUtility_1.getAllFailedUploads)(allAttachmentsWithStatuses);
418
+ var success = (0, SubmitConfirmationUtility_1.getAllSuccessfulUploads)(allAttachmentsWithStatuses);
419
+ setNumberOfAttemptedCalls(success.length + 1);
420
+ (0, ApiUtility_1.submitAttachmentIfAnyLeft)(messageIdForRetryAttachments, failed, props.mapiBaseUrl, tokenForRetryAttachments, intl, numberOfAttemptedCalls, setNumberOfAttemptedCalls, [], __spreadArray([], success, true));
421
+ setAlreadyRetried(true);
422
+ };
423
+ var retrySubmittingInvoice = function () {
424
+ setInvoiceSubmittingStatus(AttachmentUploadStatus_1.SubmittingStatus.Pending);
425
+ handleSubmit(form.getFieldsValue(), (0, uuid_1.v4)());
426
+ };
427
+ var handleSubmit = function (_values, messageId) {
410
428
  var _a, _b, _c, _d, _e, _f;
411
429
  setSubmitting(true);
412
430
  if (referenceIdentifierValidateStatus !== "" && referenceIdentifierValidateStatus !== "success") {
@@ -421,6 +439,15 @@ var CreateInvoiceConstructor = function (props) {
421
439
  ];
422
440
  // Clear the array of undefined
423
441
  attachments = attachments.filter(function (attachment) { return attachment && attachment.file; });
442
+ setAllAttachments(attachments);
443
+ var attachmentsWithStatuses = [];
444
+ attachments.forEach(function (at) {
445
+ attachmentsWithStatuses.push({
446
+ description: at.description,
447
+ file: at.file,
448
+ status: AttachmentUploadStatus_1.SubmittingStatus.Pending
449
+ });
450
+ });
424
451
  if (!chosenCustomer) {
425
452
  antd_1.message.error(intl.formatMessage(exports.translationMessages.createInvoice_selectCustomerMsg));
426
453
  // TODO: handle this better?
@@ -434,21 +461,25 @@ var CreateInvoiceConstructor = function (props) {
434
461
  var createSubmitInvoice = {
435
462
  invoiceMetadataInput: invoiceMetadataInput,
436
463
  more: attachments.length > 0,
437
- messageId: (0, uuid_1.v4)(),
464
+ messageId: messageId !== null && messageId !== void 0 ? messageId : (0, uuid_1.v4)(),
438
465
  processingMode: mapi_1.TransactionProcessingMode.Device,
439
466
  services: services,
440
467
  };
441
468
  (0, ApiUtility_1.getAuthToken)(props.rapiBaseUrl, chosenCustomer === null || chosenCustomer === void 0 ? void 0 : chosenCustomer.identifier).then(function (getAuthTokenResponse) {
442
469
  var token = getAuthTokenResponse.data;
443
- setActiveStep(activeStep + 1);
444
- setTotalNumberOfCalls((attachments === null || attachments === void 0 ? void 0 : attachments.length) + 1);
470
+ if (!messageId) {
471
+ setActiveStep(activeStep + 1);
472
+ }
473
+ setNumberOfAttemptedCalls(numberOfAttemptedCalls + 1);
474
+ setTokenForRetryAttachments(token);
445
475
  (0, utils_1.submitInvoice)(createSubmitInvoice, props.mapiBaseUrl, token, "submitInvoice", props.language)
446
476
  .then(function (submitInvoiceResponse) {
447
- var _a;
448
- setNumberOfSuccessfulCalls(numberOfSuccessfulCalls + 1);
477
+ var _a, _b;
478
+ setInvoiceSubmittingStatus(AttachmentUploadStatus_1.SubmittingStatus.Done);
449
479
  if (submitInvoiceResponse.status === 201) {
450
480
  var response = submitInvoiceResponse.data;
451
- (0, ApiUtility_1.submitAttachmentIfAnyLeft)((_a = response === null || response === void 0 ? void 0 : response.uniqueId) !== null && _a !== void 0 ? _a : "", attachments, props.mapiBaseUrl, token, intl, 1, setNumberOfSuccessfulCalls);
481
+ setMessageIdForRetryAttachments((_a = response === null || response === void 0 ? void 0 : response.uniqueId) !== null && _a !== void 0 ? _a : "");
482
+ (0, ApiUtility_1.submitAttachmentIfAnyLeft)((_b = response === null || response === void 0 ? void 0 : response.uniqueId) !== null && _b !== void 0 ? _b : "", attachmentsWithStatuses, props.mapiBaseUrl, token, intl, 1, setNumberOfAttemptedCalls, [], [], setAllAttachmentsWithStatuses);
452
483
  }
453
484
  else {
454
485
  antd_1.message.error(props.intl.formatMessage(exports.translationMessages.createInvoice_invoiceHadValidationErrors));
@@ -484,6 +515,7 @@ var CreateInvoiceConstructor = function (props) {
484
515
  })
485
516
  .catch(function (error) {
486
517
  setSubmitting(false);
518
+ setInvoiceSubmittingStatus(AttachmentUploadStatus_1.SubmittingStatus.Failed);
487
519
  if (error.response) {
488
520
  // The request was made and the server responded with a status code
489
521
  // that falls out of the range of 2xx
@@ -522,7 +554,6 @@ var CreateInvoiceConstructor = function (props) {
522
554
  recaptchaRef.current.reset();
523
555
  }
524
556
  }
525
- setIsSubmitDisabled(true);
526
557
  };
527
558
  var getReceiverRequirements = function () {
528
559
  var _a, _b, _c, _d, _e;
@@ -564,7 +595,7 @@ var CreateInvoiceConstructor = function (props) {
564
595
  name: defaultCustomer.name,
565
596
  });
566
597
  }
567
- var _4 = (0, react_1.useState)(undefined), billingLinesMetadata = _4[0], setBillingLinesMetadata = _4[1];
598
+ var _9 = (0, react_1.useState)(undefined), billingLinesMetadata = _9[0], setBillingLinesMetadata = _9[1];
568
599
  var getBillingLines = function (changedValues, allValues) {
569
600
  var invoiceLines = allValues.invoice.invoiceLines;
570
601
  if (invoiceLines) {
@@ -621,7 +652,7 @@ var CreateInvoiceConstructor = function (props) {
621
652
  }
622
653
  }, scrollToFirstError: true, onValuesChange: function (changedValues, allValues) {
623
654
  getBillingLines(changedValues, allValues);
624
- } }, formLayout_1.formItemLayout, { form: form, onFinish: handleSubmit, onFinishFailed: function (error) {
655
+ } }, formLayout_1.formItemLayout, { form: form, onFinish: function (_values) { return handleSubmit(_values); }, onFinishFailed: function (error) {
625
656
  // tslint:disable-next-line:no-console
626
657
  console.log(error);
627
658
  }, initialValues: formData }),
@@ -645,7 +676,7 @@ var CreateInvoiceConstructor = function (props) {
645
676
  return setIsSaveFieldValuesSelected(!isSaveFieldValuesSelected);
646
677
  }, localStorageFormDataVersion: props.localStorageFormDataVersion })),
647
678
  activeStep === items.length && (react_1.default.createElement(components_1.InvoicePreview, { recieverRequirements: props.receiverRequirements, form: form, chosenCustomer: chosenCustomer })),
648
- activeStep === 5 && react_1.default.createElement(components_1.SubmitConfirmation, { numberOfSuccessfulCalls: numberOfSuccessfulCalls, totalNumberOfCalls: totalNumberOfCalls, form: form }),
679
+ activeStep === 5 && react_1.default.createElement(components_1.SubmitConfirmation, { numberOfAttemptedCalls: numberOfAttemptedCalls, retryUploadingFailedAttachments: retryUploadingFailedAttachments, retrySubmittingInvoice: retrySubmittingInvoice, alreadyRetried: alreadyRetried, invoiceSubmittingStatus: invoiceSubmittingStatus, allAttachments: allAttachments, allAttachmentsWithStatuses: allAttachmentsWithStatuses }),
649
680
  activeStep === items.length && (react_1.default.createElement(antd_1.Flex, { justify: "center" },
650
681
  react_1.default.createElement(antd_1.Flex, { gap: isMobile ? "middle" : 20, vertical: true, align: "end", style: { width: "100%", maxWidth: "900px" } },
651
682
  react_1.default.createElement(antd_1.Flex, { vertical: true, style: activeStep !== items.length ? { display: "none" } : {} },
@@ -154,8 +154,17 @@
154
154
  "referenceIdentifiers_values_validation_message": "This value doesn't exist",
155
155
  "saveInformation_label": "Save information",
156
156
  "submitConfirmation_SuccessfullyUploadedAttachment": "Successfully uploaded attachment:",
157
+ "submitConfirmation_attachmentFailedToUpload": "Attachment failed to upload:",
157
158
  "submitConfirmation_footer_text": "If any questions arise, please contact us at",
159
+ "submitConfirmation_retryButton": "Retry",
160
+ "submitConfirmation_retryFailedAttachments": "Retry failed attachments",
161
+ "submitConfirmation_submitWithFailedAttachmentsInfoMessage": "Invoice will be delivered without failed attachments within 24 hours.",
162
+ "submitConfirmation_submittingAttachment": "Submitting attachment:",
163
+ "submitConfirmation_submittingInvoice": "Submitting invoice...",
164
+ "submitConfirmation_submittingInvoiceFailed": "Submitting invoice failed",
165
+ "submitConfirmation_submittingInvoiceSuccessful": "Successfully submitted invoice",
158
166
  "submitConfirmation_successfullyCreatedInvoice": "Successfully created invoice",
167
+ "submitConfirmation_successfullyUploadedAttachment": "Successfully uploaded attachment:",
159
168
  "submitConfirmation_text": "The invoice has been sent to the customer.",
160
169
  "submitConfirmation_title": "Invoice sent",
161
170
  "supplier_address_city": "City",
@@ -154,8 +154,17 @@
154
154
  "referenceIdentifiers_values_validation_message": "Þetta gildi er ekki til",
155
155
  "saveInformation_label": "Vista upplýsingar",
156
156
  "submitConfirmation_SuccessfullyUploadedAttachment": "Viðhengi sem hefur verið sent:",
157
+ "submitConfirmation_attachmentFailedToUpload": "Ekki tókst að hlaða upp viðhengi:",
157
158
  "submitConfirmation_footer_text": "Ef spurningar vakna, hafið samband",
159
+ "submitConfirmation_retryButton": "Endurkeyra",
160
+ "submitConfirmation_retryFailedAttachments": "Endurkeyra viðhengi sem tókst ekki að senda",
161
+ "submitConfirmation_submitWithFailedAttachmentsInfoMessage": "Reikningur verður sendur innan 24 stunda án viðhengja á villu",
162
+ "submitConfirmation_submittingAttachment": "Sendi viðhengi:",
163
+ "submitConfirmation_submittingInvoice": "Sendi reikning...",
164
+ "submitConfirmation_submittingInvoiceFailed": "Villa við að senda reikning",
165
+ "submitConfirmation_submittingInvoiceSuccessful": "Reikningur sendur",
158
166
  "submitConfirmation_successfullyCreatedInvoice": "Reikningur hefur verið stofnaður",
167
+ "submitConfirmation_successfullyUploadedAttachment": "Viðhengi hlaðið upp:",
159
168
  "submitConfirmation_text": "Reikningur hefur verið sendur til viðskiptavinar.",
160
169
  "submitConfirmation_title": "Reikningur sendur",
161
170
  "supplier_address_city": "Borg",
@@ -155,8 +155,17 @@ declare const _default: {
155
155
  referenceIdentifiers_values_validation_message: string;
156
156
  saveInformation_label: string;
157
157
  submitConfirmation_SuccessfullyUploadedAttachment: string;
158
+ submitConfirmation_attachmentFailedToUpload: string;
158
159
  submitConfirmation_footer_text: string;
160
+ submitConfirmation_retryButton: string;
161
+ submitConfirmation_retryFailedAttachments: string;
162
+ submitConfirmation_submitWithFailedAttachmentsInfoMessage: string;
163
+ submitConfirmation_submittingAttachment: string;
164
+ submitConfirmation_submittingInvoice: string;
165
+ submitConfirmation_submittingInvoiceFailed: string;
166
+ submitConfirmation_submittingInvoiceSuccessful: string;
159
167
  submitConfirmation_successfullyCreatedInvoice: string;
168
+ submitConfirmation_successfullyUploadedAttachment: string;
160
169
  submitConfirmation_text: string;
161
170
  submitConfirmation_title: string;
162
171
  supplier_address_city: string;
@@ -354,8 +363,17 @@ declare const _default: {
354
363
  referenceIdentifiers_values_validation_message: string;
355
364
  saveInformation_label: string;
356
365
  submitConfirmation_SuccessfullyUploadedAttachment: string;
366
+ submitConfirmation_attachmentFailedToUpload: string;
357
367
  submitConfirmation_footer_text: string;
368
+ submitConfirmation_retryButton: string;
369
+ submitConfirmation_retryFailedAttachments: string;
370
+ submitConfirmation_submitWithFailedAttachmentsInfoMessage: string;
371
+ submitConfirmation_submittingAttachment: string;
372
+ submitConfirmation_submittingInvoice: string;
373
+ submitConfirmation_submittingInvoiceFailed: string;
374
+ submitConfirmation_submittingInvoiceSuccessful: string;
358
375
  submitConfirmation_successfullyCreatedInvoice: string;
376
+ submitConfirmation_successfullyUploadedAttachment: string;
359
377
  submitConfirmation_text: string;
360
378
  submitConfirmation_title: string;
361
379
  supplier_address_city: string;
@@ -2,7 +2,7 @@ import { ImportDocumentValidationData, MessageOutput } from "@unimaze/api-client
2
2
  import { InvoiceMetadataInput, TransactionProcessingMode } from "@unimaze/api-clients/lib/mapi";
3
3
  import { AxiosPromise, CancelToken } from "axios";
4
4
  import { LanguageProp } from "../common/types/CommonProps";
5
- import { UploadFile } from "antd/es/upload/interface";
5
+ import { AttachmentProps } from "../create-invoice";
6
6
  import { IntlShape } from "react-intl";
7
7
  interface CreateSubmitInvoice {
8
8
  messageId: string;
@@ -23,8 +23,5 @@ declare const submitDocumentFetch: (data: any, attachDocument: AttachDocument, m
23
23
  declare const submitInvoice: (createSubmitInvoice: CreateSubmitInvoice, mapiBaseUrl: string, token: string, callName?: string, language?: LanguageProp) => AxiosPromise<ImportDocumentValidationData[] | MessageOutput>;
24
24
  declare const getAuthToken: (rapiBaseUrl: string, entityIsoIdentifier: string) => AxiosPromise<string>;
25
25
  declare const getCancelToken: (callName: string, showMessage?: boolean) => CancelToken;
26
- declare const submitAttachmentIfAnyLeft: (_messageId: string, _attachments: {
27
- description: string;
28
- file: UploadFile;
29
- }[], _mapiBaseUrl: string, token: string, intl: IntlShape, numberOfSuccessfulCalls: number, setNumberOfSuccessfulCalls: (numberOfSuccessfulCalls: number) => void) => void;
26
+ declare const submitAttachmentIfAnyLeft: (_messageId: string, _attachments: AttachmentProps[], _mapiBaseUrl: string, token: string, intl: IntlShape, numberOfAttemptedCalls: number, setNumberOfAttemptedCalls: (numberOfAttemptedCalls: number) => void, numberOfFailedAttempts: number[], allAttachmentsWithStatuses: AttachmentProps[], setAllAttachmentsWithStatuses?: (allNewAttachments: AttachmentProps[]) => void) => void;
30
27
  export { submitInvoice, CreateSubmitInvoice, submitDocument, AttachDocument, submitDocumentFetch, submitAttachmentIfAnyLeft, getAuthToken, getCancelToken };
@@ -10,6 +10,15 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
13
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
24
  };
@@ -21,6 +30,7 @@ var mapi_1 = require("@unimaze/api-clients/lib/mapi");
21
30
  var axios_1 = __importDefault(require("axios"));
22
31
  var antd_1 = require("antd");
23
32
  var create_invoice_1 = require("../create-invoice");
33
+ var AttachmentUploadStatus_1 = require("../common/components/submit-confirmation/AttachmentUploadStatus");
24
34
  var initialiseTransactionApi = function (mapiBaseUrl) {
25
35
  var apiConfig = {
26
36
  basePath: mapiBaseUrl,
@@ -118,31 +128,62 @@ var getCancelToken = function (callName, showMessage) {
118
128
  return window[callName].token;
119
129
  };
120
130
  exports.getCancelToken = getCancelToken;
121
- var submitAttachmentIfAnyLeft = function (_messageId, _attachments, _mapiBaseUrl, token, intl, numberOfSuccessfulCalls, setNumberOfSuccessfulCalls) {
131
+ var submitAttachmentIfAnyLeft = function (_messageId, _attachments, _mapiBaseUrl, token, intl, numberOfAttemptedCalls, setNumberOfAttemptedCalls, numberOfFailedAttempts, allAttachmentsWithStatuses, setAllAttachmentsWithStatuses) {
122
132
  if (_attachments && _attachments.length > 0) {
123
- var nextFileArray = _attachments.splice(0, 1);
124
- var nextFile = nextFileArray[0].file.originFileObj;
125
- var nextFileDescription_1 = nextFileArray[0].description;
133
+ var nextFileArray_1 = _attachments.splice(0, 1);
134
+ var nextFile = nextFileArray_1[0].file.originFileObj;
135
+ var nextFileDescription_1 = nextFileArray_1[0].description;
126
136
  if (!nextFile)
127
137
  throw new Error("NextFile is empty");
128
138
  var createAttachDocument = {
129
139
  messageId: _messageId,
130
140
  contentType: nextFile.type,
131
- more: _attachments.length > 0,
141
+ more: numberOfFailedAttempts.length > 0 ? true : _attachments.length > 0,
132
142
  name: nextFileDescription_1, // nextFile.name,
133
143
  };
134
- submitDocumentFetch(nextFile, createAttachDocument, _mapiBaseUrl, token)
144
+ var newNumberOfAttachments_1 = numberOfAttemptedCalls + 1;
145
+ setNumberOfAttemptedCalls(newNumberOfAttachments_1);
146
+ // TODO remove aa bb just testing
147
+ submitDocumentFetch(nextFileDescription_1 === 'aa' || nextFileDescription_1 === 'bb' ? undefined : nextFile, createAttachDocument, _mapiBaseUrl, token)
135
148
  .then(function (submitDocumentResponse) {
136
149
  if (submitDocumentResponse.status === 200 || submitDocumentResponse.status === 201) {
137
- var newProgress = numberOfSuccessfulCalls + 1;
138
- setNumberOfSuccessfulCalls(newProgress);
139
- submitAttachmentIfAnyLeft(_messageId, _attachments, _mapiBaseUrl, token, intl, newProgress, setNumberOfSuccessfulCalls);
150
+ var newAttachmentsWithStatuses = __spreadArray(__spreadArray([], allAttachmentsWithStatuses, true), [{
151
+ description: nextFileDescription_1,
152
+ file: nextFileArray_1[0].file,
153
+ status: AttachmentUploadStatus_1.SubmittingStatus.Done,
154
+ }], false);
155
+ if (typeof setAllAttachmentsWithStatuses === 'function') {
156
+ setAllAttachmentsWithStatuses(newAttachmentsWithStatuses);
157
+ }
158
+ submitAttachmentIfAnyLeft(_messageId, _attachments, _mapiBaseUrl, token, intl, newNumberOfAttachments_1, setNumberOfAttemptedCalls, numberOfFailedAttempts, newAttachmentsWithStatuses, setAllAttachmentsWithStatuses);
140
159
  }
141
160
  else {
142
161
  antd_1.message.error("".concat(intl.formatMessage(create_invoice_1.translationMessages.createInvoice_ErrorUploadedAttachmentMsg, {
143
162
  attachment: nextFileDescription_1,
144
163
  }), " - ").concat(submitDocumentResponse.statusText));
164
+ var newAttachmentsWithStatuses = __spreadArray(__spreadArray([], allAttachmentsWithStatuses, true), [{
165
+ description: nextFileDescription_1,
166
+ file: nextFileArray_1[0].file,
167
+ status: AttachmentUploadStatus_1.SubmittingStatus.Failed,
168
+ }], false);
169
+ if (typeof setAllAttachmentsWithStatuses === 'function') {
170
+ setAllAttachmentsWithStatuses(newAttachmentsWithStatuses);
171
+ }
172
+ submitAttachmentIfAnyLeft(_messageId, _attachments, _mapiBaseUrl, token, intl, newNumberOfAttachments_1, setNumberOfAttemptedCalls, numberOfFailedAttempts, newAttachmentsWithStatuses, setAllAttachmentsWithStatuses);
173
+ }
174
+ }).catch(function (error) {
175
+ antd_1.message.error("".concat(intl.formatMessage(create_invoice_1.translationMessages.createInvoice_ErrorUploadedAttachmentMsg, {
176
+ attachment: nextFileDescription_1,
177
+ }), " - ").concat(error));
178
+ var newAttachmentsWithStatuses = __spreadArray(__spreadArray([], allAttachmentsWithStatuses, true), [{
179
+ description: nextFileDescription_1,
180
+ file: nextFileArray_1[0].file,
181
+ status: AttachmentUploadStatus_1.SubmittingStatus.Failed,
182
+ }], false);
183
+ if (typeof setAllAttachmentsWithStatuses === 'function') {
184
+ setAllAttachmentsWithStatuses(newAttachmentsWithStatuses);
145
185
  }
186
+ submitAttachmentIfAnyLeft(_messageId, _attachments, _mapiBaseUrl, token, intl, newNumberOfAttachments_1, setNumberOfAttemptedCalls, numberOfFailedAttempts, newAttachmentsWithStatuses, setAllAttachmentsWithStatuses);
146
187
  });
147
188
  }
148
189
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unimaze/billing",
3
- "version": "0.21.64",
3
+ "version": "0.21.65",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",