Skip to content

Commit

Permalink
feat(fe-piattaforma): polling tabella registro attivita
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrifantini committed Sep 23, 2024
1 parent 6c75ddf commit a5abc53
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const ActivityReportTable = forwardRef(function ActivityReportTable(
dispatch(showLoader());
searchActivityReport(
newPage - 1,
10,
parseInt(projectId),
enteId ? parseInt(enteId) : projectContext!.idEnte
)
Expand Down Expand Up @@ -127,6 +128,12 @@ const ActivityReportTable = forwardRef(function ActivityReportTable(

useEffect(() => {
searchReports(1);

const interval = setInterval(() => {
searchReports(1);
}, 30000);

return () => clearInterval(interval);
}, [projectId]);

useImperativeHandle(
Expand Down
49 changes: 46 additions & 3 deletions fe-piattaforma/src/components/CSVUploader/CSVUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import WarningModal from '../FileHandling/WarningModal';
import { closeModal, openModal } from '../../redux/features/modal/modalSlice';
import { selectProfile } from '../../redux/features/user/userSlice';
import { ProjectContext } from '../../contexts/ProjectContext';
import { useParams } from 'react-router-dom';
import { searchActivityReport } from '../../services/activityReportService';
import { hideLoader, showLoader } from '../../redux/features/app/appSlice';

function showErrorFormatCSV() {
dispatchNotify({
Expand Down Expand Up @@ -53,6 +56,7 @@ export default function CSVUploader({
const { codiceRuolo: userRole } = useAppSelector(selectProfile) || {};
const projectContext = useContext(ProjectContext);
const [selectedFile, setSelectedFile] = useState<File[] | null>(null);
const { projectId, enteId } = useParams();

const handleFileInput = useCallback(
(filesToUpload: File[]) => {
Expand Down Expand Up @@ -89,18 +93,57 @@ export default function CSVUploader({
[userRole]
);


const checkTable = async () => {
if (projectId && (enteId || projectContext)) {
try {
dispatch(showLoader());
const res = await searchActivityReport(
0,
100,
parseInt(projectId),
enteId ? parseInt(enteId) : projectContext!.idEnte
)
.finally(() => dispatch(hideLoader()));
for (const element of res.data.content) {
if (element.jobStatus === 'IN_PROGRESS') {
dispatchNotify({
title: 'IMPOSSIBILE AVVIARE INSERIMENTO DATI',
status: 'error',
message: `E' già in corso un inserimento dati (errore CM01)`,
closable: true,
duration: 'slow',
});
return false;
}
}
return true;
} catch (err) {
return false;
}
}
return false;
}


const handleDrop = useCallback(
(event) => {
async (event) => {
event.preventDefault();
showConfirmDialog(event.dataTransfer.files);
const canProceed = await checkTable();
if (canProceed) {
showConfirmDialog(event.dataTransfer.files);
}
},
[handleFileInput, showConfirmDialog]
);

const handleInput = useCallback(
(e) => {
async (e) => {
e.preventDefault();
const canProceed = await checkTable();
if (canProceed) {
showConfirmDialog(e.target.files);
}
},
[handleFileInput, showConfirmDialog]
);
Expand Down
3 changes: 2 additions & 1 deletion fe-piattaforma/src/services/activityReportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {compressPayload, toBase64} from '../utils/common'

export function searchActivityReport(
page: number,
size: number,
idProgetto: number,
idEnte: number
): Promise<AxiosResponse<Page<RegistroAttivita>>> {
Expand All @@ -26,7 +27,7 @@ export function searchActivityReport(
idProgetto,
idProgramma,
},
{ params: { page } }
{ params: { page, size } }
);
}

Expand Down

0 comments on commit a5abc53

Please sign in to comment.