diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js
index 6d27b2d9..276ec23d 100644
--- a/lib/new-admin/graphql/schema.js
+++ b/lib/new-admin/graphql/schema.js
@@ -327,7 +327,7 @@ const typeDefs = gql`
insertBlacklistRow(cryptoCode: String!, address: String!): Blacklist
createPromoCode(code: String!, discount: Int!): PromoCode
deletePromoCode(codeId: ID!): PromoCode
- clearNotification(id: ID!): Notification
+ toggleClearNotification(id: ID!, read: Boolean!): Notification
clearAllNotifications: Notification
}
`
@@ -418,7 +418,7 @@ const resolvers = {
// revokeToken: (...[, { token }]) => tokenManager.revokeToken(token)
createPromoCode: (...[, { code, discount }]) => promoCodeManager.createPromoCode(code, discount),
deletePromoCode: (...[, { codeId }]) => promoCodeManager.deletePromoCode(codeId),
- clearNotification: (...[, { id }]) => notifierQueries.markAsRead(id),
+ toggleClearNotification: (...[, { id, read }]) => notifierQueries.setRead(id, read),
clearAllNotifications: () => notifierQueries.markAllAsRead()
}
}
diff --git a/lib/notifier/queries.js b/lib/notifier/queries.js
index 6b68416a..bfa71742 100644
--- a/lib/notifier/queries.js
+++ b/lib/notifier/queries.js
@@ -56,10 +56,9 @@ const getNotifications = () => {
const sql = `SELECT * FROM notifications ORDER BY created DESC`
return db.any(sql).catch(console.error)
}
-
-const markAsRead = (id) => {
- const sql = `UPDATE notifications SET read = 't' WHERE id = $1`
- return db.none(sql, [id]).catch(console.error)
+const setRead = (id, read) => {
+ const sql = `UPDATE notifications SET read = $1 WHERE id = $2`
+ return db.none(sql, [read, id]).catch(console.error)
}
const markAllAsRead = () => {
@@ -87,7 +86,7 @@ module.exports = {
clearBlacklistNotification,
getValidNotifications,
getNotifications,
- markAsRead,
+ setRead,
markAllAsRead,
hasUnreadNotifications,
getAlerts,
diff --git a/new-lamassu-admin/src/components/NotificationCenter/NotificationCenter.js b/new-lamassu-admin/src/components/NotificationCenter/NotificationCenter.js
index 8292530f..659c956c 100644
--- a/new-lamassu-admin/src/components/NotificationCenter/NotificationCenter.js
+++ b/new-lamassu-admin/src/components/NotificationCenter/NotificationCenter.js
@@ -35,10 +35,11 @@ const GET_NOTIFICATIONS = gql`
}
`
-const CLEAR_NOTIFICATION = gql`
- mutation clearNotification($id: ID!) {
- clearNotification(id: $id) {
+const TOGGLE_CLEAR_NOTIFICATION = gql`
+ mutation toggleClearNotification($id: ID!, $read: Boolean!) {
+ toggleClearNotification(id: $id, read: $read) {
id
+ read
}
}
`
@@ -67,7 +68,7 @@ const NotificationCenter = ({ close, notifyUnread }) => {
if (!hasUnread) {
notifyUnread && notifyUnread()
}
- const [clearNotification] = useMutation(CLEAR_NOTIFICATION, {
+ const [toggleClearNotification] = useMutation(TOGGLE_CLEAR_NOTIFICATION, {
onError: () => console.error('Error while clearing notification'),
refetchQueries: () => ['getNotifications']
})
@@ -76,9 +77,6 @@ const NotificationCenter = ({ close, notifyUnread }) => {
refetchQueries: () => ['getNotifications']
})
- const handleClearNotification = id => {
- clearNotification({ variables: { id } })
- }
const buildNotifications = () => {
const notificationsToShow =
!showingUnread || !hasUnread
@@ -96,7 +94,11 @@ const NotificationCenter = ({ close, notifyUnread }) => {
created={n.created}
read={n.read}
valid={n.valid}
- onClear={handleClearNotification}
+ toggleClear={() =>
+ toggleClearNotification({
+ variables: { id: n.id, read: !n.read }
+ })
+ }
/>
)
})
@@ -123,14 +125,16 @@ const NotificationCenter = ({ close, notifyUnread }) => {
{showingUnread ? 'Show all' : 'Show unread'}
)}
-