diff --git a/apps/meteor/client/views/admin/settings/MemoizedSetting.tsx b/apps/meteor/client/views/admin/settings/MemoizedSetting.tsx index a7433afc66c25..b3a29b8a30305 100644 --- a/apps/meteor/client/views/admin/settings/MemoizedSetting.tsx +++ b/apps/meteor/client/views/admin/settings/MemoizedSetting.tsx @@ -101,8 +101,8 @@ const MemoizedSetting = ({ {callout} )} + {showUpgradeButton} - {showUpgradeButton} ); }; diff --git a/apps/meteor/client/views/admin/settings/Setting.tsx b/apps/meteor/client/views/admin/settings/Setting.tsx index eb0413d53d84f..d9076e5fb4f62 100644 --- a/apps/meteor/client/views/admin/settings/Setting.tsx +++ b/apps/meteor/client/views/admin/settings/Setting.tsx @@ -2,7 +2,6 @@ import type { ISettingColor, SettingEditor, SettingValue } from '@rocket.chat/co import { isSettingColor, isSetting } from '@rocket.chat/core-typings'; import { Button } from '@rocket.chat/fuselage'; import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; -import { ExternalLink } from '@rocket.chat/ui-client'; import { useSettingStructure, useTranslation } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import React, { useEffect, useMemo, useState, useCallback } from 'react'; @@ -113,9 +112,9 @@ function Setting({ className = undefined, settingId, sectionChanged }: SettingPr const showUpgradeButton = useMemo( () => shouldDisableEnterprise ? ( - - - + ) : undefined, [shouldDisableEnterprise, t], ); diff --git a/apps/meteor/client/views/omnichannel/additionalForms.tsx b/apps/meteor/client/views/omnichannel/additionalForms.tsx index 16f6c9bcb440f..9978aba5586dc 100644 --- a/apps/meteor/client/views/omnichannel/additionalForms.tsx +++ b/apps/meteor/client/views/omnichannel/additionalForms.tsx @@ -1,4 +1,4 @@ -import BusinessHoursMultipleContainer from '../../../ee/client/omnichannel/additionalForms/BusinessHoursMultipleContainer'; +import BusinessHoursMultiple from '../../../ee/client/omnichannel/additionalForms/BusinessHoursMultiple'; import ContactManager from '../../../ee/client/omnichannel/additionalForms/ContactManager'; import CurrentChatTags from '../../../ee/client/omnichannel/additionalForms/CurrentChatTags'; import CustomFieldsAdditionalForm from '../../../ee/client/omnichannel/additionalForms/CustomFieldsAdditionalForm'; @@ -18,7 +18,7 @@ export { MaxChatsPerAgentDisplay, EeNumberInput, EeTextAreaInput, - BusinessHoursMultipleContainer, + BusinessHoursMultiple, EeTextInput, ContactManager, CurrentChatTags, diff --git a/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.js b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.js deleted file mode 100644 index ba01289ffe455..0000000000000 --- a/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.js +++ /dev/null @@ -1,31 +0,0 @@ -import { Field, MultiSelect } from '@rocket.chat/fuselage'; -import { useTranslation } from '@rocket.chat/ui-contexts'; -import React, { useMemo } from 'react'; - -import TimeRangeFieldsAssembler from './TimeRangeFieldsAssembler'; - -export const DAYS_OF_WEEK = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; - -const BusinessHoursForm = ({ values, handlers, className = undefined }) => { - const t = useTranslation(); - - const daysOptions = useMemo(() => DAYS_OF_WEEK.map((day) => [day, t(day)]), [t]); - - const { daysOpen, daysTime } = values; - - const { handleDaysOpen, handleDaysTime } = handlers; - - return ( - <> - - {t('Open_days_of_the_week')} - - - - - - - ); -}; - -export default BusinessHoursForm; diff --git a/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.stories.tsx b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.stories.tsx index d2861a33fa564..3bfbcb7aa4fed 100644 --- a/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.stories.tsx +++ b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.stories.tsx @@ -1,5 +1,4 @@ import { Box } from '@rocket.chat/fuselage'; -import { action } from '@storybook/addon-actions'; import type { ComponentMeta, ComponentStory } from '@storybook/react'; import React from 'react'; @@ -19,17 +18,3 @@ export default { export const Default: ComponentStory = (args) => ; Default.storyName = 'BusinessHoursForm'; -Default.args = { - values: { - daysOpen: ['Monday', 'Tuesday', 'Saturday'], - daysTime: { - Monday: { start: '00:00', finish: '08:00' }, - Tuesday: { start: '00:00', finish: '08:00' }, - Saturday: { start: '00:00', finish: '08:00' }, - }, - }, - handlers: { - handleDaysOpen: action('handleDaysOpen'), - handleDaysTime: action('handleDaysTime'), - }, -}; diff --git a/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.tsx b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.tsx new file mode 100644 index 0000000000000..71a3a5b27ed42 --- /dev/null +++ b/apps/meteor/client/views/omnichannel/businessHours/BusinessHoursForm.tsx @@ -0,0 +1,123 @@ +import type { SelectOption } from '@rocket.chat/fuselage'; +import { InputBox, Field, MultiSelect, FieldGroup, Box, Select, FieldLabel, FieldRow } from '@rocket.chat/fuselage'; +import { useUniqueId } from '@rocket.chat/fuselage-hooks'; +import type { TranslationKey } from '@rocket.chat/ui-contexts'; +import { useTranslation } from '@rocket.chat/ui-contexts'; +import React, { useMemo } from 'react'; +import { useFormContext, Controller, useFieldArray } from 'react-hook-form'; + +import { useTimezoneNameList } from '../../../hooks/useTimezoneNameList'; +import { BusinessHoursMultiple } from '../additionalForms'; +import { defaultWorkHours, DAYS_OF_WEEK } from './mapBusinessHoursForm'; + +type mappedDayTime = { + day: string; + start: { + time: string; + }; + finish: { + time: string; + }; + open: boolean; +}; + +export type BusinessHoursFormData = { + name: string; + timezoneName: string; + daysOpen: string[]; + daysTime: mappedDayTime[]; + departmentsToApplyBusinessHour: string; + active: boolean; + departments: { + value: string; + label: string; + }[]; +}; + +// TODO: replace `Select` in favor `SelectFiltered` +// TODO: add time validation for start and finish not be equal on UI +// TODO: add time validation for start not be higher than finish on UI +const BusinessHoursForm = ({ type }: { type?: 'default' | 'custom' }) => { + const t = useTranslation(); + const timeZones = useTimezoneNameList(); + const timeZonesOptions: SelectOption[] = useMemo(() => timeZones.map((name) => [name, t(name as TranslationKey)]), [t, timeZones]); + const daysOptions: SelectOption[] = useMemo(() => DAYS_OF_WEEK.map((day) => [day, t(day as TranslationKey)]), [t]); + + const { watch, control } = useFormContext(); + const { daysTime } = watch(); + const { fields: daysTimeFields, replace } = useFieldArray({ control, name: 'daysTime' }); + + const timezoneField = useUniqueId(); + const daysOpenField = useUniqueId(); + const daysTimeField = useUniqueId(); + + const handleChangeDaysTime = (values: string[]) => { + const newValues = values + .map((item) => daysTime.find(({ day }) => day === item) || defaultWorkHours(true).find(({ day }) => day === item)) + .filter((item): item is mappedDayTime => Boolean(item)); + replace(newValues); + }; + + return ( + + {type === 'custom' && } + + {t('Timezone')} + +