Skip to content

Commit

Permalink
Fix/opening days message (#25)
Browse files Browse the repository at this point in the history
* dynamically built opening days message

* bump version 0.3.41
  • Loading branch information
whirmill committed Oct 19, 2019
1 parent 0747d5a commit 6f6a3d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
42 changes: 37 additions & 5 deletions src/components/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
}
Expand Down Expand Up @@ -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
}.`
}, '')
}

Expand Down

0 comments on commit 6f6a3d8

Please sign in to comment.