- added beneficiary stats page;
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { Tooltip, ResponsiveContainer, Cell, Pie, PieChart } from 'recharts';
|
||||
import { Tooltip, ResponsiveContainer, Cell, Pie, PieChart, Legend } from 'recharts';
|
||||
import { isEmpty } from 'ramda';
|
||||
import getBandoLabel from '../../helpers/getBandoLabel';
|
||||
|
||||
// components
|
||||
// tools
|
||||
import getBandoLabel from '../../helpers/getBandoLabel';
|
||||
|
||||
|
||||
const ChartDomandePerStato = ({ title, data = [] }) => {
|
||||
@@ -36,15 +36,13 @@ const ChartDomandePerStato = ({ title, data = [] }) => {
|
||||
}
|
||||
return acc;
|
||||
}, {
|
||||
inProgress: {value: 0, label: 'In corso'},
|
||||
approved: {value: 0, label: 'Approvato'},
|
||||
rejected: {value: 0, label: 'Respinto'}
|
||||
inProgress: {value: 0, label: __('In corso', 'gepafin')},
|
||||
approved: {value: 0, label: __('Approvato', 'gepafin')},
|
||||
rejected: {value: 0, label: __('Respinto', 'gepafin')}
|
||||
});
|
||||
setChartData(grouped)
|
||||
}, [data]);
|
||||
|
||||
console.log('chartData', chartData)
|
||||
|
||||
return (<div className="chartCard">
|
||||
{title ? <span className="chartCard__title">{title}</span> : null}
|
||||
{chartData && !isEmpty(chartData)
|
||||
@@ -70,6 +68,7 @@ const ChartDomandePerStato = ({ title, data = [] }) => {
|
||||
))}
|
||||
</Pie>
|
||||
<Tooltip content={<CustomTooltip />} />
|
||||
<Legend verticalAlign="top" height={36}/>
|
||||
</PieChart>
|
||||
</ResponsiveContainer>
|
||||
</div> : null}
|
||||
|
||||
56
src/components/ChartRichiesteVsApprovate/index.js
Normal file
56
src/components/ChartRichiesteVsApprovate/index.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
||||
import { isEmpty } from 'ramda';
|
||||
|
||||
// components
|
||||
|
||||
|
||||
const ChartRichiesteVsApprovate = ({ title, data = [] }) => {
|
||||
|
||||
// Custom tooltip
|
||||
const CustomTooltip = ({ active, payload, label }) => {
|
||||
if (active && payload && payload.length) {
|
||||
return (
|
||||
<div className="chartCard__tooltip">
|
||||
<p className="chartCard__tooltipTitle">{label}</p>
|
||||
<p className="chartCard__tooltipText">
|
||||
{__('In bozza', 'gepafin')}: {payload[0].value}
|
||||
</p>
|
||||
<p className="chartCard__tooltipText">
|
||||
{__('Inviate', 'gepafin')}: {payload[1].value}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return (<div className="chartCard">
|
||||
{title ? <span className="chartCard__title">{title}</span> : null}
|
||||
{data && !isEmpty(data)
|
||||
? <div className="chartCard__chart">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart
|
||||
data={data}
|
||||
margin={{
|
||||
top: 20,
|
||||
right: 30,
|
||||
left: 20,
|
||||
bottom: 60,
|
||||
}}
|
||||
>
|
||||
<CartesianGrid strokeDasharray="3 3"/>
|
||||
<XAxis dataKey="month"/>
|
||||
<YAxis/>
|
||||
<Tooltip content={<CustomTooltip/>}/>
|
||||
<Legend/>
|
||||
<Bar dataKey="totalRequested" fill="#8884d8" stackId="a" name={__('Richiesti', 'gepafin')}/>
|
||||
<Bar dataKey="totalApproved" fill="#EEC137" stackId="a" name={__('Approvati', 'gepafin')}/>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div> : null}
|
||||
</div>)
|
||||
}
|
||||
|
||||
export default ChartRichiesteVsApprovate;
|
||||
@@ -112,7 +112,7 @@ const Dashboard = () => {
|
||||
currency: 'EUR',
|
||||
currencyDisplay: 'symbol'
|
||||
}}
|
||||
locales="en-US"/></span>
|
||||
locales="it-IT"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty, pathOr } from 'ramda';
|
||||
import { isEmpty } from 'ramda';
|
||||
|
||||
// store
|
||||
import { storeSet } from '../../store';
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { is, isEmpty, uniq } from 'ramda';
|
||||
|
||||
// store
|
||||
import { useStore } from '../../../../store';
|
||||
|
||||
// api
|
||||
import ApplicationService from '../../../../service/application-service';
|
||||
|
||||
// tools
|
||||
import getNumberWithCurrency from '../../../../helpers/getNumberWithCurrency';
|
||||
|
||||
// components
|
||||
import { FilterMatchMode, FilterOperator } from 'primereact/api';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import ProperBandoLabel from '../../../../components/ProperBandoLabel';
|
||||
import translationStrings from '../../../../translationStringsForComponents';
|
||||
|
||||
|
||||
const BeneficiarioUltimeDomandeTable = () => {
|
||||
const chosenCompanyId = useStore().main.chosenCompanyId();
|
||||
const [items, setItems] = useState(null);
|
||||
// eslint-disable-next-line
|
||||
const [filters, setFilters] = useState(null);
|
||||
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
||||
// eslint-disable-next-line
|
||||
const [statuses, setStatuses] = useState([]);
|
||||
const perPage = 5;
|
||||
|
||||
const getPaginationQuery = (status = 'DRAFT', curPage = 1) => {
|
||||
return {
|
||||
"globalFilters": {
|
||||
//"year": 0,
|
||||
"page": curPage,
|
||||
//"search": "",
|
||||
"limit": perPage,
|
||||
},
|
||||
//"daysRange": 0,
|
||||
"status": status
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!isEmpty(chosenCompanyId) && chosenCompanyId !== 0 && !localAsyncRequest) {
|
||||
const bodyParams = getPaginationQuery(
|
||||
['SOCCORSO', 'APPROVED', 'REJECTED', 'EVALUATION', 'SUBMIT'],
|
||||
1
|
||||
);
|
||||
|
||||
setLocalAsyncRequest(true);
|
||||
ApplicationService.getApplicationsPaginated(bodyParams, getApplCallback, errGetApplCallback, [
|
||||
['companyId', chosenCompanyId],
|
||||
['statuses', ['SOCCORSO', 'APPROVED', 'REJECTED', 'EVALUATION', 'SUBMIT']] // 'NDG', 'ADMISSIBLE', 'APPOINTMENT'
|
||||
]);
|
||||
}
|
||||
}, [chosenCompanyId]);
|
||||
|
||||
const getApplCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
if (resp.data && is(Array, resp.data.body)) {
|
||||
setItems(getFormattedBandiData(resp.data.body));
|
||||
setStatuses(uniq(items.map(o => o.status)))
|
||||
initFilters();
|
||||
}
|
||||
}
|
||||
setLocalAsyncRequest(false);
|
||||
}
|
||||
|
||||
const errGetApplCallback = () => {
|
||||
setLocalAsyncRequest(false);
|
||||
}
|
||||
|
||||
const getFormattedBandiData = (data) => {
|
||||
return [...(data || [])].map((d) => {
|
||||
d.callEndDate = new Date(d.callEndDate);
|
||||
d.modifiedDate = new Date(d.modifiedDate);
|
||||
d.submissionDate = new Date(d.submissionDate);
|
||||
|
||||
return d;
|
||||
});
|
||||
};
|
||||
|
||||
const formatDate = (value) => {
|
||||
return value.toLocaleDateString('it-IT', {
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
|
||||
const initFilters = () => {
|
||||
setFilters({
|
||||
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
||||
callTitle: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }]
|
||||
},
|
||||
companyName: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }]
|
||||
},
|
||||
modifiedDate: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }]
|
||||
},
|
||||
callEndDate: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }]
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const dateSubmissionBodyTemplate = (rowData) => {
|
||||
return formatDate(rowData.submissionDate);
|
||||
};
|
||||
|
||||
const importoBodyTemplate = (rowData) => {
|
||||
return getNumberWithCurrency(rowData.amountRequested);
|
||||
};
|
||||
|
||||
const statusBodyTemplate = (rowData) => {
|
||||
return <ProperBandoLabel status={rowData.status}/>;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="appPageSection__table">
|
||||
<DataTable value={items} showGridlines rows={5} loading={localAsyncRequest} dataKey="id"
|
||||
stripedRows
|
||||
emptyMessage={translationStrings.emptyMessage}>
|
||||
<Column field="callTitle" header={__('Bando', 'gepafin')}
|
||||
style={{ minWidth: '8rem' }}/>
|
||||
<Column header={__('Anno', 'gepafin')} dataType="date"
|
||||
style={{ minWidth: '8rem' }}
|
||||
body={dateSubmissionBodyTemplate}/>
|
||||
<Column field="amountRequested"
|
||||
header={__('Importo finanziato', 'gepafin')}
|
||||
style={{ minWidth: '7rem' }}
|
||||
body={importoBodyTemplate}/>
|
||||
<Column field="status" header={__('Stato progetto', 'gepafin')}
|
||||
style={{ minWidth: '7rem' }} body={statusBodyTemplate}/>
|
||||
</DataTable>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default BeneficiarioUltimeDomandeTable;
|
||||
@@ -1,178 +0,0 @@
|
||||
import React, { useState, useEffect} from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { is, isNil, uniq } from 'ramda';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
// api
|
||||
import AmendmentsService from '../../../../service/amendments-service';
|
||||
|
||||
// tools
|
||||
import getBandoLabel from '../../../../helpers/getBandoLabel';
|
||||
import getBandoSeverity from '../../../../helpers/getBandoSeverity';
|
||||
|
||||
// components
|
||||
import { FilterMatchMode, FilterOperator } from 'primereact/api';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import ProperBandoLabel from '../../../../components/ProperBandoLabel';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Tag } from 'primereact/tag';
|
||||
|
||||
import translationStrings from '../../../../translationStringsForComponents';
|
||||
|
||||
|
||||
const PreInstructorSoccorsiTable = ({ userId = null }) => {
|
||||
const [items, setItems] = useState(null);
|
||||
const [filters, setFilters] = useState(null);
|
||||
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
||||
const [statuses, setStatuses] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isNil(userId)) {
|
||||
setLocalAsyncRequest(true);
|
||||
|
||||
if (userId === 0) {
|
||||
AmendmentsService.getSoccorsi(getCallback, errGetCallbacks);
|
||||
} else {
|
||||
AmendmentsService.getSoccorsi(getCallback, errGetCallbacks, [
|
||||
['userId', userId]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}, [userId]);
|
||||
|
||||
const getCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setItems(getFormattedData(data.data));
|
||||
setStatuses(uniq(data.data.map(o => o.status)))
|
||||
initFilters();
|
||||
}
|
||||
setLocalAsyncRequest(false);
|
||||
}
|
||||
|
||||
const errGetCallbacks = (data) => {
|
||||
setLocalAsyncRequest(false);
|
||||
}
|
||||
|
||||
const getFormattedData = (data) => {
|
||||
return data.map((d) => {
|
||||
d.startDate = is(String, d.startDate) ? new Date(d.startDate) : (d.startDate ? d.startDate : '');
|
||||
d.evaluationEndDate = is(String, d.evaluationEndDate) ? new Date(d.evaluationEndDate) : (d.evaluationEndDate ? d.evaluationEndDate : '');
|
||||
return d;
|
||||
});
|
||||
};
|
||||
|
||||
const formatDate = (value) => {
|
||||
return value.toLocaleDateString('it-IT', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
|
||||
const clearFilter = () => {
|
||||
initFilters();
|
||||
};
|
||||
|
||||
const initFilters = () => {
|
||||
setFilters({
|
||||
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
||||
callName: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }]
|
||||
},
|
||||
companyName: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }]
|
||||
},
|
||||
startDate: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }]
|
||||
},
|
||||
evaluationEndDate: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }]
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const renderHeader = () => {
|
||||
return (
|
||||
<div className="appTableHeader">
|
||||
<Button type="button" icon="pi pi-filter-slash" label={__('Pulisci', 'gepafin')} outlined onClick={clearFilter} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const dateStartBodyTemplate = (rowData) => {
|
||||
return formatDate(rowData.startDate);
|
||||
};
|
||||
|
||||
const dateExpirationBodyTemplate = (rowData) => {
|
||||
return rowData.evaluationEndDate ? formatDate(rowData.evaluationEndDate) : '';
|
||||
};
|
||||
|
||||
const dateFilterTemplate = (options) => {
|
||||
return <Calendar value={options.value} onChange={(e) => options.filterCallback(e.value, options.index)} dateFormat="mm/dd/yy" placeholder="mm/dd/yyyy" mask="99/99/9999" />;
|
||||
};
|
||||
|
||||
const statusBodyTemplate = (rowData) => {
|
||||
return <ProperBandoLabel status={rowData.status}/>;
|
||||
};
|
||||
|
||||
const statusFilterTemplate = (options) => {
|
||||
return <Dropdown value={options.value} options={statuses} onChange={(e) => options.filterCallback(e.value, options.index)} itemTemplate={statusItemTemplate} placeholder={translationStrings.selectOneLabel} className="p-column-filter" showClear />;
|
||||
};
|
||||
|
||||
const statusItemTemplate = (option) => {
|
||||
return <Tag value={getBandoLabel(option)} severity={getBandoSeverity(option)} />;
|
||||
};
|
||||
|
||||
const actionsBodyTemplate = (rowData) => {
|
||||
return <Link to={`/domande/${rowData.applicationId}/soccorso/${rowData.id}`}>
|
||||
<Button severity="info" label={__('Dettagli', 'gepafin')} size="small" />
|
||||
</Link>
|
||||
}
|
||||
|
||||
const header = renderHeader();
|
||||
|
||||
return(
|
||||
<div className="appPageSection__table">
|
||||
<DataTable value={items} paginator showGridlines rows={5} loading={localAsyncRequest} dataKey="id"
|
||||
filters={filters} stripedRows removableSort
|
||||
header={header}
|
||||
emptyMessage={translationStrings.emptyMessage}
|
||||
onFilter={(e) => setFilters(e.filters)}>
|
||||
<Column field="applicationId" header={__('ID domanda', 'gepafin')}
|
||||
sortable filterPlaceholder={__('Cerca', 'gepafin')}
|
||||
style={{ minWidth: '6rem' }}/>
|
||||
<Column field="protocolNumber" header={__('Protocollo', 'gepafin')}
|
||||
sortable filterPlaceholder={__('Cerca', 'gepafin')}
|
||||
style={{ minWidth: '6rem' }}/>
|
||||
<Column field="callName" header={__('Bando', 'gepafin')}
|
||||
filter filterPlaceholder={__('Cerca', 'gepafin')}
|
||||
style={{ minWidth: '8rem' }}/>
|
||||
<Column field="companyName" header={__('Azienda Beneficiaria', 'gepafin')}
|
||||
filter filterPlaceholder={__('Cerca', 'gepafin')}
|
||||
style={{ minWidth: '8rem' }}/>
|
||||
<Column header={__('Data richiesta', 'gepafin')}
|
||||
filterField="startDate" dataType="date"
|
||||
style={{ minWidth: '8rem' }}
|
||||
body={dateStartBodyTemplate} filter filterElement={dateFilterTemplate}/>
|
||||
<Column header={__('Scadenza', 'gepafin')}
|
||||
filterField="evaluationEndDate" dataType="date"
|
||||
style={{ minWidth: '8rem' }}
|
||||
body={dateExpirationBodyTemplate} filter filterElement={dateFilterTemplate}/>
|
||||
<Column field="status" header={__('Stato', 'gepafin')}
|
||||
style={{ minWidth: '7rem' }} body={statusBodyTemplate} filter
|
||||
filterElement={statusFilterTemplate} />
|
||||
<Column header={__('Azioni', 'gepafin')}
|
||||
body={actionsBodyTemplate}/>
|
||||
</DataTable>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PreInstructorSoccorsiTable;
|
||||
@@ -7,16 +7,14 @@ import NumberFlow from '@number-flow/react';
|
||||
import { useStore } from '../../store';
|
||||
|
||||
// components
|
||||
//import PreInstructorSoccorsiTable from './components/PreInstructorSoccorsiTable';
|
||||
import DashboardService from '../../service/dashboard-service';
|
||||
import ChartDomandePerBando from '../../components/ChartDomandePerBando';
|
||||
import ChartStatoDomande from '../../components/ChartStatoDomande';
|
||||
import ChartDomandePerStato from '../../components/ChartDomandePerStato';
|
||||
import ChartRichiesteVsApprovate from '../../components/ChartRichiesteVsApprovate';
|
||||
import BeneficiarioUltimeDomandeTable from './components/BeneficiarioUltimeDomandeTable';
|
||||
|
||||
const StatsBeneficiary = () => {
|
||||
const [mainStats, setMainStats] = useState({});
|
||||
const [chartStats, setChartStats] = useState({});
|
||||
//const userData = useStore().main.userData();
|
||||
const chosenCompanyId = useStore().main.chosenCompanyId();
|
||||
|
||||
const getStats = (resp) => {
|
||||
@@ -34,8 +32,8 @@ const StatsBeneficiary = () => {
|
||||
|
||||
useEffect(() => {
|
||||
DashboardService.getBeneficiaryStatsPage(chosenCompanyId, getStats, errGetStats);
|
||||
}, []);
|
||||
console.log(chartStats)
|
||||
}, [chosenCompanyId]);
|
||||
|
||||
return(
|
||||
<div className="appPage">
|
||||
<div className="appPage__pageHeader">
|
||||
@@ -81,7 +79,7 @@ console.log(chartStats)
|
||||
currency: 'EUR',
|
||||
currencyDisplay: 'symbol'
|
||||
}}
|
||||
locales="en-US"/></span>
|
||||
locales="it-IT"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -92,14 +90,21 @@ console.log(chartStats)
|
||||
? <div className="appPageSection">
|
||||
<h2>{__('Statistiche di sistema', 'gepafin')}</h2>
|
||||
<div className="appPageSection columns">
|
||||
{/*<ChartDomandePerBando
|
||||
title={__('Domande per bando', 'gepafin')}
|
||||
data={chartStats.applicationPerCall}/>*/}
|
||||
<ChartRichiesteVsApprovate
|
||||
title={__('Importi Richiesti VS Approvati', 'gepafin')}
|
||||
data={chartStats.requestedVsApprovedAmount}/>
|
||||
<ChartDomandePerStato
|
||||
title={__('Domande per stato', 'gepafin')}
|
||||
data={chartStats.applicationPerStatus}/>
|
||||
</div>
|
||||
</div> : null}
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Ultime richieste di finanziamento', 'gepafin')}</h2>
|
||||
<BeneficiarioUltimeDomandeTable/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ export default class ApplicationService {
|
||||
NetworkService.get(`${API_BASE_URL}/application`, callback, errCallback, queryParams);
|
||||
};
|
||||
|
||||
static getApplicationsPaginated = (body, callback, errCallback, queryParams) => {
|
||||
NetworkService.post(`${API_BASE_URL}/application/pagination`, body, callback, errCallback, queryParams);
|
||||
};
|
||||
|
||||
static getApplication = (id, callback, errCallback) => {
|
||||
NetworkService.get(`${API_BASE_URL}/application/${id}`, callback, errCallback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user