diff --git a/src/components/FormField/components/FileSelect/index.js b/src/components/FormField/components/FileSelect/index.js index abe0dce..eb26e0f 100644 --- a/src/components/FormField/components/FileSelect/index.js +++ b/src/components/FormField/components/FileSelect/index.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { classNames } from 'primereact/utils'; // components @@ -7,51 +7,104 @@ import { Button } from 'primereact/button'; import { __ } from '@wordpress/i18n'; const FileSelect = ({ - fieldName, - label, + fieldName, + label, register, - errors, - defaultValue, - config = {}, - infoText = null, - disabled = false, - - }) => { + errors, + defaultValue, + config = {}, + infoText = null, + disabled = false, + options = [] + }) => { const [stateFieldData, setStateFieldData] = useState([]); const [selectedUnconfirmed, setSelectedUnconfirmed] = useState(null); const cities = [ { - label: 'Germany', - code: 'DE', + label: 'Company files', + code: 'company-files', items: [ - { label: 'Berlin', value: 'berlin' }, - { label: 'Frankfurt', value: 'frankfurt' }, - { label: 'Hamburg', value: 'hamburg' }, - { label: 'Munich', value: 'munich' } + { + 'id': 589, + 'name': 'pdf-3-test.pdf', + 'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf', + 'type': 'DOCUMENT', + 'source': 'APPLICATION', + 'sourceId': 0, + 'createdDate': '2025-02-21T15:33:52.767089176', + 'updatedDate': '2025-02-21T15:33:52.767109885', + 'documentAttachmentId': null + }, + { + 'id': 569, + 'name': 'pdf-2-test.pdf', + 'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf', + 'type': 'DOCUMENT', + 'source': 'APPLICATION', + 'sourceId': 0, + 'createdDate': '2025-02-21T15:33:52.767089176', + 'updatedDate': '2025-02-21T15:33:52.767109885', + 'documentAttachmentId': null + }, + { + 'id': 519, + 'name': 'pdf-1-test.pdf', + 'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf', + 'type': 'DOCUMENT', + 'source': 'APPLICATION', + 'sourceId': 0, + 'createdDate': '2025-02-21T15:33:52.767089176', + 'updatedDate': '2025-02-21T15:33:52.767109885', + 'documentAttachmentId': null + } ] }, { - label: 'USA', - code: 'US', + label: 'Personal files', + code: 'personal-files', items: [ - { label: 'Chicago', value: 'chicago' }, - { label: 'Los Angeles', value: 'los Angeles' }, - { label: 'New York', value: 'New York' }, - { label: 'San Francisco', value: 'San Francisco' } - ] - }, - { - label: 'Japan', - code: 'JP', - items: [ - { label: 'Kyoto', value: 'Kyoto' }, - { label: 'Osaka', value: 'Osaka' }, - { label: 'Tokyo', value: 'Tokyo' }, - { label: 'Yokohama', value: 'Yokohama' } + { + 'id': 179, + 'name': 'pdf-13-test.pdf', + 'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf', + 'type': 'DOCUMENT', + 'source': 'APPLICATION', + 'sourceId': 0, + 'createdDate': '2025-02-21T15:33:52.767089176', + 'updatedDate': '2025-02-21T15:33:52.767109885', + 'documentAttachmentId': null + }, + { + 'id': 169, + 'name': 'pdf-12-test.pdf', + 'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf', + 'type': 'DOCUMENT', + 'source': 'APPLICATION', + 'sourceId': 0, + 'createdDate': '2025-02-21T15:33:52.767089176', + 'updatedDate': '2025-02-21T15:33:52.767109885', + 'documentAttachmentId': null + }, + { + 'id': 129, + 'name': 'pdf-11-test.pdf', + 'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf', + 'type': 'DOCUMENT', + 'source': 'APPLICATION', + 'sourceId': 0, + 'createdDate': '2025-02-21T15:33:52.767089176', + 'updatedDate': '2025-02-21T15:33:52.767109885', + 'documentAttachmentId': null + } ] } ]; + const attachSelectedFiles = useCallback(() => { + setStateFieldData([...stateFieldData, ...selectedUnconfirmed]); + setSelectedUnconfirmed([]); + }, [selectedUnconfirmed, stateFieldData]) + useEffect(() => { console.log('selectedUnconfirmed', selectedUnconfirmed) }, [selectedUnconfirmed]); @@ -68,25 +121,30 @@ const FileSelect = ({ return ( <>
setSelectedUnconfirmed(e.value)} options={cities} - optionLabel="label" + optionLabel="name" optionGroupLabel="label" optionGroupChildren="items" className="w-full md:w-14rem" - listStyle={{ maxHeight: '130px' }} /> + listStyle={{ maxHeight: '130px' }}/>