@tap-payments/auth-jsconnect 2.3.7-test → 2.3.9-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/build/@types/form.d.ts +0 -1
- package/build/components/DatePicker/DatePicker.js +5 -3
- package/build/features/app/entity/entityStore.d.ts +2 -12
- package/build/features/app/entity/entityStore.js +6 -51
- package/build/features/business/screens/BusinessType/Article.js +1 -1
- package/build/features/entity/screens/EntityName/Article.js +12 -53
- package/build/features/entity/screens/EntityName/EntityName.js +2 -3
- package/build/features/entity/screens/EntityName/ExpiryDate.js +2 -1
- package/build/features/shared/UploadFile/FileUpload.d.ts +27 -0
- package/build/features/shared/UploadFile/FileUpload.js +220 -0
- package/build/features/shared/UploadFile/UploadWrapper.d.ts +31 -0
- package/build/features/shared/UploadFile/UploadWrapper.js +114 -0
- package/build/features/shared/UploadFile/index.d.ts +2 -1
- package/build/features/shared/UploadFile/index.js +2 -1
- package/package.json +1 -1
package/build/@types/form.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ import Divider from '@mui/material/Divider';
|
|
|
30
30
|
import Collapse from '../Collapse';
|
|
31
31
|
import ExpandIcon from '../ExpandIcon';
|
|
32
32
|
import CalendarTodayOutlined from '@mui/icons-material/CalendarTodayOutlined';
|
|
33
|
-
import { scrollDown, scrollUp } from '../../utils';
|
|
33
|
+
import { convertNumbers2English, dateFormat, scrollDown, scrollUp } from '../../utils';
|
|
34
34
|
import Input from '../Input';
|
|
35
35
|
import Text from '../Text';
|
|
36
36
|
import './customStyle.css';
|
|
@@ -84,8 +84,10 @@ var DatePicker = function (_a) {
|
|
|
84
84
|
setTimeout(function () { return scrollUp(elementId); }, 550);
|
|
85
85
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
86
86
|
};
|
|
87
|
-
var formattedDate = function (
|
|
88
|
-
|
|
87
|
+
var formattedDate = function (d) {
|
|
88
|
+
var date = new Date(d);
|
|
89
|
+
var formattedDate = dateFormat(date, 'YYYY-MM-DD');
|
|
90
|
+
return convertNumbers2English(formattedDate);
|
|
89
91
|
};
|
|
90
92
|
var handleOnDateChange = function (date) {
|
|
91
93
|
setDate(date);
|
|
@@ -46,15 +46,6 @@ export declare const updateEntityName: import("@reduxjs/toolkit").AsyncThunk<{
|
|
|
46
46
|
data: any;
|
|
47
47
|
formData: EntityNameFormValues;
|
|
48
48
|
}, EntityNameFormValues, {}>;
|
|
49
|
-
interface UploadArticleParams {
|
|
50
|
-
file: File;
|
|
51
|
-
onProgress?: (value: number) => void;
|
|
52
|
-
onSuccess?: (fileId: string) => void;
|
|
53
|
-
onFailure?: (error: string) => void;
|
|
54
|
-
}
|
|
55
|
-
export declare const uploadArticle: import("@reduxjs/toolkit").AsyncThunk<{
|
|
56
|
-
data: any;
|
|
57
|
-
}, UploadArticleParams, {}>;
|
|
58
49
|
export declare const updateEntityCapital: import("@reduxjs/toolkit").AsyncThunk<{
|
|
59
50
|
data: any;
|
|
60
51
|
formData: EntityCapitalFormValues;
|
|
@@ -77,16 +68,15 @@ export interface EntityState extends SharedState<EntityData> {
|
|
|
77
68
|
customLoading?: boolean;
|
|
78
69
|
uploading?: boolean;
|
|
79
70
|
uploadingArticle?: boolean;
|
|
80
|
-
uploadingArticleError?: string | null;
|
|
81
71
|
}
|
|
82
72
|
export declare const entitySlice: import("@reduxjs/toolkit").Slice<EntityState, {
|
|
83
73
|
clearError: (state: EntityState) => void;
|
|
84
74
|
stopLoader: (state: EntityState) => void;
|
|
85
75
|
resetOTPScreen: (state: EntityState) => void;
|
|
86
76
|
uploadingStatus: (state: EntityState, action: ActionState<boolean>) => void;
|
|
87
|
-
|
|
77
|
+
uploadingArticleStatus: (state: EntityState, action: ActionState<boolean>) => void;
|
|
88
78
|
}, "entity/store">;
|
|
89
|
-
export declare const clearError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, stopLoader: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetOTPScreen: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, uploadingStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>,
|
|
79
|
+
export declare const clearError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, stopLoader: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetOTPScreen: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, uploadingStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>, uploadingArticleStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
|
|
90
80
|
declare const _default: import("redux").Reducer<EntityState, import("redux").AnyAction>;
|
|
91
81
|
export default _default;
|
|
92
82
|
export declare const entitySelector: (state: RootState) => EntityState;
|
|
@@ -240,7 +240,7 @@ export var retrieveBoardDetails = createAsyncThunk('entityRetrieveEntityInfo', f
|
|
|
240
240
|
});
|
|
241
241
|
}); });
|
|
242
242
|
export var updateEntityName = createAsyncThunk('entityUpdateEntityName', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
|
|
243
|
-
var _a, settings, entity, entityData, _b, id, data_status,
|
|
243
|
+
var _a, settings, entity, entityData, _b, id, data_status, issuingDate, expiryDate, isFL, isLegalNameEditable, isLicenseTypeEditable, isEntityTypeEditable, isLicenseNumberEditable, isUnifiedNumberEditable, isIssuingDateEditable, isExpiryDateEditable, documentResponse, document, documentBody, documentBody, payload, data, list;
|
|
244
244
|
var _c, _d;
|
|
245
245
|
return __generator(this, function (_e) {
|
|
246
246
|
switch (_e.label) {
|
|
@@ -248,7 +248,6 @@ export var updateEntityName = createAsyncThunk('entityUpdateEntityName', functio
|
|
|
248
248
|
_a = thunkApi.getState(), settings = _a.settings, entity = _a.entity;
|
|
249
249
|
entityData = (entity.data.verify.responseBody || {}).entity;
|
|
250
250
|
_b = entityData || {}, id = _b.id, data_status = _b.data_status;
|
|
251
|
-
articleId = entity.data.entityNameData.articleId;
|
|
252
251
|
issuingDate = new Date(params.issuingDate).getTime();
|
|
253
252
|
expiryDate = new Date(params.expiryDate).getTime();
|
|
254
253
|
isFL = params.licenseType === BusinessType.FL;
|
|
@@ -287,7 +286,7 @@ export var updateEntityName = createAsyncThunk('entityUpdateEntityName', functio
|
|
|
287
286
|
case 4:
|
|
288
287
|
payload = {
|
|
289
288
|
id: id,
|
|
290
|
-
AOA_file_id: articleId,
|
|
289
|
+
AOA_file_id: params.articleId,
|
|
291
290
|
license: {
|
|
292
291
|
number: isLicenseNumberEditable && params.licenseNumber ? params.licenseNumber : undefined,
|
|
293
292
|
type: isLicenseTypeEditable ? (isFL ? 'freelance' : 'commercial_registration') : undefined,
|
|
@@ -331,35 +330,6 @@ export var updateEntityName = createAsyncThunk('entityUpdateEntityName', functio
|
|
|
331
330
|
}
|
|
332
331
|
});
|
|
333
332
|
}); });
|
|
334
|
-
export var uploadArticle = createAsyncThunk('entityUploadArticle', function (_a) {
|
|
335
|
-
var file = _a.file, onProgress = _a.onProgress;
|
|
336
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
337
|
-
var typeArray, type, uploadPayload, onUploadProgress, data;
|
|
338
|
-
var _b;
|
|
339
|
-
return __generator(this, function (_c) {
|
|
340
|
-
switch (_c.label) {
|
|
341
|
-
case 0:
|
|
342
|
-
typeArray = ((_b = file === null || file === void 0 ? void 0 : file.type) === null || _b === void 0 ? void 0 : _b.split('/')) || [];
|
|
343
|
-
type = typeArray[1] || '';
|
|
344
|
-
uploadPayload = {
|
|
345
|
-
file_link_create: true,
|
|
346
|
-
title: file === null || file === void 0 ? void 0 : file.name,
|
|
347
|
-
purpose: DocumentPurpose.ARTICLE_ASSOCIATION,
|
|
348
|
-
type: type,
|
|
349
|
-
file: file
|
|
350
|
-
};
|
|
351
|
-
onUploadProgress = function (progressEvent) {
|
|
352
|
-
var progress = ((progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.loaded) / (progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.total)) * 100;
|
|
353
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress(Math.floor(progress));
|
|
354
|
-
};
|
|
355
|
-
return [4, API.fileService.uploadFileInfo(uploadPayload, { onUploadProgress: onUploadProgress })];
|
|
356
|
-
case 1:
|
|
357
|
-
data = _c.sent();
|
|
358
|
-
return [2, { data: data }];
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
333
|
export var updateEntityCapital = createAsyncThunk('entityUpdateEntityCapital', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
|
|
364
334
|
var _a, settings, entity, entityData, _b, id, data_status, isCapitalPaidEditable, isCapitalShareEditable, activities, payload, data;
|
|
365
335
|
var _c, _d, _e;
|
|
@@ -434,7 +404,6 @@ var initialState = {
|
|
|
434
404
|
customLoading: false,
|
|
435
405
|
uploading: false,
|
|
436
406
|
uploadingArticle: false,
|
|
437
|
-
uploadingArticleError: null,
|
|
438
407
|
data: {
|
|
439
408
|
flowName: FlowsTypes.ENTITY,
|
|
440
409
|
verify: {
|
|
@@ -476,8 +445,8 @@ export var entitySlice = createSlice({
|
|
|
476
445
|
uploadingStatus: function (state, action) {
|
|
477
446
|
state.uploading = action.payload;
|
|
478
447
|
},
|
|
479
|
-
|
|
480
|
-
state.
|
|
448
|
+
uploadingArticleStatus: function (state, action) {
|
|
449
|
+
state.uploadingArticle = action.payload;
|
|
481
450
|
}
|
|
482
451
|
},
|
|
483
452
|
extraReducers: function (builder) {
|
|
@@ -635,7 +604,7 @@ export var entitySlice = createSlice({
|
|
|
635
604
|
state.error = null;
|
|
636
605
|
var _a = action.payload, data = _a.data, formData = _a.formData;
|
|
637
606
|
var _b = data || {}, activityList = _b.activityList, rest = __rest(_b, ["activityList"]);
|
|
638
|
-
state.data.entityNameData = formData;
|
|
607
|
+
state.data.entityNameData = __assign(__assign({}, formData), { certificateId: undefined });
|
|
639
608
|
state.data.entityNameData.responseBody = __assign(__assign({}, state.data.entityNameData.responseBody), { rest: rest });
|
|
640
609
|
state.data.verify.responseBody = __assign(__assign({}, state.data.verify.responseBody), { entity: data === null || data === void 0 ? void 0 : data.entity, activityList: activityList });
|
|
641
610
|
if (rest === null || rest === void 0 ? void 0 : rest.activities)
|
|
@@ -644,20 +613,6 @@ export var entitySlice = createSlice({
|
|
|
644
613
|
.addCase(updateEntityName.rejected, function (state, action) {
|
|
645
614
|
state.loading = false;
|
|
646
615
|
state.error = action.error.message;
|
|
647
|
-
})
|
|
648
|
-
.addCase(uploadArticle.pending, function (state) {
|
|
649
|
-
state.uploadingArticleError = null;
|
|
650
|
-
state.uploadingArticle = true;
|
|
651
|
-
})
|
|
652
|
-
.addCase(uploadArticle.fulfilled, function (state, action) {
|
|
653
|
-
state.uploadingArticleError = null;
|
|
654
|
-
state.uploadingArticle = false;
|
|
655
|
-
var data = action.payload.data;
|
|
656
|
-
state.data.entityNameData.articleId = data === null || data === void 0 ? void 0 : data.id;
|
|
657
|
-
})
|
|
658
|
-
.addCase(uploadArticle.rejected, function (state) {
|
|
659
|
-
state.uploadingArticle = false;
|
|
660
|
-
state.uploadingArticleError = 'file_upload_article_error';
|
|
661
616
|
})
|
|
662
617
|
.addCase(updateEntityCapital.pending, function (state) {
|
|
663
618
|
state.loading = true;
|
|
@@ -711,6 +666,6 @@ export var entitySlice = createSlice({
|
|
|
711
666
|
});
|
|
712
667
|
}
|
|
713
668
|
});
|
|
714
|
-
export var clearError = (_a = entitySlice.actions, _a.clearError), stopLoader = _a.stopLoader, resetOTPScreen = _a.resetOTPScreen, uploadingStatus = _a.uploadingStatus,
|
|
669
|
+
export var clearError = (_a = entitySlice.actions, _a.clearError), stopLoader = _a.stopLoader, resetOTPScreen = _a.resetOTPScreen, uploadingStatus = _a.uploadingStatus, uploadingArticleStatus = _a.uploadingArticleStatus;
|
|
715
670
|
export default entitySlice.reducer;
|
|
716
671
|
export var entitySelector = function (state) { return state.entity; };
|
|
@@ -17,7 +17,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
17
17
|
import { useController, useFormContext } from 'react-hook-form';
|
|
18
18
|
import { useAppDispatch, useAppSelector } from '../../../../hooks';
|
|
19
19
|
import { businessSelector, clearArticleId, uploadArticle } from '../../../app/business/businessStore';
|
|
20
|
-
import UploadFile from '../../../shared/UploadFile';
|
|
20
|
+
import { UploadFile } from '../../../shared/UploadFile';
|
|
21
21
|
import { MAX_FILE_SIZE, VALID_FILE_FORMATS } from '../../../../constants';
|
|
22
22
|
import { maskFileName } from '../../../../utils';
|
|
23
23
|
import Collapse from '../../../../components/Collapse';
|
|
@@ -10,17 +10,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import React from 'react';
|
|
14
13
|
import { useTranslation } from 'react-i18next';
|
|
15
14
|
import { useController, useFormContext } from 'react-hook-form';
|
|
16
15
|
import { styled } from '@mui/material/styles';
|
|
17
|
-
import { MAX_FILE_SIZE, VALID_FILE_FORMATS } from '../../../../constants';
|
|
18
|
-
import { maskFileName } from '../../../../utils';
|
|
19
16
|
import { useAppDispatch, useAppSelector } from '../../../../hooks';
|
|
17
|
+
import { DocumentPurpose } from '../../../../@types';
|
|
20
18
|
import Collapse from '../../../../components/Collapse';
|
|
21
19
|
import { ScreenContainer } from '../../../shared/Containers';
|
|
22
|
-
import {
|
|
23
|
-
import
|
|
20
|
+
import { UploadWrapper } from '../../../shared/UploadFile';
|
|
21
|
+
import { entitySelector, uploadingArticleStatus } from '../../../app/entity/entityStore';
|
|
24
22
|
var FeatureStyled = styled(ScreenContainer)(function (_a) {
|
|
25
23
|
var theme = _a.theme;
|
|
26
24
|
return ({
|
|
@@ -28,60 +26,21 @@ var FeatureStyled = styled(ScreenContainer)(function (_a) {
|
|
|
28
26
|
});
|
|
29
27
|
});
|
|
30
28
|
var Article = function (_a) {
|
|
29
|
+
var _b, _c;
|
|
31
30
|
var show = _a.show;
|
|
32
|
-
var _b = React.useState(), error = _b[0], setError = _b[1];
|
|
33
|
-
var _c = React.useState(0), progress = _c[0], setProgress = _c[1];
|
|
34
31
|
var t = useTranslation().t;
|
|
35
|
-
var
|
|
36
|
-
var articleFileControl = useController({ name: 'articleFile', control: control });
|
|
32
|
+
var control = useFormContext().control;
|
|
37
33
|
var articleIdControl = useController({ name: 'articleId', control: control });
|
|
38
|
-
var
|
|
34
|
+
var loading = useAppSelector(entitySelector).loading;
|
|
39
35
|
var dispatch = useAppDispatch();
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
React.useEffect(function () {
|
|
44
|
-
if (!articleValue) {
|
|
45
|
-
setValue('articleFile', articleFile);
|
|
46
|
-
setValue('articleId', articleId);
|
|
47
|
-
}
|
|
48
|
-
}, [articleFile, articleId]);
|
|
49
|
-
var handleArticleChange = function (files) {
|
|
50
|
-
setError('');
|
|
51
|
-
var file = files === null || files === void 0 ? void 0 : files[0];
|
|
52
|
-
if (!file)
|
|
53
|
-
return;
|
|
54
|
-
if (!VALID_FILE_FORMATS.includes(file === null || file === void 0 ? void 0 : file.type)) {
|
|
55
|
-
setError('file_not_supported_alert');
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if ((file === null || file === void 0 ? void 0 : file.size) > MAX_FILE_SIZE) {
|
|
59
|
-
setError('file_size_alert');
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
articleFileControl.field.onChange(file);
|
|
63
|
-
dispatch(uploadArticle({
|
|
64
|
-
file: file,
|
|
65
|
-
onProgress: function (value) {
|
|
66
|
-
setProgress(value);
|
|
67
|
-
}
|
|
68
|
-
}));
|
|
36
|
+
var data = useAppSelector(entitySelector).data;
|
|
37
|
+
var handleArticleChange = function (id) {
|
|
38
|
+
articleIdControl.field.onChange(id);
|
|
69
39
|
};
|
|
70
40
|
var handleReset = function () {
|
|
71
|
-
|
|
72
|
-
articleIdControl.field.onChange('');
|
|
73
|
-
dispatch(clearArticleId());
|
|
74
|
-
setProgress(0);
|
|
41
|
+
articleIdControl.field.onChange(undefined);
|
|
75
42
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
setError(sysError);
|
|
79
|
-
articleFileControl.field.onChange(undefined);
|
|
80
|
-
setProgress(0);
|
|
81
|
-
}
|
|
82
|
-
}, [sysError]);
|
|
83
|
-
var fileName = articleValue ? maskFileName(articleValue === null || articleValue === void 0 ? void 0 : articleValue.name) : '';
|
|
84
|
-
var errorValue = error || sysError || '';
|
|
85
|
-
return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadFile, { label: t('title_article'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('article_of_association'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleArticleChange, isFileUploaded: !uploadingArticle && !!articleValue, isSubmitting: loading, isUploading: uploadingArticle, progress: progress, onReset: handleReset, error: errorValue && t(errorValue), initialFileName: fileName }) }) })));
|
|
43
|
+
var defaultFile = (_c = (_b = data.verify.responseBody) === null || _b === void 0 ? void 0 : _b.entity) === null || _c === void 0 ? void 0 : _c.AOA_file;
|
|
44
|
+
return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadWrapper, { id: 'articleId', control: control, label: t('title_article'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('article_of_association'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleArticleChange, isSubmitting: loading, onDeleteFile: handleReset, defaultFile: defaultFile, purpose: DocumentPurpose.ARTICLE_ASSOCIATION, fileUploadingStatus: function (uploading) { return dispatch(uploadingArticleStatus(uploading)); } }) }) })));
|
|
86
45
|
};
|
|
87
46
|
export default Article;
|
|
@@ -46,7 +46,7 @@ var EntityName = function (_a) {
|
|
|
46
46
|
var isAr = useLanguage().isAr;
|
|
47
47
|
var t = useTranslation().t;
|
|
48
48
|
var dispatch = useAppDispatch();
|
|
49
|
-
var _f = data.entityNameData, legalName = _f.legalName, licenseNumber = _f.licenseNumber, licenseType = _f.licenseType, entityType = _f.entityType, issuingDate = _f.issuingDate, expiryDate = _f.expiryDate, unifiedNumber = _f.unifiedNumber, certificateId = _f.certificateId, articleId = _f.articleId
|
|
49
|
+
var _f = data.entityNameData, legalName = _f.legalName, licenseNumber = _f.licenseNumber, licenseType = _f.licenseType, entityType = _f.entityType, issuingDate = _f.issuingDate, expiryDate = _f.expiryDate, unifiedNumber = _f.unifiedNumber, certificateId = _f.certificateId, articleId = _f.articleId;
|
|
50
50
|
var country_code = settingsData.businessCountry.iso2;
|
|
51
51
|
var isSACountry = React.useMemo(function () { return isSA(country_code); }, [country_code]);
|
|
52
52
|
var isKWCountry = React.useMemo(function () { return isKW(country_code); }, [country_code]);
|
|
@@ -63,8 +63,7 @@ var EntityName = function (_a) {
|
|
|
63
63
|
expiryDate: expiryDate,
|
|
64
64
|
unifiedNumber: unifiedNumber,
|
|
65
65
|
certificateId: certificateId,
|
|
66
|
-
articleId: articleId
|
|
67
|
-
articleFile: articleFile
|
|
66
|
+
articleId: articleId
|
|
68
67
|
},
|
|
69
68
|
mode: 'onChange'
|
|
70
69
|
});
|
|
@@ -14,6 +14,7 @@ import { useController, useFormContext } from 'react-hook-form';
|
|
|
14
14
|
import { useTranslation } from 'react-i18next';
|
|
15
15
|
import { alpha, Collapse, styled } from '@mui/material';
|
|
16
16
|
import { useAppDispatch, useAppSelector } from '../../../../hooks';
|
|
17
|
+
import { getFutureDate } from '../../../../utils';
|
|
17
18
|
import Text from '../../../../components/Text';
|
|
18
19
|
import { ScreenContainer } from '../../../shared/Containers';
|
|
19
20
|
import { entitySelector, clearError } from '../../../app/entity/entityStore';
|
|
@@ -40,6 +41,6 @@ var ExpiryDate = function (_a) {
|
|
|
40
41
|
dispatch(clearError());
|
|
41
42
|
oDateControl.field.onChange(data);
|
|
42
43
|
};
|
|
43
|
-
return (_jsx(Collapse, __assign({ in: !hide }, { children: _jsxs(ScreenContainer, __assign({ sx: { mt: 2.5 } }, { children: [_jsx(InputLabelStyled, { children: t('business_expiry_date') }), _jsx(DatePicker, { readOnly: true, disabled: disabled, defaultValue: dateValue ? new Date(dateValue) : new Date(), dir: 'ltr', locale: 'en', onClick: function () { return onDateClicked === null || onDateClicked === void 0 ? void 0 : onDateClicked(true); }, onDatePicked: function () { return onDateClicked === null || onDateClicked === void 0 ? void 0 : onDateClicked(false); }, onDateChange: handleExpiryDateChange })] })) })));
|
|
44
|
+
return (_jsx(Collapse, __assign({ in: !hide }, { children: _jsxs(ScreenContainer, __assign({ sx: { mt: 2.5 } }, { children: [_jsx(InputLabelStyled, { children: t('business_expiry_date') }), _jsx(DatePicker, { readOnly: true, disabled: disabled, maxDate: getFutureDate(), defaultValue: dateValue ? new Date(dateValue) : new Date(), dir: 'ltr', locale: 'en', onClick: function () { return onDateClicked === null || onDateClicked === void 0 ? void 0 : onDateClicked(true); }, onDatePicked: function () { return onDateClicked === null || onDateClicked === void 0 ? void 0 : onDateClicked(false); }, onDateChange: handleExpiryDateChange })] })) })));
|
|
44
45
|
};
|
|
45
46
|
export default ExpiryDate;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SxProps, Theme } from '@mui/material/styles';
|
|
3
|
+
import { FileInfo } from '../../../constants';
|
|
4
|
+
export declare const InputContainerStyled: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
component?: React.ElementType<any> | undefined;
|
|
7
|
+
ref?: React.Ref<unknown> | undefined;
|
|
8
|
+
sx?: SxProps<Theme> | undefined;
|
|
9
|
+
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
10
|
+
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
11
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | ("border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "color" | "zIndex" | "position" | "top" | "right" | "bottom" | "left" | "boxShadow" | "width" | "maxWidth" | "minWidth" | "height" | "maxHeight" | "minHeight" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textAlign" | "textTransform") | "ref" | "children" | "component" | "sx"> & import("@mui/system").MUIStyledCommonProps<Theme>, {}, {}>;
|
|
12
|
+
export declare type FileUploadProps = {
|
|
13
|
+
key?: string;
|
|
14
|
+
show: boolean;
|
|
15
|
+
purpose: string;
|
|
16
|
+
file: File;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
title?: string;
|
|
19
|
+
uploadedFile: FileInfo;
|
|
20
|
+
onSuccess: (file: FileInfo) => void;
|
|
21
|
+
onDelete: () => void;
|
|
22
|
+
onUpdate: (file: FileInfo, loadingStatus: boolean) => void;
|
|
23
|
+
sx?: SxProps<Theme> | undefined;
|
|
24
|
+
isSubmitting?: boolean;
|
|
25
|
+
};
|
|
26
|
+
declare const FileUpload: ({ key, show, title, file, uploadedFile, onSuccess, onDelete, onUpdate, sx, purpose, isSubmitting }: FileUploadProps) => JSX.Element;
|
|
27
|
+
export default FileUpload;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
49
|
+
import React from 'react';
|
|
50
|
+
import { useTranslation } from 'react-i18next';
|
|
51
|
+
import { alpha, styled, useTheme } from '@mui/material/styles';
|
|
52
|
+
import Box from '@mui/material/Box';
|
|
53
|
+
import ClearIcon from '@mui/icons-material/Clear';
|
|
54
|
+
import { CircularProgress as MUICircularProgress } from '@mui/material';
|
|
55
|
+
import Collapse from '../../../components/Collapse';
|
|
56
|
+
import { CircularProgress } from '../../../components/ProgressBar';
|
|
57
|
+
import Text from '../../../components/Text';
|
|
58
|
+
import Icon from '../../../components/Icon';
|
|
59
|
+
import { maskFileName } from '../../../utils';
|
|
60
|
+
import API from '../../../api';
|
|
61
|
+
import { FileStatus, ICONS_NAMES, MAX_FILE_SIZE_FOUR_MB, VALID_FILE_FORMATS } from '../../../constants';
|
|
62
|
+
import CheckIcon from '../../shared/CheckIcon';
|
|
63
|
+
var BoxStyled = styled(Box)(function (_a) {
|
|
64
|
+
var theme = _a.theme;
|
|
65
|
+
return (__assign(__assign({ direction: theme.direction }, theme.typography.subtitle2), { color: theme.palette.primary.main, fontWeight: theme.typography.fontWeightBold, background: theme.palette.background.default, padding: theme.spacing(0, 2.5, 0), width: '88%', wordBreak: 'break-all', display: 'flex', justifyContent: 'space-between' }));
|
|
66
|
+
});
|
|
67
|
+
var UploadBoxStyled = styled(Box, { shouldForwardProp: function (prop) { return prop !== 'uploading'; } })(function (_a) {
|
|
68
|
+
var theme = _a.theme, uploading = _a.uploading;
|
|
69
|
+
return (__assign(__assign({}, theme.typography.caption), { background: uploading ? alpha(theme.palette.primary.main, 0.5) : theme.palette.primary.main, color: theme.palette.common.white, fontWeight: theme.typography.fontWeightRegular, cursor: 'pointer', width: '12%', display: 'flex', justifyContent: 'center', alignItems: 'center' }));
|
|
70
|
+
});
|
|
71
|
+
var ClearIconStyled = styled(ClearIcon)(function (_a) {
|
|
72
|
+
var theme = _a.theme;
|
|
73
|
+
return ({
|
|
74
|
+
width: theme.spacing(3),
|
|
75
|
+
height: theme.spacing(3),
|
|
76
|
+
cursor: 'pointer',
|
|
77
|
+
color: theme.palette.common.white
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
export var InputContainerStyled = styled(Box)(function () { return ({
|
|
81
|
+
display: 'flex',
|
|
82
|
+
width: '100%',
|
|
83
|
+
justifyContent: 'center'
|
|
84
|
+
}); });
|
|
85
|
+
var ProgressBoxStyled = styled(Box)(function () { return ({
|
|
86
|
+
display: 'flex',
|
|
87
|
+
justifyContent: 'center',
|
|
88
|
+
alignItems: 'center'
|
|
89
|
+
}); });
|
|
90
|
+
var WarningIconStyled = styled(Icon)(function (_a) {
|
|
91
|
+
var theme = _a.theme;
|
|
92
|
+
return ({
|
|
93
|
+
width: theme.spacing(1.625),
|
|
94
|
+
height: theme.spacing(1.625),
|
|
95
|
+
marginInline: theme.spacing(0.5)
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
var ErrorIconStyled = styled(Icon)(function (_a) {
|
|
99
|
+
var theme = _a.theme;
|
|
100
|
+
return ({
|
|
101
|
+
width: theme.spacing(1.625),
|
|
102
|
+
height: theme.spacing(1.625),
|
|
103
|
+
marginInline: theme.spacing(0.5)
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
var WarningContainer = styled(Box)(function (_a) {
|
|
107
|
+
var theme = _a.theme;
|
|
108
|
+
return (__assign({ background: alpha(theme.palette.warning.main, 0.1), paddingBlock: theme.spacing(1.5), paddingInlineStart: theme.spacing(2.5), flexDirection: 'row', display: 'flex', justifyContent: 'center', color: theme.palette.warning.light, padding: theme.spacing(0.5, 1), borderRadius: '101px', alignItems: 'center', marginTop: theme.spacing(1.25) }, theme.typography.caption));
|
|
109
|
+
});
|
|
110
|
+
var FileUpload = function (_a) {
|
|
111
|
+
var key = _a.key, show = _a.show, title = _a.title, file = _a.file, uploadedFile = _a.uploadedFile, onSuccess = _a.onSuccess, onDelete = _a.onDelete, onUpdate = _a.onUpdate, sx = _a.sx, purpose = _a.purpose, isSubmitting = _a.isSubmitting;
|
|
112
|
+
var theme = useTheme();
|
|
113
|
+
var t = useTranslation().t;
|
|
114
|
+
var _b = file || {}, name = _b.name, size = _b.size, type = _b.type;
|
|
115
|
+
var _c = uploadedFile || {}, status = _c.status, progress = _c.progress, error = _c.error, fileId = _c.fileId;
|
|
116
|
+
var uploadFile = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
|
+
var uploadPayload, onUploadProgress, data, fileId;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
switch (_a.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
uploadPayload = {
|
|
122
|
+
file_link_create: true,
|
|
123
|
+
title: title || (file === null || file === void 0 ? void 0 : file.name),
|
|
124
|
+
purpose: purpose,
|
|
125
|
+
file: file
|
|
126
|
+
};
|
|
127
|
+
onUploadProgress = function (progressEvent) {
|
|
128
|
+
var progress = ((progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.loaded) / (progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.total)) * 100;
|
|
129
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { progress: Math.floor(progress), status: FileStatus.UPLOADING, error: '' });
|
|
130
|
+
onUpdate(uploadedFile, true);
|
|
131
|
+
};
|
|
132
|
+
return [4, API.fileService.uploadFile(uploadPayload, { onUploadProgress: onUploadProgress })];
|
|
133
|
+
case 1:
|
|
134
|
+
data = (_a.sent()).data;
|
|
135
|
+
fileId = (data || {}).id;
|
|
136
|
+
if (fileId) {
|
|
137
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.SUCCESS, fileId: fileId, error: '' });
|
|
138
|
+
onSuccess(uploadedFile);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { progress: 0, status: FileStatus.ERROR, error: t('file_upload_error') });
|
|
142
|
+
onUpdate(uploadedFile, false);
|
|
143
|
+
}
|
|
144
|
+
return [2];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}); };
|
|
148
|
+
var downloadFile = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
149
|
+
var onDownloadProgress, data, _a;
|
|
150
|
+
return __generator(this, function (_b) {
|
|
151
|
+
switch (_b.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
onDownloadProgress = function (progressEvent) {
|
|
154
|
+
var progress = ((progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.loaded) / (progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.total)) * 100;
|
|
155
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { progress: Math.floor(progress), status: FileStatus.DOWNLOADING, error: '' });
|
|
156
|
+
onUpdate(uploadedFile, true);
|
|
157
|
+
};
|
|
158
|
+
_b.label = 1;
|
|
159
|
+
case 1:
|
|
160
|
+
_b.trys.push([1, 3, , 4]);
|
|
161
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { progress: 0, status: FileStatus.DOWNLOADING, error: '' });
|
|
162
|
+
onUpdate(uploadedFile, true);
|
|
163
|
+
return [4, API.fileService.downloadFile(fileId, uploadedFile === null || uploadedFile === void 0 ? void 0 : uploadedFile.name, { onDownloadProgress: onDownloadProgress })];
|
|
164
|
+
case 2:
|
|
165
|
+
data = (_b.sent()).data;
|
|
166
|
+
if (data) {
|
|
167
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.SUCCESS, error: '' });
|
|
168
|
+
onSuccess(uploadedFile);
|
|
169
|
+
}
|
|
170
|
+
return [3, 4];
|
|
171
|
+
case 3:
|
|
172
|
+
_a = _b.sent();
|
|
173
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { error: t('file_download_error'), status: FileStatus.SUCCESS });
|
|
174
|
+
onUpdate(uploadedFile, false);
|
|
175
|
+
return [3, 4];
|
|
176
|
+
case 4: return [2];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}); };
|
|
180
|
+
var handleDeleteFile = function () {
|
|
181
|
+
onDelete();
|
|
182
|
+
};
|
|
183
|
+
var getProgressComponent = function () {
|
|
184
|
+
if (status === FileStatus.ERROR)
|
|
185
|
+
return _jsx(ErrorIconStyled, { src: ICONS_NAMES.ERROR_ICON });
|
|
186
|
+
if (status === FileStatus.SUCCESS)
|
|
187
|
+
return _jsx(CheckIcon, {});
|
|
188
|
+
if (status === FileStatus.DOWNLOADING && !progress)
|
|
189
|
+
return _jsx(MUICircularProgress, { size: 25, thickness: 5 });
|
|
190
|
+
if (progress)
|
|
191
|
+
return (_jsx(CircularProgress, { sx: { backgroundColor: alpha(theme.palette.primary.main, 0.05), borderRadius: '32px' }, textSx: { fontSize: theme.spacing(1.125) }, value: progress, size: 35 }));
|
|
192
|
+
return _jsx(_Fragment, {});
|
|
193
|
+
};
|
|
194
|
+
React.useEffect(function () {
|
|
195
|
+
if (!file)
|
|
196
|
+
return;
|
|
197
|
+
else if (!VALID_FILE_FORMATS.includes(type)) {
|
|
198
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.ERROR, error: t('file_not_supported_alert') });
|
|
199
|
+
onUpdate(uploadedFile, false);
|
|
200
|
+
}
|
|
201
|
+
else if (size > MAX_FILE_SIZE_FOUR_MB) {
|
|
202
|
+
uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.ERROR, error: t('file_size_alert') });
|
|
203
|
+
onUpdate(uploadedFile, false);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
if (status === FileStatus.INIT || status === FileStatus.ERROR) {
|
|
207
|
+
uploadFile();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}, [name]);
|
|
211
|
+
var canDownloadFile = fileId && status !== FileStatus.DOWNLOADING;
|
|
212
|
+
var canDeleteFile = status !== FileStatus.UPLOADING && status !== FileStatus.DOWNLOADING;
|
|
213
|
+
return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(Box, __assign({ sx: { pointerEvents: isSubmitting ? 'none' : 'auto' } }, { children: _jsxs(InputContainerStyled, __assign({ sx: __assign({ borderTop: "1px solid ".concat(alpha(theme.palette.divider, 0.8)), borderBottom: "1px solid ".concat(alpha(theme.palette.divider, 0.8)) }, sx) }, { children: [_jsxs(BoxStyled, { children: [_jsxs(Box, __assign({ sx: {
|
|
214
|
+
display: 'flex',
|
|
215
|
+
flexDirection: 'column',
|
|
216
|
+
padding: theme.spacing(1.5, 0, 1.5),
|
|
217
|
+
width: '100%'
|
|
218
|
+
} }, { children: [_jsxs(Box, __assign({ sx: { display: 'flex', flexDirection: 'row', cursor: canDownloadFile ? 'pointer' : 'auto' }, onClick: canDownloadFile ? function () { return downloadFile(); } : undefined }, { children: [_jsx(Icon, { src: ICONS_NAMES.DOC_ICON }), _jsx(Text, { children: name && maskFileName(name) })] })), _jsx(Box, __assign({ sx: { display: 'flex', flexDirection: 'row', justifyContent: 'center' } }, { children: _jsx(Collapse, __assign({ in: !!error, timeout: 400 }, { children: _jsxs(WarningContainer, { children: [_jsx(WarningIconStyled, { src: ICONS_NAMES.WARNING_ICON }), _jsx(Text, { children: t(error) })] }) })) }))] })), _jsx(ProgressBoxStyled, { children: getProgressComponent() })] }), _jsx(UploadBoxStyled, __assign({ uploading: status === FileStatus.UPLOADING || status === FileStatus.DOWNLOADING, onClick: canDeleteFile ? function () { return handleDeleteFile(); } : undefined }, { children: _jsx(ClearIconStyled, {}) }))] })) }), key) })));
|
|
219
|
+
};
|
|
220
|
+
export default FileUpload;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Control, FieldValues } from 'react-hook-form';
|
|
3
|
+
import { FileDetails } from '../../../@types';
|
|
4
|
+
export declare const InputContainerStyled: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material/styles").Theme> & {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
component?: React.ElementType<any> | undefined;
|
|
7
|
+
ref?: React.Ref<unknown> | undefined;
|
|
8
|
+
sx?: import("@mui/material/styles").SxProps<import("@mui/material/styles").Theme> | undefined;
|
|
9
|
+
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
10
|
+
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
11
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | ("border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "color" | "zIndex" | "position" | "top" | "right" | "bottom" | "left" | "boxShadow" | "width" | "maxWidth" | "minWidth" | "height" | "maxHeight" | "minHeight" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textAlign" | "textTransform") | "ref" | "children" | "component" | "sx"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
12
|
+
interface UploadWrapperProps {
|
|
13
|
+
id: string;
|
|
14
|
+
control: Control<FieldValues, any>;
|
|
15
|
+
label: string;
|
|
16
|
+
purpose: string;
|
|
17
|
+
fileTitle?: string;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
title: string;
|
|
20
|
+
subTitle: string;
|
|
21
|
+
dragDescription: string;
|
|
22
|
+
uploadingTitle: string;
|
|
23
|
+
successTitle: string;
|
|
24
|
+
isSubmitting?: boolean;
|
|
25
|
+
onFileUploaded: (fileId: string) => void;
|
|
26
|
+
fileUploadingStatus?: (uploading: boolean) => void;
|
|
27
|
+
onDeleteFile: () => void;
|
|
28
|
+
defaultFile?: FileDetails;
|
|
29
|
+
}
|
|
30
|
+
declare const UploadWrapper: ({ id, label, control, required, title, subTitle, dragDescription, uploadingTitle, successTitle, isSubmitting, onFileUploaded, fileUploadingStatus, onDeleteFile, purpose, fileTitle, defaultFile }: UploadWrapperProps) => JSX.Element;
|
|
31
|
+
export default UploadWrapper;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { useTranslation } from 'react-i18next';
|
|
15
|
+
import { useController } from 'react-hook-form';
|
|
16
|
+
import { styled } from '@mui/material/styles';
|
|
17
|
+
import Box from '@mui/material/Box';
|
|
18
|
+
import { DragAndDrop } from '../../../components/FileInput';
|
|
19
|
+
import Collapse from '../../../components/Collapse';
|
|
20
|
+
import { getFileType } from '../../../utils';
|
|
21
|
+
import { FileStatus } from '../../../constants';
|
|
22
|
+
import { InputLabelStyled } from '../../shared/Input/Input';
|
|
23
|
+
import { ScreenContainer } from '../../shared/Containers';
|
|
24
|
+
import Mandatory from '../../shared/Mandatory';
|
|
25
|
+
import FileUpload from './FileUpload';
|
|
26
|
+
var FeatureStyled = styled(ScreenContainer)(function (_a) {
|
|
27
|
+
var theme = _a.theme;
|
|
28
|
+
return ({
|
|
29
|
+
marginBlockStart: theme.spacing(0)
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
var LabelContainerStyled = styled(Box)(function (_a) {
|
|
33
|
+
var theme = _a.theme;
|
|
34
|
+
return ({
|
|
35
|
+
display: 'flex',
|
|
36
|
+
justifyContent: 'space-between',
|
|
37
|
+
padding: theme.spacing(0, 2.5, 1.25, 2.5),
|
|
38
|
+
alignItems: 'center'
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
export var InputContainerStyled = styled(Box)(function () { return ({
|
|
42
|
+
display: 'flex',
|
|
43
|
+
width: '100%',
|
|
44
|
+
justifyContent: 'center'
|
|
45
|
+
}); });
|
|
46
|
+
var UploadWrapper = function (_a) {
|
|
47
|
+
var id = _a.id, label = _a.label, control = _a.control, required = _a.required, title = _a.title, subTitle = _a.subTitle, dragDescription = _a.dragDescription, uploadingTitle = _a.uploadingTitle, successTitle = _a.successTitle, isSubmitting = _a.isSubmitting, onFileUploaded = _a.onFileUploaded, fileUploadingStatus = _a.fileUploadingStatus, onDeleteFile = _a.onDeleteFile, purpose = _a.purpose, fileTitle = _a.fileTitle, defaultFile = _a.defaultFile;
|
|
48
|
+
var t = useTranslation().t;
|
|
49
|
+
var _b = React.useState(''), error = _b[0], setError = _b[1];
|
|
50
|
+
var fileControl = useController({ name: "".concat(id, "File"), control: control });
|
|
51
|
+
var fileInfoControl = useController({ name: "".concat(id, "FileInfo"), control: control });
|
|
52
|
+
var fileData = fileControl.field.value;
|
|
53
|
+
var fileInfo = fileInfoControl.field.value;
|
|
54
|
+
React.useEffect(function () {
|
|
55
|
+
if (!fileData && !fileInfo && defaultFile) {
|
|
56
|
+
var title_1 = defaultFile.title, size = defaultFile.size, type = defaultFile.type, id_1 = defaultFile.id, docId = defaultFile.docId;
|
|
57
|
+
var fileData_1 = { name: title_1, size: size, type: getFileType(type) };
|
|
58
|
+
var fileInfoData = {
|
|
59
|
+
fileId: id_1,
|
|
60
|
+
docId: docId,
|
|
61
|
+
status: FileStatus.SUCCESS,
|
|
62
|
+
progress: 100,
|
|
63
|
+
error: '',
|
|
64
|
+
name: title_1 || ''
|
|
65
|
+
};
|
|
66
|
+
fileControl.field.onChange(fileData_1);
|
|
67
|
+
fileInfoControl.field.onChange(fileInfoData);
|
|
68
|
+
}
|
|
69
|
+
}, [defaultFile]);
|
|
70
|
+
var handleFileChange = function (files) {
|
|
71
|
+
if (!isSubmitting) {
|
|
72
|
+
if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
|
|
73
|
+
setError('');
|
|
74
|
+
var fileData_2 = files[0];
|
|
75
|
+
fileControl.field.onChange(fileData_2);
|
|
76
|
+
fileInfoControl.field.onChange({
|
|
77
|
+
fileId: '',
|
|
78
|
+
docId: '',
|
|
79
|
+
status: FileStatus.INIT,
|
|
80
|
+
progress: 0,
|
|
81
|
+
error: '',
|
|
82
|
+
name: fileData_2.name
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var handleDelete = function () {
|
|
88
|
+
if (!isSubmitting) {
|
|
89
|
+
setError('');
|
|
90
|
+
if (required)
|
|
91
|
+
setError(t('should_upload_file'));
|
|
92
|
+
fileControl.field.onChange(undefined);
|
|
93
|
+
fileInfoControl.field.onChange(undefined);
|
|
94
|
+
onDeleteFile();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var handleSuccess = function (fileInfo) {
|
|
98
|
+
if (fileInfo) {
|
|
99
|
+
fileInfoControl.field.onChange(__assign({}, fileInfo));
|
|
100
|
+
onFileUploaded(fileInfo.fileId);
|
|
101
|
+
fileUploadingStatus === null || fileUploadingStatus === void 0 ? void 0 : fileUploadingStatus(false);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var handleUpdate = function (fileInfo, loadingStatus) {
|
|
105
|
+
if (fileInfo) {
|
|
106
|
+
fileInfoControl.field.onChange(__assign({}, fileInfo));
|
|
107
|
+
fileUploadingStatus === null || fileUploadingStatus === void 0 ? void 0 : fileUploadingStatus(loadingStatus);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var fileExists = !!fileInfo;
|
|
111
|
+
var fileUploaded = (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.status) === FileStatus.SUCCESS || (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.status) === FileStatus.DOWNLOADING;
|
|
112
|
+
return (_jsxs(FeatureStyled, { children: [_jsx(LabelContainerStyled, { children: _jsx(InputLabelStyled, { children: _jsxs(_Fragment, { children: [label, required && _jsx(Mandatory, {})] }) }) }), _jsx(Collapse, __assign({ in: !fileUploaded }, { children: _jsx(InputContainerStyled, __assign({ sx: { mb: 2.5 } }, { children: _jsx(DragAndDrop, { title: title, subTitle: subTitle, description: dragDescription, fileExists: fileExists, uploadingTitle: uploadingTitle, successTitle: successTitle, progress: fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.progress, uploading: (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.status) === FileStatus.UPLOADING, uploadSuccess: fileUploaded, onSuccess: handleFileChange, error: (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.error) || error, multiple: false }) })) })), _jsx(Collapse, __assign({ in: fileExists, timeout: 300 }, { children: _jsx(FileUpload, { show: fileUploaded, purpose: purpose, title: fileTitle || '', isSubmitting: isSubmitting, uploadedFile: fileInfo, file: fileData, onSuccess: handleSuccess, onDelete: handleDelete, onUpdate: handleUpdate }) }))] }));
|
|
113
|
+
};
|
|
114
|
+
export default UploadWrapper;
|