diff --git a/fe-piattaforma/src/components/CSVUploader/CSVUploader.tsx b/fe-piattaforma/src/components/CSVUploader/CSVUploader.tsx index 157a6d7df..0227b6c5e 100644 --- a/fe-piattaforma/src/components/CSVUploader/CSVUploader.tsx +++ b/fe-piattaforma/src/components/CSVUploader/CSVUploader.tsx @@ -11,6 +11,8 @@ import { ProjectContext } from '../../contexts/ProjectContext'; import { useParams } from 'react-router-dom'; import { searchActivityReport } from '../../services/activityReportService'; import { hideLoader, showLoader } from '../../redux/features/app/appSlice'; +import { selectProjects } from '../../redux/features/administrativeArea/administrativeAreaSlice'; +import { policy } from '../../pages/administrator/AdministrativeArea/Entities/utils'; function showErrorFormatCSV() { dispatchNotify({ @@ -65,6 +67,8 @@ export default function CSVUploader({ const projectContext = useContext(ProjectContext); const [selectedFile, setSelectedFile] = useState(null); const { projectId, enteId } = useParams(); + const projectDetail = useAppSelector(selectProjects).detail?.dettagliInfoProgetto; + const fileInputConsentito = projectDetail?.policy === policy.RFD ? 'CSV' : 'EXCEL'; const handleFileInput = useCallback( (filesToUpload: File[]) => { @@ -236,7 +240,7 @@ export default function CSVUploader({ ) : ( <> -
Trascina il file dati (CSV)
+
Trascina il file dati ({fileInputConsentito})

oppure{' '}

- +
diff --git a/fe-piattaforma/src/components/FileHandling/CsvInstructions.tsx b/fe-piattaforma/src/components/FileHandling/CsvInstructions.tsx index d7bb51548..5f811650e 100644 --- a/fe-piattaforma/src/components/FileHandling/CsvInstructions.tsx +++ b/fe-piattaforma/src/components/FileHandling/CsvInstructions.tsx @@ -1,7 +1,12 @@ import React from 'react'; import uploadIcon from '../../../public/assets/img/it-upload-primary.png'; +import { selectProjects } from '../../redux/features/administrativeArea/administrativeAreaSlice'; +import { useAppSelector } from '../../redux/hooks'; +import { policy } from '../../pages/administrator/AdministrativeArea/Entities/utils'; export default function CsvInstructions({ urlGuida, attachmentGuida }: { urlGuida: string | "" , attachmentGuida: any}) { + const projectDetail = useAppSelector(selectProjects).detail?.dettagliInfoProgetto; + const fileInputConsentito = projectDetail?.policy === policy.RFD ? 'CSV' : 'EXCEL'; return (

@@ -11,7 +16,7 @@ export default function CsvInstructions({ urlGuida, attachmentGuida }: { urlGuid
  • - Trascina o seleziona il file dei dati in formato CSV + Trascina o seleziona il file dei dati in formato {fileInputConsentito} {' '} per inserirlo nello strumento di caricamento massivo.

    diff --git a/fe-piattaforma/src/components/FileHandling/ProcessFile.tsx b/fe-piattaforma/src/components/FileHandling/ProcessFile.tsx index fe66f58b5..ea17d1a1e 100644 --- a/fe-piattaforma/src/components/FileHandling/ProcessFile.tsx +++ b/fe-piattaforma/src/components/FileHandling/ProcessFile.tsx @@ -7,6 +7,7 @@ import checkImg from './../../../public/assets/img/icon-check-no-circle.png'; type CSVProcessorProps = { file: File | undefined; + removeFile: () => void; }; function showError(error: Error) { @@ -19,8 +20,8 @@ function showError(error: Error) { }); } -export default function ProcessFile({ file }: CSVProcessorProps) { - const { isProcessing, processFile } = useFileProcessor(file); +export default function ProcessFile({ file, removeFile }: CSVProcessorProps) { + const { isProcessing, processFile } = useFileProcessor(file, removeFile); const dataUploadContext = useContext(DataUploadContext); const handleProcessFile = useCallback(() => { diff --git a/fe-piattaforma/src/hooks/useFileProcessor.ts b/fe-piattaforma/src/hooks/useFileProcessor.ts index 9a6c3e7a4..1074423f7 100644 --- a/fe-piattaforma/src/hooks/useFileProcessor.ts +++ b/fe-piattaforma/src/hooks/useFileProcessor.ts @@ -84,7 +84,7 @@ const headersCSV = [ 'ES6', ]; -export function useFileProcessor(file: File | undefined) { +export function useFileProcessor(file: File | undefined, removeFile: () => void) { const { isValidFiscalCode } = useFiscalCodeValidation(); const [isProcessing, setIsProcessing] = useState(false); const projectDetail = useAppSelector(selectProjects).detail?.dettagliInfoProgetto; @@ -246,7 +246,11 @@ export function useFileProcessor(file: File | undefined) { }, }); } else { - // Operazioni SCD + setIsProcessing(false); + removeFile(); + rejectWithMessage( + 'Tipo file non supportato.' + ); } /*else { reject({ @@ -255,74 +259,81 @@ export function useFileProcessor(file: File | undefined) { }); }*/ } else if (fileExtension === 'xlsx' || fileExtension === 'xls') { - try { - const excelData = await handleExcelFileUpload(file); - - const serviziValidati: ServiziElaboratiDto[] = []; - const serviziScartati: ServiziElaboratiDto[] = []; - - if (excelData.length > 0) { - excelData.forEach((record: CSVRecord, index: number) => { - sanitizeFields(record); - const { AN14: _AN14, AN17: _AN17, ...filteredRecord } = record; - filteredRecord.AN3 = filteredRecord.AN3.trim(); - filteredRecord.SE1 = excelSerialDateToJSDate(Number(filteredRecord.SE1)); - filteredRecord.SE2 = excelSerialTimeToHHMM(Number(filteredRecord.SE2)); - const { rejectedTypes } = generateServiceName(filteredRecord.SE3); - const errors = validateFields( - filteredRecord, - isValidFiscalCode - ); - checkMapValues(record, errors); - checkMapSpaces(record, errors); - if ( - rejectedTypes.length > 0 && - filteredRecord.SE3 && - filteredRecord.SE3.trim() !== '' - ) { - errors.push( - `Servizio non riconosciuto nel campo SE3: ${rejectedTypes.join( - ', ' - )}. Assicurati che i tipi di servizio inseriti siano corretti` - ); - } - - const cfData: IPersonalInfo = - CodiceFiscaleUtils.Parser.cfDecode(filteredRecord.AN3); - - if (!getAgeGroupCodeByYear(cfData.date)) { - errors.push('Il cittadino deve essere maggiorenne.'); - } - - const isValidFields = errors.length === 0; - const servizioElaborato: ServiziElaboratiDto = - mappingDatiElaborati( + if (projectDetail?.policy == policy.SCD) { + try { + const excelData = await handleExcelFileUpload(file); + + const serviziValidati: ServiziElaboratiDto[] = []; + const serviziScartati: ServiziElaboratiDto[] = []; + + if (excelData.length > 0) { + excelData.forEach((record: CSVRecord, index: number) => { + sanitizeFields(record); + const { AN14: _AN14, AN17: _AN17, ...filteredRecord } = record; + filteredRecord.AN3 = filteredRecord.AN3.trim(); + filteredRecord.SE1 = excelSerialDateToJSDate(Number(filteredRecord.SE1)); + filteredRecord.SE2 = excelSerialTimeToHHMM(Number(filteredRecord.SE2)); + const { rejectedTypes } = generateServiceName(filteredRecord.SE3); + const errors = validateFields( filteredRecord, - errors, - index + 1, - cfData + isValidFiscalCode ); - if (isValidFields && rejectedTypes.length === 0) { - serviziValidati.push(servizioElaborato); - } else { - serviziScartati.push(servizioElaborato); - } - }); - const serviziElaborati: ElaboratoCsvRequest = { - serviziValidati: serviziValidati, - serviziScartati: serviziScartati, - estensioneInput: fileExtension - }; - resolve(serviziElaborati); + checkMapValues(record, errors); + checkMapSpaces(record, errors); + if ( + rejectedTypes.length > 0 && + filteredRecord.SE3 && + filteredRecord.SE3.trim() !== '' + ) { + errors.push( + `Servizio non riconosciuto nel campo SE3: ${rejectedTypes.join( + ', ' + )}. Assicurati che i tipi di servizio inseriti siano corretti` + ); + } + + const cfData: IPersonalInfo = + CodiceFiscaleUtils.Parser.cfDecode(filteredRecord.AN3); + + if (!getAgeGroupCodeByYear(cfData.date)) { + errors.push('Il cittadino deve essere maggiorenne.'); + } + + const isValidFields = errors.length === 0; + const servizioElaborato: ServiziElaboratiDto = + mappingDatiElaborati( + filteredRecord, + errors, + index + 1, + cfData + ); + if (isValidFields && rejectedTypes.length === 0) { + serviziValidati.push(servizioElaborato); + } else { + serviziScartati.push(servizioElaborato); + } + }); + const serviziElaborati: ElaboratoCsvRequest = { + serviziValidati: serviziValidati, + serviziScartati: serviziScartati, + estensioneInput: fileExtension + }; + resolve(serviziElaborati); + setIsProcessing(false); + } else { + rejectWithMessage( + 'Il file inserito non è conforme ai criteri di elaborazione, assicurati che siano presenti dei dati da elaborare.' + ); + } + } catch (error) { setIsProcessing(false); - } else { - rejectWithMessage( - 'Il file inserito non è conforme ai criteri di elaborazione, assicurati che siano presenti dei dati da elaborare.' - ); + reject(error); } - } catch (error) { + }else{ setIsProcessing(false); - reject(error); + rejectWithMessage( + 'Tipo file non supportato.' + ); } } else { rejectWithMessage(