169 lines
6.4 KiB
JavaScript
169 lines
6.4 KiB
JavaScript
import React, { useState, useEffect, useCallback } from 'react';
|
|
import { __ } from '@wordpress/i18n';
|
|
import { is, pathOr, isEmpty } from 'ramda';
|
|
|
|
// store
|
|
import { useStore } from '../../../../store';
|
|
|
|
// api
|
|
import ApplicationService from '../../../../service/application-service';
|
|
|
|
// components
|
|
import { DataTable } from 'primereact/datatable';
|
|
import { Column } from 'primereact/column';
|
|
import { ProgressBar } from 'primereact/progressbar';
|
|
import { Button } from 'primereact/button';
|
|
import ProperBandoLabel from '../../../../components/ProperBandoLabel';
|
|
import { Link } from 'react-router-dom';
|
|
import translationStrings from '../../../../translationStringsForComponents';
|
|
|
|
const DraftApplicationsTableAsync = () => {
|
|
const chosenCompanyId = useStore().main.chosenCompanyId();
|
|
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
|
const [items, setItems] = useState(null);
|
|
const [totalRecordsNum, setTotalRecordsNum] = useState(0);
|
|
const [lazyState, setLazyState] = useState({
|
|
first: 0,
|
|
rows: 5,
|
|
page: 0,
|
|
sortField: null,
|
|
sortOrder: null,
|
|
filters: {
|
|
id: { value: null, matchMode: 'contains' },
|
|
callTitle: { value: null, matchMode: 'contains' },
|
|
companyName: { value: null, matchMode: 'contains' }
|
|
}
|
|
});
|
|
const statuses = ['DRAFT'];
|
|
|
|
const getPaginationQuery = useCallback(() => {
|
|
let sortBy = {
|
|
columnName: "ID",
|
|
sortDesc: true
|
|
};
|
|
|
|
if (lazyState.sortField) {
|
|
sortBy = {
|
|
columnName: lazyState.sortField,
|
|
sortDesc: lazyState.sortOrder === -1
|
|
}
|
|
}
|
|
return {
|
|
globalFilters: {
|
|
page: lazyState.page ? lazyState.page + 1 : 1,
|
|
limit: lazyState.rows,
|
|
sortBy
|
|
},
|
|
status: statuses,
|
|
filters: Object.keys(lazyState.filters).reduce((acc, cur) => {
|
|
const value = pathOr('', ['filters', cur, 'value'], lazyState);
|
|
if (!isEmpty(value)) {
|
|
acc[cur] = lazyState.filters[cur];
|
|
}
|
|
return acc;
|
|
}, {}),
|
|
}
|
|
}, [lazyState]);
|
|
|
|
const onPage = (event) => {
|
|
setLazyState(event);
|
|
};
|
|
|
|
const onSort = (event) => {
|
|
event['first'] = 0;
|
|
event['page'] = 0;
|
|
setLazyState(event);
|
|
};
|
|
|
|
const onFilter = useCallback((event) => {
|
|
event['first'] = 0;
|
|
event['page'] = 0;
|
|
setLazyState(event);
|
|
}, [lazyState]);
|
|
|
|
const getApplCallback = (resp) => {
|
|
if (resp.status === 'SUCCESS') {
|
|
const { body, totalRecords,
|
|
//currentPage, totalPages, pageSize
|
|
} = resp.data;
|
|
setTotalRecordsNum(totalRecords);
|
|
setItems(getFormattedData(body));
|
|
}
|
|
setLocalAsyncRequest(false);
|
|
}
|
|
|
|
const errGetApplCallback = () => {
|
|
setLocalAsyncRequest(false);
|
|
}
|
|
|
|
const getFormattedData = (data) => {
|
|
return data.map((d) => {
|
|
d.callEndDate = is(String, d.callEndDate) ? new Date(d.callEndDate) : (d.callEndDate ? d.callEndDate : '');
|
|
d.modifiedDate = is(String, d.modifiedDate) ? new Date(d.modifiedDate) : (d.modifiedDate ? d.modifiedDate : '');
|
|
d.submissionDate = is(String, d.submissionDate) ? new Date(d.submissionDate) : (d.submissionDate ? d.submissionDate : '');
|
|
return d;
|
|
});
|
|
};
|
|
|
|
useEffect(() => {
|
|
setLocalAsyncRequest(true);
|
|
const paginationQuery = getPaginationQuery();
|
|
|
|
ApplicationService.getApplicationsPaginated(paginationQuery, getApplCallback, errGetApplCallback);
|
|
}, [lazyState, chosenCompanyId]);
|
|
|
|
const statusBodyTemplate = (rowData) => {
|
|
return <ProperBandoLabel status={rowData.status}/>;
|
|
};
|
|
|
|
const progressBodyTemplate = (options) => {
|
|
return <ProgressBar value={options.progress} color={'#64748B'}></ProgressBar>;
|
|
};
|
|
|
|
const actionsBodyTemplate = (rowData) => {
|
|
return <Link to={`/domande/${rowData.id}/preview`}>
|
|
<Button severity="info" label={__('Anteprima', 'gepafin')} icon="pi pi-eye" size="small"
|
|
iconPos="right"/>
|
|
</Link>
|
|
}
|
|
|
|
return (
|
|
<div className="appPageSection__table">
|
|
<DataTable
|
|
value={items} stripedRows showGridlines
|
|
lazy filterDisplay="menu" dataKey="id" paginator
|
|
first={lazyState.first} rows={lazyState.rows} totalRecords={totalRecordsNum} onPage={onPage}
|
|
onSort={onSort} sortField={lazyState.sortField} sortOrder={lazyState.sortOrder}
|
|
onFilter={onFilter} filters={lazyState.filters} loading={localAsyncRequest}
|
|
emptyMessage={translationStrings.emptyMessage}>
|
|
<Column field="id" header={__('ID domanda', 'gepafin')}
|
|
sortable
|
|
filterField="id" filter
|
|
filterMatchModeOptions={translationStrings.textFilterOptions}
|
|
filterPlaceholder={__('Cerca il nome', 'gepafin')}
|
|
style={{ minWidth: '8rem' }}/>
|
|
<Column field="callTitle" header={__('Bando', 'gepafin')}
|
|
sortable
|
|
filterField="callTitle" filter
|
|
filterMatchModeOptions={translationStrings.textFilterOptions}
|
|
filterPlaceholder={__('Cerca il nome', 'gepafin')}
|
|
style={{ minWidth: '8rem' }}/>
|
|
<Column field="companyName" header={__('Azienda', 'gepafin')}
|
|
sortable
|
|
filterField="companyName" filter
|
|
filterMatchModeOptions={translationStrings.textFilterOptions}
|
|
filterPlaceholder={__('Cerca il nome', 'gepafin')}
|
|
style={{ minWidth: '8rem' }}/>
|
|
<Column field="status" header={__('Stato', 'gepafin')}
|
|
style={{ minWidth: '7rem' }} body={statusBodyTemplate}/>
|
|
<Column header={__('Progressi', 'gepafin')}
|
|
style={{ minWidth: '10rem' }} field="progress" body={progressBodyTemplate}/>
|
|
<Column header={__('Azioni', 'gepafin')}
|
|
style={{ minWidth: '10rem' }}
|
|
body={actionsBodyTemplate}/>
|
|
</DataTable>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default DraftApplicationsTableAsync; |