diff --git a/app/javascript/dashboard/helper/actionCable.js b/app/javascript/dashboard/helper/actionCable.js index ccbfd6759..2b138a3fb 100644 --- a/app/javascript/dashboard/helper/actionCable.js +++ b/app/javascript/dashboard/helper/actionCable.js @@ -23,6 +23,7 @@ class ActionCableConnector extends BaseActionCableConnector { 'contact.updated': this.onContactUpdate, 'conversation.mentioned': this.onConversationMentioned, 'notification.created': this.onNotificationCreated, + 'notification.deleted': this.onNotificationDeleted, 'first.reply.created': this.onFirstReplyCreated, 'conversation.read': this.onConversationRead, 'conversation.updated': this.onConversationUpdated, @@ -195,6 +196,10 @@ class ActionCableConnector extends BaseActionCableConnector { this.app.$store.dispatch('notifications/addNotification', data); }; + onNotificationDeleted = data => { + this.app.$store.dispatch('notifications/deleteNotification', data); + }; + // eslint-disable-next-line class-methods-use-this onFirstReplyCreated = () => { bus.$emit('fetch_overview_reports'); diff --git a/app/javascript/dashboard/store/modules/notifications/actions.js b/app/javascript/dashboard/store/modules/notifications/actions.js index d28020b37..bf2f3f460 100644 --- a/app/javascript/dashboard/store/modules/notifications/actions.js +++ b/app/javascript/dashboard/store/modules/notifications/actions.js @@ -56,4 +56,7 @@ export const actions = { addNotification({ commit }, data) { commit(types.ADD_NOTIFICATION, data); }, + deleteNotification({ commit }, data) { + commit(types.DELETE_NOTIFICATION, data); + }, }; diff --git a/app/javascript/dashboard/store/modules/notifications/mutations.js b/app/javascript/dashboard/store/modules/notifications/mutations.js index 96e6816a6..9d26b593c 100644 --- a/app/javascript/dashboard/store/modules/notifications/mutations.js +++ b/app/javascript/dashboard/store/modules/notifications/mutations.js @@ -55,4 +55,10 @@ export const mutations = { Vue.set($state.meta, 'unreadCount', unreadCount); Vue.set($state.meta, 'count', count); }, + [types.DELETE_NOTIFICATION]($state, data) { + const { notification, unread_count: unreadCount, count } = data; + Vue.delete($state.records, notification.id); + Vue.set($state.meta, 'unreadCount', unreadCount); + Vue.set($state.meta, 'count', count); + }, }; diff --git a/app/javascript/dashboard/store/modules/specs/notifications/actions.spec.js b/app/javascript/dashboard/store/modules/specs/notifications/actions.spec.js index 7351905a0..6c00e38ea 100644 --- a/app/javascript/dashboard/store/modules/specs/notifications/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/notifications/actions.spec.js @@ -98,4 +98,13 @@ describe('#actions', () => { ]); }); }); + + describe('#deleteNotification', () => { + it('sends correct actions', async () => { + await actions.deleteNotification({ commit }, { data: 1 }); + expect(commit.mock.calls).toEqual([ + [types.DELETE_NOTIFICATION, { data: 1 }], + ]); + }); + }); }); diff --git a/app/javascript/dashboard/store/modules/specs/notifications/mutations.spec.js b/app/javascript/dashboard/store/modules/specs/notifications/mutations.spec.js index ab8027c6e..25d4ea506 100644 --- a/app/javascript/dashboard/store/modules/specs/notifications/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/specs/notifications/mutations.spec.js @@ -118,4 +118,27 @@ describe('#mutations', () => { expect(state.meta.count).toEqual(232); }); }); + + describe('#DELETE_NOTIFICATION', () => { + it('delete notification', () => { + const state = { + meta: { unreadCount: 4, count: 231 }, + records: { + 1: { id: 1, primary_actor_id: 1 }, + 2: { id: 2, primary_actor_id: 2 }, + }, + }; + const data = { + notification: { id: 1, primary_actor_id: 1 }, + unread_count: 5, + count: 232, + }; + mutations[types.DELETE_NOTIFICATION](state, data); + expect(state.records).toEqual({ + 2: { id: 2, primary_actor_id: 2 }, + }); + expect(state.meta.unreadCount).toEqual(5); + expect(state.meta.count).toEqual(232); + }); + }); }); diff --git a/app/javascript/dashboard/store/mutation-types.js b/app/javascript/dashboard/store/mutation-types.js index 9ba841342..1f7996ca7 100644 --- a/app/javascript/dashboard/store/mutation-types.js +++ b/app/javascript/dashboard/store/mutation-types.js @@ -133,6 +133,7 @@ export default { SET_NOTIFICATIONS_UI_FLAG: 'SET_NOTIFICATIONS_UI_FLAG', UPDATE_NOTIFICATION: 'UPDATE_NOTIFICATION', ADD_NOTIFICATION: 'ADD_NOTIFICATION', + DELETE_NOTIFICATION: 'DELETE_NOTIFICATION', UPDATE_ALL_NOTIFICATIONS: 'UPDATE_ALL_NOTIFICATIONS', SET_NOTIFICATIONS_ITEM: 'SET_NOTIFICATIONS_ITEM', SET_NOTIFICATIONS: 'SET_NOTIFICATIONS', diff --git a/app/mailers/agent_notifications/conversation_notifications_mailer.rb b/app/mailers/agent_notifications/conversation_notifications_mailer.rb index e249c3521..874449adf 100644 --- a/app/mailers/agent_notifications/conversation_notifications_mailer.rb +++ b/app/mailers/agent_notifications/conversation_notifications_mailer.rb @@ -1,5 +1,5 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer - def conversation_creation(conversation, agent) + def conversation_creation(conversation, agent, _user) return unless smtp_config_set_or_development? @agent = agent @@ -9,7 +9,7 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer send_mail_with_liquid(to: @agent.email, subject: subject) and return end - def conversation_assignment(conversation, agent) + def conversation_assignment(conversation, agent, _user) return unless smtp_config_set_or_development? @agent = agent diff --git a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb index 530d6102a..5661af714 100644 --- a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb +++ b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb @@ -14,7 +14,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do end describe 'conversation_creation' do - let(:mail) { described_class.with(account: account).conversation_creation(conversation, agent).deliver_now } + let(:mail) { described_class.with(account: account).conversation_creation(conversation, agent, nil).deliver_now } it 'renders the subject' do expect(mail.subject).to eq("#{agent.available_name}, A new conversation [ID - #{conversation @@ -27,7 +27,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do end describe 'conversation_assignment' do - let(:mail) { described_class.with(account: account).conversation_assignment(conversation, agent).deliver_now } + let(:mail) { described_class.with(account: account).conversation_assignment(conversation, agent, nil).deliver_now } it 'renders the subject' do expect(mail.subject).to eq("#{agent.available_name}, A new conversation [ID - #{conversation.display_id}] has been assigned to you.")