diff --git a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json index 16217e5ae..4cb645577 100644 --- a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json +++ b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json @@ -5,8 +5,7 @@ "LIST": { "404": "There are no inboxes attached to this account." }, - "CREATE_FLOW": [ - { + "CREATE_FLOW": [{ "title": "Choose Channel", "route": "settings_inbox_new", "body": "Choose the provider you want to integrate with Chatwoot." @@ -226,7 +225,8 @@ "SETTINGS": "Settings", "COLLABORATORS": "Collaborators", "CONFIGURATION": "Configuration", - "PRE_CHAT_FORM": "Pre Chat Form" + "PRE_CHAT_FORM": "Pre Chat Form", + "BUSINESS_HOURS": "Business Hours" }, "SETTINGS": "Settings", "FEATURES": { @@ -269,6 +269,18 @@ "REQUIRE_EMAIL": { "LABEL": "Visitors should provide their name and email address before starting the chat" } + }, + "BUSINESS_HOURS": { + "TITLE": "Set your availability", + "SUBTITLE": "Set your availability on your livechat widget", + "WEEKLY_TITLE": "Set your weekly hours", + "DAY": { + "ENABLE": "Enable availability for this day", + "UNAVAILABLE": "Unavailable", + "HOURS": "hours", + "VALIDATION_ERROR": "Starting time should be before closing time.", + "CHOOSE": "Choose" + } } } } diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/BusinessDay.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/BusinessDay.vue new file mode 100644 index 000000000..6e2cbb151 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/BusinessDay.vue @@ -0,0 +1,223 @@ + + + + + + + {{ dayName }} + + + + + + + + + + + {{ + $t('INBOX_MGMT.BUSINESS_HOURS.DAY.VALIDATION_ERROR') + }} + + + + + {{ $t('INBOX_MGMT.BUSINESS_HOURS.DAY.UNAVAILABLE') }} + + + + + {{ totalHours }} {{ $t('INBOX_MGMT.BUSINESS_HOURS.DAY.HOURS') }} + + + + + + + diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/helpers/businessHour.js b/app/javascript/dashboard/routes/dashboard/settings/inbox/helpers/businessHour.js new file mode 100644 index 000000000..dba5ad7e0 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/helpers/businessHour.js @@ -0,0 +1,20 @@ +export const generateTimeSlots = (step = 15) => { + /* + Generates a list of time strings from 12:00 AM to next 24 hours. Each new string + will be generated by adding `step` minutes to the previous one. + The list is generated by starting with a random day and adding step minutes till end of the same day. + */ + const date = new Date(1970, 1, 1); + const slots = []; + while (date.getDate() === 1) { + slots.push( + date.toLocaleTimeString('en-US', { + hour: '2-digit', + minute: '2-digit', + hour12: true, + }) + ); + date.setMinutes(date.getMinutes() + step); + } + return slots; +}; diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/helpers/specs/businessHour.spec.js b/app/javascript/dashboard/routes/dashboard/settings/inbox/helpers/specs/businessHour.spec.js new file mode 100644 index 000000000..b5f0cbef7 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/helpers/specs/businessHour.spec.js @@ -0,0 +1,17 @@ +import { generateTimeSlots } from '../businessHour'; + +describe('#generateTimeSlots', () => { + it('returns correct number of time slots', () => { + expect(generateTimeSlots(15).length).toStrictEqual((60 / 15) * 24); + }); + it('returns correct time slots', () => { + expect(generateTimeSlots(240)).toStrictEqual([ + '12:00 AM', + '04:00 AM', + '08:00 AM', + '12:00 PM', + '04:00 PM', + '08:00 PM', + ]); + }); +});