- implemneted API for notifications;

- added styles for notifications;
- added email template to amendment page;
This commit is contained in:
Vitalii Kiiko
2024-12-30 15:03:32 +01:00
parent 0fddd87190
commit d15933f043
9 changed files with 171 additions and 55 deletions

View File

@@ -8,6 +8,9 @@ import { storeGet, useStore } from '../../store';
// api
import NotificationService from '../../service/notification-service';
// tools
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
// components
import { Badge } from 'primereact/badge';
import { Sidebar } from 'primereact/sidebar';
@@ -33,11 +36,12 @@ const NotificationsSidebar = () => {
const fetchTabData = (index) => {
setChosenMsg({});
console.log('fetchTabData', index);
setLoading(true);
setTimeout(() => {
setLoading(false);
}, 7000)
if (0 === index) {
fetchMessages();
} else {
fetchMessages('READ');
}
}
const chooseNotification = (id) => {
@@ -52,28 +56,79 @@ const NotificationsSidebar = () => {
setChosenMsg({});
}
const fetchMessages = (status = 'UNREAD') => {
const chosenCompanyId = storeGet.main.chosenCompanyId();
const userData = storeGet.main.userData();
const role = pathOr('', ['role', 'roleType'], userData);
if (userData.id && chosenCompanyId !== 0 && role === 'ROLE_BENEFICIARY') {
setLoading(true);
NotificationService.getNotifications(
userData.id,
status === 'UNREAD' ? getNotifications : getNotificationsRead,
errGetNotifications,
[
['status', status],
['companyId', chosenCompanyId]
]
);
} else if (userData.id && role !== 'ROLE_BENEFICIARY') {
setLoading(true);
NotificationService.getNotifications(
userData.id,
status === 'UNREAD' ? getNotifications : getNotificationsRead,
errGetNotifications,
[
['status', status]
]
);
}
}
const getNotifications = (resp) => {
console.log('resp', resp);
if (resp.status === 'SUCCESS') {
setNotifications(resp.data);
}
set404FromErrorResponse(resp);
setLoading(false);
}
const getNotificationsRead = (resp) => {
if (resp.status === 'SUCCESS') {
setNotificationsRead(resp.data);
}
set404FromErrorResponse(resp);
setLoading(false);
}
const errGetNotifications = (resp) => {
set404FromErrorResponse(resp);
setLoading(false);
}
const makeNotificationRead = (id) => {
NotificationService.notificationMakeRead(id, makeReadCallback, makeReadErrorCallback)
}
const makeReadCallback = (resp) => {
if (resp.status === 'SUCCESS') {
if (0 === activeIndex) {
const msgs = notifications.map(o => o.id === resp.data.id ? resp.data : o);
setNotifications(msgs);
} else {
const msgs = notificationsRead.map(o => o.id === resp.data.id ? resp.data : o);
setNotificationsRead(msgs);
}
}
set404FromErrorResponse(resp);
}
const makeReadErrorCallback = (resp) => {
set404FromErrorResponse(resp);
}
useEffect(() => {
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']
]);
}
fetchMessages();
}, [chosenCompanyId, userData.id]);
return (
@@ -94,11 +149,16 @@ const NotificationsSidebar = () => {
<i className="pi pi-spin pi-spinner" style={{ fontSize: '2rem' }}></i>
</div>
: !isEmpty(chosenMsg)
? <NotificationItemChosen item={chosenMsg} closeFn={closeChosenMsg}/>
? <NotificationItemChosen
item={chosenMsg}
closeFn={closeChosenMsg}
markReadFn={makeNotificationRead}/>
: (notifications.length > 0
? <ul className="notificationsSidebar__list">
{notifications.map(o => <NotificationItem key={o.id} item={o}
clickFn={chooseNotification}/>)}
{notifications.map(o => <NotificationItem
key={o.id}
item={o}
clickFn={chooseNotification}/>)}
</ul>
: <div className="notificationsSidebar__loading">
<i className="pi pi-megaphone" style={{ fontSize: '2rem' }}></i>
@@ -111,11 +171,16 @@ const NotificationsSidebar = () => {
<i className="pi pi-spin pi-spinner" style={{ fontSize: '2rem' }}></i>
</div>
: !isEmpty(chosenMsg)
? <NotificationItemChosen item={chosenMsg} closeFn={closeChosenMsg}/>
? <NotificationItemChosen
item={chosenMsg}
closeFn={closeChosenMsg}
markReadFn={makeNotificationRead}/>
: (notificationsRead.length > 0
? <ul className="notificationsSidebar__list">
{notificationsRead.map(o => <NotificationItem key={o.id} item={o}
clickFn={chooseNotification}/>)}
{notificationsRead.map(o => <NotificationItem
key={o.id}
item={o}
clickFn={chooseNotification}/>)}
</ul>
:
<div className="notificationsSidebar__loading">