Skip to content
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

Chore: Convert additionalForms #25586

Merged
merged 2 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions apps/meteor/client/views/omnichannel/additionalForms.js

This file was deleted.

42 changes: 42 additions & 0 deletions apps/meteor/client/views/omnichannel/additionalForms.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import { ReactElement } from 'react';
import { Unsubscribe, useSubscription, Subscription } from 'use-subscription';

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface EEFormHooks {}

const createFormSubscription = (): {
registerForm: (form: EEFormHooks) => void;
unregisterForm: (form: keyof EEFormHooks) => void;
formsSubscription: Subscription<EEFormHooks>;
getForm: (form: keyof EEFormHooks) => () => ReactElement;
} => {
let forms = {} as EEFormHooks;
let updateCb = (): void => undefined;

const formsSubscription: Subscription<EEFormHooks> = {
subscribe: (cb: () => void): Unsubscribe => {
updateCb = cb;
return (): void => {
updateCb = (): void => undefined;
};
},
getCurrentValue: (): EEFormHooks => forms,
};
const registerForm = (newForm: EEFormHooks): void => {
forms = { ...forms, ...newForm };
updateCb();
};
const unregisterForm = (form: keyof EEFormHooks): void => {
delete forms[form];
updateCb();
};

const getForm = (form: keyof EEFormHooks): (() => ReactElement) => (forms as any)[form] as any;

return { registerForm, unregisterForm, formsSubscription, getForm };
};

export const { registerForm, unregisterForm, formsSubscription, getForm } = createFormSubscription();

export const useFormsSubscription = (): EEFormHooks => useSubscription(formsSubscription);
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import React from 'react';

import UserInfo from '../../../../client/views/room/contextualBar/UserInfo';

const MaxChatsPerAgentDisplay = ({ data: { livechat: { maxNumberSimultaneousChat = '' } = {} } = {} }) => {
const MaxChatsPerAgentDisplay = ({ data: { livechat: { maxNumberSimultaneousChat = 0 } = {} } = {} }) => {
const t = useTranslation();
return (
maxNumberSimultaneousChat && (
<>
<UserInfo.Label>{t('Max_number_of_chats_per_agent')}</UserInfo.Label>
<UserInfo.Info>{maxNumberSimultaneousChat}</UserInfo.Info>
</>
)
);
return maxNumberSimultaneousChat ? (
<>
<UserInfo.Label>{t('Max_number_of_chats_per_agent')}</UserInfo.Label>
<UserInfo.Info>{maxNumberSimultaneousChat}</UserInfo.Info>
</>
) : null;
};

export default MaxChatsPerAgentDisplay;
51 changes: 0 additions & 51 deletions apps/meteor/ee/client/omnichannel/additionalForms/register.js

This file was deleted.

62 changes: 62 additions & 0 deletions apps/meteor/ee/client/omnichannel/additionalForms/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { useMemo, lazy } from 'react';

import type AutoCompleteDepartment from '../../../../client/components/AutoCompleteDepartment';
import { registerForm } from '../../../../client/views/omnichannel/additionalForms';
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';
import type DepartmentForwarding from './DepartmentForwarding';
import type EeNumberInput from './EeNumberInput';
import type EeTextAreaInput from './EeTextAreaInput';
import type EeTextInput from './EeTextInput';
import type MaxChatsPerAgentContainer from './MaxChatsPerAgentContainer';
import type MaxChatsPerAgentDisplay from './MaxChatsPerAgentDisplay';
import type PrioritiesSelect from './PrioritiesSelect';

declare module '../../../../client/views/omnichannel/additionalForms' {
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
interface EEFormHooks {
useCustomFieldsAdditionalForm: () => React.LazyExoticComponent<typeof CustomFieldsAdditionalFormContainer>;
useMaxChatsPerAgent?: () => React.LazyExoticComponent<typeof MaxChatsPerAgentContainer>;
useMaxChatsPerAgentDisplay?: () => React.LazyExoticComponent<typeof MaxChatsPerAgentDisplay>;
useEeNumberInput?: () => React.LazyExoticComponent<typeof EeNumberInput>;
useEeTextAreaInput?: () => React.LazyExoticComponent<typeof EeTextAreaInput>;
useBusinessHoursMultiple?: () => React.LazyExoticComponent<typeof BusinessHoursMultipleContainer>;
useEeTextInput?: () => React.LazyExoticComponent<typeof EeTextInput>;
useBusinessHoursTimeZone?: () => React.LazyExoticComponent<typeof BusinessHoursTimeZone>;
useContactManager?: () => React.LazyExoticComponent<typeof ContactManager>;

useCurrentChatTags?: () => React.LazyExoticComponent<typeof CurrentChatTags>;
useDepartmentBusinessHours?: () => React.LazyExoticComponent<typeof DepartmentBusinessHours>;
useDepartmentForwarding?: () => React.LazyExoticComponent<typeof DepartmentForwarding>;
usePrioritiesSelect?: () => React.LazyExoticComponent<typeof PrioritiesSelect>;
useSelectForwardDepartment?: () => React.LazyExoticComponent<typeof AutoCompleteDepartment>;
}
}

hasLicense('livechat-enterprise').then((enabled) => {
if (!enabled) {
return;
}

registerForm({
useCustomFieldsAdditionalForm: () => useMemo(() => lazy(() => import('./CustomFieldsAdditionalFormContainer')), []),
useMaxChatsPerAgent: () => useMemo(() => lazy(() => import('./MaxChatsPerAgentContainer')), []),
useMaxChatsPerAgentDisplay: () => useMemo(() => lazy(() => import('./MaxChatsPerAgentDisplay')), []),
useEeNumberInput: () => useMemo(() => lazy(() => import('./EeNumberInput')), []),
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')), []),
useDepartmentForwarding: () => useMemo(() => lazy(() => import('./DepartmentForwarding')), []),
usePrioritiesSelect: () => useMemo(() => lazy(() => import('./PrioritiesSelect')), []),
useSelectForwardDepartment: () => useMemo(() => lazy(() => import('../../../../client/components/AutoCompleteDepartment')), []),
});
});