From dad53d1756a4e3c5d7c7e73dcbce8bb2e1b25c61 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Wed, 4 Oct 2023 11:59:04 +0530 Subject: [PATCH 1/6] fix: Business hour timezone gets changed upon server restart --- .../server/business-hour/Helper.ts | 29 +------------------ .../app/livechat-enterprise/server/startup.ts | 3 -- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts b/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts index a441e122ef99..a91bb87f28bb 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts @@ -1,8 +1,6 @@ import type { ILivechatBusinessHour } from '@rocket.chat/core-typings'; import { LivechatBusinessHourTypes } from '@rocket.chat/core-typings'; -import { License } from '@rocket.chat/license'; -import { LivechatBusinessHours, LivechatDepartment, LivechatDepartmentAgents, Users } from '@rocket.chat/models'; -import moment from 'moment-timezone'; +import { LivechatDepartment, LivechatDepartmentAgents, Users } from '@rocket.chat/models'; import { businessHourLogger } from '../../../../../app/livechat/server/lib/logger'; @@ -103,28 +101,3 @@ export const removeBusinessHourByAgentIds = async (agentIds: string[], businessH await Users.removeBusinessHourByAgentIds(agentIds, businessHourId); await Users.updateLivechatStatusBasedOnBusinessHours(); }; - -export const resetDefaultBusinessHourIfNeeded = async (): Promise => { - if (License.hasValidLicense()) { - return; - } - - const defaultBusinessHour = await LivechatBusinessHours.findOneDefaultBusinessHour>({ - projection: { _id: 1 }, - }); - if (!defaultBusinessHour) { - return; - } - - await LivechatBusinessHours.updateOne( - { _id: defaultBusinessHour._id }, - { - $set: { - timezone: { - name: moment.tz.guess(), - utc: String(moment().utcOffset() / 60), - }, - }, - }, - ); -}; diff --git a/apps/meteor/ee/app/livechat-enterprise/server/startup.ts b/apps/meteor/ee/app/livechat-enterprise/server/startup.ts index 29cf5c308d71..1b277d6fba52 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/startup.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/startup.ts @@ -3,7 +3,6 @@ import { Meteor } from 'meteor/meteor'; import { businessHourManager } from '../../../../app/livechat/server/business-hour'; import { SingleBusinessHourBehavior } from '../../../../app/livechat/server/business-hour/Single'; import { settings } from '../../../../app/settings/server'; -import { resetDefaultBusinessHourIfNeeded } from './business-hour/Helper'; import { MultipleBusinessHoursBehavior } from './business-hour/Multiple'; import { updatePredictedVisitorAbandonment, updateQueueInactivityTimeout } from './lib/Helper'; import { VisitorInactivityMonitor } from './lib/VisitorInactivityMonitor'; @@ -43,6 +42,4 @@ Meteor.startup(async () => { logger.debug(`Business hour manager started`); } }); - - await resetDefaultBusinessHourIfNeeded(); }); From 9149e133c235b4dc0dacd4fa608f12b1eb16f404 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Wed, 4 Oct 2023 18:07:16 +0530 Subject: [PATCH 2/6] Allow users CE to set timezone --- .../views/app/business-hours/BusinessHours.ts | 4 ---- .../app/business-hours/IBusinessHourBehavior.ts | 1 - .../client/views/app/business-hours/Single.ts | 4 ---- .../businessHours/BusinessHoursFormContainer.js | 15 ++++++++------- .../businessHours}/BusinessHoursTimeZone.js | 4 ++-- .../BusinessHoursTimeZone.stories.tsx | 2 +- .../client/SingleBusinessHour.ts | 3 --- .../ee/app/livechat-enterprise/client/startup.ts | 4 ++-- .../client/views/business-hours/Multiple.ts | 4 ---- .../omnichannel/additionalForms/register.ts | 3 --- 10 files changed, 13 insertions(+), 31 deletions(-) rename apps/meteor/{ee/client/omnichannel/additionalForms => client/views/omnichannel/businessHours}/BusinessHoursTimeZone.js (86%) rename apps/meteor/{ee/client/omnichannel/additionalForms => client/views/omnichannel/businessHours}/BusinessHoursTimeZone.stories.tsx (91%) diff --git a/apps/meteor/app/livechat/client/views/app/business-hours/BusinessHours.ts b/apps/meteor/app/livechat/client/views/app/business-hours/BusinessHours.ts index 0935ac7554e4..3c723cc46257 100644 --- a/apps/meteor/app/livechat/client/views/app/business-hours/BusinessHours.ts +++ b/apps/meteor/app/livechat/client/views/app/business-hours/BusinessHours.ts @@ -29,10 +29,6 @@ class BusinessHoursManager { showBackButton(): boolean { return this.behavior.showBackButton(); } - - showTimezoneTemplate(): boolean { - return this.behavior.showTimezoneTemplate(); - } } export const businessHourManager = new BusinessHoursManager(new SingleBusinessHourBehavior()); diff --git a/apps/meteor/app/livechat/client/views/app/business-hours/IBusinessHourBehavior.ts b/apps/meteor/app/livechat/client/views/app/business-hours/IBusinessHourBehavior.ts index 10a51fe25e25..1ba6e4a56907 100644 --- a/apps/meteor/app/livechat/client/views/app/business-hours/IBusinessHourBehavior.ts +++ b/apps/meteor/app/livechat/client/views/app/business-hours/IBusinessHourBehavior.ts @@ -4,5 +4,4 @@ export interface IBusinessHourBehavior { getView(): string; showCustomTemplate(businessHourData: ILivechatBusinessHour): boolean; showBackButton(): boolean; - showTimezoneTemplate(): boolean; } diff --git a/apps/meteor/app/livechat/client/views/app/business-hours/Single.ts b/apps/meteor/app/livechat/client/views/app/business-hours/Single.ts index 1ce09a63d79a..9b343264ca54 100644 --- a/apps/meteor/app/livechat/client/views/app/business-hours/Single.ts +++ b/apps/meteor/app/livechat/client/views/app/business-hours/Single.ts @@ -12,8 +12,4 @@ export class SingleBusinessHourBehavior implements IBusinessHourBehavior { showBackButton(): boolean { return false; } - - showTimezoneTemplate(): boolean { - return false; - } } diff --git a/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursFormContainer.js b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursFormContainer.js index c274ebee272d..9acf9d2fd167 100644 --- a/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursFormContainer.js +++ b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursFormContainer.js @@ -7,6 +7,7 @@ import { useForm } from '../../../hooks/useForm'; import { useReactiveValue } from '../../../hooks/useReactiveValue'; import { useFormsSubscription } from '../additionalForms'; import BusinessHourForm from './BusinessHoursForm'; +import BusinessHoursTimeZone from './BusinessHoursTimeZone'; const useChangeHandler = (name, ref) => useMutableCallback((val) => { @@ -29,12 +30,10 @@ const BusinessHoursFormContainer = ({ data, saveRef, onChange = () => {} }) => { const [hasChangesMultiple, setHasChangesMultiple] = useState(false); const [hasChangesTimeZone, setHasChangesTimeZone] = useState(false); - const { useBusinessHoursTimeZone = cleanFunc, useBusinessHoursMultiple = cleanFunc } = forms; + const { useBusinessHoursMultiple = cleanFunc } = forms; - const TimezoneForm = useBusinessHoursTimeZone(); const MultipleBHForm = useBusinessHoursMultiple(); - const showTimezone = useReactiveValue(useMutableCallback(() => businessHourManager.showTimezoneTemplate())); const showMultipleBHForm = useReactiveValue(useMutableCallback(() => businessHourManager.showCustomTemplate(data))); const onChangeTimezone = useChangeHandler('timezone', saveRef); @@ -45,7 +44,7 @@ const BusinessHoursFormContainer = ({ data, saveRef, onChange = () => {} }) => { saveRef.current.form = values; useEffect(() => { - onChange(hasUnsavedChanges || (showMultipleBHForm && hasChangesMultiple) || (showTimezone && hasChangesTimeZone)); + onChange(hasUnsavedChanges || (showMultipleBHForm && hasChangesMultiple) || hasChangesTimeZone); }); return ( @@ -54,9 +53,11 @@ const BusinessHoursFormContainer = ({ data, saveRef, onChange = () => {} }) => { {showMultipleBHForm && MultipleBHForm && ( )} - {showTimezone && TimezoneForm && ( - - )} + diff --git a/apps/meteor/ee/client/omnichannel/additionalForms/BusinessHoursTimeZone.js b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursTimeZone.js similarity index 86% rename from apps/meteor/ee/client/omnichannel/additionalForms/BusinessHoursTimeZone.js rename to apps/meteor/client/views/omnichannel/businessHours/BusinessHoursTimeZone.js index c305dc084e68..8826fc621455 100644 --- a/apps/meteor/ee/client/omnichannel/additionalForms/BusinessHoursTimeZone.js +++ b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursTimeZone.js @@ -2,8 +2,8 @@ import { SelectFiltered, Field } from '@rocket.chat/fuselage'; import { useTranslation } from '@rocket.chat/ui-contexts'; import React, { useMemo } from 'react'; -import { useForm } from '../../../../client/hooks/useForm'; -import { useTimezoneNameList } from '../../../../client/hooks/useTimezoneNameList'; +import { useForm } from '../../../hooks/useForm'; +import { useTimezoneNameList } from '../../../hooks/useTimezoneNameList'; const getInitialData = (data = {}) => ({ name: data ?? '', diff --git a/apps/meteor/ee/client/omnichannel/additionalForms/BusinessHoursTimeZone.stories.tsx b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursTimeZone.stories.tsx similarity index 91% rename from apps/meteor/ee/client/omnichannel/additionalForms/BusinessHoursTimeZone.stories.tsx rename to apps/meteor/client/views/omnichannel/businessHours/BusinessHoursTimeZone.stories.tsx index 35c133caf72a..af00db33322e 100644 --- a/apps/meteor/ee/client/omnichannel/additionalForms/BusinessHoursTimeZone.stories.tsx +++ b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursTimeZone.stories.tsx @@ -5,7 +5,7 @@ import React from 'react'; import BusinessHoursTimeZone from './BusinessHoursTimeZone'; export default { - title: 'Enterprise/Omnichannel/BusinessHoursTimeZone', + title: 'Omnichannel/BusinessHoursTimeZone', component: BusinessHoursTimeZone, decorators: [ (fn) => ( diff --git a/apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts b/apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts index e1f8b852fbc6..d0bb0360ff49 100644 --- a/apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts +++ b/apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts @@ -1,7 +1,4 @@ import { SingleBusinessHourBehavior } from '../../../../app/livechat/client/views/app/business-hours/Single'; export class EESingleBusinessHourBehaviour extends SingleBusinessHourBehavior { - showTimezoneTemplate(): boolean { - return true; - } } diff --git a/apps/meteor/ee/app/livechat-enterprise/client/startup.ts b/apps/meteor/ee/app/livechat-enterprise/client/startup.ts index 11027a62439b..3861aed0a163 100644 --- a/apps/meteor/ee/app/livechat-enterprise/client/startup.ts +++ b/apps/meteor/ee/app/livechat-enterprise/client/startup.ts @@ -2,14 +2,14 @@ import { Meteor } from 'meteor/meteor'; import { businessHourManager } from '../../../../app/livechat/client/views/app/business-hours/BusinessHours'; import type { IBusinessHourBehavior } from '../../../../app/livechat/client/views/app/business-hours/IBusinessHourBehavior'; +import { SingleBusinessHourBehavior } from '../../../../app/livechat/client/views/app/business-hours/Single'; import { settings } from '../../../../app/settings/client'; import { hasLicense } from '../../license/client'; -import { EESingleBusinessHourBehaviour } from './SingleBusinessHour'; import { MultipleBusinessHoursBehavior } from './views/business-hours/Multiple'; const businessHours: Record = { multiple: new MultipleBusinessHoursBehavior(), - single: new EESingleBusinessHourBehaviour(), + single: new SingleBusinessHourBehavior(), }; Meteor.startup(() => { diff --git a/apps/meteor/ee/app/livechat-enterprise/client/views/business-hours/Multiple.ts b/apps/meteor/ee/app/livechat-enterprise/client/views/business-hours/Multiple.ts index cbe3fe9088fe..a57344da73dc 100644 --- a/apps/meteor/ee/app/livechat-enterprise/client/views/business-hours/Multiple.ts +++ b/apps/meteor/ee/app/livechat-enterprise/client/views/business-hours/Multiple.ts @@ -12,10 +12,6 @@ export class MultipleBusinessHoursBehavior implements IBusinessHourBehavior { return !businessHourData._id || businessHourData.type !== LivechatBusinessHourTypes.DEFAULT; } - showTimezoneTemplate(): boolean { - return true; - } - showBackButton(): boolean { return true; } diff --git a/apps/meteor/ee/client/omnichannel/additionalForms/register.ts b/apps/meteor/ee/client/omnichannel/additionalForms/register.ts index df11a435ab5c..d52a20e40734 100644 --- a/apps/meteor/ee/client/omnichannel/additionalForms/register.ts +++ b/apps/meteor/ee/client/omnichannel/additionalForms/register.ts @@ -6,7 +6,6 @@ import { registerForm } from '../../../../client/views/omnichannel/additionalFor import { hasLicense } from '../../../app/license/client'; import type CurrentChatTags from '../tags/CurrentChatTags'; import type BusinessHoursMultipleContainer from './BusinessHoursMultipleContainer'; -import type BusinessHoursTimeZone from './BusinessHoursTimeZone'; import type ContactManager from './ContactManager'; import type CustomFieldsAdditionalFormContainer from './CustomFieldsAdditionalFormContainer'; import type DepartmentBusinessHours from './DepartmentBusinessHours'; @@ -29,7 +28,6 @@ declare module '../../../../client/views/omnichannel/additionalForms' { useEeTextAreaInput?: () => LazyExoticComponent; useBusinessHoursMultiple?: () => LazyExoticComponent; useEeTextInput?: () => LazyExoticComponent; - useBusinessHoursTimeZone?: () => LazyExoticComponent; useContactManager?: () => LazyExoticComponent; useCurrentChatTags?: () => LazyExoticComponent; @@ -54,7 +52,6 @@ hasLicense('livechat-enterprise').then((enabled) => { useEeTextAreaInput: () => useMemo(() => lazy(() => import('./EeTextAreaInput')), []), useBusinessHoursMultiple: () => useMemo(() => lazy(() => import('./BusinessHoursMultipleContainer')), []), useEeTextInput: () => useMemo(() => lazy(() => import('./EeTextInput')), []), - useBusinessHoursTimeZone: () => useMemo(() => lazy(() => import('./BusinessHoursTimeZone')), []), useContactManager: () => useMemo(() => lazy(() => import('./ContactManager')), []), useCurrentChatTags: () => useMemo(() => lazy(() => import('../tags/CurrentChatTags')), []), useDepartmentBusinessHours: () => useMemo(() => lazy(() => import('./DepartmentBusinessHours')), []), From 9fa5c8b3890eebb4403ad2837a20441d24695977 Mon Sep 17 00:00:00 2001 From: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:11:29 +0530 Subject: [PATCH 3/6] Create tidy-cows-destroy.md --- .changeset/tidy-cows-destroy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tidy-cows-destroy.md diff --git a/.changeset/tidy-cows-destroy.md b/.changeset/tidy-cows-destroy.md new file mode 100644 index 000000000000..b749a28a62ab --- /dev/null +++ b/.changeset/tidy-cows-destroy.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +fix: Business hour timezone gets changed upon server restart and move timezone field to CE From b3e65ddabc282a628524249822d2fe29969e8e38 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Wed, 4 Oct 2023 19:22:04 +0530 Subject: [PATCH 4/6] fix lint issue --- .../ee/app/livechat-enterprise/client/SingleBusinessHour.ts | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts diff --git a/apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts b/apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts deleted file mode 100644 index d0bb0360ff49..000000000000 --- a/apps/meteor/ee/app/livechat-enterprise/client/SingleBusinessHour.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { SingleBusinessHourBehavior } from '../../../../app/livechat/client/views/app/business-hours/Single'; - -export class EESingleBusinessHourBehaviour extends SingleBusinessHourBehavior { -} From d3d43b17ae978a256d051e86d60d10adf81bff15 Mon Sep 17 00:00:00 2001 From: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:07:24 +0530 Subject: [PATCH 5/6] Update tidy-cows-destroy.md --- .changeset/tidy-cows-destroy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tidy-cows-destroy.md b/.changeset/tidy-cows-destroy.md index b749a28a62ab..0b222f8157a9 100644 --- a/.changeset/tidy-cows-destroy.md +++ b/.changeset/tidy-cows-destroy.md @@ -2,4 +2,4 @@ "@rocket.chat/meteor": patch --- -fix: Business hour timezone gets changed upon server restart and move timezone field to CE +feat: Community users will now be able to customize their Business hour timezone From 2a32203504d5f7d252ad51886f637b20a456ef97 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Tue, 17 Oct 2023 18:53:12 +0530 Subject: [PATCH 6/6] fix improper initialization of Business hour manager on UI --- apps/meteor/ee/app/livechat-enterprise/client/startup.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/meteor/ee/app/livechat-enterprise/client/startup.ts b/apps/meteor/ee/app/livechat-enterprise/client/startup.ts index 3861aed0a163..3c3ec1c02139 100644 --- a/apps/meteor/ee/app/livechat-enterprise/client/startup.ts +++ b/apps/meteor/ee/app/livechat-enterprise/client/startup.ts @@ -13,9 +13,10 @@ const businessHours: Record = { }; Meteor.startup(() => { - settings.onload('Livechat_business_hour_type', async (_, value) => { + Tracker.autorun(async () => { + const bhType = settings.get('Livechat_business_hour_type'); if (await hasLicense('livechat-enterprise')) { - businessHourManager.registerBusinessHourBehavior(businessHours[(value as string).toLowerCase()]); + businessHourManager.registerBusinessHourBehavior(businessHours[bhType.toLowerCase()]); } }); });