Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions app/containers/Status/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IStatus {
status: string;
size: number;
style?: StyleProp<TextStyle>;
testID?: string;
}

const Status = React.memo(({ style, status = 'offline', size = 32, ...props }: IStatus) => {
Expand Down
52 changes: 30 additions & 22 deletions app/views/StatusView.js → app/views/StatusView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StackNavigationProp } from '@react-navigation/stack';
import { FlatList, StyleSheet } from 'react-native';
import { Dispatch } from 'redux';
import { connect } from 'react-redux';

import I18n from '../i18n';
Expand Down Expand Up @@ -53,23 +54,29 @@ const styles = StyleSheet.create({
}
});

class StatusView extends React.Component {
static propTypes = {
user: PropTypes.shape({
id: PropTypes.string,
status: PropTypes.string,
statusText: PropTypes.string
}),
theme: PropTypes.string,
navigation: PropTypes.object,
isMasterDetail: PropTypes.bool,
setUser: PropTypes.func,
Accounts_AllowInvisibleStatusOption: PropTypes.bool
};
interface IUser {
id: string;
status: string;
statusText: string;
}

constructor(props) {
super(props);
interface IStatusViewState {
statusText: string;
loading: boolean;
}

interface IStatusViewProps {
navigation: StackNavigationProp<any, 'StatusView'>;
user: IUser;
theme: string;
isMasterDetail: boolean;
setUser: (user: Partial<IUser>) => void;
Accounts_AllowInvisibleStatusOption: boolean;
}

class StatusView extends React.Component<IStatusViewProps, IStatusViewState> {
constructor(props: IStatusViewProps) {
super(props);
const { statusText } = props.user;
this.state = { statusText: statusText || '', loading: false };
this.setHeader();
Expand Down Expand Up @@ -103,7 +110,7 @@ class StatusView extends React.Component {
navigation.goBack();
};

setCustomStatus = async statusText => {
setCustomStatus = async (statusText: string) => {
const { user, setUser } = this.props;

this.setState({ loading: true });
Expand Down Expand Up @@ -147,22 +154,23 @@ class StatusView extends React.Component {
);
};

renderItem = ({ item }) => {
renderItem = ({ item }: { item: { id: string; name: string } }) => {
const { statusText } = this.state;
const { user, setUser } = this.props;
const { id, name } = item;
return (
<List.Item
title={name}
onPress={async () => {
// @ts-ignore
logEvent(events[`STATUS_${item.id.toUpperCase()}`]);
if (user.status !== item.id) {
try {
const result = await RocketChat.setUserStatus(item.id, statusText);
if (result.success) {
setUser({ status: item.id });
}
} catch (e) {
} catch (e: any) {
showErrorAlert(I18n.t(e.data.errorType));
logEvent(events.SET_STATUS_FAIL);
log(e);
Expand Down Expand Up @@ -197,14 +205,14 @@ class StatusView extends React.Component {
}
}

const mapStateToProps = state => ({
const mapStateToProps = (state: any) => ({
user: getUserSelector(state),
isMasterDetail: state.app.isMasterDetail,
Accounts_AllowInvisibleStatusOption: state.settings.Accounts_AllowInvisibleStatusOption ?? true
});

const mapDispatchToProps = dispatch => ({
setUser: user => dispatch(setUserAction(user))
const mapDispatchToProps = (dispatch: Dispatch) => ({
setUser: (user: IUser) => dispatch(setUserAction(user))
});

export default connect(mapStateToProps, mapDispatchToProps)(withTheme(StatusView));