-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[IMPROVE][Omnichannel] Refactor Office Hours feature #17824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
renatobecker
merged 39 commits into
develop
from
improvements/refactor-livechat-office-hours
Jun 21, 2020
Merged
Changes from 18 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
f5c6d6d
Change omnichannel office hours data structure
387e801
Rename omnichannel office hours templates
6d4b2e6
Renaming things from office hour to business hour
a1adbbd
Partially remove LivechatOfficeHour model
4803883
remove obsolete setting
ebd93a9
Remove settings from the template
5a911b3
Add support to cron jobs on omnichannel business hours
acf7b70
Merge branch 'develop' into improvements/refactor-livechat-office-hours
4f93201
Add dynamic template to omnichannel business hours
7d3e345
Merge branch 'develop' into improvements/refactor-livechat-office-hours
d94d750
Open and close business hours
d3e2670
Remove references to LivechatOfficeHours
bb4c82b
Merge branch 'develop' into improvements/refactor-livechat-office-hours
25c4d88
Open and close business hour automatically on startup and setting cha…
1becb7c
Merge branch 'develop' into improvements/refactor-livechat-office-hours
a2b2c9b
Improve open and close business hours process
c496ca2
Removing separated interfaces
388afa0
Merge branch 'develop' into improvements/refactor-livechat-office-hours
e0a0021
Merge branch 'develop' into improvements/refactor-livechat-office-hours
0b05ad8
Merge branch 'develop' into improvements/refactor-livechat-office-hours
9371c3d
Apply suggestions from review
83e32f5
Merge branch 'develop' into improvements/refactor-livechat-office-hours
7765960
Merge branch 'develop' into improvements/refactor-livechat-office-hours
36f3673
Merge branch 'develop' into improvements/refactor-livechat-office-hours
7e48e71
Changing pt-br term
c22bd6d
Merge branch 'develop' into improvements/refactor-livechat-office-hours
96bf764
General improvements on business hour layout
572ecea
Merge remote-tracking branch 'origin/improvements/refactor-livechat-o…
4e74a73
Merge branch 'develop' into improvements/refactor-livechat-office-hours
243cf63
Apply suggestions from review
5554c67
Merge branch 'develop' into improvements/refactor-livechat-office-hours
4e6bd27
Remove online verification
e788448
Merge branch 'develop' into improvements/refactor-livechat-office-hours
ef33a6a
Merge branch 'develop' into improvements/refactor-livechat-office-hours
b724b3f
Change data structure
ad3f2d7
Ignore if collection does not exist
704c2e1
Merge branch 'develop' into improvements/refactor-livechat-office-hours
25218ee
Merge remote-tracking branch 'origin/improvements/refactor-livechat-o…
b5f3cc8
Merge branch 'develop' into improvements/refactor-livechat-office-hours
renatobecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/livechat/client/views/app/business-hours/BusinessHours.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| export interface IBusinessHour { | ||
| getView(): string; | ||
| } | ||
|
|
||
| class BusinessHoursManager { | ||
| private businessHour: IBusinessHour; | ||
|
|
||
| constructor(businessHour: IBusinessHour) { | ||
| this.registerBusinessHour(businessHour); | ||
| } | ||
|
|
||
| registerBusinessHour(businessHour: IBusinessHour): void { | ||
| this.businessHour = businessHour; | ||
| } | ||
|
|
||
| getTemplate(): string { | ||
| return this.businessHour.getView(); | ||
| } | ||
| } | ||
|
|
||
| class Single implements IBusinessHour { | ||
| getView(): string { | ||
| return 'livechatBusinessHoursForm'; | ||
| } | ||
| } | ||
|
|
||
| export const businessHourManager = new BusinessHoursManager(new Single()); | ||
24 changes: 4 additions & 20 deletions
24
...client/views/app/livechatOfficeHours.html → ...ness-hours/livechatBusinessHoursForm.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
app/livechat/client/views/app/business-hours/livechatBusinessHoursForm.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { Meteor } from 'meteor/meteor'; | ||
| import { ReactiveVar } from 'meteor/reactive-var'; | ||
| import { Template } from 'meteor/templating'; | ||
| import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; | ||
| import toastr from 'toastr'; | ||
| import moment from 'moment'; | ||
|
|
||
| import { t, handleError, APIClient } from '../../../../../utils/client'; | ||
| import './livechatBusinessHoursForm.html'; | ||
|
|
||
| Template.livechatBusinessHoursForm.helpers({ | ||
| days() { | ||
| return Template.instance().businessHour.get().workHours; | ||
| }, | ||
| startName(day) { | ||
| return `${ day.day }_start`; | ||
| }, | ||
| finishName(day) { | ||
| return `${ day.day }_finish`; | ||
| }, | ||
| openName(day) { | ||
| return `${ day.day }_open`; | ||
| }, | ||
| start(day) { | ||
| return Template.instance().dayVars[day.day].start.get(); | ||
| }, | ||
| finish(day) { | ||
| return Template.instance().dayVars[day.day].finish.get(); | ||
| }, | ||
| name(day) { | ||
| return TAPi18n.__(day.day); | ||
| }, | ||
| open(day) { | ||
| return Template.instance().dayVars[day.day].open.get(); | ||
| }, | ||
| }); | ||
|
|
||
| const splitDayAndPeriod = (value) => value.split('_'); | ||
|
|
||
| Template.livechatBusinessHoursForm.events({ | ||
| 'change .preview-settings, keydown .preview-settings'(e, instance) { | ||
| const [day, period] = splitDayAndPeriod(e.currentTarget.name); | ||
|
|
||
| const newTime = moment(e.currentTarget.value, 'HH:mm'); | ||
|
|
||
| // check if start and stop do not cross | ||
| if (period === 'start') { | ||
| if (newTime.isSameOrBefore(moment(instance.dayVars[day].finish.get(), 'HH:mm'))) { | ||
| instance.dayVars[day].start.set(e.currentTarget.value); | ||
| } else { | ||
| e.currentTarget.value = instance.dayVars[day].start.get(); | ||
| } | ||
| } else if (period === 'finish') { | ||
| if (newTime.isSameOrAfter(moment(instance.dayVars[day].start.get(), 'HH:mm'))) { | ||
| instance.dayVars[day].finish.set(e.currentTarget.value); | ||
| } else { | ||
| e.currentTarget.value = instance.dayVars[day].finish.get(); | ||
| } | ||
| } | ||
| }, | ||
| 'change .dayOpenCheck input'(e, instance) { | ||
| const [day, period] = splitDayAndPeriod(e.currentTarget.name); | ||
| instance.dayVars[day][period].set(e.target.checked); | ||
| }, | ||
| 'change .preview-settings, keyup .preview-settings'(e, instance) { | ||
| let { value } = e.currentTarget; | ||
| if (e.currentTarget.type === 'radio') { | ||
| value = value === 'true'; | ||
| instance[e.currentTarget.name].set(value); | ||
| } | ||
| }, | ||
| 'submit .rocket-form'(e, instance) { | ||
| e.preventDefault(); | ||
|
|
||
| // convert all times to utc then update them in db | ||
| const days = []; | ||
| for (const d in instance.dayVars) { | ||
| if (instance.dayVars.hasOwnProperty(d)) { | ||
| const day = instance.dayVars[d]; | ||
| const start = moment(day.start.get(), 'HH:mm').format('HH:mm'); | ||
| const finish = moment(day.finish.get(), 'HH:mm').format('HH:mm'); | ||
| days.push({ | ||
| day: d, | ||
| start, | ||
| finish, | ||
| open: day.open.get(), | ||
| }); | ||
| } | ||
| } | ||
| Meteor.call('livechat:saveBusinessHour', { | ||
| ...instance.businessHour.get(), | ||
| workHours: days, | ||
| }, function(err /* ,result*/) { | ||
| if (err) { | ||
| return handleError(err); | ||
| } | ||
| toastr.success(t('Business_hours_updated')); | ||
| }); | ||
| }, | ||
| }); | ||
|
|
||
| Template.livechatBusinessHoursForm.onCreated(async function() { | ||
| this.dayVars = { | ||
| Monday: { | ||
|
MarcosSpessatto marked this conversation as resolved.
Outdated
|
||
| start: new ReactiveVar('08:00'), | ||
| finish: new ReactiveVar('20:00'), | ||
| open: new ReactiveVar(true), | ||
| }, | ||
| Tuesday: { | ||
| start: new ReactiveVar('00:00'), | ||
| finish: new ReactiveVar('00:00'), | ||
| open: new ReactiveVar(true), | ||
| }, | ||
| Wednesday: { | ||
| start: new ReactiveVar('00:00'), | ||
| finish: new ReactiveVar('00:00'), | ||
| open: new ReactiveVar(true), | ||
| }, | ||
| Thursday: { | ||
| start: new ReactiveVar('00:00'), | ||
| finish: new ReactiveVar('00:00'), | ||
| open: new ReactiveVar(true), | ||
| }, | ||
| Friday: { | ||
| start: new ReactiveVar('00:00'), | ||
| finish: new ReactiveVar('00:00'), | ||
| open: new ReactiveVar(true), | ||
| }, | ||
| Saturday: { | ||
| start: new ReactiveVar('00:00'), | ||
| finish: new ReactiveVar('00:00'), | ||
| open: new ReactiveVar(false), | ||
| }, | ||
| Sunday: { | ||
| start: new ReactiveVar('00:00'), | ||
| finish: new ReactiveVar('00:00'), | ||
| open: new ReactiveVar(false), | ||
| }, | ||
| }; | ||
| this.businessHour = new ReactiveVar({}); | ||
|
|
||
| const { businessHour } = await APIClient.v1.get('livechat/business-hour'); | ||
| this.businessHour.set(businessHour); | ||
| businessHour.workHours.forEach((d) => { | ||
| if (businessHour.timezone.name) { | ||
| this.dayVars[d.day].start.set(moment.utc(d.start, 'HH:mm').tz(businessHour.timezone.name).format('HH:mm')); | ||
| this.dayVars[d.day].finish.set(moment.utc(d.finish, 'HH:mm').tz(businessHour.timezone.name).format('HH:mm')); | ||
| } else { | ||
| this.dayVars[d.day].start.set(moment.utc(d.start, 'HH:mm').local().format('HH:mm')); | ||
| this.dayVars[d.day].finish.set(moment.utc(d.finish, 'HH:mm').local().format('HH:mm')); | ||
| } | ||
| this.dayVars[d.day].open.set(d.open); | ||
| }); | ||
| }); | ||
7 changes: 7 additions & 0 deletions
7
app/livechat/client/views/app/business-hours/livechatMainBusinessHours.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <template name="livechatMainBusinessHours"> | ||
| {{#requiresPermission 'view-livechat-business-hours'}} | ||
| <div class="livechat-businessHours-div"> | ||
| {{> Template.dynamic template=getTemplate}} | ||
| </div> | ||
| {{/requiresPermission}} | ||
| </template> |
10 changes: 10 additions & 0 deletions
10
app/livechat/client/views/app/business-hours/livechatMainBusinessHours.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Template } from 'meteor/templating'; | ||
|
|
||
| import './livechatMainBusinessHours.html'; | ||
| import { businessHourManager } from './BusinessHours'; | ||
|
|
||
| Template.livechatMainBusinessHours.helpers({ | ||
| getTemplate() { | ||
| return businessHourManager.getTemplate(); | ||
| }, | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.