@unimaze/billing 0.20.16 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/lib/common/components/CommonTranslations.d.ts +102 -2
  2. package/lib/common/components/CommonTranslations.js +10 -1
  3. package/lib/common/components/attachments/Attachment.d.ts +6 -4
  4. package/lib/common/components/attachments/Attachment.js +26 -10
  5. package/lib/common/components/attachments/AttachmentModal.d.ts +21 -0
  6. package/lib/common/components/attachments/AttachmentModal.js +195 -0
  7. package/lib/common/components/attachments/index.d.ts +13 -17
  8. package/lib/common/components/attachments/index.js +189 -23
  9. package/lib/common/components/base-information/AccountingCost.d.ts +7 -5
  10. package/lib/common/components/base-information/AccountingCost.js +32 -11
  11. package/lib/common/components/base-information/OrderReference.d.ts +6 -4
  12. package/lib/common/components/base-information/OrderReference.js +31 -14
  13. package/lib/common/components/base-information/ProjectReference.d.ts +9 -5
  14. package/lib/common/components/base-information/ProjectReference.js +8 -6
  15. package/lib/common/components/base-information/ReferenceIdentifiers.d.ts +32 -5
  16. package/lib/common/components/base-information/ReferenceIdentifiers.js +126 -83
  17. package/lib/common/components/base-information/index.d.ts +51 -5
  18. package/lib/common/components/base-information/index.js +99 -154
  19. package/lib/common/components/billing-lines/BillingCalculations.d.ts +7 -5
  20. package/lib/common/components/billing-lines/BillingCalculations.js +79 -46
  21. package/lib/common/components/billing-lines/BillingLinePreview.d.ts +21 -0
  22. package/lib/common/components/billing-lines/BillingLinePreview.js +41 -0
  23. package/lib/common/components/billing-lines/BillingTaxSummary.d.ts +6 -4
  24. package/lib/common/components/billing-lines/BillingTaxSummary.js +39 -13
  25. package/lib/common/components/billing-lines/NewBillingLines.d.ts +120 -4
  26. package/lib/common/components/billing-lines/NewBillingLines.js +396 -72
  27. package/lib/common/components/billing-lines/index.d.ts +33 -6
  28. package/lib/common/components/billing-lines/index.js +71 -244
  29. package/lib/common/components/component-container/Content.d.ts +2 -2
  30. package/lib/common/components/component-container/index.d.ts +1 -0
  31. package/lib/common/components/component-container/index.js +1 -1
  32. package/lib/common/components/customer/CostCenter.d.ts +6 -4
  33. package/lib/common/components/customer/CostCenter.js +25 -9
  34. package/lib/common/components/customer/CustomerContactName.d.ts +6 -4
  35. package/lib/common/components/customer/CustomerContactName.js +24 -8
  36. package/lib/common/components/customer/hardCoddedCustomer.js +19 -3
  37. package/lib/common/components/customer/index.d.ts +11 -5
  38. package/lib/common/components/customer/index.js +97 -42
  39. package/lib/common/components/date-picker/index.d.ts +21 -0
  40. package/lib/common/components/date-picker/index.js +23 -0
  41. package/lib/common/components/delivery-location/index.d.ts +6 -4
  42. package/lib/common/components/delivery-location/index.js +20 -4
  43. package/lib/common/components/editable-cell/index.js +2 -2
  44. package/lib/common/components/editable-row/index.d.ts +1 -1
  45. package/lib/common/components/editable-row/index.js +24 -7
  46. package/lib/common/components/form-item/index.d.ts +13 -6
  47. package/lib/common/components/form-item/index.js +16 -20
  48. package/lib/common/components/index.d.ts +10 -0
  49. package/lib/common/components/index.js +30 -8
  50. package/lib/common/components/input/index.d.ts +23 -0
  51. package/lib/common/components/input/index.js +37 -0
  52. package/lib/common/components/invoice/index.d.ts +40 -0
  53. package/lib/common/components/invoice/index.js +52 -0
  54. package/lib/common/components/invoice-preview/InvoicePreviewHeader.d.ts +12 -0
  55. package/lib/common/components/invoice-preview/InvoicePreviewHeader.js +105 -0
  56. package/lib/common/components/invoice-preview/index.d.ts +16 -0
  57. package/lib/common/components/invoice-preview/index.js +393 -0
  58. package/lib/common/components/locale-intl/index.d.ts +0 -10
  59. package/lib/common/components/locale-intl/index.js +50 -42
  60. package/lib/common/components/payment-method/index.d.ts +69 -6
  61. package/lib/common/components/payment-method/index.js +145 -57
  62. package/lib/common/components/payment-method/paymentMethodForConversion.js +3 -1
  63. package/lib/common/components/submit-confirmation/SubmitConfirmationSVG.d.ts +3 -0
  64. package/lib/common/components/submit-confirmation/SubmitConfirmationSVG.js +17 -0
  65. package/lib/common/components/submit-confirmation/index.d.ts +8 -0
  66. package/lib/common/components/submit-confirmation/index.js +34 -0
  67. package/lib/common/components/supplier/CityAutofill.d.ts +18 -0
  68. package/lib/common/components/supplier/CityAutofill.js +159 -0
  69. package/lib/common/components/supplier/index.d.ts +79 -5
  70. package/lib/common/components/supplier/index.js +195 -103
  71. package/lib/common/components/tooltip/index.d.ts +7 -0
  72. package/lib/common/components/tooltip/index.js +15 -0
  73. package/lib/common/components/welcome-modal/index.d.ts +15 -0
  74. package/lib/common/components/welcome-modal/index.js +26 -0
  75. package/lib/common/consts/formLayout.js +4 -3
  76. package/lib/common/consts/validationRules.d.ts +1 -1
  77. package/lib/common/consts/validationRules.js +6 -0
  78. package/lib/common/enums/index.js +5 -1
  79. package/lib/common/style/index.css +18 -0
  80. package/lib/common/types/BillingLineMetadataOverride.d.ts +2 -0
  81. package/lib/common/types/CommonProps.d.ts +15 -1
  82. package/lib/common/types/DiscountType.d.ts +1 -0
  83. package/lib/common/types/DiscountType.js +2 -0
  84. package/lib/common/types/ReceiverRequirements.d.ts +1 -1
  85. package/lib/common/types/ReceiverRequirements.js +1 -0
  86. package/lib/common/types/index.js +15 -0
  87. package/lib/create-invoice/IntlLoader.d.ts +0 -6
  88. package/lib/create-invoice/IntlLoader.js +78 -13
  89. package/lib/create-invoice/index.d.ts +65 -4
  90. package/lib/create-invoice/index.js +437 -181
  91. package/lib/enums.d.ts +2 -3
  92. package/lib/enums.js +1 -0
  93. package/lib/index.js +22 -6
  94. package/lib/translations/locales/en.json +181 -0
  95. package/lib/translations/locales/is.json +135 -116
  96. package/lib/translations/locales.d.ts +360 -161
  97. package/lib/translations/locales.js +3 -2
  98. package/lib/utils/ApiUtility.d.ts +4 -4
  99. package/lib/utils/ApiUtility.js +13 -10
  100. package/lib/utils/BillingLineUtility.d.ts +16 -5
  101. package/lib/utils/BillingLineUtility.js +65 -26
  102. package/lib/utils/ConversionUtility.js +15 -7
  103. package/lib/utils/FileUploadUtility.d.ts +4 -2
  104. package/lib/utils/FileUploadUtility.js +28 -9
  105. package/lib/utils/IntlUtility.d.ts +3 -2
  106. package/lib/utils/IntlUtility.js +2 -1
  107. package/lib/utils/LocationUtility.d.ts +1 -0
  108. package/lib/utils/LocationUtility.js +81 -0
  109. package/lib/utils/ReferenceIdentifierUtility.js +2 -1
  110. package/lib/utils/RequirementsUtility.d.ts +9 -7
  111. package/lib/utils/RequirementsUtility.js +46 -22
  112. package/lib/utils/index.js +4 -3
  113. package/package.json +36 -18
  114. package/lib/style/index.css +0 -51
