From 5d740c1069f15b735fe461f39835fbb8c291439b Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Wed, 15 Jan 2025 11:50:35 +0100 Subject: [PATCH 1/4] - added pagination for notifications (non beneficiary); --- .../NotificationItemChosen/index.js | 5 +- src/components/NotificationsSidebar/index.js | 177 +++++++++++++----- src/components/PaginatorBasic/index.js | 59 ++++++ .../components/AppSidebar/index.js | 22 +-- .../Bandi/components/AllBandiTable/index.js | 2 +- .../components/AllBandiAccordion/index.js | 2 +- .../AllBandiPreferredAccordion/index.js | 2 +- .../DraftApplicationsTable/index.js | 2 +- .../components/LatestBandiTable/index.js | 33 +++- .../LatestUsersActivityTable/index.js | 2 +- .../components/LatestBandiTable/index.js | 2 +- .../MyLatestSubmissionsTable/index.js | 2 +- .../PreInstructorDomandeTable/index.js | 2 +- .../components/AllDomandeTable/index.js | 2 +- .../AllDomandeArchiveTable/index.js | 5 +- .../BeneficiarioDomandeTable/index.js | 2 +- .../PreInstructorSoccorsiTable/index.js | 2 +- .../Users/components/AllUsersTable/index.js | 2 +- src/service/bando-service.js | 4 + src/service/notification-service.js | 8 + 20 files changed, 259 insertions(+), 78 deletions(-) create mode 100644 src/components/PaginatorBasic/index.js diff --git a/src/components/NotificationsSidebar/components/NotificationItemChosen/index.js b/src/components/NotificationsSidebar/components/NotificationItemChosen/index.js index 4588de6..24ecc1e 100644 --- a/src/components/NotificationsSidebar/components/NotificationItemChosen/index.js +++ b/src/components/NotificationsSidebar/components/NotificationItemChosen/index.js @@ -17,12 +17,13 @@ const NotificationItemChosen = ({ item, closeFn, markReadFn }) => { {getDateFromISOstring(item.createdDate)} {item.message} - + + ({currentPage} {__('di', 'gepafin')} {totalPages}) + + + : null + ) +} + +export default PaginatorBasic; \ No newline at end of file diff --git a/src/layouts/DefaultLayout/components/AppSidebar/index.js b/src/layouts/DefaultLayout/components/AppSidebar/index.js index 5c81b8f..30bc83e 100644 --- a/src/layouts/DefaultLayout/components/AppSidebar/index.js +++ b/src/layouts/DefaultLayout/components/AppSidebar/index.js @@ -45,77 +45,77 @@ const AppSidebar = () => { label: __('Bandi osservati', 'gepafin'), icon: 'pi pi-star', href: '/bandi-osservati', - id: 13, + id: 5, enable: intersection(permissions, ['VIEW_CALLS']).length }, { label: __('Gestione domande', 'gepafin'), icon: 'pi pi-file', href: '/domande', - id: 5, + id: 6, enable: intersection(permissions, ['VIEW_USERS', 'MANAGE_USERS']).length }, { label: __('Domande da valutare', 'gepafin'), icon: 'pi pi-calendar-clock', href: '/domande', - id: 6, + id: 7, enable: intersection(permissions, ['EVALUATE_APPLICATIONS']).length }, { label: __('Archivio domande', 'gepafin'), icon: 'pi pi-briefcase', href: '/domande', - id: 7, + id: 8, enable: intersection(permissions, ['APPLY_CALLS']).length }, { label: __('Archivio domande', 'gepafin'), icon: 'pi pi-briefcase', href: '/domande-archivio', - id: 5, + id: 9, enable: intersection(permissions, ['VIEW_USERS', 'MANAGE_USERS']).length }, { label: __('Archivio domande', 'gepafin'), icon: 'pi pi-briefcase', href: '/domande-archivio', - id: 6, + id: 10, enable: intersection(permissions, ['EVALUATE_APPLICATIONS']).length }, { label: __('Soccorso istruttorio', 'gepafin'), icon: , href: '/soccorso-istruttorio', - id: 8, + id: 11, enable: intersection(permissions, ['EVALUATE_APPLICATIONS']).length }, { label: __('Gestione utenti', 'gepafin'), icon: 'pi pi-users', href: '/utenti', - id: 9, + id: 12, enable: intersection(permissions, ['VIEW_USERS', 'MANAGE_USERS']).length }, { label: __('Configurazione', 'gepafin'), icon: 'pi pi-cog', //href: '/configurazione', - id: 10, + id: 13, enable: false }, { label: __('Report e Analisi', 'gepafin'), icon: 'pi pi-chart-bar', //href: '/stats', - id: 11, + id: 14, enable: false }, { label: __('Log di Sistema', 'gepafin'), icon: 'pi pi-receipt', clickFn: () => {}, - id: 12, + id: 15, enable: false } ] diff --git a/src/pages/Bandi/components/AllBandiTable/index.js b/src/pages/Bandi/components/AllBandiTable/index.js index 9bbc70f..14e457b 100644 --- a/src/pages/Bandi/components/AllBandiTable/index.js +++ b/src/pages/Bandi/components/AllBandiTable/index.js @@ -121,7 +121,7 @@ const AllBandiTable = () => { return(
- {
{
{ return (
- { const [filters, setFilters] = useState(null); const [localAsyncRequest, setLocalAsyncRequest] = useState(false); const [, setStatuses] = useState([]); + /*const [totalRecordsNum, setTotalRecordsNum] = useState(0); + const [perPageNum, setPerPageNum] = useState(0); + const getPaginationQuery = () => { + return { + "globalFilters": { + "page": 1, + "limit": 5, + "sortBy": { + "columnName": "ID", + "sortDesc": true + } + } + } + } + + const onPageChange = (e) => { + console.log('onPageChange', e) + }*/ useEffect(() => { setLocalAsyncRequest(true); BandoService.getBandi(getCallback, errGetCallbacks); + //const paginationQuery = getPaginationQuery(); + //BandoService.getBandiPaginated(paginationQuery, getCallback, errGetCallbacks); }, []); const getCallback = (data) => { if (data.status === 'SUCCESS') { + /*const { body, totalRecords, currentPage, totalPages, pageSize } = data.data; + setTotalRecordsNum(totalRecords); + setPerPageNum(pageSize); + const newItems = body.filter(o => o.status === 'PUBLISH'); + setItems(getFormattedBandiData(newItems)); + setStatuses(uniq(body.map(o => o.status)));*/ const newItems = data.data.filter(o => o.status === 'PUBLISH'); setItems(getFormattedBandiData(newItems)); - setStatuses(uniq(data.data.map(o => o.status))) + setStatuses(uniq(data.data.map(o => o.status))); initFilters(); } setLocalAsyncRequest(false); @@ -106,7 +132,10 @@ const LatestBandiTable = () => { return(
- { return(
- { return (
- { return (
- { return(
- { return (
- { const [filters, setFilters] = useState(null); const [localAsyncRequest, setLocalAsyncRequest] = useState(false); const [statuses, setStatuses] = useState([]); - const location = useLocation(); useEffect(() => { setLocalAsyncRequest(true); @@ -141,7 +140,7 @@ const AllDomandeArchiveTable = ({ updaterString = '' }) => { return (
- { return (
- { return(
- { return (
- { + NetworkService.post(`${API_BASE_URL}/call/pagination`, body, callback, errCallback, queryParams); + }; + static getBando = (id, callback, errCallback, queryParams) => { NetworkService.get(`${API_BASE_URL}/call/${id}`, callback, errCallback, queryParams); }; diff --git a/src/service/notification-service.js b/src/service/notification-service.js index c3457b2..25b77f6 100644 --- a/src/service/notification-service.js +++ b/src/service/notification-service.js @@ -8,6 +8,14 @@ export default class NotificationService { NetworkService.get(`${API_BASE_URL}/notification/user/${id}`, callback, errCallback, queryParams); }; + static getNotificationsByCompanyId = (id, companyId, callback, errCallback, queryParams) => { + NetworkService.get(`${API_BASE_URL}/notification/user/${id}/company/${companyId}/notifications`, callback, errCallback, queryParams); + }; + + static getNotificationsPagination = (id, body, callback, errCallback, queryParams) => { + NetworkService.post(`${API_BASE_URL}/notification/user/${id}/pagination`, body, callback, errCallback, queryParams); + }; + static notificationMakeRead = (id, callback, errCallback) => { NetworkService.put(`${API_BASE_URL}/notification/${id}`, {}, callback, errCallback, [ ['status', 'READ'] From f4aef029414edb580ea320c9775e0291282ada26 Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Wed, 15 Jan 2025 16:15:43 +0100 Subject: [PATCH 2/4] - saving progress; --- src/components/ChartDomandePerBando/index.js | 8 +- src/components/ChartStatoDomande/index.js | 2 +- src/pages/UserActivity/index.js | 94 ++++++++++++++------ src/service/notification-service.js | 4 +- src/service/user-action-service.js | 14 +++ 5 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 src/service/user-action-service.js diff --git a/src/components/ChartDomandePerBando/index.js b/src/components/ChartDomandePerBando/index.js index 700e6a7..b13d369 100644 --- a/src/components/ChartDomandePerBando/index.js +++ b/src/components/ChartDomandePerBando/index.js @@ -22,7 +22,10 @@ const ChartDomandePerBando = ({ title, data = [] }) => {

{label}

- {__('Domande', 'gepafin')}: {payload[0].value} + {__('In bozza', 'gepafin')}: {payload[0].value} +

+

+ {__('Inviate', 'gepafin')}: {payload[1].value}

); @@ -50,7 +53,8 @@ const ChartDomandePerBando = ({ title, data = [] }) => { }/> - + +
: null} diff --git a/src/components/ChartStatoDomande/index.js b/src/components/ChartStatoDomande/index.js index 856fd6c..e5a9ddf 100644 --- a/src/components/ChartStatoDomande/index.js +++ b/src/components/ChartStatoDomande/index.js @@ -38,7 +38,7 @@ const ChartStatoDomande = ({ title, data = [] }) => { label={({ percent }) => `${(percent * 100).toFixed(0)}%`} outerRadius={120} fill="#8884d8" - dataKey="numberOfApplications" + dataKey="numberOfSubmitedApplications" nameKey="status" > {data.map((entry, index) => ( diff --git a/src/pages/UserActivity/index.js b/src/pages/UserActivity/index.js index 8e93f5e..699cf38 100644 --- a/src/pages/UserActivity/index.js +++ b/src/pages/UserActivity/index.js @@ -15,6 +15,7 @@ import getDateFromISOstring from '../../helpers/getDateFromISOstring'; import { Button } from 'primereact/button'; import { Toast } from 'primereact/toast'; import { Dropdown } from 'primereact/dropdown'; +import UserActionService from '../../service/user-action-service'; const UserActivity = () => { @@ -25,6 +26,8 @@ const UserActivity = () => { const [user, setUser] = useState({}); const [roles, setRoles] = useState([]); const [chosenRole, setChosenRole] = useState(0); + const [actionsContext, setActionsContext] = useState([]); + const [userActions, setUserActions] = useState({}); const goBack = () => { navigate(`/utenti`); @@ -56,13 +59,13 @@ const UserActivity = () => { } const getStatValue = (key, fallback = 0) => { - return pathOr(fallback, [key], {}); + return pathOr(fallback, [key], userActions); } const handleRoleUpdate = () => { if (user.role?.id !== chosenRole) { setLoading(true); - UserService.updateUser(user.id, {roleId: chosenRole}, updateRoleCallback, errUpdateRoleCallback) + UserService.updateUser(user.id, { roleId: chosenRole }, updateRoleCallback, errUpdateRoleCallback) } } @@ -78,11 +81,37 @@ const UserActivity = () => { setLoading(false); } + const getActionsContextCallback = (resp) => { + if (resp.status === 'SUCCESS') { + setActionsContext(resp.data) + } + setLoading(false); + } + + const errGetActionsContextCallback = (resp) => { + set404FromErrorResponse(resp); + setLoading(false); + } + + const getUserActionsCallback = (resp) => { + if (resp.status === 'SUCCESS') { + setUserActions(resp.data) + } + setLoading(false); + } + + const errGetUserActionsCallback = (resp) => { + set404FromErrorResponse(resp); + setLoading(false); + } + useEffect(() => { if (id && !isEmpty(id)) { setLoading(true); UserService.getUser(id, getUserCallback, errGetUserCallback); UserService.getRoles(getRolesCallback, errGetRolesCallback); + UserActionService.getActionContext(id, getActionsContextCallback, errGetActionsContextCallback); + UserActionService.getUserActions(id, getUserActionsCallback, errGetUserActionsCallback); } }, [id]) @@ -143,7 +172,10 @@ const UserActivity = () => { disabled={isEmpty(roles) || loading} value={chosenRole} onChange={(e) => setChosenRole(e.value)} - options={roles.filter(o => [3, 5].includes(o.id)).map(o => ({ label: o.roleName, value: o.id }))} + options={roles.filter(o => [3, 5].includes(o.id)).map(o => ({ + label: o.roleName, + value: o.id + }))} optionLabel="label" placeholder={__('Seleziona ruolo', 'gepafin')}/>
+ ); + }; + + const dateBodyTemplate = (rowData) => { + return formatDate(rowData.createdDate); + }; + + const header = renderHeader(); + + return ( +
+ setFilters(e.filters)}> + + + + + +
+ ) +} + +export default UserActivityTable; diff --git a/src/pages/UserActivity/index.js b/src/pages/UserActivity/index.js index 699cf38..a29a6b7 100644 --- a/src/pages/UserActivity/index.js +++ b/src/pages/UserActivity/index.js @@ -16,6 +16,7 @@ import { Button } from 'primereact/button'; import { Toast } from 'primereact/toast'; import { Dropdown } from 'primereact/dropdown'; import UserActionService from '../../service/user-action-service'; +import UserActivityTable from './components/UserActivityTable'; const UserActivity = () => { @@ -28,6 +29,9 @@ const UserActivity = () => { const [chosenRole, setChosenRole] = useState(0); const [actionsContext, setActionsContext] = useState([]); const [userActions, setUserActions] = useState({}); + const [chosenPeriod, setChosenPeriod] = useState(''); + const [chosenActivity, setChosenActivity] = useState(''); + const goBack = () => { navigate(`/utenti`); @@ -105,6 +109,19 @@ const UserActivity = () => { setLoading(false); } + const doFilterUserActivity = () => { + let queryParams = []; + + if (!isEmpty(chosenPeriod)) { + queryParams.push(['timeFilter', chosenPeriod]) + } + if (!isEmpty(chosenActivity)) { + queryParams.push(['actionContext', chosenActivity]) + } + + UserActionService.getUserActions(id, getUserActionsCallback, errGetUserActionsCallback, queryParams); + } + useEffect(() => { if (id && !isEmpty(id)) { setLoading(true); @@ -219,9 +236,53 @@ const UserActivity = () => {
: null} +
+ {!isEmpty(userActions) ?
-

{__('Statistiche attività', 'gepafin')}

+

{__('Filtri attività', 'gepafin')}

+
+
+ + setChosenPeriod(e.value)} + options={[ + { value: 'LAST_WEEK', label: __('Ultima settimana', 'gepafin') }, + { value: 'LAST_QUARTER', label: __('Ultimo trimestre', 'gepafin') }, + { value: 'LAST_SEMESTER', label: __('Ultimo semestre', 'gepafin') }, + { value: 'LAST_YEAR', label: __('Ultimo anno', 'gepafin') } + ]} + optionLabel="label"/> +
+ {!isEmpty(actionsContext) + ?
+ + setChosenActivity(e.value)} + options={actionsContext.map(o => ({ + value: o.actionContext, + label: o.description + }))} + optionLabel="label"/> +
: null} +
+
+
+
: null} + +
+ + {!isEmpty(userActions) + ?
+

{__('Attività dettagliate', 'gepafin')}

+
: null}
)