@unimaze/billing 0.21.69 → 0.21.71

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.
@@ -174,33 +174,31 @@ var CreateInvoiceConstructor = function (props) {
174
174
  setIsMobile(false);
175
175
  }
176
176
  }, [width]);
177
- var _g = (0, react_1.useState)(false), submitting = _g[0], setSubmitting = _g[1];
178
- var _h = (0, react_1.useState)(true), isSubmitDisabled = _h[0], setIsSubmitDisabled = _h[1];
179
- var _j = (0, react_1.useState)(false), isBackButtonVisible = _j[0], setIsBackButtonVisible = _j[1];
180
- var _k = (0, react_1.useState)(true), isNextStepDisabled = _k[0], setIsNextStepDisabled = _k[1];
181
- var _l = (0, react_1.useState)(false), isNextStepVisible = _l[0], setIsNextStepVisible = _l[1];
182
- var _m = (0, react_1.useState)(0), activeStep = _m[0], setActiveStep = _m[1];
183
- var _o = (0, react_1.useState)(true), isWelcomeModalOpen = _o[0], setIsWelcomeModalOpen = _o[1];
184
- var _p = (0, react_1.useState)(""), supplierEmail = _p[0], setSupplierEmail = _p[1];
185
- var _q = (0, react_1.useState)(false), isSaveFieldValuesSelected = _q[0], setIsSaveFieldValuesSelected = _q[1];
186
- var _r = (0, react_1.useState)((0, ConversionUtility_1.profileOutputToPartyMetadata)(props.customers[0])), chosenCustomer = _r[0], setChosenCustomer = _r[1];
187
- var _s = (0, react_1.useState)(true), sendCopyDisabled = _s[0], setSendCopyDisabled = _s[1];
188
- var _t = (0, react_1.useState)(false), sendCopy = _t[0], setSendCopy = _t[1];
189
- var _u = react_1.default.useState(""), referenceIdentifierValidateStatus = _u[0], setReferenceIdentifierValidateStatus = _u[1];
190
- var _v = (0, react_1.useState)(true), referenceIdentifierIsMandatory = _v[0], setReferenceIdentifierIsMandatory = _v[1];
191
- var _w = (0, react_1.useState)(false), outsideVatScope = _w[0], setOutsideVatScope = _w[1];
192
- var _x = (0, react_1.useState)(false), captchaVerified = _x[0], setCaptchaVerified = _x[1];
193
- var _y = (0, react_1.useState)({}), removedInvoiceLine = _y[0], setRemovedInvoiceLine = _y[1];
194
- var _z = (0, react_1.useState)(undefined), missingRequiredDataTooltip = _z[0], setMissingRequiredDataTooltip = _z[1];
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];
203
- var _8 = (0, react_1.useState)(true), showWelcomeModal = _8[0], setShowWelcomeModal = _8[1];
177
+ var _g = (0, react_1.useState)(true), isSubmitDisabled = _g[0], setIsSubmitDisabled = _g[1];
178
+ var _h = (0, react_1.useState)(false), isBackButtonVisible = _h[0], setIsBackButtonVisible = _h[1];
179
+ var _j = (0, react_1.useState)(true), isNextStepDisabled = _j[0], setIsNextStepDisabled = _j[1];
180
+ var _k = (0, react_1.useState)(false), isNextStepVisible = _k[0], setIsNextStepVisible = _k[1];
181
+ var _l = (0, react_1.useState)(0), activeStep = _l[0], setActiveStep = _l[1];
182
+ var _m = (0, react_1.useState)(true), isWelcomeModalOpen = _m[0], setIsWelcomeModalOpen = _m[1];
183
+ var _o = (0, react_1.useState)(""), supplierEmail = _o[0], setSupplierEmail = _o[1];
184
+ var _p = (0, react_1.useState)(false), isSaveFieldValuesSelected = _p[0], setIsSaveFieldValuesSelected = _p[1];
185
+ var _q = (0, react_1.useState)((0, ConversionUtility_1.profileOutputToPartyMetadata)(props.customers[0])), chosenCustomer = _q[0], setChosenCustomer = _q[1];
186
+ var _r = (0, react_1.useState)(false), sendCopy = _r[0], setSendCopy = _r[1];
187
+ var _s = react_1.default.useState(""), referenceIdentifierValidateStatus = _s[0], setReferenceIdentifierValidateStatus = _s[1];
188
+ var _t = (0, react_1.useState)(true), referenceIdentifierIsMandatory = _t[0], setReferenceIdentifierIsMandatory = _t[1];
189
+ var _u = (0, react_1.useState)(false), outsideVatScope = _u[0], setOutsideVatScope = _u[1];
190
+ var _v = (0, react_1.useState)(false), captchaVerified = _v[0], setCaptchaVerified = _v[1];
191
+ var _w = (0, react_1.useState)({}), removedInvoiceLine = _w[0], setRemovedInvoiceLine = _w[1];
192
+ var _x = (0, react_1.useState)(undefined), missingRequiredDataTooltip = _x[0], setMissingRequiredDataTooltip = _x[1];
193
+ var _y = (0, react_1.useState)(false), newLineSaved = _y[0], setNewLineSaved = _y[1];
194
+ var _z = (0, react_1.useState)(0), numberOfAttemptedCalls = _z[0], setNumberOfAttemptedCalls = _z[1];
195
+ var _0 = (0, react_1.useState)(''), messageIdForRetryAttachments = _0[0], setMessageIdForRetryAttachments = _0[1];
196
+ var _1 = (0, react_1.useState)(''), tokenForRetryAttachments = _1[0], setTokenForRetryAttachments = _1[1];
197
+ var _2 = (0, react_1.useState)([]), allAttachments = _2[0], setAllAttachments = _2[1];
198
+ var _3 = (0, react_1.useState)(false), alreadyRetried = _3[0], setAlreadyRetried = _3[1];
199
+ var _4 = (0, react_1.useState)(AttachmentUploadStatus_1.SubmittingStatus.Pending), invoiceSubmittingStatus = _4[0], setInvoiceSubmittingStatus = _4[1];
200
+ var _5 = (0, react_1.useState)([]), allAttachmentsWithStatuses = _5[0], setAllAttachmentsWithStatuses = _5[1];
201
+ var _6 = (0, react_1.useState)(true), showWelcomeModal = _6[0], setShowWelcomeModal = _6[1];
204
202
  var url = new URL(window.location.href);