@@ -1,2 +1,102 @@
1
- /// <reference types="react-intl" />
2
- export declare const commonTranslationMessages: ReactIntl.Messages<"taxCategoryType_labels_StandardRated" | "taxCategoryType_labels_ReducedRated" | "taxCategoryType_labels_ZeroRated" | "taxCategoryType_labels_Exempt" | "taxCategoryType_labels_OutsideTaxScope" | "taxCategoryType_labels_ReverseCharged" | "taxCategoryType_labels_FreeExportTaxNotCharged" | "taxCategoryType_labels_ExemptEuropeanEconomicArea" | "unitOfMeasure_labels_Piece" | "unitOfMeasure_labels_Kilogram" | "unitOfMeasure_labels_Month" | "unitOfMeasure_labels_Package" | "unitOfMeasure_labels_Year" | "unitOfMeasure_labels_Day" | "unitOfMeasure_labels_Hour" | "unitOfMeasure_labels_Kilometre" | "unitOfMeasure_labels_Metre" | "unitOfMeasure_labels_Litre" | "unitOfMeasure_labels_SquareMetre" | "unitOfMeasure_labels_CubicMetre" | "unitOfMeasure_labels_Tonne" | "unitOfMeasure_labels_KiloWattHour" | "unitOfMeasure_labels_One">;
1
+ export declare const commonTranslationMessages: {
2
+ taxCategoryType_labels_StandardRated: {
3
+ id: string;
4
+ defaultMessage: string;
5
+ };
6
+ taxCategoryType_labels_ReducedRated: {
7
+ id: string;
8
+ defaultMessage: string;
9
+ };
10
+ taxCategoryType_labels_ZeroRated: {
11
+ id: string;
12
+ defaultMessage: string;
13
+ };
14
+ taxCategoryType_labels_Exempt: {
15
+ id: string;
16
+ defaultMessage: string;
17
+ };
18
+ taxCategoryType_labels_OutsideTaxScope: {
19
+ id: string;
20
+ defaultMessage: string;
21
+ };
22
+ taxCategoryType_labels_ReverseCharged: {
23
+ id: string;
24
+ defaultMessage: string;
25
+ };
26
+ taxCategoryType_labels_FreeExportTaxNotCharged: {
27
+ id: string;
28
+ defaultMessage: string;
29
+ };
30
+ taxCategoryType_labels_ExemptEuropeanEconomicArea: {
31
+ id: string;
32
+ defaultMessage: string;
33
+ };
34
+ unitOfMeasure_labels_Piece: {
35
+ id: string;
36
+ defaultMessage: string;
37
+ };
38
+ unitOfMeasure_labels_Kilogram: {
39
+ id: string;
40
+ defaultMessage: string;
41
+ };
42
+ unitOfMeasure_labels_Month: {
43
+ id: string;
44
+ defaultMessage: string;
45
+ };
46
+ unitOfMeasure_labels_Package: {
47
+ id: string;
48
+ defaultMessage: string;
49
+ };
50
+ unitOfMeasure_labels_Year: {
51
+ id: string;
52
+ defaultMessage: string;
53
+ };
54
+ unitOfMeasure_labels_Day: {
55
+ id: string;
56
+ defaultMessage: string;
57
+ };
58
+ unitOfMeasure_labels_Hour: {
59
+ id: string;
60
+ defaultMessage: string;
61
+ };
62
+ unitOfMeasure_labels_Kilometre: {
63
+ id: string;
64
+ defaultMessage: string;
65
+ };
66
+ unitOfMeasure_labels_Metre: {
67
+ id: string;
68
+ defaultMessage: string;
69
+ };
70
+ unitOfMeasure_labels_Litre: {
71
+ id: string;
72
+ defaultMessage: string;
73
+ };
74
+ unitOfMeasure_labels_SquareMetre: {
75
+ id: string;
76
+ defaultMessage: string;
77
+ };
78
+ unitOfMeasure_labels_CubicMetre: {
79
+ id: string;
80
+ defaultMessage: string;
81
+ };
82
+ unitOfMeasure_labels_Tonne: {
83
+ id: string;
84
+ defaultMessage: string;
85
+ };
86
+ unitOfMeasure_labels_KiloWattHour: {
87
+ id: string;
88
+ defaultMessage: string;
89
+ };
90
+ unitOfMeasure_labels_One: {
91
+ id: string;
92
+ defaultMessage: string;
93
+ };
94
+ saveInformation_label: {
95
+ id: string;
96
+ defaultMessage: string;
97
+ };
98
+ missingRequiredData: {
99
+ id: string;
100
+ defaultMessage: string;
101
+ };
102
+ };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commonTranslationMessages = void 0;
3
4
  var react_intl_1 = require("react-intl");
