From 0fddd871908944bd3253a268497cda8e3fc1ec2e Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Fri, 27 Dec 2024 17:00:13 +0100 Subject: [PATCH] - saving progress; --- src/components/NotificationsSidebar/index.js | 51 ++++++++++++-------- src/service/notification-service.js | 10 ++++ 2 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 src/service/notification-service.js diff --git a/src/components/NotificationsSidebar/index.js b/src/components/NotificationsSidebar/index.js index 55b08f5..1a690ee 100644 --- a/src/components/NotificationsSidebar/index.js +++ b/src/components/NotificationsSidebar/index.js @@ -1,6 +1,12 @@ import React, { useEffect, useState } from 'react'; import { __ } from '@wordpress/i18n'; -import { head, isEmpty } from 'ramda'; +import { head, isEmpty, pathOr } from 'ramda'; + +// store +import { storeGet, useStore } from '../../store'; + +// api +import NotificationService from '../../service/notification-service'; // components import { Badge } from 'primereact/badge'; @@ -10,6 +16,8 @@ import NotificationItem from './components/NotificationItem'; import NotificationItemChosen from './components/NotificationItemChosen'; const NotificationsSidebar = () => { + const chosenCompanyId = useStore().main.chosenCompanyId(); + const userData = useStore().main.userData(); const [activeIndex, setActiveIndex] = useState(0); const [loading, setLoading] = useState(false); const [notificationsVisible, setNotificationsVisible] = useState(false); @@ -44,26 +52,29 @@ const NotificationsSidebar = () => { setChosenMsg({}); } + const getNotifications = (resp) => { + console.log('resp', resp); + } + + const errGetNotifications = (resp) => { + + } + useEffect(() => { - setNotifications(() => { - const msg = { - 'id': 35, - 'createdDate': '2024-12-23T14:55:27.278103', - 'updatedDate': '2024-12-23T14:55:27.278103', - 'userId': 30, - 'title': 'Il Risultato della Valutazione per la Richiesta È Disponibile', - 'message': 'Il risultato della valutazione per la richiesta ai sensi del protocollo n. 10000015 è ora disponibile.', - 'status': 'UNREAD', - 'companyId': 103, - 'redirectUrl': 'EVALUATION_RESULT', - 'notificationType': 'EVALUATION_RESULT' - }; - return Array.from({ length: 33 }, (_, index) => ({ - ...msg, - id: msg.id + index - })); - }) - }, []); + const role = pathOr('', ['role', 'roleType'], userData); + + console.log('chosenCompanyId', chosenCompanyId, role) + if (userData.id && chosenCompanyId !== 0 && role === 'ROLE_BENEFICIARY') { + NotificationService.getNotifications(userData.id, getNotifications, errGetNotifications, [ + ['status', 'UNREAD'], + ['companyId', chosenCompanyId] + ]); + } else if (userData.id && role !== 'ROLE_BENEFICIARY') { + NotificationService.getNotifications(userData.id, getNotifications, errGetNotifications, [ + ['status', 'UNREAD'] + ]); + } + }, [chosenCompanyId, userData.id]); return ( <> diff --git a/src/service/notification-service.js b/src/service/notification-service.js new file mode 100644 index 0000000..cd33e34 --- /dev/null +++ b/src/service/notification-service.js @@ -0,0 +1,10 @@ +import { NetworkService } from './network-service'; + +const API_BASE_URL = process.env.REACT_APP_API_EXECUTION_ADDRESS; + +export default class NotificationService { + + static getNotifications = (id, callback, errCallback, queryParams) => { + NetworkService.get(`${API_BASE_URL}/notification/user/${id}`, callback, errCallback, queryParams); + }; +}