@arquimedes.co/eureka-forms 0.2.28 → 0.2.31-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.
Files changed (21) hide show
  1. package/dist/App.d.ts +2 -0
  2. package/dist/FormComponents/Form/ColumnForm/ColumnForm.d.ts +1 -1
  3. package/dist/FormComponents/Form/ColumnForm/ColumnForm.js +24 -4
  4. package/dist/FormComponents/Form/Form.d.ts +2 -0
  5. package/dist/FormComponents/Section/Section.d.ts +2 -0
  6. package/dist/FormComponents/Step/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +3 -3
  7. package/dist/FormComponents/Step/DatePickerStep/MaterialDatePickerStep/MaterialDatePickerStep.js +1 -1
  8. package/dist/FormComponents/Step/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.d.ts +7 -5
  9. package/dist/FormComponents/Step/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.js +53 -40
  10. package/dist/FormComponents/Step/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.module.css +10 -2
  11. package/dist/FormComponents/Step/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.d.ts +9 -6
  12. package/dist/FormComponents/Step/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.js +165 -74
  13. package/dist/FormComponents/Step/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.module.css +9 -1
  14. package/dist/FormComponents/Step/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.js +3 -3
  15. package/dist/FormComponents/Step/TextAreaStep/MaterialTextAreaStep/MaterialTextAreaStep.js +2 -2
  16. package/dist/FormComponents/Step/TextInputStep/MaterialTextInputStep/MaterialTextInputStep.js +1 -1
  17. package/dist/constants/Files/FileExtensions.js +3 -0
  18. package/dist/controllers/FileService.d.ts +3 -3
  19. package/dist/controllers/FileService.js +2 -2
  20. package/dist/shared/RoundedSelect/RoundedSelect.js +3 -0
  21. package/package.json +3 -2
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),
@@ -83,10 +94,11 @@ function ColumnForm(_a) {
83
94
  switch (_c.label) {
84
95
  case 0:
85
96
  if (!(apiKey || internal)) return [3 /*break*/, 8];
86
- return [4 /*yield*/, trigger()];
97
+ return [4 /*yield*/, trigger(undefined, { shouldFocus: true })];
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;
@@ -31,7 +31,7 @@ import StepComponent from '../../Step';
31
31
  import { Controller } from 'react-hook-form';
32
32
  import { calcFillerSize, calcStepWidth } from '../../StepFunctions';
33
33
  function ClassifierSelector(_a) {
34
- var step = _a.step, form = _a.form, level = _a.level, errors = _a.errors, value = _a.value, onBlur = _a.onBlur, control = _a.control, onChange = _a.onChange, postview = _a.postview, formStyle = _a.formStyle, getValues = _a.getValues, widthStats = _a.widthStats, handleSizeChange = _a.handleSizeChange, others = __rest(_a, ["step", "form", "level", "errors", "value", "onBlur", "control", "onChange", "postview", "formStyle", "getValues", "widthStats", "handleSizeChange"]);
34
+ var step = _a.step, form = _a.form, level = _a.level, errors = _a.errors, value = _a.value, onBlur = _a.onBlur, control = _a.control, onChange = _a.onChange, postview = _a.postview, inputRef = _a.inputRef, formStyle = _a.formStyle, getValues = _a.getValues, widthStats = _a.widthStats, handleSizeChange = _a.handleSizeChange, others = __rest(_a, ["step", "form", "level", "errors", "value", "onBlur", "control", "onChange", "postview", "inputRef", "formStyle", "getValues", "widthStats", "handleSizeChange"]);
35
35
  var _b = useState(level === 0 ? calcFillerSize(step, form.steps, getValues(), form) : 0), fillerSize = _b[0], setFillerSize = _b[1];
36
36
  if (!step.idClassifier) {
37
37
  return _jsx("div", {}, void 0);
@@ -56,7 +56,7 @@ function ClassifierSelector(_a) {
56
56
  } }, { children: _jsxs(RoundedSelect, __assign({ fullWidth: true, value: value, cantEdit: postview, errorColor: formStyle.errorColor, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, label: step.label ? step.label : classifier.name, required: step.required, containerMargin: "0px", height: '31px', onBlur: onBlur, handleUpdate: function (event) {
57
57
  onChange(event.target.value);
58
58
  sizeChange();
59
- }, helperText: errors[step.id]
59
+ }, inputRef: inputRef, helperText: errors[step.id]
60
60
  ? errors[step.id].message
61
61
  : step.description, error: !!errors[step.id] }, { children: [_jsx(MenuItem, __assign({ value: '' }, { children: _jsx("em", { children: "Sin Seleccionar" }, void 0) }), 'EMPTY'), classifier.children
62
62
  .filter(function (classifier) {
@@ -100,6 +100,6 @@ function ClassifierSelectorStep(props) {
100
100
  : undefined,
101
101
  }, shouldUnregister: true, render: function (_a) {
102
102
  var field = _a.field;
103
- return (_jsx(ClassifierSelector, __assign({}, props, { value: field.value, onChange: field.onChange, onBlur: field.onBlur }), void 0));
103
+ return (_jsx(ClassifierSelector, __assign({}, props, { inputRef: field.ref, value: field.value, onChange: field.onChange, onBlur: field.onBlur }), void 0));
104
104
  } }, void 0));
105
105
  }
@@ -27,7 +27,7 @@ function DatePickerStep(_a) {
27
27
  : undefined,
28
28
  }, shouldUnregister: true, render: function (_a) {
29
29
  var field = _a.field;
30
- return (_jsx(RoundedDatePicker, __assign({}, field, { showIcon: step.showIcon, cantEdit: postview, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, textColor: formStyle.textColor, errorColor: formStyle.errorColor, fontWeight: 400, label: step.label, helperText: errors[step.id]
30
+ return (_jsx(RoundedDatePicker, __assign({}, field, { showIcon: step.showIcon, inputRef: field.ref, cantEdit: postview, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, textColor: formStyle.textColor, errorColor: formStyle.errorColor, fontWeight: 400, label: step.label, helperText: errors[step.id]
31
31
  ? errors[step.id].message
32
32
  : step.description, error: !!errors[step.id], required: step.required }), void 0));
33
33
  } }, void 0) }), void 0));
@@ -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,13 +1,16 @@
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 {
9
- lblFile: string;
10
- name: string;
11
+ export interface UploadedFileObject {
12
+ fileName: string;
13
+ S3Key: string;
11
14
  }
12
15
  declare function UploadStepComponent(props: FileUploadStepProps): JSX.Element;
13
16
  export default UploadStepComponent;
@@ -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.lblFile),
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, value = _a.value, domain = _a.domain, btnRef = _a.btnRef, postview = _a.postview, onChange = _a.onChange, formStyle = _a.formStyle, 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);
109
+ }
110
+ if (filesToFetchLink.length > 0) {
111
+ getLinks(filesToFetchLink);
112
+ onChange(__spreadArray(__spreadArray([], value, true), filesToFetchLink, true));
85
113
  }
86
- }, [fileUploaded]);
87
- function getUploadUrlsAsync(pFiles) {
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*/];
150
+ }
151
+ });
152
+ });
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*/];
125
174
  }
