From 6f6a3d82d36c35d7bc38b41b80d5b9b3e655b90b Mon Sep 17 00:00:00 2001 From: Lorenzo De Santis Date: Sat, 19 Oct 2019 11:10:06 +0200 Subject: [PATCH] Fix/opening days message (#25) * dynamically built opening days message * bump version 0.3.41 --- package.json | 2 +- src/components/Widget.js | 42 +++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 25a3b4c..9e2e9ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hype-chat-widget", - "version": "0.3.40", + "version": "0.3.41", "license": "MIT", "description": "Zopim + QnA Chat Web Widget (React)", "main": "dist/index.js", diff --git a/src/components/Widget.js b/src/components/Widget.js index faba6c7..3ff0167 100644 --- a/src/components/Widget.js +++ b/src/components/Widget.js @@ -417,8 +417,7 @@ class App extends Component { ? 'Non riesco a rispondere alla tua domanda e al momento non ci sono operatori disponibili.' : 'Al momento non ci sono operatori disponibili.' }`, - subMsg: `Puoi chattare con un operatore dal Lunedì al Venerdì, esclusi i festivi, - ${this.getOperatorAvailabilityString()}.` + subMsg: this.getOperatorAvailabilityString() } }) } @@ -567,9 +566,42 @@ class App extends Component { getOperatorAvailabilityString() { return this.props.data.chatbot.chatOperatorSettings.reduce((res, next) => { - return `${res}${res.length > 0 ? ' o ' : ' '}dalle ${ - next.startTime - } alle ${next.endTime}` + const daysMap = { + '0': 'Domenica', + '1': 'Lunedì', + '2': 'Martedì', + '3': 'Mercoledì', + '4': 'Giovedì', + '5': 'Venerdì', + '6': 'Sabato' + } + const zChatOperatorSettings = zChat.getOperatingHours() + const schedules = + zChatOperatorSettings[`${zChatOperatorSettings.type}_schedule`] + + const createReadableDayFromFirstAvailableSchedule = (res, next) => { + if (!res && !!schedules[next] && schedules[next].length > 0) { + res = next + } + return res + } + const startDay = + daysMap[ + Object.keys(schedules).reduce( + createReadableDayFromFirstAvailableSchedule, + null + ) + ] + const endDay = + daysMap[ + Object.keys(schedules) + .reverse() + .reduce(createReadableDayFromFirstAvailableSchedule, null) + ] + return `Puoi chattare con un operatore dal ${startDay} al ${endDay}, esclusi i festivi, + ${res}${res.length > 0 ? ' o ' : ' '}dalle ${next.startTime} alle ${ + next.endTime + }.` }, '') }