Skip to content

Commit 8ed6f42

Browse files
committed
refactor(livechat): do not use FunctionalComponent to declare components
1 parent 93f3be2 commit 8ed6f42

10 files changed

Lines changed: 46 additions & 37 deletions

File tree

packages/livechat/src/components/Screen/ScreenProvider.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FunctionalComponent } from 'preact';
1+
import type { ComponentChildren } from 'preact';
22
import { createContext } from 'preact';
33
import { useContext, useEffect, useState } from 'preact/hooks';
44
import { parse } from 'query-string';
@@ -68,7 +68,11 @@ export const ScreenContext = createContext<ScreenContextValue>({
6868
onOpenWindow: () => undefined,
6969
} as ScreenContextValue);
7070

71-
export const ScreenProvider: FunctionalComponent = ({ children }) => {
71+
type ScreenProviderProps = {
72+
children: ComponentChildren;
73+
};
74+
75+
export const ScreenProvider = ({ children }: ScreenProviderProps) => {
7276
const store = useContext(StoreContext);
7377
const { token, dispatch, config, sound, minimized = true, undocked, expanded = false, alerts, modal, iframe, customFieldsQueue } = store;
7478
const { department, name, email } = iframe.guest || {};

packages/livechat/src/components/Tooltip/Tooltip.stories.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { ComponentProps } from 'preact';
44
import Tooltip from './Tooltip';
55
import TooltipContainer from './TooltipContainer';
66
import TooltipTrigger from './TooltipTrigger';
7-
import { withTooltip } from './withTooltip';
87
import { Button } from '../Button';
98

109
const placements = [null, 'left', 'top', 'right', 'bottom', 'top-left', 'top-right', 'bottom-left', 'bottom-right'] as const;
@@ -51,12 +50,3 @@ ConnectedToAnotherComponent.args = {
5150
content: 'A simple tool tip',
5251
};
5352
ConnectedToAnotherComponent.decorators = [(storyFn) => <TooltipContainer>{storyFn()}</TooltipContainer>];
54-
55-
const MyButton = withTooltip(Button);
56-
57-
export const WithTooltip: StoryFn<{ tooltip?: string }> = ({ tooltip }) => <MyButton tooltip={tooltip}>A simple button</MyButton>;
58-
WithTooltip.storyName = 'withTooltip()';
59-
WithTooltip.args = {
60-
tooltip: 'A simple tool tip',
61-
};
62-
WithTooltip.decorators = [(storyFn) => <TooltipContainer>{storyFn()}</TooltipContainer>];
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export { default, default as Tooltip } from './Tooltip';
22
export { default as TooltipContainer } from './TooltipContainer';
33
export { default as TooltipTrigger } from './TooltipTrigger';
4-
export { withTooltip } from './withTooltip';

packages/livechat/src/components/Tooltip/withTooltip.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/livechat/src/routes/Chat/connector.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TFunction } from 'i18next';
2-
import type { FunctionalComponent } from 'preact';
2+
import type { Ref } from 'preact';
33
import { useContext } from 'preact/hooks';
44
import { withTranslation } from 'react-i18next';
55

@@ -9,7 +9,14 @@ import { canRenderMessage } from '../../helpers/canRenderMessage';
99
import { formatAgent } from '../../helpers/formatAgent';
1010
import { StoreContext } from '../../store';
1111

12-
export const ChatConnector: FunctionalComponent<{ path: string; default: boolean; t: TFunction }> = ({ ref, t }) => {
12+
type ChatConnectorProps = {
13+
path: string;
14+
default: boolean;
15+
t: TFunction;
16+
ref?: Ref<any>;
17+
};
18+
19+
export const ChatConnector = ({ ref, t }: ChatConnectorProps) => {
1320
const { theme } = useContext(ScreenContext);
1421
const {
1522
config: {

packages/livechat/src/routes/ChatFinished/container.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import type { TFunction } from 'i18next';
2-
import type { FunctionalComponent } from 'preact';
32
import { useContext } from 'preact/hooks';
43
import { route } from 'preact-router';
54
import { withTranslation } from 'react-i18next';
65

76
import ChatFinished from './component';
87
import { StoreContext } from '../../store';
98

10-
const ChatFinishedContainer: FunctionalComponent<{ path: string; t: TFunction }> = ({ ref, t }) => {
9+
type ChatFinishedContainerProps = {
10+
ref?: any;
11+
t: TFunction;
12+
path: string;
13+
};
14+
15+
const ChatFinishedContainer = ({ ref, t }: ChatFinishedContainerProps) => {
1116
const {
1217
config: {
1318
messages: { conversationFinishedMessage: greeting, conversationFinishedText: message },

packages/livechat/src/routes/GDPRAgreement/container.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import type { TFunction } from 'i18next';
2-
import type { FunctionalComponent } from 'preact';
2+
import type { Ref } from 'preact';
33
import { useContext } from 'preact/hooks';
44
import { route } from 'preact-router';
55
import { withTranslation } from 'react-i18next';
66

77
import GDPRAgreement from './component';
88
import { StoreContext } from '../../store';
99

10-
const GDPRContainer: FunctionalComponent<{ t: TFunction }> = ({ ref, t }) => {
10+
type GDPRContainerProps = {
11+
t: TFunction;
12+
ref?: Ref<any>;
13+
};
14+
15+
const GDPRContainer = ({ ref, t }: GDPRContainerProps) => {
1116
const { config: { messages: { dataProcessingConsentText: consentText = '' } = {} } = {}, dispatch } = useContext(StoreContext);
1217

1318
const handleAgree = async () => {

packages/livechat/src/routes/LeaveMessage/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { FunctionalComponent } from 'preact';
21
import { useContext, useRef } from 'preact/hooks';
32
import type { JSXInternal } from 'preact/src/jsx';
43
import type { FieldValues, SubmitHandler } from 'react-hook-form';
@@ -22,7 +21,11 @@ import { parentCall } from '../../lib/parentCall';
2221
import { createToken } from '../../lib/random';
2322
import { StoreContext } from '../../store';
2423

25-
const LeaveMessage: FunctionalComponent<{ path: string }> = () => {
24+
type LeaveMessageProps = {
25+
path: string;
26+
};
27+
28+
const LeaveMessage = (_: LeaveMessageProps) => {
2629
const {
2730
config: {
2831
departments = [],

packages/livechat/src/routes/Register/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { FunctionalComponent } from 'preact';
21
import { useContext, useEffect, useMemo, useRef } from 'preact/hooks';
32
import type { JSXInternal } from 'preact/src/jsx';
43
import { route } from 'preact-router';
@@ -26,7 +25,11 @@ type FormPayloadCustomField = { [key: string]: string };
2625

2726
export type RegisterFormValues = { name: string; email: string; department?: string; [key: string]: any };
2827

29-
export const Register: FunctionalComponent<{ path: string }> = () => {
28+
type RegisterProps = {
29+
path: string;
30+
};
31+
32+
export const Register = (_: RegisterProps) => {
3033
const { t } = useTranslation();
3134

3235
const topRef = useRef<HTMLDivElement>(null);

packages/livechat/src/routes/TriggerMessage/container.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FunctionalComponent } from 'preact';
1+
import type { Ref } from 'preact';
22
import { useContext, useEffect } from 'preact/hooks';
33
import { route } from 'preact-router';
44

@@ -9,7 +9,12 @@ import { formatAgent } from '../../helpers/formatAgent';
99
import { parentCall } from '../../lib/parentCall';
1010
import { StoreContext } from '../../store';
1111

12-
export const TriggerMessageContainer: FunctionalComponent<{ path: string }> = ({ ref }) => {
12+
type TriggerMessageContainerProps = {
13+
path: string;
14+
ref?: Ref<any>;
15+
};
16+
17+
export const TriggerMessageContainer = ({ ref }: TriggerMessageContainerProps) => {
1318
const { messages, agent, unread } = useContext(StoreContext);
1419
const { theme, onRestore } = useContext(ScreenContext);
1520

0 commit comments

Comments
 (0)