import React, { useState, useEffect, useRef } from 'react'; import { __ } from '@wordpress/i18n'; import { useNavigate, useParams } from 'react-router-dom'; // components import getBandoLabel from '../../helpers/getBandoLabel'; import { Button } from 'primereact/button'; import { Skeleton } from 'primereact/skeleton'; import { Steps } from 'primereact/steps'; import BandoEditFormStep1 from './components/BandoEditFormStep1'; import BandoEditFormStep2 from './components/BandoEditFormStep2'; import { Messages } from 'primereact/messages'; import { is, isNil } from 'ramda'; const BandoEdit = () => { const navigate = useNavigate(); const { id } = useParams(); const [activeStep, setActiveStep] = useState(0) const [data, setData] = useState({}); const [isLoading, setIsLoading] = useState(true); const [selectedTemplate, setSelectedTemplate] = useState(null); const [templates, setTemplate] = useState(null); const formRef = useRef(null); const stepErrorMsgs = useRef(null); const stepItems = [ { label: __('Testi', 'gepafin'), command: () => { if (activeStep === 0) { return false } stepErrorMsgs.current.clear(); if (formRef.current.isFormValid()) { goToStep(0) } else { stepErrorMsgs.current.show([ { sticky: true, severity: 'error', summary: 'Error', detail: __('Potrai andare su altro step dopo risolvere errori della forma', 'gepafin'), closable: true } ]); } } }, { label: __('Gestione', 'gepafin'), command: () => { if (activeStep === 1) { return false } stepErrorMsgs.current.clear(); const isFormValid = formRef.current.isFormValid(); console.log('before go to step 1:', isFormValid) if (isFormValid) { goToStep(1); } else { stepErrorMsgs.current.show([ { sticky: true, severity: 'error', summary: 'Error', detail: __('Potrai andare su altro step dopo risolvere errori della forma', 'gepafin'), closable: true } ]); } } } ]; const goToStep = (step) => { setActiveStep(step); } const openBandoFormManagement = () => { navigate('/bandi/11/forms'); } useEffect(() => { const parsed = parseInt(id) const bandoId = !isNaN(parsed) ? parsed : 0; const data = 0 === bandoId ? { status: 'draft', name: '' } : { "name": "Innovazione digitale 2024", "confidi": false, "descriptionShort": "Supporto alle PMI per progetti di digitalizzazione e innovazione tecnologica.", "descriptionLong": "Il bando \"Innovazione Digitale 2024\" mira a sostenere le PMI nell'adozione di tecnologie digitali innovative. I progetti finanziabili includono l'implementazione di soluzioni di intelligenza artificiale, blockchain, IoT, e altre tecnologie avanzate che possono migliorare la competitività delle imprese.", "documentationRequested": "Documentazione richiesta*", "dates": [ "2024-08-27T22:00:00.000Z", "2024-10-29T23:00:00.000Z" ], "amount": 0, "amountMax": 0, "aimedTo": [ { "id": 3, "value": "PMI con sede in Umbria", "status": "existing" } ], "faq": [ { "id": 2, "question": "Question 1?", "answer": "Lorem ipsum dolor", "visible": true, "status": "existing" } ], "documentation": [ /*{ createdDate: "2024-08-23T12:40:47.700350791", description: null, filePath: "https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/SCR-20240820-kiwn.pdf", id: 10, name: "SCR-20240820-kiwn.pdf", updatedDate: "2024-08-23T12:40:47.700373894" }*/ ], status: 'draft', id: 11 } if (bandoId === 0) { setData(data); setIsLoading(false); } else { setTimeout(() => { if (!isNil(data.dates) && data.dates.length) { data.dates = data.dates.map(v => is(String, v) ? new Date(v) : v); } setData(data); const templates = [ { name: 'Il mio template', value: 22 }, { name: 'Template #11', value: 11 }, ]; setTemplate(templates); setIsLoading(false); }, 2000); } }, [id]); return (
{__('Stato:', 'gepafin')} {getBandoLabel(data.status)}