From cfb10ada601271c9c0bb6b556dc81aa7d04c55b0 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Mon, 14 Mar 2022 10:23:20 -0300 Subject: [PATCH] Chore: Migrate REST API - editLivechat to Typescript (#3878) --- app/definitions/ILivechatEditView.ts | 40 +++++++++++++++++++++++++ app/lib/rocketchat/services/restApi.ts | 3 +- app/views/LivechatEditView.tsx | 41 ++------------------------ 3 files changed, 45 insertions(+), 39 deletions(-) create mode 100644 app/definitions/ILivechatEditView.ts diff --git a/app/definitions/ILivechatEditView.ts b/app/definitions/ILivechatEditView.ts new file mode 100644 index 00000000..d173d54e --- /dev/null +++ b/app/definitions/ILivechatEditView.ts @@ -0,0 +1,40 @@ +import { TextInput } from 'react-native'; + +import { ILivechatVisitor } from './ILivechatVisitor'; +import { ISubscription } from './ISubscription'; + +export interface ITitle { + title: string; + theme: string; +} + +export interface IInputs { + livechatData: { + [key: string]: any; + }; + name: string; + email: string; + phone?: string; + topic: string; + tag: string[]; + [key: string]: any; +} + +export type TParams = ILivechatVisitor & IInputs; + +export interface ILivechat extends ISubscription { + // Param dynamic depends on server + sms?: string; +} + +export interface IInputsRefs { + [index: string]: TextInput | null; + name: TextInput | null; + phone: TextInput | null; + topic: TextInput | null; +} + +export interface ICustomFields { + visitor?: { [key: string]: string }; + livechat?: { [key: string]: string }; +} diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 738e323a..4d86fc14 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -4,6 +4,7 @@ import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType'; import { SubscriptionType, INotificationPreferences, IRoomNotifications } from '../../../definitions'; import { ISpotlight } from '../../../definitions/ISpotlight'; import { IAvatarSuggestion, IParams } from '../../../definitions/IProfileViewInterfaces'; +import { TParams } from '../../../definitions/ILivechatEditView'; export const createChannel = ({ name, @@ -337,7 +338,7 @@ export const closeLivechat = (rid: string, comment: string) => // RC 0.29.0 sdk.methodCallWrapper('livechat:closeRoom', rid, comment, { clientAction: true }); -export const editLivechat = (userData: any, roomData: any) => +export const editLivechat = (userData: TParams, roomData: TParams): Promise<{ error?: string }> => // RC 0.55.0 sdk.methodCallWrapper('livechat:saveInfo', userData, roomData); diff --git a/app/views/LivechatEditView.tsx b/app/views/LivechatEditView.tsx index 22dcada2..f709245f 100644 --- a/app/views/LivechatEditView.tsx +++ b/app/views/LivechatEditView.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { StackNavigationProp } from '@react-navigation/stack'; import { RouteProp } from '@react-navigation/native'; -import { ScrollView, StyleSheet, Text, TextInput as RNTextInput } from 'react-native'; +import { ScrollView, StyleSheet, Text } from 'react-native'; import { connect } from 'react-redux'; import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit'; @@ -18,8 +18,8 @@ import { getUserSelector } from '../selectors/login'; import Button from '../containers/Button'; import SafeAreaView from '../containers/SafeAreaView'; import { MultiSelect } from '../containers/UIKit/MultiSelect'; -import { ILivechatVisitor } from '../definitions/ILivechatVisitor'; -import { IApplicationState, ISubscription } from '../definitions'; +import { ICustomFields, IInputsRefs, TParams, ITitle, ILivechat } from '../definitions/ILivechatEditView'; +import { IApplicationState } from '../definitions'; import { ChatsStackParamList } from '../stacks/types'; import sharedStyles from './Styles'; @@ -42,41 +42,6 @@ const styles = StyleSheet.create({ } }); -interface ITitle { - title: string; - theme: string; -} - -interface IInputs { - livechatData: { - [key: string]: any; - }; - name: string; - email: string; - phone?: string; - topic: string; - tag: string[]; - [key: string]: any; -} - -type TParams = ILivechatVisitor & IInputs; - -interface ILivechat extends ISubscription { - // Param dynamic depends on server - sms?: string; -} - -interface IInputsRefs { - [index: string]: RNTextInput | null; - name: RNTextInput | null; - phone: RNTextInput | null; - topic: RNTextInput | null; -} - -interface ICustomFields { - visitor?: { [key: string]: string }; - livechat?: { [key: string]: string }; -} interface ILivechatEditViewProps { // TODO: Refactor when migrate models user: any;