@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.
@@ -22,56 +22,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
62
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
63
27
  };
64
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.translationMessages = void 0;
65
30
  var React = __importStar(require("react"));
66
31
  var react_intl_1 = require("react-intl");
67
32
  var antd_1 = require("antd");
68
33
  var icons_1 = require("@ant-design/icons");
69
34
  var AttachmentModal_1 = __importDefault(require("./AttachmentModal"));
70
35
  var react_use_1 = require("react-use");
71
- var FileUploadUtility_1 = require("../../../utils/FileUploadUtility");
72
- var lodash_1 = __importDefault(require("lodash"));
73
36
  var react_1 = require("react");
74
- var translationMessages = (0, react_intl_1.defineMessages)({
37
+ var AttachmentList_1 = __importDefault(require("./AttachmentList"));
38
+ var AttachmentsUtility_1 = require("../../../utils/AttachmentsUtility");
39
+ exports.translationMessages = (0, react_intl_1.defineMessages)({
75
40
  attachment_title: {
76
41
  id: "attachment_title",
77
42
  defaultMessage: "Attachments",
@@ -86,18 +51,14 @@ var translationMessages = (0, react_intl_1.defineMessages)({
86
51
  },
87
52
  });
88
53
  var AttachmentsGroup = function (props) {
89
- var _a = React.useState(false), isModalOpen = _a[0], setIsModalOpen = _a[1];
90
- var _b = React.useState([]), attachments = _b[0], setAttachments = _b[1];
91
- var _c = (0, react_1.useState)([]), tempAttachments = _c[0], setTempAttachments = _c[1];
92
- var _d = React.useState(false), displayAttachments = _d[0], setDisplayAttachments = _d[1];
93
- var _e = React.useState(false), previewOpen = _e[0], setPreviewOpen = _e[1];
94
- var _f = React.useState(undefined), previewImage = _f[0], setPreviewImage = _f[1];
95
- var _g = React.useState(""), previewDescription = _g[0], setPreviewDescription = _g[1];
96
- var _h = React.useState(""), previewPDFUrl = _h[0], setPreviewPDFUrl = _h[1];
54
+ var formInstance = props.formInstance, uploadSizeLimit = props.uploadSizeLimit, attachmentTooltipText = props.attachmentTooltipText, languageString = props.languageString;
55
+ var _a = (0, react_1.useState)(false), isModalOpen = _a[0], setIsModalOpen = _a[1];
56
+ var _b = (0, react_1.useState)([]), attachments = _b[0], setAttachments = _b[1];
57
+ var _c = (0, react_1.useState)(false), displayAttachmentList = _c[0], setDisplayAttachmentList = _c[1];
58
+ var _d = (0, react_1.useState)(false), isMobile = _d[0], setIsMobile = _d[1];
97
59
  var width = (0, react_use_1.useWindowSize)().width;
98
- var _j = React.useState(false), isMobile = _j[0], setIsMobile = _j[1];
99
60
  var token = antd_1.theme.useToken().token;
100
- React.useEffect(function () {
61
+ (0, react_1.useEffect)(function () {
101
62
  if (width < 768) {
102
63
  setIsMobile(true);
103
64
  }
@@ -105,143 +66,19 @@ var AttachmentsGroup = function (props) {
105
66
  setIsMobile(false);
106
67
  }
107
68
  }, [width]);
69
+ (0, react_1.useEffect)(function () {
70
+ (0, AttachmentsUtility_1.updateFormState)(attachments, formInstance);
71
+ setDisplayAttachmentList(attachments.length > 0);
72
+ }, [attachments]);
108
73
  var removeFile = function (file) {
109
74
  var updatedAttachments = attachments.filter(function (attachment) { return attachment.file.uid !== file.uid; });
110
- setTempAttachments(updatedAttachments);
111
75
  setAttachments(updatedAttachments);
112
- clearFileFields(file);
113
- };
114
- var clearFileFields = function (file) {
115
- // tslint:disable-next-line:no-shadowed-variable
116
- var fileIndex = attachments.findIndex(function (attachment) { return attachment.file.uid === file.uid; });
117
- if (fileIndex === -1)
118
- return;
119
- props.formInstance.setFields([
120
- {
121
- name: ["attachments", "file".concat(fileIndex + 1), "file"],
122
- value: undefined,
123
- },
124
- ]);
125
- props.formInstance.setFields([
126
- {
127
- name: ["attachments", "file".concat(fileIndex + 1), "description"],
128
- value: undefined,
129
- },
130
- ]);
131
- };
132
- var handlePreview = function (file, description) { return __awaiter(void 0, void 0, void 0, function () {
133
- var reader, _a;
134
- return __generator(this, function (_b) {
135
- switch (_b.label) {
136
- case 0:
137
- if (!file.originFileObj)
138
- return [2 /*return*/];
139
- if (!(file.type === "application/pdf")) return [3 /*break*/, 1];
140
- reader = new FileReader();
141
- reader.onload = function (e) {
142
- var blob = file.originFileObj ? new Blob([file.originFileObj], { type: "application/pdf" }) : null;
143
- if (blob) {
144
- var url = URL.createObjectURL(blob);
145
- setPreviewPDFUrl(url);
146
- }
147
- };
148
- reader.readAsArrayBuffer(file.originFileObj);
149
- return [3 /*break*/, 4];
150
- case 1:
151
- if (!(!file.url && !file.preview)) return [3 /*break*/, 3];
152
- _a = file;
153
- return [4 /*yield*/, (0, FileUploadUtility_1.getBase64)(file.originFileObj)];
154
- case 2:
155
- _a.preview = (_b.sent());
156
- _b.label = 3;
157
- case 3:
158
- setPreviewImage(file.url || file.preview);
159
- _b.label = 4;
160
- case 4:
161
- setPreviewDescription(description);
162
- setPreviewOpen(true);
163
- return [2 /*return*/];
164
- }
165
- });
166
- }); };
167
- var handleClosePreview = function () {
168
- if (previewPDFUrl) {
169
- URL.revokeObjectURL(previewPDFUrl);
170
- setPreviewPDFUrl("");
171
- }
172
- if (previewImage) {
173
- setPreviewImage("");
174
- }
175
- setPreviewDescription("");
176
- setPreviewOpen(false);
177
- };
178
- var clearAttachmentsInForm = function () {
179
- props.formInstance.setFields([
180
- {
181
- name: ["attachments", "file".concat(1), "file"],
182
- value: undefined,
183
- },
184
- ]);
185
- props.formInstance.setFields([
186
- {
187
- name: ["attachments", "file".concat(1), "description"],
188
- value: undefined,
189
- },
190
- ]);
191
- props.formInstance.setFields([
192
- {
193
- name: ["attachments", "file".concat(2), "file"],
194
- value: undefined,
195
- },
196
- ]);
197
- props.formInstance.setFields([
198
- {
199
- name: ["attachments", "file".concat(2), "description"],
200
- value: undefined,
201
- },
202
- ]);
203
- props.formInstance.setFields([
204
- {
205
- name: ["attachments", "file".concat(3), "file"],
206
- value: undefined,
207
- },
208
- ]);
209
- props.formInstance.setFields([
210
- {
211
- name: ["attachments", "file".concat(3), "description"],
212
- value: undefined,
213
- },
214
- ]);
215
76
  };
216
- var updateFormState = function (attachmentsForForm) {
217
- clearAttachmentsInForm();
218
- attachmentsForForm.forEach(function (at, index) {
219
- props.formInstance.setFields([
220
- {
221
- name: ["attachments", "file".concat(index + 1), "file"],
222
- value: at.file,
223
- },
224
- ]);
225
- props.formInstance.setFields([
226
- {
227
- name: ["attachments", "file".concat(index + 1), "description"],
228
- value: at.description,
229
- },
230
- ]);
231
- });
232
- };
233
- var saveFiles = function () {
234
- var clonedAttachments = lodash_1.default.cloneDeep(tempAttachments);
235
- var filteredAttachments = clonedAttachments.filter(function (at) { return at.description; });
236
- setAttachments(filteredAttachments);
237
- updateFormState(filteredAttachments);
238
- setTempAttachments(filteredAttachments);
239
- setDisplayAttachments(true);
240
- setIsModalOpen(false);
77
+ var saveFiles = function (attachmentsFromModal) {
78
+ setAttachments(attachmentsFromModal);
241
79
  };
242
80
  var onModalCancel = function () {
243
- setTempAttachments(attachments);
244
- updateFormState(attachments);
81
+ (0, AttachmentsUtility_1.updateFormState)(attachments, formInstance);
245
82
  setIsModalOpen(false);
246
83
  };
247
84
  return (React.createElement(antd_1.Flex, { style: {
@@ -251,33 +88,15 @@ var AttachmentsGroup = function (props) {
251
88
  padding: isMobile ? "20px" : "35px 0",
252
89
  }, justify: "center" },
253
90
  React.createElement(antd_1.Flex, { vertical: true, style: { width: "100%", maxWidth: "900px" }, gap: "small" },
254
- React.createElement(antd_1.Typography.Title, { level: 5, style: { margin: 0 } }, props.intl.formatMessage(translationMessages.attachment_title)),
255
- React.createElement(antd_1.Typography.Text, { type: "secondary" }, (props.languageString === "en" || props.languageString === "is") && props.attachmentTooltipText
256
- ? props.attachmentTooltipText[props.languageString]
257
- : props.intl.formatMessage(translationMessages.attachment_tooltip_title, {
258
- uploadSizeLimit: props.uploadSizeLimit / 1024,
91
+ React.createElement(antd_1.Typography.Title, { level: 5, style: { margin: 0 } }, props.intl.formatMessage(exports.translationMessages.attachment_title)),
92
+ React.createElement(antd_1.Typography.Text, { type: "secondary" }, (languageString === "en" || languageString === "is") && attachmentTooltipText
93
+ ? attachmentTooltipText[languageString]
94
+ : props.intl.formatMessage(exports.translationMessages.attachment_tooltip_title, {
95
+ uploadSizeLimit: uploadSizeLimit / 1024,
259
96
  })),
260
- React.createElement(antd_1.Button, { size: "large", style: { width: "100%" }, onClick: function () { return setIsModalOpen(true); }, icon: React.createElement(icons_1.PaperClipOutlined, null) }, props.intl.formatMessage(translationMessages.attachment_addAttachmentButton_title)),
261
- displayAttachments && attachments.length > 0 && (React.createElement(antd_1.Flex, { vertical: true, gap: "small" },
262
- React.createElement(antd_1.Flex, { vertical: true },
263
- React.createElement(antd_1.Typography.Text, { disabled: true }, props.intl.formatMessage(translationMessages.attachment_title))),
264
- React.createElement(antd_1.Divider, { style: { padding: 0, margin: 0 } }),
265
- attachments.map(function (attachment) { return (React.createElement(antd_1.Flex, { gap: "middle", justify: "space-between" },
266
- React.createElement(antd_1.Button, { type: "link", onClick: function () { return handlePreview(attachment.file, attachment.description); }, style: { padding: 0 }, size: "small" },
267
- React.createElement(icons_1.PaperClipOutlined, { style: { fontSize: token.fontSizeIcon } }),
268
- attachment.file.name),
269
- React.createElement(antd_1.Flex, { gap: "middle" },
270
- React.createElement(icons_1.EditOutlined, { style: { fontSize: token.fontSizeHeading4 }, onClick: function () {
271
- setIsModalOpen(true);
272
- } }),
273
- React.createElement(icons_1.DeleteOutlined, { style: { fontSize: token.fontSizeHeading4 }, onClick: function () {
274
- removeFile(attachment.file);
275
- } })))); }))),
276
- React.createElement(AttachmentModal_1.default, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, attachments: tempAttachments, setAttachments: setTempAttachments, uploadSizeLimit: props.uploadSizeLimit, formInstance: props.formInstance, onRemove: removeFile, onSave: saveFiles, onCancel: onModalCancel }),
277
- React.createElement(antd_1.Modal, { open: previewOpen, onCancel: handleClosePreview, footer: null },
278
- previewPDFUrl && (React.createElement("iframe", { src: previewPDFUrl, style: { width: "100%", height: "700px", maxHeight: "75vh" } })),
279
- previewImage && React.createElement(antd_1.Image, { src: previewImage, preview: false }),
280
- React.createElement(antd_1.Typography.Text, null, previewDescription)))));
97
+ React.createElement(antd_1.Button, { size: "large", style: { width: "100%" }, onClick: function () { return setIsModalOpen(true); }, icon: React.createElement(icons_1.PaperClipOutlined, null) }, props.intl.formatMessage(exports.translationMessages.attachment_addAttachmentButton_title)),
98
+ displayAttachmentList && attachments.length > 0 && (React.createElement(AttachmentList_1.default, { attachments: attachments, setIsModalOpen: setIsModalOpen, removeFile: removeFile })),
99
+ React.createElement(AttachmentModal_1.default, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, attachments: attachments, uploadSizeLimit: uploadSizeLimit, form: formInstance, onSave: saveFiles, onCancel: onModalCancel }))));
281
100
  };
282
101
  var AttachmentGroupIntl = (0, react_intl_1.injectIntl)(AttachmentsGroup);
283
102
  exports.default = AttachmentGroupIntl;
@@ -241,7 +241,7 @@ var SingleBillingLine = function (props) {
241
241
  message: props.intl.formatMessage(NewBillingLines_1.translationMessages.billingLines_itemNo_and_itemName_validationMessage, { limit: 50 }),
242
242
  },
243
243
  ] }, (0, BillingLineUtility_1.getCorrectInputNode)("itemNo", props.intl, props.intl.formatMessage(NewBillingLines_1.translationMessages.billingLines_itemNo), (0, RequirementsUtility_1.getFieldIsRequired)(props.receiverRequirements, ReceiverRequirements_1.AvailableFields["invoiceLines.itemNo"], false))),
244
- React.createElement(form_item_1.default, { className: "umz_noValidationMessage", receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["invoiceLines.name"], defaultIsRequired: true, fieldName: [fieldName, "name"], defaultLabel: props.intl.formatMessage(NewBillingLines_1.translationMessages.billingLines_name), verticalLabels: true, onlyLabelOnFirstInList: true, index: index, rules: [
244
+ React.createElement(form_item_1.default, { className: "umz_noValidationMessage", receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["invoiceLines.name"], defaultIsRequired: true, fieldName: [fieldName, "name"], defaultLabel: props.intl.formatMessage(NewBillingLines_1.translationMessages.billingLines_name), verticalLabels: true, onlyLabelOnFirstInList: true, index: index, additionalRules: [
245
245
  {
246
246
  max: 100,
247
247
  message: props.intl.formatMessage(NewBillingLines_1.translationMessages.billingLines_itemNo_and_itemName_validationMessage, { limit: 100 }),
@@ -2,6 +2,8 @@ import { BillingLineMetadataOverride } from "../types/BillingLineMetadataOverrid
2
2
  import { RuleObject } from "rc-field-form/lib/interface";
3
3
  import { StoreValue } from 'antd/es/form/interface';
4
4
  import { IntlShape } from "react-intl";
5
+ import { FormInstance } from "antd/es/form";
6
+ export declare const requiredValidator: (form: FormInstance, index: number, requiredMessage: string) => (_: unknown, value: string) => Promise<void>;
5
7
  export declare const noWhitespaceValidator: (intl: IntlShape) => (_: RuleObject, value: StoreValue) => Promise<void>;
6
8
  export type ValidationRulesObject = {
7
9
  [key in keyof Omit<BillingLineMetadataOverride, 'key'>]: RuleObject[];
@@ -1,7 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validationRules = exports.noWhitespaceValidator = void 0;
3
+ exports.validationRules = exports.noWhitespaceValidator = exports.requiredValidator = void 0;
4
4
  var CommonTranslations_1 = require("../components/CommonTranslations");
5
+ var requiredValidator = function (form, index, requiredMessage) {
6
+ return function (_, value) {
7
+ var hasFile = form.getFieldValue([
8
+ "attachments",
9
+ "file".concat(index + 1),
10
+ "file",
11
+ ]);
12
+ if (!hasFile) {
13
+ return Promise.resolve();
14
+ }
15
+ if (!value || !value.trim()) {
16
+ return Promise.reject(new Error(requiredMessage));
17
+ }
18
+ return Promise.resolve();
19
+ };
20
+ };
21
+ exports.requiredValidator = requiredValidator;
5
22
  var noWhitespaceValidator = function (intl) {
6
23
  return function (_, value) {
7
24
  if (!value) {