Chore: Evaluate RoomMembersView - TypeScript (#4116)
* Chore: Evaluate RoomMembersView - TypeScript * evaluate show action sheet * fix tsubscriptionmodel
This commit is contained in:
parent
fe1b8b75bd
commit
888bcae48e
|
@ -2,20 +2,14 @@ import React from 'react';
|
||||||
import { Text, View } from 'react-native';
|
import { Text, View } from 'react-native';
|
||||||
|
|
||||||
import { themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
import { CustomIcon, TIconsName } from '../CustomIcon';
|
import { CustomIcon } from '../CustomIcon';
|
||||||
import { useTheme } from '../../theme';
|
import { useTheme } from '../../theme';
|
||||||
import { Button } from './Button';
|
import { Button } from './Button';
|
||||||
|
import { TActionSheetOptionsItem } from './Provider';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
|
|
||||||
export interface IActionSheetItem {
|
export interface IActionSheetItem {
|
||||||
item: {
|
item: TActionSheetOptionsItem;
|
||||||
title: string;
|
|
||||||
icon: TIconsName;
|
|
||||||
danger?: boolean;
|
|
||||||
testID?: string;
|
|
||||||
onPress: () => void;
|
|
||||||
right?: Function;
|
|
||||||
};
|
|
||||||
hide(): void;
|
hide(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,14 @@ import React, { ForwardedRef, forwardRef, useContext, useRef } from 'react';
|
||||||
import ActionSheet from './ActionSheet';
|
import ActionSheet from './ActionSheet';
|
||||||
import { TIconsName } from '../CustomIcon';
|
import { TIconsName } from '../CustomIcon';
|
||||||
|
|
||||||
export type TActionSheetOptionsItem = { title: string; icon: TIconsName; onPress: () => void; danger?: boolean };
|
export type TActionSheetOptionsItem = {
|
||||||
|
title: string;
|
||||||
|
icon: TIconsName;
|
||||||
|
danger?: boolean;
|
||||||
|
testID?: string;
|
||||||
|
onPress: () => void;
|
||||||
|
right?: () => React.ReactElement;
|
||||||
|
};
|
||||||
|
|
||||||
export type TActionSheetOptions = {
|
export type TActionSheetOptions = {
|
||||||
options: TActionSheetOptionsItem[];
|
options: TActionSheetOptionsItem[];
|
||||||
|
|
|
@ -85,7 +85,7 @@ export function hasRole(role): boolean {
|
||||||
return userRoles.indexOf(role) > -1;
|
return userRoles.indexOf(role) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function hasPermission(permissions, rid?: any) {
|
export async function hasPermission(permissions, rid?: any): boolean[] {
|
||||||
let roomRoles = [];
|
let roomRoles = [];
|
||||||
if (rid) {
|
if (rid) {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { NavigatorScreenParams } from '@react-navigation/core';
|
||||||
|
|
||||||
import { IAttachment } from '../../definitions/IAttachment';
|
import { IAttachment } from '../../definitions/IAttachment';
|
||||||
import { IMessage } from '../../definitions/IMessage';
|
import { IMessage } from '../../definitions/IMessage';
|
||||||
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
|
import { ISubscription, SubscriptionType, TSubscriptionModel } from '../../definitions/ISubscription';
|
||||||
import { TRoomModel } from '../../definitions';
|
|
||||||
|
|
||||||
export type MasterDetailChatsStackParamList = {
|
export type MasterDetailChatsStackParamList = {
|
||||||
RoomView: {
|
RoomView: {
|
||||||
|
@ -56,7 +55,7 @@ export type ModalStackParamList = {
|
||||||
};
|
};
|
||||||
RoomMembersView: {
|
RoomMembersView: {
|
||||||
rid: string;
|
rid: string;
|
||||||
room: TRoomModel;
|
room: TSubscriptionModel;
|
||||||
};
|
};
|
||||||
DiscussionsView: {
|
DiscussionsView: {
|
||||||
rid: string;
|
rid: string;
|
||||||
|
|
|
@ -66,7 +66,7 @@ const LivechatEditView = ({
|
||||||
}: ILivechatEditViewProps) => {
|
}: ILivechatEditViewProps) => {
|
||||||
const [customFields, setCustomFields] = useState<ICustomFields>({});
|
const [customFields, setCustomFields] = useState<ICustomFields>({});
|
||||||
const [availableUserTags, setAvailableUserTags] = useState<string[]>([]);
|
const [availableUserTags, setAvailableUserTags] = useState<string[]>([]);
|
||||||
const [permissions, setPermissions] = useState([]);
|
const [permissions, setPermissions] = useState<boolean[]>([]);
|
||||||
|
|
||||||
const params = {} as TParams;
|
const params = {} as TParams;
|
||||||
const inputs = {} as IInputsRefs;
|
const inputs = {} as IInputsRefs;
|
||||||
|
|
|
@ -43,7 +43,7 @@ import { Services } from '../../lib/services';
|
||||||
interface IRoomInfoEditViewState {
|
interface IRoomInfoEditViewState {
|
||||||
room: ISubscription;
|
room: ISubscription;
|
||||||
avatar: IAvatar;
|
avatar: IAvatar;
|
||||||
permissions: Record<TSupportedPermissions, string>;
|
permissions: { [key in TSupportedPermissions]?: boolean };
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
topic?: string;
|
topic?: string;
|
||||||
|
@ -93,7 +93,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
this.state = {
|
this.state = {
|
||||||
room: {} as ISubscription,
|
room: {} as ISubscription,
|
||||||
avatar: {} as IAvatar,
|
avatar: {} as IAvatar,
|
||||||
permissions: {} as Record<TSupportedPermissions, string>,
|
permissions: {},
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
topic: '',
|
topic: '',
|
||||||
|
@ -158,7 +158,6 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
// @ts-ignore - Solved by migrating the hasPermission function
|
|
||||||
permissions: {
|
permissions: {
|
||||||
'set-readonly': result[0],
|
'set-readonly': result[0],
|
||||||
'set-react-when-readonly': result[1],
|
'set-react-when-readonly': result[1],
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { connect } from 'react-redux';
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription } from 'rxjs';
|
||||||
|
|
||||||
import { themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
import { withActionSheet } from '../../containers/ActionSheet';
|
import { TActionSheetOptions, TActionSheetOptionsItem, withActionSheet } from '../../containers/ActionSheet';
|
||||||
import ActivityIndicator from '../../containers/ActivityIndicator';
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
||||||
import * as HeaderButton from '../../containers/HeaderButton';
|
import * as HeaderButton from '../../containers/HeaderButton';
|
||||||
import * as List from '../../containers/List';
|
import * as List from '../../containers/List';
|
||||||
|
@ -13,7 +13,7 @@ import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
import SearchBox from '../../containers/SearchBox';
|
import SearchBox from '../../containers/SearchBox';
|
||||||
import StatusBar from '../../containers/StatusBar';
|
import StatusBar from '../../containers/StatusBar';
|
||||||
import { LISTENER } from '../../containers/Toast';
|
import { LISTENER } from '../../containers/Toast';
|
||||||
import { IApplicationState, IBaseScreen, IUser, SubscriptionType, TRoomModel, TUserModel } from '../../definitions';
|
import { IApplicationState, IBaseScreen, IUser, SubscriptionType, TSubscriptionModel, TUserModel } from '../../definitions';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import database from '../../lib/database';
|
import database from '../../lib/database';
|
||||||
import { CustomIcon } from '../../containers/CustomIcon';
|
import { CustomIcon } from '../../containers/CustomIcon';
|
||||||
|
@ -27,6 +27,7 @@ import { goRoom, TGoRoomItem } from '../../utils/goRoom';
|
||||||
import { showConfirmationAlert, showErrorAlert } from '../../utils/info';
|
import { showConfirmationAlert, showErrorAlert } from '../../utils/info';
|
||||||
import log from '../../utils/log';
|
import log from '../../utils/log';
|
||||||
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
||||||
|
import { TSupportedPermissions } from '../../reducers/permissions';
|
||||||
import { getRoomTitle, hasPermission, isGroupChat, RoomTypes } from '../../lib/methods';
|
import { getRoomTitle, hasPermission, isGroupChat, RoomTypes } from '../../lib/methods';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import { Services } from '../../lib/services';
|
import { Services } from '../../lib/services';
|
||||||
|
@ -37,13 +38,13 @@ interface IRoomMembersViewProps extends IBaseScreen<ModalStackParamList, 'RoomMe
|
||||||
rid: string;
|
rid: string;
|
||||||
members: string[];
|
members: string[];
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
room: TRoomModel;
|
room: TSubscriptionModel;
|
||||||
user: {
|
user: {
|
||||||
id: string;
|
id: string;
|
||||||
token: string;
|
token: string;
|
||||||
roles: string[];
|
roles: string[];
|
||||||
};
|
};
|
||||||
showActionSheet: (params: any) => {}; // TODO: this work?
|
showActionSheet: (params: TActionSheetOptions) => {};
|
||||||
theme: TSupportedThemes;
|
theme: TSupportedThemes;
|
||||||
isMasterDetail: boolean;
|
isMasterDetail: boolean;
|
||||||
useRealName: boolean;
|
useRealName: boolean;
|
||||||
|
@ -64,14 +65,14 @@ interface IRoomMembersViewState {
|
||||||
rid: string;
|
rid: string;
|
||||||
members: TUserModel[];
|
members: TUserModel[];
|
||||||
membersFiltered: TUserModel[];
|
membersFiltered: TUserModel[];
|
||||||
room: TRoomModel;
|
room: TSubscriptionModel;
|
||||||
end: boolean;
|
end: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMembersViewState> {
|
class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMembersViewState> {
|
||||||
private mounted: boolean;
|
private mounted: boolean;
|
||||||
private permissions: any; // TODO: fix when get props from api
|
private permissions: { [key in TSupportedPermissions]?: boolean };
|
||||||
private roomObservable!: Observable<TRoomModel>;
|
private roomObservable!: Observable<TSubscriptionModel>;
|
||||||
private subscription!: Subscription;
|
private subscription!: Subscription;
|
||||||
private roomRoles: any;
|
private roomRoles: any;
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
|
||||||
rid,
|
rid,
|
||||||
members: [],
|
members: [],
|
||||||
membersFiltered: [],
|
membersFiltered: [],
|
||||||
room: room || ({} as TRoomModel),
|
room: room || ({} as TSubscriptionModel),
|
||||||
end: false
|
end: false
|
||||||
};
|
};
|
||||||
if (room && room.observe) {
|
if (room && room.observe) {
|
||||||
|
@ -109,7 +110,6 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
|
||||||
this.mounted = true;
|
this.mounted = true;
|
||||||
this.fetchMembers();
|
this.fetchMembers();
|
||||||
|
|
||||||
// @ts-ignore - TODO: room param is wrong
|
|
||||||
if (isGroupChat(room)) {
|
if (isGroupChat(room)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ class RoomMembersView extends React.Component<IRoomMembersViewProps, IRoomMember
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
const { showActionSheet, user, theme } = this.props;
|
const { showActionSheet, user, theme } = this.props;
|
||||||
|
|
||||||
const options: {}[] = [
|
const options: TActionSheetOptionsItem[] = [
|
||||||
{
|
{
|
||||||
icon: 'message',
|
icon: 'message',
|
||||||
title: I18n.t('Direct_message'),
|
title: I18n.t('Direct_message'),
|
||||||
|
|
Loading…
Reference in New Issue