-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Convert additionalForms (#25586)
Co-authored-by: Martin <martin.schoeler@rocket.chat>
- Loading branch information
1 parent
9551660
commit 5b4b8be
Showing
5 changed files
with
111 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,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); |
This file contains 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
51 changes: 0 additions & 51 deletions
51
apps/meteor/ee/client/omnichannel/additionalForms/register.js
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
apps/meteor/ee/client/omnichannel/additionalForms/register.ts
This file contains 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,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')), []), | ||
}); | ||
}); |