### Problem Currently, the attachment button visibility in the widget uses both the SDK's `enableFileUpload` flag AND the inbox's attachment settings with an AND condition. This creates an issue for users who want to control attachments solely through inbox settings, since the SDK flag defaults to `true` even when not explicitly provided. **Before:** - SDK not set → `enableFileUpload: true` (default) + inbox setting = attachment shown only if both true - SDK set to false → `enableFileUpload: false` + inbox setting = attachment always hidden - SDK set to true → `enableFileUpload: true` + inbox setting = attachment shown only if both true This meant users couldn't rely solely on inbox settings when the SDK flag wasn't explicitly provided. ### Solution Changed the logic to prioritize explicit SDK configuration when provided, and fall back to inbox settings when not provided: **After:** - SDK not set → `enableFileUpload: undefined` → use inbox setting only - SDK set to false → `enableFileUpload: false` → hide attachment (SDK controls) - SDK set to true → `enableFileUpload: true` → show attachment (SDK controls) --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import { computed } from 'vue';
|
|
import { useStore } from 'vuex';
|
|
|
|
export function useAttachments() {
|
|
const store = useStore();
|
|
|
|
const shouldShowFilePicker = computed(
|
|
() => store.getters['appConfig/getShouldShowFilePicker']
|
|
);
|
|
|
|
const shouldShowEmojiPicker = computed(
|
|
() => store.getters['appConfig/getShouldShowEmojiPicker']
|
|
);
|
|
|
|
const hasAttachmentsEnabled = computed(() => {
|
|
const channelConfig = window.chatwootWebChannel;
|
|
return channelConfig?.enabledFeatures?.includes('attachments') || false;
|
|
});
|
|
|
|
const hasEmojiPickerEnabled = computed(() => {
|
|
const channelConfig = window.chatwootWebChannel;
|
|
return channelConfig?.enabledFeatures?.includes('emoji_picker') || false;
|
|
});
|
|
|
|
const canHandleAttachments = computed(() => {
|
|
// If enableFileUpload was explicitly set via SDK, prioritize that
|
|
if (shouldShowFilePicker.value !== undefined) {
|
|
return shouldShowFilePicker.value;
|
|
}
|
|
|
|
// Otherwise, fall back to inbox settings only
|
|
return hasAttachmentsEnabled.value;
|
|
});
|
|
|
|
return {
|
|
shouldShowFilePicker,
|
|
shouldShowEmojiPicker,
|
|
hasAttachmentsEnabled,
|
|
hasEmojiPickerEnabled,
|
|
canHandleAttachments,
|
|
};
|
|
}
|