[IMPROVE] Types from currentChatsPage.tsx (#22967)

* improve ts types from currentChatsPage.tsx

* Fix infinite reload

* lint

Co-authored-by: Martin <martin.schoeler@rocket.chat>
pull/22965/head^2
Tiago Evangelista Pinto 5 years ago committed by GitHub
parent e7a3f0b9b7
commit 09586fa1e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      client/components/GenericTable/GenericTable.tsx
  2. 9
      client/contexts/ServerContext/endpoints/v1/livechat/rooms.ts
  3. 38
      client/views/omnichannel/currentChats/CurrentChatsPage.tsx
  4. 4
      client/views/omnichannel/currentChats/FilterByText.tsx

@ -19,16 +19,16 @@ import LoadingRow from './LoadingRow';
const defaultParamsValue = { text: '', current: 0, itemsPerPage: 25 } as const;
const defaultSetParamsValue = (): void => undefined;
type Params = { text?: string; current?: number; itemsPerPage?: 25 | 50 | 100 };
type GenericTableParams = { text?: string; current?: number; itemsPerPage?: 25 | 50 | 100 };
type GenericTableProps<
FilterProps extends { onChange?: (params: Params) => void },
FilterProps extends { onChange?: (params: GenericTableParams) => void },
ResultProps extends { _id?: Key },
> = {
fixed?: boolean;
header?: ReactNode;
params?: Params;
setParams?: (params: Params) => void;
params?: GenericTableParams;
setParams?: (params: GenericTableParams) => void;
children?: (props: ResultProps, key: number) => ReactElement;
renderFilter?: (props: FilterProps) => ReactElement;
renderRow?: (props: ResultProps) => ReactElement;
@ -38,7 +38,10 @@ type GenericTableProps<
} & FilterProps;
const GenericTable: {
<FilterProps extends { onChange?: (params: Params) => void }, ResultProps extends { _id?: Key }>(
<
FilterProps extends { onChange?: (params: GenericTableParams) => void },
ResultProps extends { _id?: Key },
>(
props: GenericTableProps<FilterProps, ResultProps> & RefAttributes<HTMLElement>,
): ReactElement | null;
} = forwardRef(function GenericTable(

@ -1,3 +1,5 @@
import { IOmnichannelRoom } from '../../../../../../definition/IRoom';
export type LivechatRoomsEndpoint = {
GET: (params: {
guest: string;
@ -11,5 +13,10 @@ export type LivechatRoomsEndpoint = {
current: number;
itemsPerPage: number;
tags: string[];
}) => { value: any; reload: () => void };
}) => {
rooms: IOmnichannelRoom[];
count: number;
offset: number;
total: number;
};
};

@ -1,17 +1,39 @@
import React, { FC, memo } from 'react';
import React, { Dispatch, FC, Key, memo, ReactElement, ReactNode, SetStateAction } from 'react';
import { IOmnichannelRoom } from '../../../../definition/IRoom';
import GenericTable from '../../../components/GenericTable';
import Page from '../../../components/Page';
import FilterByText from './FilterByText';
type CurrentChatsPageData = {
rooms: IOmnichannelRoom[];
count: number;
offset: number;
total: number;
};
type CurrentChatsPageDataParams = {
guest: string;
fname: string;
servedBy: string;
status: string;
department: string;
from: string;
to: string;
customFields: any;
current: number;
itemsPerPage: number;
tags: string[];
};
const CurrentChatsPage: FC<{
data: any;
header: any;
setParams: any;
params: any;
title: any;
renderRow: any;
reload: any;
data?: CurrentChatsPageData;
header: ReactNode;
setParams: Dispatch<SetStateAction<CurrentChatsPageDataParams>>;
params: CurrentChatsPageDataParams;
title: string;
renderRow: (props: { _id?: Key }) => ReactElement;
reload: () => void;
}> = ({ data, header, setParams, params, title, renderRow, reload }) => (
<Page>
<Page.Header title={title} />

@ -18,7 +18,7 @@ import RemoveAllClosed from './RemoveAllClosed';
type FilterByTextType = FC<{
setFilter: Dispatch<SetStateAction<any>>;
reload?: any;
reload?: () => void;
}>;
const FilterByText: FilterByTextType = ({ setFilter, reload, ...props }) => {
@ -107,7 +107,7 @@ const FilterByText: FilterByTextType = ({ setFilter, reload, ...props }) => {
const onDeleteAll = async (): Promise<void> => {
try {
await removeClosedChats();
reload();
reload && reload();
dispatchToastMessage({ type: 'success', message: t('Chat_removed') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });

Loading…
Cancel
Save