126
175
  });
127
176
  });
128
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
- }, 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
- if (!postview) {
137
- var input = inputRef.current;
138
- if (input !== null) {
139
- clearErrors(step.id);
140
- input.click();
219
+ }, multiple: true, accept: getAcceptedExtensions() }, void 0), _jsxs("div", __assign({ className: styles.btnContainer }, { children: [_jsx("input", { ref: btnRef, className: styles.hiddenInput }, void 0), _jsx(RoundedButton, { disabled: postview, text: 'Examinar' + (step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
220
+ if (!postview) {
221
+ var input = inputRef.current;
222
+ if (input !== null) {
223
+ clearErrors(step.id);
224
+ setError(undefined);
225
+ input.click();
226
+ }
141
227
  }
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);
142
236
  }
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.name !== fileToDelete.name; });
145
- var tempFiles = files.filter(function (file) {
146
- return file.postInfo.name !== fileToDelete.name;
147
- });
148
- setFiles(tempFiles);
149
- onChange(tempArray);
150
- setUploadedFiles(tempArray);
151
- }, handleUploaded: function (info) {
152
- setFileUploaded(info);
153
- } }, index)); }) }), void 0)] }), void 0));
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, { btnRef: field.ref, onChange: field.onChange, value: field.value }), void 0));
163
254
  } }, void 0));
