From 82c9e07f0f995e31225c68fe1cfcb7e2d6cf24a7 Mon Sep 17 00:00:00 2001 From: sundasnoreen12 Date: Thu, 16 May 2024 12:53:36 +0500 Subject: [PATCH] refactor: optimize function for empty array --- src/notification-preferences/data/utils.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/notification-preferences/data/utils.js b/src/notification-preferences/data/utils.js index 795aee9..0873a2b 100644 --- a/src/notification-preferences/data/utils.js +++ b/src/notification-preferences/data/utils.js @@ -5,5 +5,11 @@ export const notificationChannels = () => ({ WEB: 'web', ...(getConfig().SHOW_EM export const shouldHideAppPreferences = (preferences, appId) => { const appPreferences = preferences.filter(pref => pref.appId === appId); - return appPreferences.length === 1 && appPreferences[0].id === 'core' && !appPreferences[0].coreNotificationTypes.length; + if (appPreferences.length !== 1) { + return false; + } + + const firstPreference = appPreferences[0]; + + return firstPreference?.id === 'core' && (!firstPreference.coreNotificationTypes?.length); };