diff --git a/src/components/FormField/components/FileSelect/index.js b/src/components/FormField/components/FileSelect/index.js
index 089b625..7c0a151 100644
--- a/src/components/FormField/components/FileSelect/index.js
+++ b/src/components/FormField/components/FileSelect/index.js
@@ -1,7 +1,7 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { classNames } from 'primereact/utils';
import { __ } from '@wordpress/i18n';
-import { isEmpty, pathOr, pluck } from 'ramda';
+import { isEmpty, isNil, pathOr, pluck } from 'ramda';
// service
import FileUploadService from '../../../../service/file-upload-service';
@@ -27,7 +27,8 @@ const FileSelect = ({
sourceId = 0,
source = 'DOCUMENT',
documentCategories = [],
- saveFormCallback
+ saveFormCallback,
+ attachFilesCallback,
}) => {
//const [stateFieldData, setStateFieldData] = useState([]);
const stateFieldData = useRef([]);
@@ -52,6 +53,16 @@ const FileSelect = ({
setAddNewMode(false);
}, [selectedUnconfirmed]);
+ const attachSelectedFilesCallback = useCallback(() => {
+ const existingIds = pluck('id', stateFieldData.current);
+ const selectedToBeAdded = selectedUnconfirmed.filter(o => !existingIds.includes(o.id));
+ setSelectedUnconfirmed([]);
+
+ // eslint-disable-next-line array-callback-return
+ selectedToBeAdded.map(o => attachFilesCallback(o));
+ setAddNewMode(false);
+ }, [selectedUnconfirmed]);
+
const doGoBackToListOfFiles = () => {
setSelectedUnconfirmed([]);
setAddNewMode(false);
@@ -100,7 +111,8 @@ const FileSelect = ({
defaultFocus: 'reject',
acceptClassName: 'p-button-danger',
accept: () => removeAttached(id),
- reject: () => {}
+ reject: () => {
+ }
});
};
@@ -116,19 +128,19 @@ const FileSelect = ({
? o
: documentCategories.includes(o.category.id))
.reduce((acc, cur) => {
- const catName = pathOr('', ['category', 'categoryName'], cur);
- const catLabel = pathOr('', ['category', 'description'], cur);
+ const catName = pathOr('', ['category', 'categoryName'], cur);
+ const catLabel = pathOr('', ['category', 'description'], cur);
- if (!acc[catName]) {
- acc[catName] = {
- code: catName,
- label: catLabel,
- items: []
- };
- }
- acc[catName].items.push(cur)
- return acc;
- }, {});
+ if (!acc[catName]) {
+ acc[catName] = {
+ code: catName,
+ label: catLabel,
+ items: []
+ };
+ }
+ acc[catName].items.push(cur)
+ return acc;
+ }, {});
setOptionsTransformed(Object.values(optionsDefault));
}
@@ -137,13 +149,14 @@ const FileSelect = ({
useEffect(() => {
stateFieldData.current = defaultValue;
}, [defaultValue]);
- //console.log([...stateFieldData.current])
+
return (
<>
-
+ {!isNil(label)
+ ? : null}
{addNewMode
?
@@ -160,7 +173,7 @@ const FileSelect = ({
?
: