- added page managebandi;
- improved styles of the pages and sections;
This commit is contained in:
115
src/pages/Bando/index.js
Normal file
115
src/pages/Bando/index.js
Normal file
@@ -0,0 +1,115 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useForm, Controller } from 'react-hook-form';
|
||||
import { classNames } from 'primereact/utils';
|
||||
|
||||
// components
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import getBandoLabel from '../../helpers/getBandoLabel';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const Bando = () => {
|
||||
const { id } = useParams();
|
||||
const [data, setData] = useState({});
|
||||
const {
|
||||
control,
|
||||
reset,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
getValues
|
||||
} = useForm(data);
|
||||
const onSubmit = data => console.log(data);
|
||||
console.log(errors, getValues());
|
||||
|
||||
const onPublish = () => {
|
||||
console.log('click onPublish');
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const parsed = parseInt(id)
|
||||
const bandoId = !isNaN(parsed) ? parsed : 0;
|
||||
|
||||
const data = 0 === bandoId
|
||||
? {
|
||||
status: 'draft',
|
||||
name: null,
|
||||
description: null
|
||||
}
|
||||
: {
|
||||
name: 'Bando Innovazione 2024',
|
||||
description: '',
|
||||
start_date: '2024-08-08T00:00:00+00:00',
|
||||
end_date: '2024-08-30T00:00:00+00:00',
|
||||
submissions: 24,
|
||||
status: 'publish',
|
||||
id: 11
|
||||
}
|
||||
setData(data);
|
||||
reset();
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<div className="appPage">
|
||||
<div className="appPage__pageHeader">
|
||||
<h1>{__('Creazione/Modifica Bando', 'gepafin')}</h1>
|
||||
<p>
|
||||
{__('Stato:', 'gepafin')}
|
||||
<span>{getBandoLabel(data.status)}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
{data
|
||||
? <form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="appForm__field">
|
||||
<label htmlFor="name" className={classNames({ 'p-error': errors.name })}>
|
||||
{__('Titolo del Bando', 'gepafin')}*
|
||||
</label>
|
||||
<Controller
|
||||
name="name"
|
||||
control={control}
|
||||
defaultValue={data['name']}
|
||||
rules={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
render={({ field, fieldState }) => (
|
||||
<InputText id={field.name}
|
||||
{...field}
|
||||
autoFocus
|
||||
className={classNames({ 'p-invalid': fieldState.invalid })}/>
|
||||
)}/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__field">
|
||||
<label htmlFor="description" className={classNames({ 'p-error': errors.description })}>
|
||||
{__('Descrizione', 'gepafin')}*
|
||||
</label>
|
||||
<Controller
|
||||
name="description"
|
||||
control={control}
|
||||
defaultValue={data['description']}
|
||||
rules={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
render={({ field, fieldState }) => (
|
||||
<InputTextarea id={field.name}
|
||||
{...field}
|
||||
className={classNames({ 'p-invalid': fieldState.invalid })}/>
|
||||
)}/>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
<Button
|
||||
type="submit"
|
||||
label={__('Salva Bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
|
||||
<Button
|
||||
onClick={onPublish}
|
||||
label={__('Pubblica', 'gepafin')} icon="pi pi-upload" iconPos="right"/>
|
||||
</div>
|
||||
</div>
|
||||
</form> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Bando;
|
||||
Reference in New Issue
Block a user