- saving progress;

This commit is contained in:
Vitalii Kiiko
2025-02-21 12:22:44 +01:00
parent 126cc3169b
commit bee7e15733
10 changed files with 426 additions and 34 deletions

View File

@@ -0,0 +1,97 @@
import React, { useEffect, useState } from 'react';
import { classNames } from 'primereact/utils';
// components
import { ListBox } from 'primereact/listbox';
import { Button } from 'primereact/button';
import { __ } from '@wordpress/i18n';
const FileSelect = ({
fieldName,
label,
register,
errors,
defaultValue,
config = {},
infoText = null,
disabled = false,
}) => {
const [stateFieldData, setStateFieldData] = useState([]);
const [selectedUnconfirmed, setSelectedUnconfirmed] = useState(null);
const cities = [
{
label: 'Germany',
code: 'DE',
items: [
{ label: 'Berlin', value: 'berlin' },
{ label: 'Frankfurt', value: 'frankfurt' },
{ label: 'Hamburg', value: 'hamburg' },
{ label: 'Munich', value: 'munich' }
]
},
{
label: 'USA',
code: 'US',
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' }
]
}
];
useEffect(() => {
console.log('selectedUnconfirmed', selectedUnconfirmed)
}, [selectedUnconfirmed]);
useEffect(() => {
setStateFieldData(defaultValue);
register(fieldName, config)
}, []);
useEffect(() => {
setStateFieldData(defaultValue);
}, [defaultValue]);
return (
<>
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
{label}{config.required || config.isRequired ? <span className="appForm__field--required">*</span> : null}
</label>
<div className="fileselectInner">
<ListBox multiple
value={selectedUnconfirmed}
onChange={(e) => setSelectedUnconfirmed(e.value)}
options={cities}
optionLabel="label"
optionGroupLabel="label"
optionGroupChildren="items"
className="w-full md:w-14rem"
listStyle={{ maxHeight: '130px' }} />
<div className="">
<Button
severity="success"
label={__('Conferma selezionati', 'gepafin')} icon="pi pi-plus" size="small" iconPos="right" />
<p>{__('Selezionati')}</p>
<ul>
</ul>
</div>
</div>
{infoText ? <small>{infoText}</small> : null}
</>)
}
export default FileSelect;

View File

@@ -18,6 +18,7 @@ import Fileupload from './components/Fileupload';
import Table from './components/Table';
import PasswordField from './components/PasswordField';
import CriteriaTable from './components/CriteriaTable';
import FileSelect from './components/FileSelect';
const FormField = (props) => {
const fields = {
@@ -35,7 +36,8 @@ const FormField = (props) => {
checkboxes: Checkboxes,
table: Table,
criteria_table: CriteriaTable,
password: PasswordField
password: PasswordField,
fileselect: FileSelect,
}
const Comp = !isNil(fields[props.type]) ? fields[props.type] : null;