@arquimedes.co/eureka-forms 0.2.29 → 0.2.30-test

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.
package/dist/App.d.ts CHANGED
@@ -19,6 +19,8 @@ export interface AppProps {
19
19
  valuesData?: Record<string, unknown>;
20
20
  /** Custom steps to display */
21
21
  customSteps?: Record<string, CustomStep>;
22
+ /** Function to call on postview to fetch the download url of a file */
23
+ fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
22
24
  }
23
25
  export interface CustomStep {
24
26
  component: ReactNode;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { FormComponentProps } from '../Form';
3
- declare function ColumnForm({ form, apiKey, reload, domain, postview, internal, formStyle, widthStats, customSteps, originalValues, }: FormComponentProps): JSX.Element;
3
+ declare function ColumnForm({ form, apiKey, reload, domain, postview, internal, formStyle, widthStats, customSteps, originalValues, ...others }: FormComponentProps): JSX.Element;
4
4
  export default ColumnForm;
@@ -45,6 +45,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __rest = (this && this.__rest) || function (s, e) {
49
+ var t = {};
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ };
48
59
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
49
60
  import { useEffect, useState } from 'react';
50
61
  import SectionComponent from '../../Section/Section';
@@ -59,7 +70,7 @@ import axios from 'axios';
59
70
  import axiosInstance from '../../../AxiosAPI';
60
71
  function ColumnForm(_a) {
61
72
  var _this = this;
62
- var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, domain = _a.domain, postview = _a.postview, internal = _a.internal, formStyle = _a.formStyle, widthStats = _a.widthStats, customSteps = _a.customSteps, originalValues = _a.originalValues;
73
+ var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, domain = _a.domain, postview = _a.postview, internal = _a.internal, formStyle = _a.formStyle, widthStats = _a.widthStats, customSteps = _a.customSteps, originalValues = _a.originalValues, others = __rest(_a, ["form", "apiKey", "reload", "domain", "postview", "internal", "formStyle", "widthStats", "customSteps", "originalValues"]);
63
74
  var _b = useState(false), tempError = _b[0], setTempError = _b[1];
64
75
  var _c = useForm({
65
76
  defaultValues: mapOriginal(originalValues, form),
@@ -87,6 +98,7 @@ function ColumnForm(_a) {
87
98
  case 1:
88
99
  valid = _c.sent();
89
100
  values = getValues();
101
+ console.log(values);
90
102
  if (!!valid) return [3 /*break*/, 2];
91
103
  console.log('ERRORS:', errors);
92
104
  setTempError(true);
@@ -101,8 +113,8 @@ function ColumnForm(_a) {
101
113
  idStep = _a[_i];
102
114
  updateValue(idStep, values, form, customSteps);
103
115
  }
116
+ console.log('UPDATED:', values);
104
117
  url = "https://" + domain + ".forms." + process.env.REACT_APP_DOMAIN + "/api/ticket?apiKey=" + (internal ? form.apiKey : apiKey) + "&domain=" + domain;
105
- console.log(values);
106
118
  payload = {
107
119
  formValues: { steps: values },
108
120
  };
@@ -133,7 +145,7 @@ function ColumnForm(_a) {
133
145
  return (_jsxs("div", __assign({ className: styles.container, style: { color: formStyle.textColor } }, { children: [loading && _jsx("div", { className: styles.curtain }, void 0), showConfirmation !== undefined && (_jsx(ConfirmationDialog, { formStyle: formStyle, confirmation: showConfirmation, onClose: function () {
134
146
  reload();
135
147
  setShowConfirmation(undefined);
136
- } }, void 0)), sections.map(function (idSection, index) { return (_jsx(SectionComponent, { form: form, domain: domain, postview: postview, clearErrors: clearErrors, widthStats: widthStats, control: control, getValues: getValues, originalValues: originalValues, errors: errors, index: index, setSections: setSections, section: form.sections[idSection], formStyle: formStyle, customSteps: customSteps }, index)); }), form.terms &&
148
+ } }, void 0)), sections.map(function (idSection, index) { return (_jsx(SectionComponent, __assign({ form: form, domain: domain, postview: postview, clearErrors: clearErrors, widthStats: widthStats, control: control, getValues: getValues, originalValues: originalValues, errors: errors, index: index, setSections: setSections, section: form.sections[idSection], formStyle: formStyle, customSteps: customSteps }, others), index)); }), form.terms &&
137
149
  !internal &&
138
150
  form.terms.map(function (term, index) { return (_jsx(TermComponent, { setValue: setValue, postview: postview, tempError: tempError, term: term, control: control, errors: errors, form: form, formStyle: formStyle }, index)); }), !postview && (_jsx("div", __assign({ className: styles.submitBtnContainer }, { children: _jsxs("button", __assign({ "data-testid": "login__submit", className: styles.submitBtn, onClick: function () {
139
151
  onSubmit();
@@ -201,6 +213,14 @@ var updateValue = function (idStep, values, form, customSteps) {
201
213
  }
202
214
  break;
203
215
  }
216
+ case Types.FILEUPLOAD: {
217
+ var value = values[step.id];
218
+ values[step.id] = value.map(function (val) { return ({
219
+ fileName: val.fileName,
220
+ S3Key: val.S3Key,
221
+ }); });
222
+ break;
223
+ }
204
224
  default:
205
225
  var custom = customSteps[idStep];
206
226
  if (custom !== undefined) {
@@ -17,6 +17,8 @@ export interface FormComponentProps {
17
17
  formStyle: FormStyle;
18
18
  domain?: string;
19
19
  apiKey: string | undefined;
20
+ /** Function to call on postview to fetch the download url of a file */
21
+ fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
20
22
  }
21
23
  declare function FormComponent({ form, internal, postview, organization, containerRef, ...others }: Omit<FormComponentProps, 'widthStats' | 'formStyle'> & {
22
24
  containerRef: any;
@@ -15,6 +15,8 @@ export interface RecursiveData {
15
15
  getValues: UseFormGetValues<FieldValues>;
16
16
  originalValues: Record<string, any>;
17
17
  customSteps: Record<string, CustomStep>;
18
+ /** Function to call on postview to fetch the download url of a file */
19
+ fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
18
20
  }
19
21
  export interface SectionComponentProps extends RecursiveData {
20
22
  section: Section;
@@ -1,11 +1,13 @@
1
1
  /// <reference types="react" />
2
- import { FileObj } from '../MaterialFileUploadStep';
2
+ import { FileObject, UploadedFileObject } from '../MaterialFileUploadStep';
3
3
  import { FormStyle } from '../../../../../@Types/Form';
4
4
  interface FileComponentProps {
5
- fileInfo: FileObj;
6
- handleUploaded: Function;
7
- handleRemoveUploaded: Function;
5
+ file: FileObject | UploadedFileObject;
8
6
  formStyle: FormStyle;
7
+ error: boolean;
8
+ handleRemove: Function;
9
+ /** Function to call on postview to fetch the download url of a file */
10
+ fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
9
11
  }
10
- declare function FileUploadComponent({ fileInfo, formStyle, handleUploaded, handleRemoveUploaded, }: FileComponentProps): JSX.Element;
12
+ declare function FileUploadComponent({ file, formStyle, error, handleRemove, fetchDownloadUrl, }: FileComponentProps): JSX.Element;
11
13
  export default FileUploadComponent;
@@ -46,65 +46,78 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
49
- import { useEffect, useState } from 'react';
50
- import { postFile } from '../../../../../controllers/FileService';
51
49
  import styles from './FileComponent.module.css';
52
50
  import ClearRoundedIcon from '@material-ui/icons/ClearRounded';
53
51
  import DescriptionRoundedIcon from '@material-ui/icons/DescriptionRounded';
52
+ import ErrorRoundedIcon from '@material-ui/icons/ErrorRounded';
54
53
  import Loader from '../../../../../shared/Loader/Loader';
55
- var timeout = function (ms) {
56
- return new Promise(function (resolve) { return setTimeout(resolve, ms); });
57
- };
54
+ import { useState } from 'react';
58
55
  function FileUploadComponent(_a) {
59
56
  var _this = this;
60
- var fileInfo = _a.fileInfo, formStyle = _a.formStyle, handleUploaded = _a.handleUploaded, handleRemoveUploaded = _a.handleRemoveUploaded;
61
- var _b = useState(undefined), file = _b[0], setFile = _b[1];
62
- var uploadFile = function (file) { return __awaiter(_this, void 0, void 0, function () {
63
- var resp, error_1;
57
+ var _b;
58
+ var file = _a.file, formStyle = _a.formStyle, error = _a.error, handleRemove = _a.handleRemove, fetchDownloadUrl = _a.fetchDownloadUrl;
59
+ var _c = useState(false), downloading = _c[0], setDownloading = _c[1];
60
+ if (!file) {
61
+ return _jsx("div", {}, void 0);
62
+ }
63
+ var downloadFile = function () { return __awaiter(_this, void 0, void 0, function () {
64
+ var fileUrl, a, error_1;
64
65
  return __generator(this, function (_a) {
65
66
  switch (_a.label) {
66
67
  case 0:
67
- _a.trys.push([0, 2, , 3]);
68
- setFile(__assign(__assign({}, file), { loading: 'UPLOADING' }));
69
- return [4 /*yield*/, Promise.all([
70
- postFile(file.file, file.postInfo),
71
- timeout(1000),
72
- ])];
68
+ if (!(fetchDownloadUrl && file.S3Key && file.fileName)) return [3 /*break*/, 4];
69
+ _a.label = 1;
73
70
  case 1:
74
- resp = _a.sent();
75
- setFile(__assign(__assign({}, file), { loading: 'DONE', postInfo: resp[0] }));
76
- handleUploaded(resp[0]);
77
- return [3 /*break*/, 3];
71
+ _a.trys.push([1, 3, , 4]);
72
+ setDownloading(true);
73
+ return [4 /*yield*/, fetchDownloadUrl(file.S3Key, file.fileName)];
78
74
  case 2:
75
+ fileUrl = _a.sent();
76
+ a = document.createElement('a');
77
+ a.href = fileUrl;
78
+ a.setAttribute('download', file.fileName);
79
+ a.click();
80
+ setDownloading(false);
81
+ return [3 /*break*/, 4];
82
+ case 3:
79
83
  error_1 = _a.sent();
80
84
  console.error(error_1);
81
- return [3 /*break*/, 3];
82
- case 3: return [2 /*return*/];
85
+ return [3 /*break*/, 4];
86
+ case 4: return [2 /*return*/];
83
87
  }
84
88
  });
85
89
  }); };
86
- useEffect(function () {
87
- if (fileInfo.loading === 'TRY_UPLOADING' && !file) {
88
- uploadFile(fileInfo);
89
- }
90
- }, [fileInfo]);
91
90
  var calcIcon = function () {
92
- switch (file ? file.loading : fileInfo.loading) {
93
- case 'STARTING':
94
- case 'TRY_UPLOADING':
95
- return _jsx("div", { className: styles.waitingForUpload }, void 0);
96
- case 'UPLOADING':
97
- return (_jsx("div", __assign({ className: styles.loaderContainer }, { children: _jsx(Loader, { size: 26, color: formStyle.primaryColor }, void 0) }), void 0));
98
- case 'DONE':
99
- return (_jsx("div", __assign({ className: styles.documentIcon, style: { color: formStyle.primaryColor } }, { children: _jsx(DescriptionRoundedIcon, {}, void 0) }), void 0));
100
- default:
101
- return _jsx("div", {}, void 0);
91
+ if (downloading) {
92
+ return (_jsx("div", __assign({ className: styles.loaderContainer }, { children: _jsx(Loader, { size: 26, color: formStyle.primaryColor }, void 0) }), void 0));
93
+ }
94
+ else if (file.state !== undefined) {
95
+ switch (file.state) {
96
+ case 'STARTING':
97
+ case 'UPLOADING':
98
+ return (_jsx("div", __assign({ className: styles.loaderContainer }, { children: _jsx(Loader, { size: 26, color: formStyle.primaryColor }, void 0) }), void 0));
99
+ case 'DONE':
100
+ return (_jsx("div", __assign({ className: styles.documentIcon, style: { color: formStyle.primaryColor } }, { children: _jsx(DescriptionRoundedIcon, {}, void 0) }), void 0));
101
+ case 'ERROR':
102
+ return (_jsx("div", __assign({ className: styles.documentIcon, style: { color: formStyle.errorColor } }, { children: _jsx(ErrorRoundedIcon, {}, void 0) }), void 0));
103
+ default:
104
+ return _jsx("div", {}, void 0);
105
+ }
106
+ }
107
+ else {
108
+ return (_jsx("div", __assign({ className: styles.documentIcon, style: { color: formStyle.primaryColor } }, { children: _jsx(DescriptionRoundedIcon, {}, void 0) }), void 0));
102
109
  }
103
110
  };
104
- return (_jsxs("div", __assign({ className: styles.container }, { children: [_jsx("div", __assign({ className: styles.iconContainer }, { children: calcIcon() }), void 0), _jsx("div", __assign({ className: styles.label }, { children: file ? file.file.name : fileInfo.file.name }), void 0), _jsx("div", __assign({ className: styles.deletBtn, onClick: function () {
105
- if (file && file.loading === 'DONE') {
106
- handleRemoveUploaded(fileInfo.postInfo);
111
+ return (_jsxs("div", __assign({ className: styles.container }, { children: [_jsx("div", __assign({ className: styles.iconContainer }, { children: calcIcon() }), void 0), _jsx("div", __assign({ className: fetchDownloadUrl && file.S3Key
112
+ ? styles.downloadableLbl
113
+ : styles.label, style: {
114
+ color: error ? formStyle.errorColor : formStyle.textColor,
115
+ }, onClick: function () {
116
+ if (fetchDownloadUrl !== undefined && file.S3Key) {
117
+ downloadFile();
107
118
  }
108
- } }, { children: file && file.loading === 'DONE' && (_jsx(ClearRoundedIcon, { fontSize: "inherit" }, void 0)) }), void 0)] }), void 0));
119
+ } }, { children: (_b = file.file.name) !== null && _b !== void 0 ? _b : file.fileName }), void 0), _jsx("div", __assign({ className: styles.deletBtn, onClick: function () {
120
+ handleRemove();
121
+ } }, { children: file.state !== undefined && (_jsx(ClearRoundedIcon, { fontSize: "inherit" }, void 0)) }), void 0)] }), void 0));
109
122
  }
110
123
  export default FileUploadComponent;
@@ -14,14 +14,21 @@
14
14
  height: 30px;
15
15
  }
16
16
 
17
- .label {
17
+ .label,
18
+ .downloadableLbl {
18
19
  font-size: 1rem;
19
20
  margin-left: 2px;
20
21
  cursor: default;
21
22
  white-space: nowrap;
22
23
  overflow: hidden;
23
24
  text-overflow: ellipsis;
24
- max-width: calc(100% - 70px);
25
+ max-width: calc(100% - 80px);
26
+ }
27
+ .downloadableLbl {
28
+ cursor: pointer;
29
+ }
30
+ .downloadableLbl:hover {
31
+ text-decoration: underline;
25
32
  }
26
33
  .deletBtn {
27
34
  font-size: 26px;
@@ -46,6 +53,7 @@
46
53
  .iconContainer {
47
54
  height: 30px;
48
55
  width: 30px;
56
+ margin-left: 10px;
49
57
  display: flex;
50
58
  align-items: center;
51
59
  justify-content: center;
@@ -1,11 +1,14 @@
1
1
  /// <reference types="react" />
2
2
  import { FileUploadStepProps } from '../FileUploadStep';
3
- export interface FileObj {
4
- loading: 'STARTING' | 'TRY_UPLOADING' | 'UPLOADING' | 'DONE';
3
+ export interface FileObject {
4
+ state: 'STARTING' | 'UPLOADING' | 'DONE' | 'CANCEL' | 'ERROR';
5
5
  file: File;
6
- postInfo?: any;
6
+ postInfo: any;
7
+ fileName?: string;
8
+ S3Key?: string;
9
+ error?: boolean;
7
10
  }
8
- export interface UploadedFileObj {
11
+ export interface UploadedFileObject {
9
12
  fileName: string;
10
13
  S3Key: string;
11
14
  }
@@ -60,106 +60,197 @@ import { Controller } from 'react-hook-form';
60
60
  import RoundedButton from '../../../../shared/RoundedButton/RoundedButton';
61
61
  import { useEffect, useRef, useState } from 'react';
62
62
  import { getAcceptedExtensions } from '../../../../constants/Files/FileExtensions';
63
- import maxFileSize from '../../../../constants/Files/FileMaxSize';
64
- import { getUploadUrls } from '../../../../controllers/FileService';
63
+ import { getUploadUrls, postFile } from '../../../../controllers/FileService';
65
64
  import FileComponent from './FileComponent/FileComponent';
65
+ import maxSize from '../../../../constants/Files/FileMaxSize';
66
66
  function FileUploadStep(_a) {
67
- var _b;
68
- var step = _a.step, errors = _a.errors, postview = _a.postview, onChange = _a.onChange, formStyle = _a.formStyle, domain = _a.domain, clearErrors = _a.clearErrors, originalValues = _a.originalValues;
69
- var _c = useState(((_b = originalValues[step.id]) !== null && _b !== void 0 ? _b : []).map(function (file) {
70
- var _a;
71
- return ((_a = {
72
- file: new File([], file.fileName),
73
- loading: 'DONE',
74
- }) !== null && _a !== void 0 ? _a : []);
75
- })), files = _c[0], setFiles = _c[1];
76
- var _d = useState(undefined), fileUploaded = _d[0], setFileUploaded = _d[1];
77
- var _e = useState([]), uploadedFiles = _e[0], setUploadedFiles = _e[1];
67
+ var step = _a.step, errors = _a.errors, postview = _a.postview, onChange = _a.onChange, value = _a.value, formStyle = _a.formStyle, domain = _a.domain, clearErrors = _a.clearErrors, fetchDownloadUrl = _a.fetchDownloadUrl;
68
+ var _b = useState(undefined), error = _b[0], setError = _b[1];
69
+ var _c = useState([]), fileChange = _c[0], setFileChange = _c[1];
78
70
  var inputRef = useRef();
79
71
  useEffect(function () {
80
- if (fileUploaded) {
81
- var tempArray = __spreadArray(__spreadArray([], uploadedFiles, true), [fileUploaded], false);
82
- onChange(tempArray);
83
- clearErrors(step.id);
84
- setUploadedFiles(tempArray);
72
+ var filesToFetchLink = [];
73
+ var filesChanged = [];
74
+ for (var _i = 0, fileChange_1 = fileChange; _i < fileChange_1.length; _i++) {
75
+ var file = fileChange_1[_i];
76
+ if (file.state === 'STARTING') {
77
+ filesToFetchLink.push(file);
78
+ }
79
+ if (file.state === 'UPLOADING') {
80
+ uploadFile(file);
81
+ filesChanged.push(file);
82
+ }
83
+ if (file.state === 'DONE' ||
84
+ file.state === 'ERROR') {
85
+ filesChanged.push(file);
86
+ }
87
+ if (file.state === 'CANCEL') {
88
+ var newValue = __spreadArray([], value, true);
89
+ for (var i = 0; i < value.length; i++) {
90
+ if (value[i].file === file.file) {
91
+ newValue.splice(i, 1);
92
+ break;
93
+ }
94
+ }
95
+ onChange(newValue);
96
+ }
97
+ }
98
+ if (filesChanged.length > 0) {
99
+ var newValue = __spreadArray([], value, true);
100
+ for (var _a = 0, filesChanged_1 = filesChanged; _a < filesChanged_1.length; _a++) {
101
+ var file = filesChanged_1[_a];
102
+ for (var i = 0; i < value.length; i++) {
103
+ if (value[i].file === file.file) {
104
+ newValue[i] = file;
105
+ }
106
+ }
107
+ }
108
+ onChange(newValue);
85
109
  }
86
- }, [fileUploaded]);
87
- function getUploadUrlsAsync(pFiles) {
110
+ if (filesToFetchLink.length > 0) {
111
+ getLinks(filesToFetchLink);
112
+ onChange(__spreadArray(__spreadArray([], value, true), filesToFetchLink, true));
113
+ }
114
+ }, [fileChange]);
115
+ function getLinks(pFiles) {
88
116
  return __awaiter(this, void 0, void 0, function () {
89
- var largeFile, currentFiles, fileLinks_1, error_1;
117
+ var fileLinks_1, errorsExt_1, error_1;
90
118
  return __generator(this, function (_a) {
91
119
  switch (_a.label) {
92
120
  case 0:
93
- largeFile = pFiles.find(function (file) { return file.size > maxFileSize; });
94
- if (!largeFile) return [3 /*break*/, 1];
95
- console.error('FILE IS TOO LARGE', largeFile);
96
- return [3 /*break*/, 5];
121
+ _a.trys.push([0, 2, , 3]);
122
+ return [4 /*yield*/, getUploadUrls(pFiles.map(function (file) { return file.file; }), domain)];
97
123
  case 1:
98
- currentFiles = __spreadArray([], files, true);
99
- setFiles(__spreadArray(__spreadArray([], files, true), pFiles.map(function (file) {
100
- return ({
101
- loading: 'STARTING',
102
- file: file,
103
- postInfo: null,
104
- });
105
- }), true));
106
- _a.label = 2;
107
- case 2:
108
- _a.trys.push([2, 4, , 5]);
109
- return [4 /*yield*/, getUploadUrls(pFiles, domain)];
110
- case 3:
111
124
  fileLinks_1 = _a.sent();
112
- setFiles(__spreadArray(__spreadArray([], currentFiles, true), pFiles.map(function (file, index) {
113
- return ({
114
- postInfo: fileLinks_1[index],
115
- loading: 'TRY_UPLOADING',
116
- file: file,
117
- });
118
- }), true));
119
- return [3 /*break*/, 5];
120
- case 4:
125
+ errorsExt_1 = [];
126
+ setFileChange(pFiles.map(function (file, index) {
127
+ var _a;
128
+ if (fileLinks_1[index] === 'ERROR:INVALIDEXTENSION') {
129
+ errorsExt_1.push((_a = file.file.name.split('.').pop()) !== null && _a !== void 0 ? _a : '');
130
+ return __assign(__assign({}, file), { state: 'ERROR' });
131
+ }
132
+ else {
133
+ return __assign(__assign({}, file), { state: 'UPLOADING', postInfo: fileLinks_1[index] });
134
+ }
135
+ }));
136
+ if (errorsExt_1.length === 1) {
137
+ setError('La extención .' + errorsExt_1[0] + ' no es válida');
138
+ }
139
+ else if (errorsExt_1.length > 1) {
140
+ setError('Las extenciónes .' +
141
+ errorsExt_1.join(',.') +
142
+ ' no son válidas');
143
+ }
144
+ return [3 /*break*/, 3];
145
+ case 2:
121
146
  error_1 = _a.sent();
122
- console.error('ERROR');
123
- return [3 /*break*/, 5];
124
- case 5: return [2 /*return*/];
147
+ console.error(error_1);
148
+ return [3 /*break*/, 3];
149
+ case 3: return [2 /*return*/];
125
150
  }
126
151
  });
127
152
  });
128
153
  }
154
+ function uploadFile(pFile) {
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ var resp, error_2;
157
+ return __generator(this, function (_a) {
158
+ switch (_a.label) {
159
+ case 0:
160
+ _a.trys.push([0, 2, , 3]);
161
+ return [4 /*yield*/, Promise.all([
162
+ postFile(pFile.file, pFile.postInfo),
163
+ new Promise(function (resolve) { return setTimeout(resolve, 1000); }),
164
+ ])];
165
+ case 1:
166
+ resp = _a.sent();
167
+ setFileChange([__assign(__assign(__assign({}, pFile), { state: 'DONE' }), resp[0])]);
168
+ return [3 /*break*/, 3];
169
+ case 2:
170
+ error_2 = _a.sent();
171
+ console.error(error_2);
172
+ return [3 /*break*/, 3];
173
+ case 3: return [2 /*return*/];
174
+ }
175
+ });
176
+ });
177
+ }
178
+ var calcErrorMsg = function () {
179
+ if (!!errors[step.id]) {
180
+ var errNum = value.filter(function (val) { return val.state === 'ERROR'; }).length;
181
+ if (errNum === 1) {
182
+ return 'Este archivo no es válido';
183
+ }
184
+ else if (errNum > 1) {
185
+ return 'Estos archivos no son válidos';
186
+ }
187
+ else {
188
+ return 'Este campo es obligatorio';
189
+ }
190
+ }
191
+ return '';
192
+ };
129
193
  return (_jsxs("div", __assign({ className: styles.container }, { children: [_jsx("div", __assign({ className: styles.labelLabel }, { children: step.label }), void 0), step.description && (_jsx("div", __assign({ className: styles.stepDescriptionLabel }, { children: step.description }), void 0)), _jsx("input", { type: "file", ref: inputRef, className: styles.filesInput, onChange: function (e) {
130
194
  var files = e.target.files;
131
195
  if (files) {
132
196
  var filesArray = Array.from(files);
133
- getUploadUrlsAsync(filesArray);
197
+ var maxFiles = filesArray.filter(function (file) { return file.size > maxSize; });
198
+ if (maxFiles.length > 0) {
199
+ setError('El tamaño máximo de carga es de 30Mb.');
200
+ }
201
+ else {
202
+ setFileChange(filesArray
203
+ .filter(function (file) {
204
+ return value.find(function (val) {
205
+ return val.file ===
206
+ file;
207
+ }) === undefined;
208
+ })
209
+ .map(function (file) {
210
+ return ({
211
+ state: 'STARTING',
212
+ file: file,
213
+ postInfo: null,
214
+ });
215
+ }));
216
+ }
217
+ inputRef.current.value = '';
134
218
  }
135
219
  }, multiple: true, accept: getAcceptedExtensions() }, void 0), _jsx("div", __assign({ className: styles.btnContainer }, { children: _jsx(RoundedButton, { disabled: postview, text: 'Examinar' + (step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
136
220
  if (!postview) {
137
221
  var input = inputRef.current;
138
222
  if (input !== null) {
139
223
  clearErrors(step.id);
224
+ setError(undefined);
140
225
  input.click();
141
226
  }
142
227
  }
143
- } }, void 0) }), void 0), !!errors[step.id] && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" }), void 0)), _jsx("div", __assign({ className: styles.filesContainer }, { children: files.map(function (file, index) { return (_jsx(FileComponent, { formStyle: formStyle, fileInfo: file, handleRemoveUploaded: function (fileToDelete) {
144
- var tempArray = uploadedFiles.filter(function (file) { return file.S3Key !== fileToDelete.S3Key; });
145
- var tempFiles = files.filter(function (file) {
146
- return file.postInfo.S3Key !== fileToDelete.S3Key;
147
- });
148
- setFiles(tempFiles);
149
- onChange(tempArray);
150
- setUploadedFiles(tempArray);
151
- }, handleUploaded: function (info) {
152
- setFileUploaded(info);
153
- } }, index)); }) }), void 0)] }), void 0));
228
+ } }, void 0) }), void 0), _jsx("div", __assign({ className: styles.filesContainer }, { children: value.map(function (file, index) { return (_jsx(FileComponent, { formStyle: formStyle, file: file, error: (!!errors[step.id] &&
229
+ file.state !== 'DONE') ||
230
+ file.state === 'ERROR', handleRemove: function () {
231
+ if (value.filter(function (val) {
232
+ return val.state === 'ERROR';
233
+ }).length === 1) {
234
+ clearErrors(step.id);
235
+ setError(undefined);
236
+ }
237
+ if (file.state !== undefined) {
238
+ setFileChange([
239
+ __assign(__assign({}, file), { state: 'CANCEL' }),
240
+ ]);
241
+ }
242
+ }, fetchDownloadUrl: fetchDownloadUrl }, index)); }) }), void 0), _jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: error !== null && error !== void 0 ? error : calcErrorMsg() }), void 0)] }), void 0));
154
243
  }
155
244
  function UploadStepComponent(props) {
156
- return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: [], rules: props.step.required
157
- ? {
158
- validate: function (array) { return array.length > 0; },
159
- }
160
- : {}, shouldUnregister: true, render: function (_a) {
245
+ return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: [], rules: {
246
+ validate: function (array) {
247
+ return ((props.step.required && array.length > 0) ||
248
+ !props.step.required) &&
249
+ array.find(function (file) { return !file.S3Key; }) === undefined;
250
+ },
251
+ }, shouldUnregister: true, render: function (_a) {
161
252
  var field = _a.field;
162
- return (_jsx(FileUploadStep, __assign({}, props, { onChange: field.onChange }), void 0));
253
+ return (_jsx(FileUploadStep, __assign({}, props, { onChange: field.onChange, value: field.value }), void 0));
163
254
  } }, void 0));
164
255
  }
165
256
  export default UploadStepComponent;
@@ -32,11 +32,12 @@
32
32
  .btnContainer {
33
33
  margin-top: 5px;
34
34
  margin-left: 10px;
35
+ margin-bottom: 3px;
35
36
  width: fit-content;
36
37
  }
37
38
  .errorMsg {
38
39
  font-size: 0.75rem;
39
- margin-top: 7px;
40
+ margin-top: 5px;
40
41
  margin-left: 14px;
41
42
  }
42
43
 
@@ -61,5 +61,8 @@ var extensions = [
61
61
  'wpd',
62
62
  'csv',
63
63
  'tex',
64
+ 'msg',
65
+ 'zip',
66
+ 'rar',
64
67
  ];
65
68
  export default extensions;
@@ -1,4 +1,4 @@
1
- export declare function getUploadUrls(files: Array<File>, domain?: string): Promise<Array<Record<string, any>>>;
1
+ export declare function getUploadUrls(files: Array<File>, domain?: string): Promise<(Record<string, any> | string)[]>;
2
2
  export declare function postFile(file: File, postInfo: Record<string, any>): Promise<{
3
3
  fileName: string;
4
4
  S3Key: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version": "0.2.29",
4
+ "version": "0.2.30-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",