Files
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

128 lines
4.2 KiB
TypeScript

import type { SelectOption } from '@rocket.chat/fuselage';
import { InputBox, Field, MultiSelect, FieldGroup, Box, Select, FieldLabel, FieldRow, Callout } from '@rocket.chat/fuselage';
import type { TranslationKey } from '@rocket.chat/ui-contexts';
import { useId, useMemo } from 'react';
import { useFormContext, Controller, useFieldArray } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
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
export type BusinessHoursFormProps = { type?: 'default' | 'custom' };
const BusinessHoursForm = ({ type }: BusinessHoursFormProps) => {
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<BusinessHoursFormData>();
const { daysTime } = watch();
const { fields: daysTimeFields, replace } = useFieldArray({ control, name: 'daysTime' });
const timezoneField = useId();
const daysOpenField = useId();
const daysTimeField = useId();
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 (
<FieldGroup>
{type === 'custom' && <BusinessHoursMultiple />}
<Field>
<FieldLabel htmlFor={timezoneField}>{t('Timezone')}</FieldLabel>
<FieldRow>
<Controller
name='timezoneName'
control={control}
render={({ field }) => <Select id={timezoneField} {...field} options={timeZonesOptions} />}
/>
</FieldRow>
<Callout title={t('Daylight_savings_time')} type='info' marginBlockStart='x8'>
{t('Business_hours_will_update_automatically')}
</Callout>
</Field>
<Field>
<FieldLabel htmlFor={daysOpenField}>{t('Open_days_of_the_week')}</FieldLabel>
<FieldRow>
<Controller
name='daysOpen'
control={control}
render={({ field: { onChange, value, name, onBlur } }) => (
<MultiSelect
id={daysOpenField}
onBlur={onBlur}
name={name}
onChange={(values) => {
handleChangeDaysTime(values);
onChange(values);
}}
options={daysOptions}
value={value}
placeholder={t('Select_an_option')}
width='full'
/>
)}
/>
</FieldRow>
</Field>
{daysTimeFields.map((dayTime, index) => (
<Field key={dayTime.id}>
<FieldLabel>{t(dayTime.day as TranslationKey)}</FieldLabel>
<FieldRow>
<Box display='flex' flexDirection='column' flexGrow={1} marginInlineEnd={2}>
<FieldLabel htmlFor={`${daysTimeField + index}-start`}>{t('Open')}</FieldLabel>
<Controller
name={`daysTime.${index}.start.time`}
render={({ field }) => <InputBox id={`${daysTimeField + index}-start`} type='time' {...field} />}
/>
</Box>
<Box display='flex' flexDirection='column' flexGrow={1} marginInlineStart={2}>
<FieldLabel htmlFor={`${daysTimeField + index}-finish`}>{t('Close')}</FieldLabel>
<Controller
name={`daysTime.${index}.finish.time`}
render={({ field }) => <InputBox id={`${daysTimeField + index}-finish`} type='time' {...field} />}
/>
</Box>
</FieldRow>
</Field>
))}
</FieldGroup>
);
};
export default BusinessHoursForm;