4
- exports.commonTranslationMessages = react_intl_1.defineMessages({
5
+ exports.commonTranslationMessages = (0, react_intl_1.defineMessages)({
5
6
  taxCategoryType_labels_StandardRated: {
6
7
  id: "taxCategoryType_labels_StandardRated",
7
8
  defaultMessage: "Standard rated",
@@ -94,4 +95,12 @@ exports.commonTranslationMessages = react_intl_1.defineMessages({
94
95
  id: "unitOfMeasure_labels_One",
95
96
  defaultMessage: "One",
96
97
  },
98
+ saveInformation_label: {
99
+ id: "saveInformation_label",
100
+ defaultMessage: "Save information",
101
+ },
102
+ missingRequiredData: {
103
+ id: "missingRequiredData",
104
+ defaultMessage: "Missing required data:",
105
+ },
97
106
  });
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
- import { InjectedIntlProps } from "react-intl";
2
+ import { WrappedComponentProps } from "react-intl";
3
3
  import { FormInstance } from "antd/es/form";
4
4
  import { ValidateStatus } from "antd/lib/form/FormItem";
5
5
  import { UploadFile } from "antd/es/upload/interface";
6
- interface Props extends InjectedIntlProps {
6
+ interface Props extends WrappedComponentProps {
7
7
  fieldName: "file1" | "file2" | "file3";
8
8
  formInstance: FormInstance;
9
9
  uploadSizeLimit: number;
@@ -12,7 +12,9 @@ interface Props extends InjectedIntlProps {
12
12
  attachmentFieldValidation: ValidateStatus;
13
13
  setAttachmentFieldValidation: (attachmentFieldValidation: ValidateStatus) => void;
14
14
  }
15
- declare const _default: React.ComponentClass<Pick<Props, "file" | "fieldName" | "formInstance" | "uploadSizeLimit" | "setFile" | "attachmentFieldValidation" | "setAttachmentFieldValidation">, any> & {
16
- WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
15
+ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omit<Props, "intl"> & {
16
+ forwardedRef?: React.Ref<any> | undefined;
17
+ } & React.RefAttributes<any>> & {
18
+ WrappedComponent: React.ComponentType<Props>;
17
19
  };
18
20
  export default _default;
@@ -10,11 +10,27 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
13
29
  var __importStar = (this && this.__importStar) || function (mod) {
14
30
  if (mod && mod.__esModule) return mod;
15
31
  var result = {};
16
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
17
- result["default"] = mod;
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
18
34
  return result;
19
35
  };
20
36
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -24,7 +40,7 @@ var antd_1 = require("antd");
24
40
  var react_intl_1 = require("react-intl");
25
41
  var formLayout_1 = require("../../consts/formLayout");
26
42
  var FileUploadUtility_1 = require("../../../utils/FileUploadUtility");
27
- var translationMessages = react_intl_1.defineMessages({
43
+ var translationMessages = (0, react_intl_1.defineMessages)({
28
44
  attachment_labels_Reference: {
29
45
  id: "attachment_labels_Reference",
30
46
  defaultMessage: "Reference",
@@ -94,13 +110,13 @@ var Attachment = function (props) {
94
110
  if (info.file.status === "removed")
95
111
  return;
96
112
  props.setAttachmentFieldValidation("validating");
97
- var ifFileIsValid = FileUploadUtility_1.reportIfFileIsValid(info.file, uploadSizeLimit, {
113
+ var ifFileIsValid = (0, FileUploadUtility_1.reportIfFileIsValid)(info.file, uploadSizeLimit, {
98
114
  uploadErrorToLarge: props.intl.formatMessage(translationMessages.attachment_error_fileTooLarge, { uploadSizeLimit: uploadSizeLimit / 1024 }),
99
115
  uploadErrorWrongType: props.intl.formatMessage(translationMessages.attachment_error_fileWrongType),
100
- uploadFailed: props.intl.formatMessage(translationMessages.attachment_error_fileFailedToUpload),
116
+ uploadFailed: props.intl.formatMessage(translationMessages.attachment_error_fileFailedToUpload), // "failed",
101
117
  });
102
118
  if (!ifFileIsValid) {
103
- formInstance.resetFields(["attachments", "" + props.fieldName, "file"]);
119
+ formInstance.resetFields(["attachments", "".concat(props.fieldName), "file"]);
104
120
  props.setAttachmentFieldValidation("error");
105
121
  props.setFile([]);
106
122
  }
@@ -110,12 +126,12 @@ var Attachment = function (props) {
110
126
  }
111
127
  };
112
128
  return (React.createElement(React.Fragment, null,
113
- React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemVerticalLayout, { label: props.intl.formatMessage(translationMessages.attachment_labels_File), name: ["attachments", "" + fieldName, "file"], valuePropName: "fileList", getValueFromEvent: normFile, validateStatus: props.attachmentFieldValidation }),
114
- React.createElement(antd_1.Upload.Dragger, { name: "attachment:" + fieldName, multiple: false, onRemove: handleRemoveFile, onChange: function (info) {
129
+ React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemVerticalLayout, { label: props.intl.formatMessage(translationMessages.attachment_labels_File), name: ["attachments", "".concat(fieldName), "file"], valuePropName: "fileList", getValueFromEvent: normFile, validateStatus: props.attachmentFieldValidation }),
130
+ React.createElement(antd_1.Upload.Dragger, { name: "attachment:".concat(fieldName), multiple: false, onRemove: handleRemoveFile, onChange: function (info) {
115
131
  verifyTheAttachment(info, props.uploadSizeLimit, props.formInstance);
116
132
  }, beforeUpload: function (file) { return false; }, fileList: props.file },
117
133
  React.createElement("p", null, props.intl.formatMessage(translationMessages.attachment_labels_uploadFileMsg)))),
118
- React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemVerticalLayout, { label: props.intl.formatMessage(translationMessages.attachment_labels_Description), name: ["attachments", "" + fieldName, "description"], rules: [
134
+ React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemVerticalLayout, { label: props.intl.formatMessage(translationMessages.attachment_labels_Description), name: ["attachments", "".concat(fieldName), "description"], rules: [
119
135
  {
120
136
  required: props.file.length > 0,
121
137
  message: props.intl.formatMessage(translationMessages.attachment_labels_Description_requiredMessage),
@@ -145,4 +161,4 @@ var Attachment = function (props) {
145
161
  ] }),
146
162
  React.createElement(antd_1.Input, null))));
147
163
  };
148
- exports.default = react_intl_1.injectIntl(React.memo(Attachment));
164
+ exports.default = (0, react_intl_1.injectIntl)(React.memo(Attachment));
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ import { WrappedComponentProps } from "react-intl";
3
+ import { FormInstance } from "antd/es/form";
4
+ import { UploadFile } from "antd/es/upload/interface";
5
+ import { AttachmentType } from ".";
6
+ interface AttachmentModalProps extends WrappedComponentProps {
7
+ isModalOpen: boolean;
8
+ setIsModalOpen: (isModalOpen: boolean) => void;
9
+ attachments: AttachmentType[];
10
+ setAttachments: (attachments: AttachmentType[]) => void;
11
+ uploadSizeLimit: number;
12
+ formInstance: FormInstance;
13
+ onRemove: (file: UploadFile) => void;
14
+ onSave: () => void;
15
+ }
16
+ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omit<AttachmentModalProps, "intl"> & {
17
+ forwardedRef?: React.Ref<any> | undefined;
18
+ } & React.RefAttributes<any>> & {
19
+ WrappedComponent: React.ComponentType<AttachmentModalProps>;
20
+ };
21
+ export default _default;
@@ -0,0 +1,195 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
37
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
38
+ if (ar || !(i in from)) {
39
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
40
+ ar[i] = from[i];
41
+ }
42
+ }
43
+ return to.concat(ar || Array.prototype.slice.call(from));
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ var React = __importStar(require("react"));
47
+ var react_intl_1 = require("react-intl");
48
+ var antd_1 = require("antd");
49
+ var icons_1 = require("@ant-design/icons");
50
+ var FileUploadUtility_1 = require("../../../utils/FileUploadUtility");
51
+ var lib_1 = require("antd/lib");
52
+ var formLayout_1 = require("../../consts/formLayout");
53
+ var translationMessages = (0, react_intl_1.defineMessages)({
54
+ attachment_title: {
55
+ id: "attachment_title",
56
+ defaultMessage: "Attachments",
57
+ },
58
+ attachment_saveButton_title: {
59
+ id: "attachment_saveButton_title",
60
+ defaultMessage: "Save attachments",
61
+ },
62
+ attachment_error_fileTooLarge: {
63
+ id: "attachment_error_fileTooLarge",
64
+ defaultMessage: "File size must be less than {uploadSizeLimit}KB",
65
+ },
66
+ attachment_error_fileWrongType: {
67
+ id: "attachment_error_fileWrongType",
68
+ defaultMessage: "Wrong file type",
69
+ },
70
+ attachment_error_fileFailedToUpload: {
71
+ id: "attachment_error_fileFailedToUpload",
72
+ defaultMessage: "File failed to upload",
73
+ },
74
+ attachment_labels_uploadFileMsg: {
75
+ id: "attachment_labels_uploadFileMsg",
76
+ defaultMessage: "Upload attachment",
77
+ },
78
+ attachment_labels_onUploadFileMsg: {
79
+ id: "attachment_labels_onUploadFileMsg",
80
+ defaultMessage: "Uploading",
81
+ },
82
+ attachment_labels_Description_requiredMessage: {
83
+ id: "attachment_labels_Description_requiredMessage",
84
+ defaultMessage: "Please input the description",
85
+ },
86
+ attachment_labels_Description: {
87
+ id: "attachment_labels_Description",
88
+ defaultMessage: "Description",
89
+ },
90
+ });
91
+ var AttachmentModal = function (props) {
92
+ var _a = React.useState(false), isUploading = _a[0], setIsUploading = _a[1];
93
+ var _b = React.useState(true), isSaveAttachmentsDisabled = _b[0], setIsSaveAttachmentsDisabled = _b[1];
94
+ var normFile = function (e) {
95
+ if (!e)
96
+ return;
97
+ if (Array.isArray(e)) {
98
+ return e;
99
+ }
100
+ return e.fileList;
101
+ };
102
+ var updateFile = function (file, updatedProps) {
103
+ var fileIndex = props.attachments.findIndex(function (attachment) { return attachment.file.uid === file.uid; });
104
+ if (fileIndex === -1) {
105
+ props.setAttachments(__spreadArray(__spreadArray([], props.attachments, true), [{ uid: file.uid, file: file, description: "", fieldValidation: "" }], false));
106
+ }
107
+ else {
108
+ var updatedAttachments = props.attachments.map(function (attachment) {
109
+ if (attachment.file.uid === file.uid) {
110
+ return __assign(__assign({}, attachment), updatedProps);
111
+ }
112
+ return attachment;
113
+ });
114
+ props.setAttachments(updatedAttachments);
115
+ }
116
+ };
117
+ React.useEffect(function () {
118
+ var _isSaveAttachmentsDisabled = props.attachments.some(function (attachment) { return attachment.fieldValidation !== "success" || !attachment.description; });
119
+ setIsSaveAttachmentsDisabled(_isSaveAttachmentsDisabled);
120
+ }, [props.attachments]);
121
+ var verifyAttachment = function (info, uploadSizeLimit, formInstance) {
122
+ if (info.file.status === "removed")
123
+ return;
124
+ var isValid = (0, FileUploadUtility_1.reportIfFileIsValid)(info.file, uploadSizeLimit, {
125
+ uploadErrorToLarge: props.intl.formatMessage(translationMessages.attachment_error_fileTooLarge, {
126
+ uploadSizeLimit: uploadSizeLimit / 1024,
127
+ }),
128
+ uploadErrorWrongType: props.intl.formatMessage(translationMessages.attachment_error_fileWrongType),
129
+ uploadFailed: props.intl.formatMessage(translationMessages.attachment_error_fileFailedToUpload),
130
+ });
131
+ if (!isValid) {
132
+ info.file.status = "error";
133
+ updateFile(info.file, { file: __assign({}, info.file), fieldValidation: "error" });
134
+ }
135
+ else {
136
+ updateFile(info.file, { file: __assign({}, info.file), fieldValidation: "success" });
137
+ }
138
+ };
139
+ var uploadProps = {
140
+ name: "file",
141
+ headers: {
142
+ authorization: "authorization-text",
143
+ },
144
+ accept: FileUploadUtility_1.validFileTypes.join(","),
145
+ showUploadList: false,
146
+ onRemove: function (file) {
147
+ props.onRemove(file);
148
+ },
149
+ onChange: function (info) {
150
+ if (info.file.status === "uploading") {
151
+ setIsUploading(true);
152
+ var fileIndex = props.attachments.findIndex(function (attachment) { return attachment.file.uid === info.file.uid; });
153
+ if (fileIndex === -1) {
154
+ props.setAttachments(__spreadArray(__spreadArray([], props.attachments, true), [
155
+ { uid: info.file.uid, file: info.file, description: "", fieldValidation: "" },
156
+ ], false));
157
+ }
158
+ }
159
+ else if (info.file.status === "done" || info.file.status === "error") {
160
+ setIsUploading(false);
161
+ verifyAttachment(info, props.uploadSizeLimit, props.formInstance);
162
+ }
163
+ },
164
+ fileList: props.attachments.map(function (attachment) { return attachment.file; }),
165
+ disabled: isUploading || props.attachments.length >= 3,
166
+ };
167
+ return (React.createElement(antd_1.Modal, { open: props.isModalOpen, onCancel: function () { return props.setIsModalOpen(false); }, title: props.intl.formatMessage(translationMessages.attachment_title), footer: React.createElement(antd_1.Button, { disabled: isSaveAttachmentsDisabled, icon: React.createElement(icons_1.CheckCircleOutlined, null), type: "primary", style: { width: "100%" }, size: "large", onClick: function () {
168
+ props.onSave();
169
+ props.setIsModalOpen(false);
170
+ } }, props.intl.formatMessage(translationMessages.attachment_saveButton_title)) },
171
+ React.createElement(lib_1.Form.Item, __assign({}, formLayout_1.fullWidthInput, { valuePropName: "fileList", getValueFromEvent: normFile, className: "upload-container" }),
172
+ React.createElement(antd_1.Upload, __assign({}, uploadProps, { style: { width: '100%' } }),
173
+ React.createElement(antd_1.Button, { loading: isUploading, disabled: uploadProps.disabled, icon: React.createElement(icons_1.UploadOutlined, null), size: "large", style: { width: "100%" } }, isUploading
174
+ ? props.intl.formatMessage(translationMessages.attachment_labels_onUploadFileMsg)
175
+ : props.intl.formatMessage(translationMessages.attachment_labels_uploadFileMsg)))),
176
+ props.attachments.length > 0 && (React.createElement(antd_1.Flex, { vertical: true },
177
+ React.createElement(antd_1.Typography.Text, null, props.intl.formatMessage(translationMessages.attachment_title)),
178
+ React.createElement("hr", null),
179
+ props.attachments.map(function (attachment, index) { return (React.createElement(antd_1.Flex, { gap: "middle", vertical: true },
180
+ React.createElement(antd_1.Flex, { gap: "middle", justify: "space-between" },
181
+ React.createElement(antd_1.Typography.Text, { type: attachment.file.status === "error" ? "danger" : undefined },
182
+ React.createElement(icons_1.PaperClipOutlined, null)),
183
+ React.createElement(antd_1.Typography.Text, { type: attachment.file.status === "error" ? "danger" : undefined, style: { width: "100%" } }, attachment.file.name),
184
+ React.createElement(lib_1.Form.Item, { name: ["attachments", "file".concat(index + 1), "file"], initialValue: attachment.file, hidden: true }),
185
+ attachment.file.status === "uploading" ? (React.createElement(icons_1.LoadingOutlined, null)) : (React.createElement(antd_1.Typography.Text, { type: attachment.file.status === "error" ? "danger" : undefined },
186
+ React.createElement(icons_1.DeleteOutlined, { onClick: function () { return props.onRemove(attachment.file); } })))),
187
+ attachment.fieldValidation === "success" && (React.createElement(lib_1.Form.Item, __assign({}, formLayout_1.fullWidthInput, { rules: [
188
+ {
189
+ required: true,
190
+ message: props.intl.formatMessage(translationMessages.attachment_labels_Description_requiredMessage),
191
+ },
192
+ ], name: ["attachments", "file".concat(index + 1), "description"] }),
193
+ React.createElement(antd_1.Input, { prefix: React.createElement(antd_1.Typography.Text, { type: "danger" }, "*"), placeholder: props.intl.formatMessage(translationMessages.attachment_labels_Description), onChange: function (e) { return updateFile(attachment.file, { description: e.target.value }); } }))))); })))));
194
+ };
195
+ exports.default = (0, react_intl_1.injectIntl)(AttachmentModal);
@@ -1,10 +1,10 @@
1
- import * as React from 'react';
2
- import { InjectedIntlProps } from "react-intl";
1
+ import * as React from "react";
2
+ import { WrappedComponentProps } from "react-intl";
3
3
  import { FormInstance } from "antd/es/form";
4
4
  import { LanguageProp } from "../../types/CommonProps";
5
5
  import { UploadFile } from "antd/es/upload/interface";
6
6
  import { ValidateStatus } from "antd/lib/form/FormItem";
7
- interface Props extends InjectedIntlProps {
7
+ interface Props extends WrappedComponentProps {
8
8
  formInstance: FormInstance;
9
9
  uploadSizeLimit: number;
10
10
  attachmentTooltipText?: {
@@ -12,20 +12,16 @@ interface Props extends InjectedIntlProps {
12
12
  en: string;
13
13
  };
14
14
  languageString: LanguageProp;
15
- file1: UploadFile[];
16
- setFile1: (file: UploadFile[]) => void;
17
- attachmentFieldValidation1: ValidateStatus;
18
- setAttachmentFieldValidation1: (attachmentFieldValidation: ValidateStatus) => void;
19
- file2: UploadFile[];
20
- setFile2: (file: UploadFile[]) => void;
21
- attachmentFieldValidation2: ValidateStatus;
22
- setAttachmentFieldValidation2: (attachmentFieldValidation: ValidateStatus) => void;
23
- file3: UploadFile[];
24
- setFile3: (file: UploadFile[]) => void;
25
- attachmentFieldValidation3: ValidateStatus;
26
- setAttachmentFieldValidation3: (attachmentFieldValidation: ValidateStatus) => void;
27
15
  }
28
- declare const AttachmentGroupIntl: React.ComponentClass<Pick<Props, "file1" | "file2" | "file3" | "formInstance" | "uploadSizeLimit" | "attachmentTooltipText" | "languageString" | "setFile1" | "attachmentFieldValidation1" | "setAttachmentFieldValidation1" | "setFile2" | "attachmentFieldValidation2" | "setAttachmentFieldValidation2" | "setFile3" | "attachmentFieldValidation3" | "setAttachmentFieldValidation3">, any> & {
29
- WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
16
+ export type AttachmentType = {
17
+ uid: string;
18
+ file: UploadFile;
19
+ fieldValidation: ValidateStatus;
20
+ description: string;
21
+ };
22
+ declare const AttachmentGroupIntl: React.ForwardRefExoticComponent<import("react-intl").Omit<Props, "intl"> & {
23
+ forwardedRef?: React.Ref<any> | undefined;
24
+ } & React.RefAttributes<any>> & {
25
+ WrappedComponent: React.ComponentType<Props>;
30
26
  };
31
27
  export default AttachmentGroupIntl;