Chore: Evaluate CannedResponsesListView - TypeScript (#4149)

This commit is contained in:
Reinaldo Neto 2022-05-02 21:30:20 -03:00 committed by GitHub
parent 243d016bf1
commit fe1b8b75bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 40 deletions

View File

@ -1,23 +1,3 @@
export interface IDepartment {
_id: string;
enabled: boolean;
name: string;
description: string;
showOnRegistration: boolean;
showOnOfflineForm: boolean;
requestTagBeforeClosingChat: boolean;
email: string;
chatClosingTags: string[];
offlineMessageChannelName: string;
maxNumberSimultaneousChat: number;
abandonedRoomsCloseCustomMessage: string;
waitingQueueMessage: string;
departmentsAllowedToForward: string;
_updatedAt: Date;
numAgents: number;
ancestors: string[];
}
export interface ICannedResponse { export interface ICannedResponse {
_id: string; _id: string;
shortcut: string; shortcut: string;

View File

@ -13,6 +13,11 @@ export interface ILivechatDepartment {
_updatedAt?: Date; _updatedAt?: Date;
businessHourId?: string; businessHourId?: string;
fallbackForwardDepartment?: string; fallbackForwardDepartment?: string;
maxNumberSimultaneousChat: number;
abandonedRoomsCloseCustomMessage: string;
waitingQueueMessage: string;
departmentsAllowedToForward: string;
ancestors: string[];
// extra optional fields // extra optional fields
[k: string]: any; [k: string]: any;
} }

View File

@ -1,12 +1,12 @@
import React from 'react'; import React from 'react';
import { IDepartment } from '../../../definitions/ICannedResponse'; import { ILivechatDepartment } from '../../../definitions/ILivechatDepartment';
import DropdownItem from './DropdownItem'; import DropdownItem from './DropdownItem';
interface IDropdownItemFilter { interface IDropdownItemFilter {
currentDepartment: IDepartment; currentDepartment: ILivechatDepartment;
value: IDepartment; value: ILivechatDepartment;
onPress: (value: IDepartment) => void; onPress: (value: ILivechatDepartment) => void;
} }
const DropdownItemFilter = ({ currentDepartment, value, onPress }: IDropdownItemFilter): JSX.Element => ( const DropdownItemFilter = ({ currentDepartment, value, onPress }: IDropdownItemFilter): JSX.Element => (

View File

@ -1,14 +1,14 @@
import React from 'react'; import React from 'react';
import { IDepartment } from '../../../definitions/ICannedResponse'; import { ILivechatDepartment } from '../../../definitions/ILivechatDepartment';
import DropdownItem from './DropdownItem'; import DropdownItem from './DropdownItem';
interface IDropdownItemHeader { interface IDropdownItemHeader {
department: IDepartment; department: ILivechatDepartment;
onPress: () => void; onPress: () => void;
} }
const DropdownItemHeader = ({ department, onPress }: IDropdownItemHeader): JSX.Element => ( const DropdownItemHeader = ({ department, onPress }: IDropdownItemHeader): React.ReactElement => (
<DropdownItem text={department?.name} iconName='filter' onPress={onPress} /> <DropdownItem text={department?.name} iconName='filter' onPress={onPress} />
); );

View File

@ -6,19 +6,19 @@ import styles from '../styles';
import { themes } from '../../../lib/constants'; import { themes } from '../../../lib/constants';
import { TSupportedThemes, withTheme } from '../../../theme'; import { TSupportedThemes, withTheme } from '../../../theme';
import * as List from '../../../containers/List'; import * as List from '../../../containers/List';
import { IDepartment } from '../../../definitions/ICannedResponse';
import DropdownItemFilter from './DropdownItemFilter'; import DropdownItemFilter from './DropdownItemFilter';
import DropdownItemHeader from './DropdownItemHeader'; import DropdownItemHeader from './DropdownItemHeader';
import { ROW_HEIGHT } from './DropdownItem'; import { ROW_HEIGHT } from './DropdownItem';
import { ILivechatDepartment } from '../../../definitions/ILivechatDepartment';
const ANIMATION_DURATION = 200; const ANIMATION_DURATION = 200;
interface IDropdownProps { interface IDropdownProps {
theme?: TSupportedThemes; theme?: TSupportedThemes;
currentDepartment: IDepartment; currentDepartment: ILivechatDepartment;
onClose: () => void; onClose: () => void;
onDepartmentSelected: (value: IDepartment) => void; onDepartmentSelected: (value: ILivechatDepartment) => void;
departments: IDepartment[]; departments: ILivechatDepartment[];
} }
class Dropdown extends React.Component<IDropdownProps> { class Dropdown extends React.Component<IDropdownProps> {

View File

@ -25,11 +25,13 @@ import CannedResponseItem from './CannedResponseItem';
import Dropdown from './Dropdown'; import Dropdown from './Dropdown';
import DropdownItemHeader from './Dropdown/DropdownItemHeader'; import DropdownItemHeader from './Dropdown/DropdownItemHeader';
import styles from './styles'; import styles from './styles';
import { ICannedResponse, IDepartment } from '../../definitions/ICannedResponse'; import { ICannedResponse } from '../../definitions/ICannedResponse';
import { ChatsStackParamList } from '../../stacks/types'; import { ChatsStackParamList } from '../../stacks/types';
import { ISubscription } from '../../definitions/ISubscription'; import { ISubscription } from '../../definitions/ISubscription';
import { getRoomTitle, getUidDirectMessage } from '../../lib/methods'; import { getRoomTitle, getUidDirectMessage } from '../../lib/methods';
import { Services } from '../../lib/services'; import { Services } from '../../lib/services';
import { IApplicationState } from '../../definitions';
import { ILivechatDepartment } from '../../definitions/ILivechatDepartment';
const COUNT = 25; const COUNT = 25;
@ -46,7 +48,7 @@ const fixedScopes = [
_id: 'user', _id: 'user',
name: I18n.t('Private') name: I18n.t('Private')
} }
] as IDepartment[]; ] as ILivechatDepartment[];
interface ICannedResponsesListViewProps { interface ICannedResponsesListViewProps {
navigation: StackNavigationProp<ChatsStackParamList, 'CannedResponsesListView'>; navigation: StackNavigationProp<ChatsStackParamList, 'CannedResponsesListView'>;
@ -58,7 +60,7 @@ const CannedResponsesListView = ({ navigation, route }: ICannedResponsesListView
const [cannedResponses, setCannedResponses] = useState<ICannedResponse[]>([]); const [cannedResponses, setCannedResponses] = useState<ICannedResponse[]>([]);
const [cannedResponsesScopeName, setCannedResponsesScopeName] = useState<ICannedResponse[]>([]); const [cannedResponsesScopeName, setCannedResponsesScopeName] = useState<ICannedResponse[]>([]);
const [departments, setDepartments] = useState<IDepartment[]>([]); const [departments, setDepartments] = useState<ILivechatDepartment[]>([]);
// states used by the filter in Header and Dropdown // states used by the filter in Header and Dropdown
const [isSearching, setIsSearching] = useState(false); const [isSearching, setIsSearching] = useState(false);
@ -74,8 +76,8 @@ const CannedResponsesListView = ({ navigation, route }: ICannedResponsesListView
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
const { theme } = useTheme(); const { theme } = useTheme();
const { isMasterDetail } = useSelector((state: any) => state.app); const isMasterDetail = useSelector((state: IApplicationState) => state.app.isMasterDetail);
const { rooms } = useSelector((state: any) => state.room); const rooms = useSelector((state: IApplicationState) => state.room.rooms);
const getRoomFromDb = async () => { const getRoomFromDb = async () => {
const { rid } = route.params; const { rid } = route.params;
@ -92,9 +94,9 @@ const CannedResponsesListView = ({ navigation, route }: ICannedResponsesListView
const getDepartments = debounce(async () => { const getDepartments = debounce(async () => {
try { try {
const res: any = await Services.getDepartments(); const res = await Services.getDepartments();
if (res.success) { if (res.success) {
setDepartments([...fixedScopes, ...res.departments]); setDepartments([...fixedScopes, ...(res.departments as ILivechatDepartment[])]);
} }
} catch (e) { } catch (e) {
setDepartments(fixedScopes); setDepartments(fixedScopes);
@ -119,7 +121,7 @@ const CannedResponsesListView = ({ navigation, route }: ICannedResponsesListView
t: room.t, t: room.t,
fname: name fname: name
}), }),
t: room.t as any, t: room.t,
roomUserId: getUidDirectMessage(room), roomUserId: getUidDirectMessage(room),
usedCannedResponse: item.text usedCannedResponse: item.text
}; };
@ -214,7 +216,7 @@ const CannedResponsesListView = ({ navigation, route }: ICannedResponsesListView
searchCallback(text, scope, departmentId); searchCallback(text, scope, departmentId);
}; };
const onDepartmentSelect = (value: IDepartment) => { const onDepartmentSelect = (value: ILivechatDepartment) => {
let department = ''; let department = '';
let depId = ''; let depId = '';