205
203
  var skipWelcomeModal = url.searchParams.has("skipintro");
206
204
  if (skipWelcomeModal) {
@@ -211,7 +209,7 @@ var CreateInvoiceConstructor = function (props) {
211
209
  var getDefaultPaymentType = function (defaultPaymentType) {
212
210
  return defaultPaymentType || mapi_1.PaymentMeansType.DomesticClaim;
213
211
  };
214
- var _9 = (0, react_1.useState)({
212
+ var _7 = (0, react_1.useState)({
215
213
  invoice: {
216
214
  supplier: {
217
215
  address: {
@@ -237,22 +235,79 @@ var CreateInvoiceConstructor = function (props) {
237
235
  },
238
236
  issueDate: (0, dayjs_1.default)(),
239
237
  },
240
- }), formData = _9[0], setFormData = _9[1];
241
- var values = antd_1.Form.useWatch([], form);
242
- var validateBillingLinesAndRefIdentifierField = function (isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty) {
243
- var validationErrors = (0, ValidationUtility_1.validateInvoiceFieldsWithoutRules)(form, isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty, setIsNextStepDisabled, referenceIdentifierIsMandatory, referenceIdentifierValidateStatus, intl);
244
- var billingLineValidationMessage = (0, ValidationUtility_1.validateBillingLines)(form, setIsNextStepDisabled, intl);
245
- return [validationErrors, billingLineValidationMessage];
246
- };
238
+ }), formData = _7[0], setFormData = _7[1];
247
239
  (0, react_1.useEffect)(function () {
248
- var referenceIdentifiersDefinitions = (0, ReferenceIdentifierUtility_1.getReferenceIdentifierFieldDefinitions)(props.receiverRequirements);
249
- var isSingleReferenceIdentifier = (referenceIdentifiersDefinitions === null || referenceIdentifiersDefinitions === void 0 ? void 0 : referenceIdentifiersDefinitions.length) === 1;
250
- var isMultipleReferenceIdentifier = (referenceIdentifiersDefinitions === null || referenceIdentifiersDefinitions === void 0 ? void 0 : referenceIdentifiersDefinitions.length) > 1;
251
- var someRequiredFieldsEmpty = function () {
252
- var _a, _b, _c;
253
- var referenceIdentifierType = form.getFieldValue(["invoice", "referenceIdentifiers"]);
254
- return ((_a = referenceIdentifierType[0]) === null || _a === void 0 ? void 0 : _a.code) ? !((_c = (_b = referenceIdentifierType[0]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.trim()) : false;
255
- };
240
+ var _a, _b, _c;
241
+ var savedValuesObject = (0, LocalStorageUtility_1.getFormFromLocalStorage)(props.localStorageFormDataVersion);
242
+ if (savedValuesObject) {
243
+ if ((chosenCustomer === null || chosenCustomer === void 0 ? void 0 : chosenCustomer.identifier) !== ((_b = (_a = savedValuesObject === null || savedValuesObject === void 0 ? void 0 : savedValuesObject.invoice) === null || _a === void 0 ? void 0 : _a.customer) === null || _b === void 0 ? void 0 : _b.locationIdentifier)) {
244
+ var customerFromLocalStorage = (_c = savedValuesObject.invoice) === null || _c === void 0 ? void 0 : _c.customer;
245
+ setChosenCustomer(customerFromLocalStorage);
246
+ }
247
+ var invoice = savedValuesObject.invoice, rest = __rest(savedValuesObject, ["invoice"]);
248
+ var issueDate = invoice.issueDate, restOfInvoice = __rest(invoice, ["issueDate"]);
249
+ form.setFieldsValue(__assign({ invoice: restOfInvoice }, rest));
250
+ }
251
+ }, []);
252
+ (0, react_1.useEffect)(function () {
253
+ validateFields();
254
+ }, [form, activeStep, newLineSaved, referenceIdentifierValidateStatus]);
255
+ (0, react_1.useEffect)(function () {
256
+ setSupplierEmail(form.getFieldValue(["invoice", "supplier", "contact", "electronicMail"]));
257
+ }, [form.getFieldValue(["invoice", "supplier", "contact", "electronicMail"])]);
258
+ (0, react_1.useEffect)(function () {
259
+ setOutsideVatScope(!!form.getFieldValue(["outsideVatScope"]));
260
+ }, [form.getFieldValue(["outsideVatScope"])]);
261
+ (0, react_1.useEffect)(function () {
262
+ setIsSubmitDisabled(!captchaVerified);
263
+ }, [captchaVerified]);
264
+ (0, react_1.useEffect)(function () {
265
+ setIsBackButtonVisible(activeStep > 0 && activeStep <= items.length);
266
+ setIsNextStepVisible(activeStep < items.length);
267
+ }, [activeStep]);
268
+ (0, react_1.useEffect)(function () {
269
+ if (outsideVatScope) {
270
+ form.resetFields([["invoice", "supplier", "vatNumber"]]);
271
+ }
272
+ var invoiceLines = form.getFieldValue(["invoice", "invoiceLines"]);
273
+ if (outsideVatScope) {
274
+ invoiceLines = invoiceLines.map(function (invoiceLine) {
275
+ invoiceLine.taxCategoryType = mapi_1.TaxCategoryTypeEnum.OutsideTaxScope;
276
+ return invoiceLine;
277
+ });
278
+ }
279
+ else {
280
+ invoiceLines = invoiceLines.map(function (invoiceLine) {
281
+ invoiceLine.taxCategoryType = mapi_1.TaxCategoryTypeEnum.StandardRated;
282
+ return invoiceLine;
283
+ });
284
+ }
285
+ form.setFieldsValue({
286
+ invoice: {
287
+ invoiceLines: invoiceLines,
288
+ },
289
+ });
290
+ }, [outsideVatScope]);
291
+ (0, react_1.useEffect)(function () {
292
+ getReceiverRequirements();
293
+ }, [chosenCustomer]);
294
+ // useEffect(() => {
295
+ // if (supplierEmail) {
296
+ // form.validateFields([["invoice", "supplier", "contact", "electronicMail"]])
297
+ // .then(() => {
298
+ // setSendCopyDisabled(!supplierEmail);
299
+ // setSendCopy(true);
300
+ // })
301
+ // .catch(() => {
302
+ // setSendCopyDisabled(true);
303
+ // setSendCopy(false);
304
+ // });
305
+ // } else {
306
+ // setSendCopy(false);
307
+ // setSendCopyDisabled(true);
308
+ // }
309
+ // }, [supplierEmail]);
310
+ var validateFields = function () {
256
311
  switch (activeStep) {
257
312
  case 0: {
258
313
  form.validateFields(formPaths_1.customerFieldPaths, { validateOnly: true })
@@ -277,13 +332,21 @@ var CreateInvoiceConstructor = function (props) {
277
332
  break;
278
333
  }
279
334
  case 2: {
335
+ var referenceIdentifiersDefinitions = (0, ReferenceIdentifierUtility_1.getReferenceIdentifierFieldDefinitions)(props.receiverRequirements);
336
+ var isSingleReferenceIdentifier_1 = (referenceIdentifiersDefinitions === null || referenceIdentifiersDefinitions === void 0 ? void 0 : referenceIdentifiersDefinitions.length) === 1;
337
+ var isMultipleReferenceIdentifier_1 = (referenceIdentifiersDefinitions === null || referenceIdentifiersDefinitions === void 0 ? void 0 : referenceIdentifiersDefinitions.length) > 1;
338
+ var someRequiredFieldsEmpty_1 = function () {
339
+ var _a, _b, _c;
340
+ var referenceIdentifierType = form.getFieldValue(["invoice", "referenceIdentifiers"]);
341
+ return ((_a = referenceIdentifierType[0]) === null || _a === void 0 ? void 0 : _a.code) ? !((_c = (_b = referenceIdentifierType[0]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.trim()) : false;
342
+ };
280
343
  form.validateFields(formPaths_1.invoiceFieldPaths, { validateOnly: true })
281
344
  .then(function () {
282
- var additionalValidationMessages = validateBillingLinesAndRefIdentifierField(isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty);
345
+ var additionalValidationMessages = validateBillingLinesAndRefIdentifierField(isMultipleReferenceIdentifier_1, isSingleReferenceIdentifier_1, someRequiredFieldsEmpty_1);
283
346
  additionalValidationMessages.filter(function (messageEntry) { return messageEntry !== undefined; }).length > 0 ? setMissingRequiredDataTooltip((0, RequirementsUtility_1.getRequiredTooltipMessage)(intl.formatMessage(CommonTranslations_1.commonTranslationMessages.missingRequiredData), additionalValidationMessages)) : setMissingRequiredDataTooltip(undefined);
284
347
  })
285
348
  .catch(function (error) {
286
- var additionalValidationMessages = validateBillingLinesAndRefIdentifierField(isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty);
349
+ var additionalValidationMessages = validateBillingLinesAndRefIdentifierField(isMultipleReferenceIdentifier_1, isSingleReferenceIdentifier_1, someRequiredFieldsEmpty_1);
287
350
  (0, ValidationUtility_1.handleValidationErrors)(error, setMissingRequiredDataTooltip, setIsNextStepDisabled, props.receiverRequirements, intl, additionalValidationMessages);
288
351
  });
289
352
  break;
@@ -304,7 +367,12 @@ var CreateInvoiceConstructor = function (props) {
304
367
  return;
305
368
  }
306
369
  }
307
- }, [form, values, activeStep, newLineSaved, referenceIdentifierValidateStatus]);
370
+ };
371
+ var validateBillingLinesAndRefIdentifierField = function (isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty) {
372
+ var validationErrors = (0, ValidationUtility_1.validateInvoiceFieldsWithoutRules)(form, isMultipleReferenceIdentifier, isSingleReferenceIdentifier, someRequiredFieldsEmpty, setIsNextStepDisabled, referenceIdentifierIsMandatory, referenceIdentifierValidateStatus, intl);
373
+ var billingLineValidationMessage = (0, ValidationUtility_1.validateBillingLines)(form, setIsNextStepDisabled, intl);
374
+ return [validationErrors, billingLineValidationMessage];
375
+ };
308
376
  var saveFieldValuesToLocalStorage = function () {
309
377
  var _a, _b, _c, _d;
310
378
  var flatFields = form.getFieldsValue();
@@ -356,71 +424,6 @@ var CreateInvoiceConstructor = function (props) {
356
424
  saveFieldValuesToLocalStorage();
357
425
  }
358
426
  };
359
- (0, react_1.useEffect)(function () {
360
- var _a, _b, _c;
361
- var savedValuesObject = (0, LocalStorageUtility_1.getFormFromLocalStorage)(props.localStorageFormDataVersion);
362
- if (savedValuesObject) {
363
- if ((chosenCustomer === null || chosenCustomer === void 0 ? void 0 : chosenCustomer.identifier) !== ((_b = (_a = savedValuesObject === null || savedValuesObject === void 0 ? void 0 : savedValuesObject.invoice) === null || _a === void 0 ? void 0 : _a.customer) === null || _b === void 0 ? void 0 : _b.locationIdentifier)) {
364
- var customerFromLocalStorage = (_c = savedValuesObject.invoice) === null || _c === void 0 ? void 0 : _c.customer;
365
- setChosenCustomer(customerFromLocalStorage);
366
- }
367
- var invoice = savedValuesObject.invoice, rest = __rest(savedValuesObject, ["invoice"]);
368
- var issueDate = invoice.issueDate, restOfInvoice = __rest(invoice, ["issueDate"]);
369
- form.setFieldsValue(__assign({ invoice: restOfInvoice }, rest));
370
- }
371
- }, []);
372
- (0, react_1.useEffect)(function () {
373
- setSupplierEmail(form.getFieldValue(["invoice", "supplier", "contact", "electronicMail"]));
374
- }, [form.getFieldValue(["invoice", "supplier", "contact", "electronicMail"])]);
375
- (0, react_1.useEffect)(function () {
376
- setOutsideVatScope(!!form.getFieldValue(["outsideVatScope"]));
377
- }, [form.getFieldValue(["outsideVatScope"])]);
378
- (0, react_1.useEffect)(function () {
379
- setIsSubmitDisabled(!captchaVerified);
380
- }, [captchaVerified]);
381
- (0, react_1.useEffect)(function () {
382
- setIsBackButtonVisible(activeStep > 0 && activeStep <= items.length);
383
- setIsNextStepVisible(activeStep < items.length);
384
- }, [activeStep]);
385
- (0, react_1.useEffect)(function () {
386
- if (outsideVatScope) {
387
- form.resetFields([["invoice", "supplier", "vatNumber"]]);
388
- }
389
- var invoiceLines = form.getFieldValue(["invoice", "invoiceLines"]);
390
- if (outsideVatScope) {
391
- invoiceLines = invoiceLines.map(function (invoiceLine) {
392
- invoiceLine.taxCategoryType = mapi_1.TaxCategoryTypeEnum.OutsideTaxScope;
393
- return invoiceLine;
394
- });
395
- }
396
- else {
397
- invoiceLines = invoiceLines.map(function (invoiceLine) {
398
- invoiceLine.taxCategoryType = mapi_1.TaxCategoryTypeEnum.StandardRated;
399
- return invoiceLine;
400
- });
401
- }
402
- form.setFieldsValue({
403
- invoice: {
404
- invoiceLines: invoiceLines,
405
- },
406
- });
407
- }, [outsideVatScope]);
408
- // useEffect(() => {
409
- // if (supplierEmail) {
410
- // form.validateFields([["invoice", "supplier", "contact", "electronicMail"]])
411
- // .then(() => {
412
- // setSendCopyDisabled(!supplierEmail);
413
- // setSendCopy(true);
414
- // })
415
- // .catch(() => {
416
- // setSendCopyDisabled(true);
417
- // setSendCopy(false);
418
- // });
419
- // } else {
420
- // setSendCopy(false);
421
- // setSendCopyDisabled(true);
422
- // }
423
- // }, [supplierEmail]);
424
427
  var retryUploadingFailedAttachments = function (_failedAttachments) {
425
428
  var failed = (0, SubmitConfirmationUtility_1.getAllFailedUploads)(allAttachmentsWithStatuses);
426
429
  var success = (0, SubmitConfirmationUtility_1.getAllSuccessfulUploads)(allAttachmentsWithStatuses);
@@ -434,10 +437,8 @@ var CreateInvoiceConstructor = function (props) {
434
437
  };
435
438
  var handleSubmit = function (_values, messageId) {
436
439
  var _a, _b, _c, _d, _e, _f;
437
- setSubmitting(true);
438
440
  if (referenceIdentifierValidateStatus !== "" && referenceIdentifierValidateStatus !== "success") {
439
441
  form.scrollToField(["invoice", "referenceIdentifiers", 0, "value"]);
440
- setSubmitting(false);
441
442
  return;
442
443
  }
443
444
  var attachments = [
@@ -459,7 +460,6 @@ var CreateInvoiceConstructor = function (props) {
459
460
  if (!chosenCustomer) {
460
461
  antd_1.message.error(intl.formatMessage(exports.translationMessages.createInvoice_selectCustomerMsg));
461
462
  // TODO: handle this better?
462
- setSubmitting(false);
463
463
  return;
464
464
  }
465
465
  var services = sendCopy
@@ -492,7 +492,6 @@ var CreateInvoiceConstructor = function (props) {
492
492
  else {
493
493
  antd_1.message.error(props.intl.formatMessage(exports.translationMessages.createInvoice_invoiceHadValidationErrors));
494
494
  }
495
- setSubmitting(false);
496
495
  form.resetFields();
497
496
  form.setFields([
498
497
  {
@@ -522,7 +521,6 @@ var CreateInvoiceConstructor = function (props) {
522
521
  // location.reload();
523
522
  })
524
523
  .catch(function (error) {
525
- setSubmitting(false);
526
524
  setInvoiceSubmittingStatus(AttachmentUploadStatus_1.SubmittingStatus.Failed);
527
525
  if (error.response) {
528
526
  // The request was made and the server responded with a status code
@@ -582,9 +580,6 @@ var CreateInvoiceConstructor = function (props) {
582
580
  props.getReceiverRequirements(chosenCustomer.identifier);
583
581
  }
584
582
  };
585
- (0, react_1.useEffect)(function () {
586
- getReceiverRequirements();
587
- }, [chosenCustomer]);
588
583
  var defaultCustomer;
589
584
  if (props.customers.length === 1 && !chosenCustomer) {
590
585
  defaultCustomer = props.customers[0];
@@ -603,7 +598,7 @@ var CreateInvoiceConstructor = function (props) {
603
598
  name: defaultCustomer.name,
604
599
  });
605
600
  }
606
- var _10 = (0, react_1.useState)(undefined), billingLinesMetadata = _10[0], setBillingLinesMetadata = _10[1];
601
+ var _8 = (0, react_1.useState)(undefined), billingLinesMetadata = _8[0], setBillingLinesMetadata = _8[1];
607
602
  var getBillingLines = function (changedValues, allValues) {
608
603
  var invoiceLines = allValues.invoice.invoiceLines;
609
604
  if (invoiceLines) {
@@ -660,6 +655,12 @@ var CreateInvoiceConstructor = function (props) {
660
655
  }
661
656
  }, scrollToFirstError: true, onValuesChange: function (changedValues, allValues) {
662
657
  getBillingLines(changedValues, allValues);
658
+ // Skip validation for description field of attachments for performance reasons
659
+ if (changedValues.attachments)
660
+ return;
661
+ setTimeout(function () {
662
+ validateFields();
663
+ }, 0);
663
664
  } }, formLayout_1.formItemLayout, { form: form, onFinish: function (_values) { return handleSubmit(_values); }, onFinishFailed: function (error) {
664
665
  // tslint:disable-next-line:no-console
665
666
  console.log(error);
@@ -10,6 +10,42 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
50
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
51
  if (ar || !(i in from)) {
@@ -31,6 +67,7 @@ var axios_1 = __importDefault(require("axios"));
31
67
  var antd_1 = require("antd");
32
68
  var create_invoice_1 = require("../create-invoice");
33
69
  var AttachmentUploadStatus_1 = require("../common/components/submit-confirmation/AttachmentUploadStatus");
70
+ var chardet_1 = __importDefault(require("chardet"));
34
71
  var initialiseTransactionApi = function (mapiBaseUrl) {
35
72
  var apiConfig = {
36
73
  basePath: mapiBaseUrl,
@@ -78,20 +115,55 @@ var submitDocument = function (data, attachDocument, mapiBaseUrl, apiKey) {
78
115
  // )
79
116
  };
80
117
  exports.submitDocument = submitDocument;
81
- var submitDocumentFetch = function (data, attachDocument, mapiBaseUrl, token) {
82
- var messageId = attachDocument.messageId, name = attachDocument.name, contentType = attachDocument.contentType, more = attachDocument.more;
83
- var headers = {
84
- Authorization: "Bearer ".concat(token),
85
- "Content-Type": "application/octet-stream",
86
- "X-test": "test",
87
- };
88
- var responsePromise = fetch("".concat(mapiBaseUrl, "/api/v1/messages/").concat(messageId, "/documents?Name=").concat(name, "&ContentType=").concat(contentType, "&More=").concat(more), {
89
- method: "POST",
90
- headers: headers,
91
- body: data
118
+ function getEncoding(file) {
119
+ var _a;
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var bytes, _b;
122
+ return __generator(this, function (_c) {
123
+ switch (_c.label) {
124
+ case 0:
125
+ _b = Uint8Array.bind;
126
+ return [4 /*yield*/, file.arrayBuffer()];
127
+ case 1:
128
+ bytes = new (_b.apply(Uint8Array, [void 0, _c.sent()]))();
129
+ return [2 /*return*/, (_a = chardet_1.default.detect(bytes)) !== null && _a !== void 0 ? _a : "utf-8"];
130
+ }
131
+ });
92
132
  });
93
- return responsePromise;
94
- };
133
+ }
134
+ var submitDocumentFetch = function (data, attachDocument, mapiBaseUrl, token) { return __awaiter(void 0, void 0, void 0, function () {
135
+ var messageId, name, contentType, more, headers, params, _a, _b, _c, responsePromise;
136
+ return __generator(this, function (_d) {
137
+ switch (_d.label) {
138
+ case 0:
139
+ messageId = attachDocument.messageId, name = attachDocument.name, contentType = attachDocument.contentType, more = attachDocument.more;
140
+ headers = {
141
+ Authorization: "Bearer ".concat(token),
142
+ "Content-Type": "application/octet-stream",
143
+ "X-test": "test",
144
+ };
145
+ params = new URLSearchParams({
146
+ Name: name,
147
+ More: String(more),
148
+ // ContentType does not work correctly here for "application/pdf", so we add it manually to the fetch path
149
+ });
150
+ if (!(contentType === "text/csv" || data.type === "text/csv")) return [3 /*break*/, 2];
151
+ _b = (_a = params).set;
152
+ _c = ["Encoding"];
153
+ return [4 /*yield*/, getEncoding(data)];
154
+ case 1:
155
+ _b.apply(_a, _c.concat([_d.sent()]));
156
+ _d.label = 2;
157
+ case 2:
158
+ responsePromise = fetch("".concat(mapiBaseUrl, "/api/v1/messages/").concat(messageId, "/documents?ContentType=").concat(contentType, "&").concat(params.toString()), {
159
+ method: "POST",
160
+ headers: headers,
161
+ body: data
162
+ });
163
+ return [2 /*return*/, responsePromise];
164
+ }
165
+ });
166
+ }); };
95
167
  exports.submitDocumentFetch = submitDocumentFetch;
96
168
  var submitInvoice = function (createSubmitInvoice, mapiBaseUrl, token, callName, language) {
97
169
  var transactionApi = initialiseTransactionApi(mapiBaseUrl);
@@ -1,4 +1,15 @@
1
1
  import { SubmittingStatus } from "../common/components/submit-confirmation/AttachmentUploadStatus";
2
- declare const getSubmittingStatus: (name: string, failedUploads: string[], attachments: string[], numberOfAttemptedCalls: number) => SubmittingStatus;
2
+ import { AttachmentType } from "../common/components/attachments";
3
+ import { FormInstance } from "antd/es/form";
4
+ import { UploadFile } from "antd/es/upload/interface";
5
+ import { Dispatch, SetStateAction } from "react";
6
+ import { UploadChangeParam } from "antd/lib/upload";
7
+ import { IntlShape } from "react-intl";
3
8
  declare const isRetryButtonVisible: (numberOfAttemptedCalls: number, totalNumberOfCalls: number, numberOfSuccessfulCalls: number, numberOfFailedUploads: number, alreadyRetried: boolean, invoiceSubmittingStatus: SubmittingStatus) => boolean;
4
- export { getSubmittingStatus, isRetryButtonVisible };
9
+ declare const updateFormState: (attachmentsForForm: AttachmentType[], form: FormInstance) => void;
10
+ declare const hasDuplicateDescriptions: (attachments: AttachmentType[]) => boolean;
11
+ declare const hasEmptyDescriptions: (attachments: AttachmentType[]) => boolean;
12
+ declare const hasInvalidStatus: (attachments: AttachmentType[]) => boolean;
13
+ declare const updateFile: (file: UploadFile, updatedProps: Partial<AttachmentType>, setLocalAttachments: Dispatch<SetStateAction<AttachmentType[]>>) => void;
14
+ declare const verifyAttachment: (info: UploadChangeParam, sizeLimit: number, remove: (file: UploadFile) => void, intl: IntlShape, setLocalAttachments: Dispatch<SetStateAction<AttachmentType[]>>) => void;
15
+ export { isRetryButtonVisible, updateFormState, hasDuplicateDescriptions, hasEmptyDescriptions, hasInvalidStatus, updateFile, verifyAttachment };
@@ -1,17 +1,29 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
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
+ };
2
22
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRetryButtonVisible = exports.getSubmittingStatus = void 0;
23
+ exports.verifyAttachment = exports.updateFile = exports.hasInvalidStatus = exports.hasEmptyDescriptions = exports.hasDuplicateDescriptions = exports.updateFormState = exports.isRetryButtonVisible = void 0;
4
24
  var AttachmentUploadStatus_1 = require("../common/components/submit-confirmation/AttachmentUploadStatus");
5
- var getSubmittingStatus = function (name, failedUploads, attachments, numberOfAttemptedCalls) {
6
- var index = attachments.findIndex(function (att) { return att === name; });
7
- if (failedUploads.includes(name))
8
- return AttachmentUploadStatus_1.SubmittingStatus.Failed;
9
- if (index < numberOfAttemptedCalls && !failedUploads.includes(name))
10
- return AttachmentUploadStatus_1.SubmittingStatus.Done;
11
- if (index <= numberOfAttemptedCalls || index > numberOfAttemptedCalls)
12
- return AttachmentUploadStatus_1.SubmittingStatus.Pending;
13
- };
14
- exports.getSubmittingStatus = getSubmittingStatus;
25
+ var FileUploadUtility_1 = require("./FileUploadUtility");
26
+ var AttachmentModal_1 = require("../common/components/attachments/AttachmentModal");
15
27
  var isRetryButtonVisible = function (numberOfAttemptedCalls, totalNumberOfCalls, numberOfSuccessfulCalls, numberOfFailedUploads, alreadyRetried, invoiceSubmittingStatus) {
16
28
  if (invoiceSubmittingStatus === AttachmentUploadStatus_1.SubmittingStatus.Failed)
17
29
  return true;
@@ -20,3 +32,78 @@ var isRetryButtonVisible = function (numberOfAttemptedCalls, totalNumberOfCalls,
20
32
  }
21
33
  };
22
34
  exports.isRetryButtonVisible = isRetryButtonVisible;
35
+ var updateFormState = function (attachmentsForForm, form) {
36
+ var fields = [];
37
+ // Populate existing attachments into fields
38
+ attachmentsForForm.forEach(function (attachment, index) {
39
+ fields.push({
40
+ name: ["attachments", "file".concat(index + 1), "file"],
41
+ value: attachment.file,
42
+ }, {
43
+ name: ["attachments", "file".concat(index + 1), "description"],
44
+ value: attachment.description,
45
+ });
46
+ });
47
+ // Clear any remaining attachment fields
48
+ for (var i = attachmentsForForm.length + 1; i <= 3; i++) {
49
+ fields.push({
50
+ name: ["attachments", "file".concat(i), "file"],
51
+ value: undefined,
52
+ }, {
53
+ name: ["attachments", "file".concat(i), "description"],
54
+ value: undefined,
55
+ });
56
+ }
57
+ form.setFields(fields);
58
+ };
59
+ exports.updateFormState = updateFormState;
60
+ var hasDuplicateDescriptions = function (attachments) {
61
+ var descriptions = attachments
62
+ .map(function (attachment) { return attachment.description.trim(); })
63
+ .filter(Boolean);
64
+ return new Set(descriptions).size !== descriptions.length;
65
+ };
66
+ exports.hasDuplicateDescriptions = hasDuplicateDescriptions;
67
+ var hasEmptyDescriptions = function (attachments) {
68
+ return attachments.some(function (attachment) { return !attachment.description.trim(); });
69
+ };
70
+ exports.hasEmptyDescriptions = hasEmptyDescriptions;
71
+ var hasInvalidStatus = function (attachments) {
72
+ return attachments.some(function (attachment) { return attachment.fieldValidation !== "success"; });
73
+ };
74
+ exports.hasInvalidStatus = hasInvalidStatus;
75
+ var updateFile = function (file, updatedProps, setLocalAttachments) {
76
+ setLocalAttachments(function (prev) {
77
+ var fileIndex = prev.findIndex(function (attachment) { return attachment.file.uid === file.uid; });
78
+ if (fileIndex === -1) {
79
+ // If not found then add attachment
80
+ return __spreadArray(__spreadArray([], prev, true), [
81
+ __assign({ uid: file.uid, file: file, description: "", fieldValidation: "" }, updatedProps),
82
+ ], false);
83
+ }
84
+ return prev.map(function (attachment) {
85
+ // Else if found - update
86
+ return attachment.file.uid === file.uid
87
+ ? __assign(__assign({}, attachment), updatedProps) : attachment;
88
+ });
89
+ });
90
+ };
91
+ exports.updateFile = updateFile;
92
+ var verifyAttachment = function (info, sizeLimit, remove, intl, setLocalAttachments) {
93
+ if (info.file.status === "removed")
94
+ return;
95
+ var isValid = (0, FileUploadUtility_1.reportIfFileIsValid)(info.file, sizeLimit, {
96
+ uploadErrorToLarge: intl.formatMessage(AttachmentModal_1.translationMessages.attachment_error_fileTooLarge, {
97
+ uploadSizeLimit: sizeLimit / 1024,
98
+ }),
99
+ uploadErrorWrongType: intl.formatMessage(AttachmentModal_1.translationMessages.attachment_error_fileWrongType),
100
+ uploadFailed: intl.formatMessage(AttachmentModal_1.translationMessages.attachment_error_fileFailedToUpload),
101
+ });
102
+ if (isValid) {
103
+ updateFile(info.file, { file: __assign({}, info.file), fieldValidation: "success" }, setLocalAttachments);
104
+ }
105
+ else {
106
+ remove(info.file);
107
+ }
108
+ };
109
+ exports.verifyAttachment = verifyAttachment;
@@ -6,4 +6,5 @@ declare const reportIfFileIsValid: (file: UploadFile, uploadSizeLimit: number, e
6
6
  uploadErrorToLarge: string;
7
7
  }) => boolean;
8
8
  declare const getBase64: (file: Blob) => Promise<string | ArrayBuffer | null>;
9
- export { validFileTypes, reportIfFileIsValid, getBase64 };
9
+ declare const getFileListFromEvent: (e: any) => any;
10
+ export { validFileTypes, reportIfFileIsValid, getBase64, getFileListFromEvent };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBase64 = exports.reportIfFileIsValid = exports.validFileTypes = void 0;
3
+ exports.getFileListFromEvent = exports.getBase64 = exports.reportIfFileIsValid = exports.validFileTypes = void 0;
4
4
  var antd_1 = require("antd");
5
5
  var validFileTypes = [
6
6
  "application/pdf",
@@ -43,3 +43,12 @@ var getBase64 = function (file) {
43
43
  });
44
44
  };
45
45
  exports.getBase64 = getBase64;
46
+ var getFileListFromEvent = function (e) {
47
+ if (!e)
48
+ return;
49
+ if (Array.isArray(e)) {
50
+ return e;
51
+ }
52
+ return e.fileList;
53
+ };
54
+ exports.getFileListFromEvent = getFileListFromEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unimaze/billing",
3
- "version": "0.21.69",
3
+ "version": "0.21.71",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -11,6 +11,7 @@
11
11
  "@ant-design/compatible": "latest",
12
12
  "@unimaze/api-clients": "3.2.0",
13
13
  "antd-mask-input": "^0.1.13",
14
+ "chardet": "^2.2.0",
14
15
  "dayjs": "^1.11.10",
15
16
  "lodash": "^4.17.21",
16
17
  "react-hot-loader": "^4.12.20",