feature/IO-3096-GlobalNotifications - add Dayjs, minor packages on backend
This commit is contained in:
@@ -79,7 +79,7 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
__typename: notif.__typename
|
__typename: notif.__typename
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.sort((a, b) => day(b.created_at).diff(day(a.created_at)));
|
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
|
||||||
setNotifications(processedNotifications);
|
setNotifications(processedNotifications);
|
||||||
setError(null);
|
setError(null);
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
const handleMarkAllRead = useCallback(() => {
|
const handleMarkAllRead = useCallback(() => {
|
||||||
markAllNotificationsRead()
|
markAllNotificationsRead()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const timestamp = day().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
setNotifications((prev) => {
|
setNotifications((prev) => {
|
||||||
const updatedNotifications = prev.map((notif) =>
|
const updatedNotifications = prev.map((notif) =>
|
||||||
notif.read === null && notif.associationid === userAssociationId
|
notif.read === null && notif.associationid === userAssociationId
|
||||||
@@ -137,7 +137,7 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
variables: { id: notificationId }
|
variables: { id: notificationId }
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const timestamp = day().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
setNotifications((prev) => {
|
setNotifications((prev) => {
|
||||||
return prev.map((notif) =>
|
return prev.map((notif) =>
|
||||||
notif.id === notificationId && !notif.read ? { ...notif, read: timestamp } : notif
|
notif.id === notificationId && !notif.read ? { ...notif, read: timestamp } : notif
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
MARK_NOTIFICATION_READ
|
MARK_NOTIFICATION_READ
|
||||||
} from "../../graphql/notifications.queries.js";
|
} from "../../graphql/notifications.queries.js";
|
||||||
import { gql, useMutation } from "@apollo/client";
|
import { gql, useMutation } from "@apollo/client";
|
||||||
import day from "../../utils/day.js";
|
|
||||||
|
|
||||||
const SocketContext = createContext(null);
|
const SocketContext = createContext(null);
|
||||||
|
|
||||||
@@ -27,7 +26,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
|
|
||||||
const [markNotificationRead] = useMutation(MARK_NOTIFICATION_READ, {
|
const [markNotificationRead] = useMutation(MARK_NOTIFICATION_READ, {
|
||||||
update: (cache, { data: { update_notifications } }) => {
|
update: (cache, { data: { update_notifications } }) => {
|
||||||
const timestamp = day().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
const updatedNotification = update_notifications.returning[0];
|
const updatedNotification = update_notifications.returning[0];
|
||||||
|
|
||||||
cache.modify({
|
cache.modify({
|
||||||
@@ -80,7 +79,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
const [markAllNotificationsRead] = useMutation(MARK_ALL_NOTIFICATIONS_READ, {
|
const [markAllNotificationsRead] = useMutation(MARK_ALL_NOTIFICATIONS_READ, {
|
||||||
variables: { associationid: userAssociationId },
|
variables: { associationid: userAssociationId },
|
||||||
update: (cache) => {
|
update: (cache) => {
|
||||||
const timestamp = day().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
cache.modify({
|
cache.modify({
|
||||||
fields: {
|
fields: {
|
||||||
notifications(existing = [], { readField }) {
|
notifications(existing = [], { readField }) {
|
||||||
@@ -203,7 +202,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
scenario_text: JSON.stringify(notifications.map((notif) => notif.body)),
|
scenario_text: JSON.stringify(notifications.map((notif) => notif.body)),
|
||||||
fcm_text: notifications.map((notif) => notif.body).join(". ") + ".",
|
fcm_text: notifications.map((notif) => notif.body).join(". ") + ".",
|
||||||
scenario_meta: JSON.stringify(notifications.map((notif) => notif.variables || {})),
|
scenario_meta: JSON.stringify(notifications.map((notif) => notif.variables || {})),
|
||||||
created_at: day(notifications[0].timestamp).toISOString(),
|
created_at: new Date(notifications[0].timestamp).toISOString(),
|
||||||
read: null,
|
read: null,
|
||||||
job: { ro_number: jobRoNumber }
|
job: { ro_number: jobRoNumber }
|
||||||
};
|
};
|
||||||
@@ -225,8 +224,8 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
|
|||||||
query: GET_NOTIFICATIONS,
|
query: GET_NOTIFICATIONS,
|
||||||
variables: baseVariables,
|
variables: baseVariables,
|
||||||
data: {
|
data: {
|
||||||
notifications: [newNotification, ...existingNotifications].sort((a, b) =>
|
notifications: [newNotification, ...existingNotifications].sort(
|
||||||
day(b.created_at).diff(day(a.created_at))
|
(a, b) => new Date(b.created_at) - new Date(a.created_at)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
broadcast: true
|
broadcast: true
|
||||||
|
|||||||
Reference in New Issue
Block a user