Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/containers/UIKit/MultiSelect/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import ActivityIndicator from '../../ActivityIndicator';
import styles from './styles';

interface IInput {
children: JSX.Element;
children?: JSX.Element;
onPress: Function;
theme: string;
inputStyle: object;
inputStyle?: object;
disabled?: boolean | object;
placeholder?: string;
loading?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { StackNavigationProp } from '@react-navigation/stack';
import { RouteProp } from '@react-navigation/native';
import { StyleSheet, View } from 'react-native';
import { Dispatch } from 'redux';
import { connect } from 'react-redux';
import { isEmpty } from 'lodash';

import I18n from '../i18n';
import { withTheme } from '../theme';
Expand All @@ -10,6 +13,7 @@ import RocketChat from '../lib/rocketchat';
import OrSeparator from '../containers/OrSeparator';
import Input from '../containers/UIKit/MultiSelect/Input';
import { forwardRoom as forwardRoomAction } from '../actions/room';
import { ILivechatDepartment } from './definition/ILivechatDepartment';

const styles = StyleSheet.create({
container: {
Expand All @@ -18,20 +22,52 @@ const styles = StyleSheet.create({
}
});

const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }) => {
const [departments, setDepartments] = useState([]);
const [departmentId, setDepartment] = useState();
const [users, setUsers] = useState([]);
// TODO: Refactor when migrate room
interface IRoom {
departmentId?: any;
servedBy?: {
_id: string;
};
}

interface ITransferData {
roomId: string;
userId?: string;
departmentId?: string;
}

interface IUser {
username: string;
_id: string;
}

interface IParsedData {
label: string;
value: string;
}

interface IForwardLivechatViewProps {
navigation: StackNavigationProp<any, 'ForwardLivechatView'>;
route: RouteProp<{ ForwardLivechatView: { rid: string } }, 'ForwardLivechatView'>;
theme: string;
forwardRoom: (rid: string, transferData: ITransferData) => void;
}

const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }: IForwardLivechatViewProps) => {
const [departments, setDepartments] = useState<IParsedData[]>([]);
const [departmentId, setDepartment] = useState('');
const [users, setUsers] = useState<IParsedData[]>([]);
const [userId, setUser] = useState();
const [room, setRoom] = useState();
const [room, setRoom] = useState<IRoom>({});

const rid = route.params?.rid;

const getDepartments = async () => {
try {
const result = await RocketChat.getDepartments();
if (result.success) {
setDepartments(result.departments.map(department => ({ label: department.name, value: department._id })));
const deps = result.departments as ILivechatDepartment[];
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
setDepartments(deps.map<IParsedData>(department => ({ label: department.name, value: department._id })));
}
} catch {
// do nothing
Expand All @@ -47,7 +83,8 @@ const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }) => {
term
});
if (result.success) {
const parsedUsers = result.items.map(user => ({ label: user.username, value: user._id }));
const usersItems = result.items as IUser[];
const parsedUsers = usersItems.map<IParsedData>(user => ({ label: user.username, value: user._id }));
setUsers(parsedUsers);
return parsedUsers;
}
Expand All @@ -69,7 +106,7 @@ const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }) => {
};

const submit = () => {
const transferData = { roomId: rid };
const transferData = { roomId: rid } as ITransferData;

if (!departmentId && !userId) {
return;
Expand All @@ -85,11 +122,14 @@ const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }) => {
};

useEffect(() => {
navigation.setOptions({
title: I18n.t('Forward_Chat')
});
getRoom();
}, []);

useEffect(() => {
if (room) {
if (!isEmpty(room)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this line to working properly with the useState({})

getUsers();
getDepartments();
}
Expand Down Expand Up @@ -129,18 +169,9 @@ const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }) => {
</View>
);
};
ForwardLivechatView.propTypes = {
forwardRoom: PropTypes.func,
navigation: PropTypes.object,
route: PropTypes.object,
theme: PropTypes.string
};
ForwardLivechatView.navigationOptions = {
title: I18n.t('Forward_Chat')
};

const mapDispatchToProps = dispatch => ({
forwardRoom: (rid, transferData) => dispatch(forwardRoomAction(rid, transferData))
const mapDispatchToProps = (dispatch: Dispatch) => ({
forwardRoom: (rid: string, transferData: ITransferData) => dispatch(forwardRoomAction(rid, transferData))
});

export default connect(null, mapDispatchToProps)(withTheme(ForwardLivechatView));
15 changes: 15 additions & 0 deletions app/views/definition/ILivechatDepartment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface ILivechatDepartment {
_id: string;
name: string;
enabled: boolean;
description: string;
showOnRegistration: boolean;
showOnOfflineForm: boolean;
requestTagBeforeClosingChat: boolean;
email: string;
chatClosingTags: string[];
offlineMessageChannelName: string;
numAgents: number;
_updatedAt?: Date;
businessHourId?: string;
}