diff --git a/app/builders/messages/facebook/message_builder.rb b/app/builders/messages/facebook/message_builder.rb index 3b3248ed1..f19d3c8b7 100644 --- a/app/builders/messages/facebook/message_builder.rb +++ b/app/builders/messages/facebook/message_builder.rb @@ -27,7 +27,7 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder end ensure_contact_avatar rescue Koala::Facebook::AuthenticationError - Rails.logger.error "Facebook Authorization expired for Inbox #{@inbox.id}" + @inbox.channel.authorization_error! rescue StandardError => e ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception true diff --git a/app/javascript/dashboard/components/layout/sidebarComponents/Secondary.vue b/app/javascript/dashboard/components/layout/sidebarComponents/Secondary.vue index 724576347..4b19a3ec3 100644 --- a/app/javascript/dashboard/components/layout/sidebarComponents/Secondary.vue +++ b/app/javascript/dashboard/components/layout/sidebarComponents/Secondary.vue @@ -95,6 +95,7 @@ export default { ), type: inbox.channel_type, phoneNumber: inbox.phone_number, + reauthorizationRequired: inbox.reauthorization_required, })) .sort((a, b) => a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1 diff --git a/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryChildNavItem.vue b/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryChildNavItem.vue index 7bf57df1a..4d2601774 100644 --- a/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryChildNavItem.vue +++ b/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryChildNavItem.vue @@ -30,6 +30,14 @@ {{ count }} + + + @@ -57,6 +65,10 @@ export default { type: String, default: '', }, + warningIcon: { + type: String, + default: '', + }, count: { type: String, default: '', diff --git a/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryNavItem.vue b/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryNavItem.vue index ffd8018d5..1fcde8948 100644 --- a/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryNavItem.vue +++ b/app/javascript/dashboard/components/layout/sidebarComponents/SecondaryNavItem.vue @@ -34,6 +34,7 @@ :label-color="child.color" :should-truncate="child.truncateLabel" :icon="computedInboxClass(child)" + :warning-icon="computedInboxErrorClass(child)" /> { return 'chat'; } }; + +export const getInboxWarningIconClass = (type, reauthorizationRequired) => { + if (type === INBOX_TYPES.FB && reauthorizationRequired) { + return 'warning'; + } + return ''; +}; diff --git a/app/javascript/dashboard/helper/specs/inbox.spec.js b/app/javascript/dashboard/helper/specs/inbox.spec.js index f6d6aa9f0..2db937be1 100644 --- a/app/javascript/dashboard/helper/specs/inbox.spec.js +++ b/app/javascript/dashboard/helper/specs/inbox.spec.js @@ -1,4 +1,4 @@ -import { getInboxClassByType } from '../inbox'; +import { getInboxClassByType, getInboxWarningIconClass } from '../inbox'; describe('#Inbox Helpers', () => { describe('getInboxClassByType', () => { @@ -34,4 +34,12 @@ describe('#Inbox Helpers', () => { expect(getInboxClassByType('Channel::Email')).toEqual('mail'); }); }); + + describe('getInboxWarningIconClass', () => { + it('should return correct class for warning', () => { + expect(getInboxWarningIconClass('Channel::FacebookPage', true)).toEqual( + 'warning' + ); + }); + }) }); diff --git a/app/javascript/dashboard/i18n/locale/en/settings.json b/app/javascript/dashboard/i18n/locale/en/settings.json index e8709c62f..9299be2b5 100644 --- a/app/javascript/dashboard/i18n/locale/en/settings.json +++ b/app/javascript/dashboard/i18n/locale/en/settings.json @@ -185,7 +185,8 @@ "REPORTS_TEAM": "Team", "SET_AVAILABILITY_TITLE": "Set yourself as", "BETA": "Beta", - "REPORTS_OVERVIEW": "Overview" + "REPORTS_OVERVIEW": "Overview", + "FACEBOOK_REAUTHORIZE": "Your Facebook connection has expired, please reconnect your Facebook page to continue services" }, "CREATE_ACCOUNT": { "NO_ACCOUNT_WARNING": "Uh oh! We could not find any Chatwoot accounts. Please create a new account to continue.", diff --git a/spec/builders/messages/facebook/message_builder_spec.rb b/spec/builders/messages/facebook/message_builder_spec.rb index d928f99ee..bb08bd9b6 100644 --- a/spec/builders/messages/facebook/message_builder_spec.rb +++ b/spec/builders/messages/facebook/message_builder_spec.rb @@ -37,7 +37,7 @@ describe ::Messages::Facebook::MessageBuilder do allow(fb_object).to receive(:get_object).and_raise(Koala::Facebook::AuthenticationError.new(500, 'Error validating access token')) message_builder - expect(facebook_channel.authorization_error_count).to eq(1) + expect(facebook_channel.authorization_error_count).to eq(2) end end end diff --git a/spec/models/channel/facebook_page_spec.rb b/spec/models/channel/facebook_page_spec.rb index 02baac4a1..f0f0e036e 100644 --- a/spec/models/channel/facebook_page_spec.rb +++ b/spec/models/channel/facebook_page_spec.rb @@ -22,9 +22,11 @@ RSpec.describe Channel::FacebookPage do it 'calls channel notifier mail for facebook' do admin_mailer = double mailer_double = double + expect(AdministratorNotifications::ChannelNotificationsMailer).to receive(:with).and_return(admin_mailer) expect(admin_mailer).to receive(:facebook_disconnect).with(channel.inbox).and_return(mailer_double) expect(mailer_double).to receive(:deliver_later) + channel.prompt_reauthorization! end end