- added btn 'csv report';
This commit is contained in:
@@ -5,6 +5,7 @@ import translationStrings from '../../../../translationStringsForComponents';
|
||||
|
||||
// api
|
||||
import BandoService from '../../../../service/bando-service';
|
||||
import ApplicationService from '../../../../service/application-service';
|
||||
|
||||
// tools
|
||||
import getTimeParsedFromString from '../../../../helpers/getTimeParsedFromString';
|
||||
@@ -13,6 +14,7 @@ import getFormattedDateString from '../../../../helpers/getFormattedDateString';
|
||||
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
||||
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
||||
import getQueryParamsForPaginatedEndpoint from '../../../../helpers/getQueryParamsForPaginatedEndpoint';
|
||||
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||
|
||||
// components
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
@@ -21,6 +23,7 @@ import ProperBandoLabel from '../../../../components/ProperBandoLabel';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const LatestBandiTableInstructorManagerAsync = () => {
|
||||
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
||||
@@ -39,7 +42,7 @@ const LatestBandiTableInstructorManagerAsync = () => {
|
||||
status: { value: null, matchMode: 'equals' }
|
||||
}
|
||||
});
|
||||
const statuses = ['PUBLISH'];
|
||||
const statuses = ['PUBLISH', 'EXPIRED'];
|
||||
|
||||
const getPaginationQuery = useCallback(() => getQueryParamsForPaginatedEndpoint(lazyState, statuses, 'id'), [lazyState]);
|
||||
|
||||
@@ -121,6 +124,43 @@ const LatestBandiTableInstructorManagerAsync = () => {
|
||||
return getFormattedDateString(rowData.endDate) + ' ' + getTimeFromISOstring(endTimeObg);
|
||||
};
|
||||
|
||||
const actionsBodyTemplate = (rowData) => {
|
||||
return <div className="appPageSection__tableActions">
|
||||
<Button type="button"
|
||||
size="small"
|
||||
icon="pi pi-receipt"
|
||||
iconPos="right"
|
||||
label={__('CSV', 'gepafin')}
|
||||
onClick={() => exportToCSV(rowData.id)}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
const exportToCSV = (applicationId) => {
|
||||
setLocalAsyncRequest(true);
|
||||
ApplicationService.downloadCsvReport(
|
||||
applicationId,
|
||||
(resp) => getCsvReportback(resp, applicationId),
|
||||
errCsvReportCallback
|
||||
)
|
||||
}
|
||||
|
||||
const getCsvReportback = (resp, applicationId) => {
|
||||
const file = new Blob([resp], { type: 'text/csv' });
|
||||
const url = window.URL.createObjectURL(file);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', `call-${applicationId}-applications-report.csv`);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
setLocalAsyncRequest(false);
|
||||
}
|
||||
|
||||
const errCsvReportCallback = (resp) => {
|
||||
set404FromErrorResponse(resp);
|
||||
setLocalAsyncRequest(false);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setLocalAsyncRequest(true);
|
||||
const paginationQuery = getPaginationQuery();
|
||||
@@ -162,6 +202,8 @@ const LatestBandiTableInstructorManagerAsync = () => {
|
||||
header={__('Stato', 'gepafin')}
|
||||
style={{ minWidth: '7rem' }}
|
||||
body={statusBodyTemplate} />
|
||||
<Column header={__('Azioni', 'gepafin')}
|
||||
body={actionsBodyTemplate}/>
|
||||
</DataTable>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user