2022-04-18 12:45:20 +00:00
|
|
|
import { utcToZonedTime } from 'date-fns-tz';
|
|
|
|
import { isTimeAfter } from 'shared/helpers/DateHelper';
|
2021-03-13 08:36:25 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
computed: {
|
|
|
|
channelConfig() {
|
|
|
|
return window.chatwootWebChannel;
|
|
|
|
},
|
|
|
|
replyTime() {
|
|
|
|
return window.chatwootWebChannel.replyTime;
|
|
|
|
},
|
|
|
|
replyTimeStatus() {
|
|
|
|
switch (this.replyTime) {
|
|
|
|
case 'in_a_few_minutes':
|
|
|
|
return this.$t('REPLY_TIME.IN_A_FEW_MINUTES');
|
|
|
|
case 'in_a_few_hours':
|
|
|
|
return this.$t('REPLY_TIME.IN_A_FEW_HOURS');
|
|
|
|
case 'in_a_day':
|
|
|
|
return this.$t('REPLY_TIME.IN_A_DAY');
|
|
|
|
default:
|
|
|
|
return this.$t('REPLY_TIME.IN_A_FEW_HOURS');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
outOfOfficeMessage() {
|
|
|
|
return this.channelConfig.outOfOfficeMessage;
|
|
|
|
},
|
|
|
|
isInBetweenTheWorkingHours() {
|
|
|
|
const {
|
|
|
|
openHour,
|
|
|
|
openMinute,
|
|
|
|
closeHour,
|
|
|
|
closeMinute,
|
|
|
|
closedAllDay,
|
2022-02-22 09:28:49 +00:00
|
|
|
openAllDay,
|
2021-03-13 08:36:25 +00:00
|
|
|
} = this.currentDayAvailability;
|
2022-02-22 09:28:49 +00:00
|
|
|
|
2022-04-21 08:44:56 +00:00
|
|
|
if (openAllDay) {
|
2022-04-18 12:45:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-03-13 08:36:25 +00:00
|
|
|
|
2022-04-21 08:44:56 +00:00
|
|
|
if (closedAllDay) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-18 12:45:20 +00:00
|
|
|
const { utcOffset } = this.channelConfig;
|
|
|
|
const today = this.getDateWithOffset(utcOffset);
|
|
|
|
const currentHours = today.getHours();
|
|
|
|
const currentMinutes = today.getMinutes();
|
|
|
|
const isAfterStartTime = isTimeAfter(
|
|
|
|
currentHours,
|
|
|
|
currentMinutes,
|
|
|
|
openHour,
|
|
|
|
openMinute
|
|
|
|
);
|
|
|
|
const isBeforeEndTime = isTimeAfter(
|
|
|
|
closeHour,
|
|
|
|
closeMinute,
|
|
|
|
currentHours,
|
|
|
|
currentMinutes
|
|
|
|
);
|
|
|
|
return isAfterStartTime && isBeforeEndTime;
|
2021-03-13 08:36:25 +00:00
|
|
|
},
|
|
|
|
currentDayAvailability() {
|
2022-04-18 12:45:20 +00:00
|
|
|
const { utcOffset } = this.channelConfig;
|
|
|
|
const dayOfTheWeek = this.getDateWithOffset(utcOffset).getDay();
|
2021-03-13 08:36:25 +00:00
|
|
|
const [workingHourConfig = {}] = this.channelConfig.workingHours.filter(
|
|
|
|
workingHour => workingHour.day_of_week === dayOfTheWeek
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
closedAllDay: workingHourConfig.closed_all_day,
|
|
|
|
openHour: workingHourConfig.open_hour,
|
|
|
|
openMinute: workingHourConfig.open_minutes,
|
|
|
|
closeHour: workingHourConfig.close_hour,
|
|
|
|
closeMinute: workingHourConfig.close_minutes,
|
2022-02-22 09:28:49 +00:00
|
|
|
openAllDay: workingHourConfig.open_all_day,
|
2021-03-13 08:36:25 +00:00
|
|
|
};
|
|
|
|
},
|
2021-10-12 12:28:33 +00:00
|
|
|
isInBusinessHours() {
|
2022-04-18 12:45:20 +00:00
|
|
|
const { workingHoursEnabled } = this.channelConfig;
|
2021-10-12 12:28:33 +00:00
|
|
|
return workingHoursEnabled ? this.isInBetweenTheWorkingHours : true;
|
|
|
|
},
|
2021-03-13 08:36:25 +00:00
|
|
|
},
|
2022-04-18 12:45:20 +00:00
|
|
|
|
|
|
|
methods: {
|
|
|
|
getDateWithOffset(utcOffset) {
|
|
|
|
return utcToZonedTime(new Date().toISOString(), utcOffset);
|
|
|
|
},
|
|
|
|
},
|
2021-03-13 08:36:25 +00:00
|
|
|
};
|