164
255
  }
165
256
  export default UploadStepComponent;
@@ -32,14 +32,22 @@
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
 
43
44
  .filesContainer {
44
45
  padding-top: 5px;
45
46
  }
47
+
48
+ .hiddenInput {
49
+ height: 0;
50
+ width: 0;
51
+ padding: 0;
52
+ border-width: 0;
53
+ }
@@ -31,7 +31,7 @@ import StepComponent from '../../Step';
31
31
  import { calcFillerSize, calcStepWidth } from '../../StepFunctions';
32
32
  import { Controller } from 'react-hook-form';
33
33
  function Selector(_a) {
34
- var step = _a.step, form = _a.form, value = _a.value, level = _a.level, onBlur = _a.onBlur, control = _a.control, onChange = _a.onChange, postview = _a.postview, formStyle = _a.formStyle, getValues = _a.getValues, widthStats = _a.widthStats, handleSizeChange = _a.handleSizeChange, errors = _a.errors, others = __rest(_a, ["step", "form", "value", "level", "onBlur", "control", "onChange", "postview", "formStyle", "getValues", "widthStats", "handleSizeChange", "errors"]);
34
+ var step = _a.step, form = _a.form, value = _a.value, level = _a.level, onBlur = _a.onBlur, control = _a.control, onChange = _a.onChange, postview = _a.postview, formStyle = _a.formStyle, getValues = _a.getValues, widthStats = _a.widthStats, handleSizeChange = _a.handleSizeChange, errors = _a.errors, inputRef = _a.inputRef, others = __rest(_a, ["step", "form", "value", "level", "onBlur", "control", "onChange", "postview", "formStyle", "getValues", "widthStats", "handleSizeChange", "errors", "inputRef"]);
35
35
  var _b = useState(level === 0 ? calcFillerSize(step, form.steps, getValues(), form) : 0), fillerSize = _b[0], setFillerSize = _b[1];
36
36
  var sizeChange = function () {
37
37
  handleSizeChange();
@@ -46,7 +46,7 @@ function Selector(_a) {
46
46
  : calcStepWidth(step.size, form),
47
47
  maxWidth: '100%',
48
48
  minHeight: step.description || step.required ? '55px' : '43px',
49
- } }, { children: _jsxs(RoundedSelect, __assign({ value: value, fullWidth: true, cantEdit: postview, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, errorColor: formStyle.errorColor, color: formStyle.textColor, label: step.label, required: step.required, containerMargin: "0px", height: '31px', onBlur: onBlur, handleUpdate: function (event) {
49
+ } }, { children: _jsxs(RoundedSelect, __assign({ value: value, fullWidth: true, inputRef: inputRef, cantEdit: postview, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, errorColor: formStyle.errorColor, color: formStyle.textColor, label: step.label, required: step.required, containerMargin: "0px", height: '31px', onBlur: onBlur, handleUpdate: function (event) {
50
50
  onChange(event.target.value);
51
51
  sizeChange();
52
52
  }, helperText: errors[step.id]
@@ -93,7 +93,7 @@ function SelectorStep(props) {
93
93
  : undefined,
94
94
  }, shouldUnregister: true, render: function (_a) {
95
95
  var field = _a.field;
96
- return (_jsx(Selector, __assign({}, props, { value: field.value, onChange: field.onChange, onBlur: field.onBlur }), void 0));
96
+ return (_jsx(Selector, __assign({}, props, { inputRef: field.ref, value: field.value, onChange: field.onChange, onBlur: field.onBlur }), void 0));
97
97
  } }, void 0));
98
98
  }
99
99
  export default SelectorStep;
@@ -76,7 +76,7 @@ function TextAreaStep(_a) {
76
76
  : {}, shouldUnregister: true, render: function (_a) {
77
77
  var _b;
78
78
  var field = _a.field;
79
- return (_jsx(Editor, { onBlur: field.onBlur, editorState: field.value, onEditorStateChange: field.onChange, toolbarClassName: styles.toolbar, editorClassName: styles.editor, wrapperClassName: styles.wrapper, editorStyle: { lineHeight: '85%' }, placeholder: (_b = step.description) !== null && _b !== void 0 ? _b : '', toolbar: {
79
+ return (_jsx(Editor, { editorRef: field.ref, onBlur: field.onBlur, editorState: field.value, onEditorStateChange: field.onChange, toolbarClassName: styles.toolbar, editorClassName: styles.editor, wrapperClassName: styles.wrapper, editorStyle: { lineHeight: '85%' }, placeholder: (_b = step.description) !== null && _b !== void 0 ? _b : '', toolbar: {
80
80
  options: ['inline', 'list', 'history'],
81
81
  inline: {
82
82
  options: [
@@ -103,7 +103,7 @@ function TextAreaStep(_a) {
103
103
  : undefined,
104
104
  }, shouldUnregister: true, render: function (_a) {
105
105
  var field = _a.field;
106
- return (_jsx(RoundedTextField, __assign({}, field, { label: step.label, required: step.required, cantEdit: postview, fontWeight: 400, multiline: true, minRows: 4, maxRows: 6, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, textColor: formStyle.textColor, errorColor: formStyle.errorColor, backgroundColor: formStyle.backgroundColor, innerBackgroundColor: formStyle.stepBackgroundColor, helperText: errors[step.id]
106
+ return (_jsx(RoundedTextField, __assign({}, field, { label: step.label, inputRef: field.ref, required: step.required, cantEdit: postview, fontWeight: 400, multiline: true, minRows: 4, maxRows: 6, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, textColor: formStyle.textColor, errorColor: formStyle.errorColor, backgroundColor: formStyle.backgroundColor, innerBackgroundColor: formStyle.stepBackgroundColor, helperText: errors[step.id]
107
107
  ? errors[step.id].message
108
108
  : step.description, error: !!errors[step.id] }), void 0));
109
109
  } }, void 0) }), void 0));
@@ -35,7 +35,7 @@ function TextInputStep(_a) {
35
35
  : undefined,
36
36
  }, shouldUnregister: true, render: function (_a) {
37
37
  var field = _a.field;
38
- return (_jsx(RoundedTextField, __assign({}, field, { label: step.label, cantEdit: postview, required: step.required, fontWeight: 400, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, textColor: formStyle.textColor, errorColor: formStyle.errorColor, backgroundColor: formStyle.backgroundColor, innerBackgroundColor: formStyle.stepBackgroundColor, helperText: errors[step.id]
38
+ return (_jsx(RoundedTextField, __assign({}, field, { label: step.label, inputRef: field.ref, cantEdit: postview, required: step.required, fontWeight: 400, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, textColor: formStyle.textColor, errorColor: formStyle.errorColor, backgroundColor: formStyle.backgroundColor, innerBackgroundColor: formStyle.stepBackgroundColor, helperText: errors[step.id]
39
39
  ? errors[step.id].message
40
40
  : step.description, error: !!errors[step.id] }), void 0));
41
41
  } }, void 0) }), void 0));
@@ -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,5 +1,5 @@
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
- lblFile: string;
4
- name: string;
3
+ fileName: string;
4
+ S3Key: string;
5
5
  }>;
@@ -85,8 +85,8 @@ export function postFile(file, postInfo) {
85
85
  case 1:
86
86
  _a.sent();
87
87
  return [2 /*return*/, {
88
- lblFile: file.name,
89
- name: postInfo.name,
88
+ fileName: file.name,
89
+ S3Key: postInfo.S3Key,
90
90
  }];
91
91
  }
92
92
  });
@@ -82,6 +82,9 @@ var useOutlinedInputStyles = function (props) {
82
82
  '&$focused $notchedOutline': {
83
83
  borderColor: props.focusColor,
84
84
  },
85
+ '& .EF-MuiSelect-icon.Mui-disabled': {
86
+ color: props.outlineColor,
87
+ },
85
88
  borderRadius: 10,
86
89
  color: props.color,
87
90
  },
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.28",
4
+ "version": "0.2.31-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",
@@ -74,5 +74,6 @@
74
74
  "main": "./dist/index.lib.js",
75
75
  "files": [
76
76
  "/dist"
77
- ]
77
+ ],
78
+ "proxy": "https://arquimedes.forms.eureka-test.click"
78
79
  }