Composable replacement with mixin in Widget App.vue

This commit is contained in:
Fayaz Ahmed
2024-08-07 15:27:55 +05:30
parent 8c374539a5
commit 2386cb17a5
2 changed files with 18 additions and 3 deletions
@@ -5,9 +5,10 @@ import { isTimeAfter } from 'shared/helpers/DateHelper';
/**
* Composable for handling availability-related computations.
* @param {Object} i18n - Vue i18n instance for translations.
* @param {Object} availableAgents - Available agents object.
* @returns {Object} An object containing computed properties and methods for availability management.
*/
export function useAvailability(i18n) {
export function useAvailability(availableAgents, i18n) {
const channelConfig = computed(() => window.chatwootWebChannel);
const replyTime = computed(() => window.chatwootWebChannel.replyTime);
@@ -24,6 +25,15 @@ export function useAvailability(i18n) {
}
});
const isOnline = computed(() => {
const { workingHoursEnabled } = channelConfig.value;
const anyAgentOnline = availableAgents.value.length > 0;
if (workingHoursEnabled) {
return isInBetweenTheWorkingHours.value;
}
return anyAgentOnline;
});
const replyWaitMessage = computed(() => {
const { workingHoursEnabled } = channelConfig.value;
if (workingHoursEnabled) {
@@ -111,6 +121,7 @@ export function useAvailability(i18n) {
currentDayAvailability,
isInBetweenTheWorkingHours,
isInBusinessHours,
isOnline,
getDateWithOffset,
};
}