From f9b330fa3f144f06c472b8d2882e9f04f4a70688 Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed Date: Tue, 27 Aug 2024 08:36:12 +0530 Subject: [PATCH] refactor: introduced a feature check method --- .../widget/composables/useConfig.js | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/app/javascript/widget/composables/useConfig.js b/app/javascript/widget/composables/useConfig.js index a94410517..3813837b2 100644 --- a/app/javascript/widget/composables/useConfig.js +++ b/app/javascript/widget/composables/useConfig.js @@ -11,13 +11,14 @@ export function useConfig() { */ const channelConfig = computed(() => window.chatwootWebChannel); - /** - * Computed property to check if the inbox avatar is enabled for the bot. - * @returns {Boolean} True if the inbox avatar is enabled for the bot, false otherwise. - */ - const useInboxAvatarForBot = computed(() => - channelConfig.value.enabledFeatures.includes('use_inbox_avatar_for_bot') - ); + const createFeatureChecker = feature => + computed(() => channelConfig.value.enabledFeatures.includes(feature)); + + // Use the helper function for feature checks + const useInboxAvatarForBot = createFeatureChecker('use_inbox_avatar_for_bot'); + const hasEmojiPickerEnabled = createFeatureChecker('emoji_picker'); + const hasAttachmentsEnabled = createFeatureChecker('attachments'); + const hasEndConversationEnabled = createFeatureChecker('end_conversation'); /** * Computed property to check if the agent bot is connected. @@ -33,30 +34,6 @@ export function useConfig() { */ const inboxAvatarUrl = computed(() => channelConfig.value.avatarUrl); - /** - * Computed property to check if the emoji picker is enabled. - * @returns {Boolean} True if the emoji picker is enabled, false otherwise. - */ - const hasEmojiPickerEnabled = computed(() => - channelConfig.value.enabledFeatures.includes('emoji_picker') - ); - - /** - * Computed property to check if attachments are enabled. - * @returns {Boolean} True if attachments are enabled, false otherwise. - */ - const hasAttachmentsEnabled = computed(() => - channelConfig.value.enabledFeatures.includes('attachments') - ); - - /** - * Computed property to check if end conversation is enabled. - * @returns {Boolean} True if end conversation is enabled, false otherwise. - */ - const hasEndConversationEnabled = computed(() => - channelConfig.value.enabledFeatures.includes('end_conversation') - ); - /** * Computed property to check if the pre-chat form is enabled. * @returns {Boolean} True if the pre-chat form is enabled, false otherwise.