chore: Refactor audio notification helper (#6148)

This commit is contained in:
Pranav Raj S
2022-12-29 20:01:14 -08:00
committed by GitHub
parent 11f6e6bc61
commit cd3b6ebf28
10 changed files with 131 additions and 273 deletions

View File

@@ -1,4 +1,5 @@
import AnalyticsHelper from './AnalyticsHelper';
import DashboardAudioNotificationHelper from './AudioAlerts/DashboardAudioNotificationHelper';
export const CHATWOOT_SET_USER = 'CHATWOOT_SET_USER';
export const CHATWOOT_RESET = 'CHATWOOT_RESET';
@@ -13,6 +14,23 @@ export const initializeAnalyticsEvents = () => {
window.bus.$on(ANALYTICS_RESET, () => {});
};
const initializeAudioAlerts = user => {
// InitializeAudioNotifications
const { ui_settings: uiSettings } = user || {};
const {
always_play_audio_alert: alwaysPlayAudioAlert,
enable_audio_alerts: audioAlertType,
notification_tone: audioAlertTone,
} = uiSettings;
DashboardAudioNotificationHelper.setInstanceValues({
currentUserId: user.id,
audioAlertType: audioAlertType || 'none',
audioAlertTone: audioAlertTone || 'ding',
alwaysPlayAudioAlert: alwaysPlayAudioAlert || false,
});
};
export const initializeChatwootEvents = () => {
window.bus.$on(CHATWOOT_RESET, () => {
if (window.$chatwoot) {
@@ -32,5 +50,7 @@ export const initializeChatwootEvents = () => {
cloudCustomer: 'true',
});
}
initializeAudioAlerts(user);
});
};