forked from BLC/sgeUpdated
Add 'sge-frontend/' from commit '5fa787e054b25ac53edc7ff0275ea7960a709401'
git-subtree-dir: sge-frontend git-subtree-mainline:876c278ac4git-subtree-split:5fa787e054
This commit is contained in:
162
sge-frontend/src/redux/actions/notifications/index.js
Normal file
162
sge-frontend/src/redux/actions/notifications/index.js
Normal file
@@ -0,0 +1,162 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getQuickNotifications = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
getQuickNotifications {
|
||||
id
|
||||
createdDateTime
|
||||
title
|
||||
message
|
||||
read
|
||||
notificationType
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const getQuickNotifications = response.data.data.getQuickNotifications;
|
||||
dispatch({
|
||||
type: "GET_QUICKNOTIFICATIONS",
|
||||
payload: {
|
||||
getQuickNotifications,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const setNotificationRead = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
setNotificationRead(id: "${id}") {
|
||||
id
|
||||
createdDateTime
|
||||
title
|
||||
message
|
||||
read
|
||||
notificationType
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const setNotificationRead = response.data.data.setNotificationRead;
|
||||
dispatch({
|
||||
type: "GET_SETNOTIFICATIONREAD",
|
||||
payload: {
|
||||
setNotificationRead,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getAllNotifications = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
getAllNotifications(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
sortBy: [{ direction: DESC, field: "createdDateTime" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
createdDateTime
|
||||
title
|
||||
message
|
||||
read
|
||||
notificationType
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const getAllNotifications = response.data.data.getAllNotifications;
|
||||
dispatch({
|
||||
type: "GET_ALLNOTIFICATION",
|
||||
payload: {
|
||||
getAllNotifications,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const notificationRemove = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
notificationRemove(id: "${data.selectedId}")
|
||||
}
|
||||
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const notificationRemove = response.data.data.notificationRemove;
|
||||
dispatch({
|
||||
type: "GET_NOTIFICATIONREMOVE",
|
||||
payload: {
|
||||
notificationRemove,
|
||||
},
|
||||
});
|
||||
if (notificationRemove === true) {
|
||||
let currentPage = data.currentPage;
|
||||
let rowsPerPage = data.rowsPerPage;
|
||||
dispatch(getAllNotifications({ currentPage, rowsPerPage }));
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user