chore: migrate redux module inviteUsers to typescript
This commit is contained in:
parent
2946c4724e
commit
68a8bf942d
|
@ -1,54 +0,0 @@
|
||||||
import * as types from './actionsTypes';
|
|
||||||
|
|
||||||
export function inviteLinksSetToken(token) {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.SET_TOKEN,
|
|
||||||
token
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inviteLinksRequest(token) {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.REQUEST,
|
|
||||||
token
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inviteLinksSuccess() {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.SUCCESS
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inviteLinksFailure() {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.FAILURE
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inviteLinksClear() {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.CLEAR
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inviteLinksCreate(rid) {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.CREATE,
|
|
||||||
rid
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inviteLinksSetParams(params) {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.SET_PARAMS,
|
|
||||||
params
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inviteLinksSetInvite(invite) {
|
|
||||||
return {
|
|
||||||
type: types.INVITE_LINKS.SET_INVITE,
|
|
||||||
invite
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
import { Action } from 'redux';
|
||||||
|
|
||||||
|
import { TInvite } from '../reducers/inviteLinks';
|
||||||
|
import { INVITE_LINKS } from './actionsTypes';
|
||||||
|
|
||||||
|
interface IInviteLinksGeneric extends Action {
|
||||||
|
token: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IInviteLinksCreate extends Action {
|
||||||
|
rid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IInviteLinksSetInvite extends Action {
|
||||||
|
invite: TInvite;
|
||||||
|
}
|
||||||
|
|
||||||
|
type TParams = Record<string, any>;
|
||||||
|
|
||||||
|
interface IInviteLinksSetParams extends Action {
|
||||||
|
params: TParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TActionInviteLinks = IInviteLinksGeneric & IInviteLinksCreate & IInviteLinksSetInvite & IInviteLinksSetParams;
|
||||||
|
|
||||||
|
export const inviteLinksSetToken = (token: string): IInviteLinksGeneric => ({
|
||||||
|
type: INVITE_LINKS.SET_TOKEN,
|
||||||
|
token
|
||||||
|
});
|
||||||
|
|
||||||
|
export const inviteLinksRequest = (token: string): IInviteLinksGeneric => ({
|
||||||
|
type: INVITE_LINKS.REQUEST,
|
||||||
|
token
|
||||||
|
});
|
||||||
|
|
||||||
|
export const inviteLinksSuccess = (): Action => ({
|
||||||
|
type: INVITE_LINKS.SUCCESS
|
||||||
|
});
|
||||||
|
|
||||||
|
export const inviteLinksFailure = (): Action => ({
|
||||||
|
type: INVITE_LINKS.FAILURE
|
||||||
|
});
|
||||||
|
|
||||||
|
export const inviteLinksClear = (): Action => ({
|
||||||
|
type: INVITE_LINKS.CLEAR
|
||||||
|
});
|
||||||
|
|
||||||
|
export const inviteLinksCreate = (rid: string): IInviteLinksCreate => ({
|
||||||
|
type: INVITE_LINKS.CREATE,
|
||||||
|
rid
|
||||||
|
});
|
||||||
|
|
||||||
|
export const inviteLinksSetParams = (params: TParams): IInviteLinksSetParams => ({
|
||||||
|
type: INVITE_LINKS.SET_PARAMS,
|
||||||
|
params
|
||||||
|
});
|
||||||
|
|
||||||
|
export const inviteLinksSetInvite = (invite: TInvite): IInviteLinksSetInvite => ({
|
||||||
|
type: INVITE_LINKS.SET_INVITE,
|
||||||
|
invite
|
||||||
|
});
|
|
@ -24,11 +24,12 @@ export function selectServerFailure() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serverRequest(server, username = null, fromServerHistory = false) {
|
// TODO
|
||||||
|
export function serverRequest(server, username, fromServerHistory = false) {
|
||||||
return {
|
return {
|
||||||
type: SERVER.REQUEST,
|
type: SERVER.REQUEST,
|
||||||
server,
|
server,
|
||||||
username,
|
username: username || null,
|
||||||
fromServerHistory
|
fromServerHistory
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ export * from './INotification';
|
||||||
export * from './IRoom';
|
export * from './IRoom';
|
||||||
export * from './IServer';
|
export * from './IServer';
|
||||||
export * from './ISubscription';
|
export * from './ISubscription';
|
||||||
|
export * from './IServerHistory';
|
||||||
|
|
||||||
export interface IBaseScreen<T extends Record<string, object | undefined>, S extends string> {
|
export interface IBaseScreen<T extends Record<string, object | undefined>, S extends string> {
|
||||||
navigation: StackNavigationProp<T, S>;
|
navigation: StackNavigationProp<T, S>;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
|
||||||
import { TActionActiveUsers } from '../../actions/activeUsers';
|
import { TActionActiveUsers } from '../../actions/activeUsers';
|
||||||
|
import { TActionInviteLinks } from '../../actions/inviteLinks';
|
||||||
|
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
||||||
// REDUCERS
|
// REDUCERS
|
||||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||||
|
import { IInviteLinks } from '../../reducers/inviteLinks';
|
||||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||||
|
|
||||||
export interface IApplicationState {
|
export interface IApplicationState {
|
||||||
|
@ -19,7 +21,7 @@ export interface IApplicationState {
|
||||||
customEmojis: any;
|
customEmojis: any;
|
||||||
activeUsers: IActiveUsers;
|
activeUsers: IActiveUsers;
|
||||||
usersTyping: any;
|
usersTyping: any;
|
||||||
inviteLinks: any;
|
inviteLinks: IInviteLinks;
|
||||||
createDiscussion: any;
|
createDiscussion: any;
|
||||||
inquiry: any;
|
inquiry: any;
|
||||||
enterpriseModules: any;
|
enterpriseModules: any;
|
||||||
|
@ -28,4 +30,4 @@ export interface IApplicationState {
|
||||||
roles: any;
|
roles: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers;
|
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionInviteLinks;
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
import {
|
||||||
|
inviteLinksClear,
|
||||||
|
inviteLinksFailure,
|
||||||
|
inviteLinksRequest,
|
||||||
|
inviteLinksSetInvite,
|
||||||
|
inviteLinksSetParams,
|
||||||
|
inviteLinksSetToken,
|
||||||
|
inviteLinksSuccess
|
||||||
|
} from '../actions/inviteLinks';
|
||||||
|
import { initialState } from './inviteLinks';
|
||||||
|
import { mockedStore } from './mockedStore';
|
||||||
|
|
||||||
|
describe('test roles reducer', () => {
|
||||||
|
const invite = {
|
||||||
|
_id: 'nZestg',
|
||||||
|
days: 1,
|
||||||
|
maxUses: 0,
|
||||||
|
createdAt: '2022-01-17T20:32:44.695Z',
|
||||||
|
expires: '2022-01-18T20:32:44.695Z',
|
||||||
|
uses: 0,
|
||||||
|
_updatedAt: '2022-01-17T20:32:44.695Z',
|
||||||
|
url: 'https://go.rocket.chat/invite?host=open.rocket.chat&path=invite%2FnZestg',
|
||||||
|
success: true,
|
||||||
|
token: ''
|
||||||
|
};
|
||||||
|
it('should return initial state', () => {
|
||||||
|
const state = mockedStore.getState().inviteLinks;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return initialState after call inviteLinksFailure', () => {
|
||||||
|
mockedStore.dispatch(inviteLinksFailure());
|
||||||
|
const state = mockedStore.getState().inviteLinks;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return initialState after call inviteLinksSuccess', () => {
|
||||||
|
mockedStore.dispatch(inviteLinksSuccess());
|
||||||
|
const state = mockedStore.getState().inviteLinks;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correctly token after call inviteLinksSetToken', () => {
|
||||||
|
mockedStore.dispatch(inviteLinksSetToken('xxx'));
|
||||||
|
const { token } = mockedStore.getState().inviteLinks;
|
||||||
|
expect(token).toEqual('xxx');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correctly invite value after call inviteLinksSetInvite', () => {
|
||||||
|
mockedStore.dispatch(inviteLinksSetInvite(invite));
|
||||||
|
const state = mockedStore.getState().inviteLinks;
|
||||||
|
expect(state.invite).toEqual(invite);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return modified store after call inviteLinksSetParams', () => {
|
||||||
|
mockedStore.dispatch(inviteLinksSetParams({ token: 'nZestg' }));
|
||||||
|
const { token } = mockedStore.getState().inviteLinks;
|
||||||
|
expect(token).toEqual('nZestg');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return initialState after call inviteLinksClear', () => {
|
||||||
|
mockedStore.dispatch(inviteLinksClear());
|
||||||
|
const state = mockedStore.getState().inviteLinks;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return actual state after call inviteLinksRequest', () => {
|
||||||
|
mockedStore.dispatch(inviteLinksRequest('xxx'));
|
||||||
|
const state = mockedStore.getState().inviteLinks;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,18 +1,26 @@
|
||||||
|
import { TActionInviteLinks } from '../actions/inviteLinks';
|
||||||
import { INVITE_LINKS } from '../actions/actionsTypes';
|
import { INVITE_LINKS } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
export type TInvite = { url: string; expires: string; maxUses: number; uses: number; [x: string]: any };
|
||||||
|
|
||||||
|
export interface IInviteLinks {
|
||||||
|
token: string;
|
||||||
|
days: number;
|
||||||
|
maxUses: number;
|
||||||
|
invite: TInvite;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const initialState: IInviteLinks = {
|
||||||
token: '',
|
token: '',
|
||||||
days: 1,
|
days: 1,
|
||||||
maxUses: 0,
|
maxUses: 0,
|
||||||
invite: {}
|
invite: { url: '', expires: '', maxUses: 0, uses: 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (state = initialState, action) => {
|
export default (state = initialState, action: TActionInviteLinks): IInviteLinks => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case INVITE_LINKS.SET_TOKEN:
|
case INVITE_LINKS.SET_TOKEN:
|
||||||
return {
|
return { ...state, token: action.token };
|
||||||
token: action.token
|
|
||||||
};
|
|
||||||
case INVITE_LINKS.SET_PARAMS:
|
case INVITE_LINKS.SET_PARAMS:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
|
@ -1,25 +1,21 @@
|
||||||
|
import { StackNavigationOptions } from '@react-navigation/stack';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { TextInputProps, View } from 'react-native';
|
import { TextInputProps, View } from 'react-native';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import RNPickerSelect from 'react-native-picker-select';
|
import RNPickerSelect from 'react-native-picker-select';
|
||||||
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
import { connect } from 'react-redux';
|
||||||
import { RouteProp } from '@react-navigation/core';
|
|
||||||
import { Dispatch } from 'redux';
|
|
||||||
|
|
||||||
import {
|
import { inviteLinksCreate, inviteLinksSetParams } from '../../actions/inviteLinks';
|
||||||
inviteLinksCreate as inviteLinksCreateAction,
|
|
||||||
inviteLinksSetParams as inviteLinksSetParamsAction
|
|
||||||
} from '../../actions/inviteLinks';
|
|
||||||
import * as List from '../../containers/List';
|
|
||||||
import Button from '../../containers/Button';
|
|
||||||
import I18n from '../../i18n';
|
|
||||||
import StatusBar from '../../containers/StatusBar';
|
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
import { withTheme } from '../../theme';
|
import Button from '../../containers/Button';
|
||||||
|
import * as List from '../../containers/List';
|
||||||
import SafeAreaView from '../../containers/SafeAreaView';
|
import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
|
import StatusBar from '../../containers/StatusBar';
|
||||||
|
import { IApplicationState, IBaseScreen } from '../../definitions';
|
||||||
|
import I18n from '../../i18n';
|
||||||
|
import { ChatsStackParamList } from '../../stacks/types';
|
||||||
|
import { withTheme } from '../../theme';
|
||||||
import { events, logEvent } from '../../utils/log';
|
import { events, logEvent } from '../../utils/log';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import { ChatsStackParamList } from '../../stacks/types';
|
|
||||||
|
|
||||||
const OPTIONS = {
|
const OPTIONS = {
|
||||||
days: [
|
days: [
|
||||||
|
@ -68,12 +64,7 @@ const OPTIONS = {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
interface IInviteUsersEditViewProps {
|
interface IInviteUsersEditViewProps extends IBaseScreen<ChatsStackParamList, 'InviteUsersEditView'> {
|
||||||
navigation: StackNavigationProp<ChatsStackParamList, 'InviteUsersEditView'>;
|
|
||||||
route: RouteProp<ChatsStackParamList, 'InviteUsersEditView'>;
|
|
||||||
theme: string;
|
|
||||||
createInviteLink(rid: string): void;
|
|
||||||
inviteLinksSetParams(params: { [key: string]: number }): void;
|
|
||||||
days: number;
|
days: number;
|
||||||
maxUses: number;
|
maxUses: number;
|
||||||
}
|
}
|
||||||
|
@ -91,18 +82,18 @@ class InviteUsersEditView extends React.Component<IInviteUsersEditViewProps, any
|
||||||
}
|
}
|
||||||
|
|
||||||
onValueChangePicker = (key: string, value: number) => {
|
onValueChangePicker = (key: string, value: number) => {
|
||||||
|
const { dispatch } = this.props;
|
||||||
logEvent(events.IU_EDIT_SET_LINK_PARAM);
|
logEvent(events.IU_EDIT_SET_LINK_PARAM);
|
||||||
const { inviteLinksSetParams } = this.props;
|
|
||||||
const params = {
|
const params = {
|
||||||
[key]: value
|
[key]: value
|
||||||
};
|
};
|
||||||
inviteLinksSetParams(params);
|
dispatch(inviteLinksSetParams(params));
|
||||||
};
|
};
|
||||||
|
|
||||||
createInviteLink = () => {
|
createInviteLink = () => {
|
||||||
|
const { dispatch, navigation } = this.props;
|
||||||
logEvent(events.IU_EDIT_CREATE_LINK);
|
logEvent(events.IU_EDIT_CREATE_LINK);
|
||||||
const { createInviteLink, navigation } = this.props;
|
dispatch(inviteLinksCreate(this.rid));
|
||||||
createInviteLink(this.rid);
|
|
||||||
navigation.pop();
|
navigation.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -151,14 +142,9 @@ class InviteUsersEditView extends React.Component<IInviteUsersEditViewProps, any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state: any) => ({
|
const mapStateToProps = (state: IApplicationState) => ({
|
||||||
days: state.inviteLinks.days,
|
days: state.inviteLinks.days,
|
||||||
maxUses: state.inviteLinks.maxUses
|
maxUses: state.inviteLinks.maxUses
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
export default connect(mapStateToProps)(withTheme(InviteUsersEditView));
|
||||||
inviteLinksSetParams: (params: object) => dispatch(inviteLinksSetParamsAction(params)),
|
|
||||||
createInviteLink: (rid: string) => dispatch(inviteLinksCreateAction(rid))
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(InviteUsersEditView));
|
|
||||||
|
|
|
@ -1,62 +1,49 @@
|
||||||
|
import { StackNavigationOptions } from '@react-navigation/stack';
|
||||||
|
import moment from 'moment';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { ScrollView, Share, View } from 'react-native';
|
import { ScrollView, Share, View } from 'react-native';
|
||||||
import moment from 'moment';
|
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { StackNavigationProp, StackNavigationOptions } from '@react-navigation/stack';
|
|
||||||
import { RouteProp } from '@react-navigation/core';
|
|
||||||
import { Dispatch } from 'redux';
|
|
||||||
|
|
||||||
import { ChatsStackParamList } from '../../stacks/types';
|
import { inviteLinksClear, inviteLinksCreate } from '../../actions/inviteLinks';
|
||||||
import {
|
|
||||||
inviteLinksClear as inviteLinksClearAction,
|
|
||||||
inviteLinksCreate as inviteLinksCreateAction
|
|
||||||
} from '../../actions/inviteLinks';
|
|
||||||
import RCTextInput from '../../containers/TextInput';
|
|
||||||
import Markdown from '../../containers/markdown';
|
|
||||||
import Button from '../../containers/Button';
|
|
||||||
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
|
||||||
import I18n from '../../i18n';
|
|
||||||
import StatusBar from '../../containers/StatusBar';
|
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
import { withTheme } from '../../theme';
|
import Button from '../../containers/Button';
|
||||||
|
import Markdown from '../../containers/markdown';
|
||||||
import SafeAreaView from '../../containers/SafeAreaView';
|
import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
|
import StatusBar from '../../containers/StatusBar';
|
||||||
|
import RCTextInput from '../../containers/TextInput';
|
||||||
|
import { IApplicationState, IBaseScreen } from '../../definitions';
|
||||||
|
import I18n from '../../i18n';
|
||||||
|
import { TInvite } from '../../reducers/inviteLinks';
|
||||||
|
import { ChatsStackParamList } from '../../stacks/types';
|
||||||
|
import { withTheme } from '../../theme';
|
||||||
import { events, logEvent } from '../../utils/log';
|
import { events, logEvent } from '../../utils/log';
|
||||||
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
|
|
||||||
interface IInviteUsersViewProps {
|
interface IInviteUsersViewProps extends IBaseScreen<ChatsStackParamList, 'InviteUsersView'> {
|
||||||
navigation: StackNavigationProp<ChatsStackParamList, 'InviteUsersView'>;
|
|
||||||
route: RouteProp<ChatsStackParamList, 'InviteUsersView'>;
|
|
||||||
theme: string;
|
|
||||||
timeDateFormat: string;
|
timeDateFormat: string;
|
||||||
invite: {
|
invite: TInvite;
|
||||||
url: string;
|
|
||||||
expires: number;
|
|
||||||
maxUses: number;
|
|
||||||
uses: number;
|
|
||||||
};
|
|
||||||
createInviteLink(rid: string): void;
|
|
||||||
clearInviteLink(): void;
|
|
||||||
}
|
}
|
||||||
class InviteUsersView extends React.Component<IInviteUsersViewProps, any> {
|
class InviteUsersView extends React.Component<IInviteUsersViewProps, any> {
|
||||||
private rid: string;
|
|
||||||
|
|
||||||
static navigationOptions = (): StackNavigationOptions => ({
|
static navigationOptions = (): StackNavigationOptions => ({
|
||||||
title: I18n.t('Invite_users')
|
title: I18n.t('Invite_users')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
private rid: string;
|
||||||
|
|
||||||
constructor(props: IInviteUsersViewProps) {
|
constructor(props: IInviteUsersViewProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.rid = props.route.params?.rid;
|
this.rid = props.route.params?.rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { createInviteLink } = this.props;
|
const { dispatch } = this.props;
|
||||||
createInviteLink(this.rid);
|
dispatch(inviteLinksCreate(this.rid));
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
const { clearInviteLink } = this.props;
|
const { dispatch } = this.props;
|
||||||
clearInviteLink();
|
dispatch(inviteLinksClear());
|
||||||
}
|
}
|
||||||
|
|
||||||
share = () => {
|
share = () => {
|
||||||
|
@ -133,16 +120,9 @@ class InviteUsersView extends React.Component<IInviteUsersViewProps, any> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state: any) => ({
|
const mapStateToProps = (state: IApplicationState) => ({
|
||||||
timeDateFormat: state.settings.Message_TimeAndDateFormat,
|
timeDateFormat: state.settings.Message_TimeAndDateFormat,
|
||||||
days: state.inviteLinks.days,
|
|
||||||
maxUses: state.inviteLinks.maxUses,
|
|
||||||
invite: state.inviteLinks.invite
|
invite: state.inviteLinks.invite
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
export default connect(mapStateToProps)(withTheme(InviteUsersView));
|
||||||
createInviteLink: (rid: string) => dispatch(inviteLinksCreateAction(rid)),
|
|
||||||
clearInviteLink: () => dispatch(inviteLinksClearAction())
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(InviteUsersView));
|
|
||||||
|
|
|
@ -1,39 +1,37 @@
|
||||||
import React from 'react';
|
|
||||||
import { Text, Keyboard, StyleSheet, View, BackHandler, Image } from 'react-native';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { Base64 } from 'js-base64';
|
|
||||||
import parse from 'url-parse';
|
|
||||||
import { Q } from '@nozbe/watermelondb';
|
import { Q } from '@nozbe/watermelondb';
|
||||||
|
import { Base64 } from 'js-base64';
|
||||||
|
import React from 'react';
|
||||||
|
import { BackHandler, Image, Keyboard, StyleSheet, Text, View } from 'react-native';
|
||||||
import { TouchableOpacity } from 'react-native-gesture-handler';
|
import { TouchableOpacity } from 'react-native-gesture-handler';
|
||||||
import Orientation from 'react-native-orientation-locker';
|
import Orientation from 'react-native-orientation-locker';
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
import { connect } from 'react-redux';
|
||||||
import { Dispatch } from 'redux';
|
import parse from 'url-parse';
|
||||||
|
|
||||||
import UserPreferences from '../../lib/userPreferences';
|
import { inviteLinksClear } from '../../actions/inviteLinks';
|
||||||
import EventEmitter from '../../utils/events';
|
import { selectServerRequest, serverFinishAdd, serverRequest } from '../../actions/server';
|
||||||
import { selectServerRequest, serverRequest, serverFinishAdd as serverFinishAddAction } from '../../actions/server';
|
|
||||||
import { inviteLinksClear as inviteLinksClearAction } from '../../actions/inviteLinks';
|
|
||||||
import sharedStyles from '../Styles';
|
|
||||||
import Button from '../../containers/Button';
|
|
||||||
import OrSeparator from '../../containers/OrSeparator';
|
|
||||||
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
|
||||||
import I18n from '../../i18n';
|
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
import { events, logEvent } from '../../utils/log';
|
import Button from '../../containers/Button';
|
||||||
import { withTheme } from '../../theme';
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
||||||
import { BASIC_AUTH_KEY, setBasicAuth } from '../../utils/fetch';
|
|
||||||
import * as HeaderButton from '../../containers/HeaderButton';
|
import * as HeaderButton from '../../containers/HeaderButton';
|
||||||
import { showConfirmationAlert } from '../../utils/info';
|
import OrSeparator from '../../containers/OrSeparator';
|
||||||
|
import { IBaseScreen, TServerHistory } from '../../definitions';
|
||||||
|
import { withDimensions } from '../../dimensions';
|
||||||
|
import I18n from '../../i18n';
|
||||||
import database from '../../lib/database';
|
import database from '../../lib/database';
|
||||||
import { sanitizeLikeString } from '../../lib/database/utils';
|
import { sanitizeLikeString } from '../../lib/database/utils';
|
||||||
import SSLPinning from '../../utils/sslPinning';
|
|
||||||
import RocketChat from '../../lib/rocketchat';
|
import RocketChat from '../../lib/rocketchat';
|
||||||
import { isTablet } from '../../utils/deviceInfo';
|
import UserPreferences from '../../lib/userPreferences';
|
||||||
import { verticalScale, moderateScale } from '../../utils/scaling';
|
|
||||||
import { withDimensions } from '../../dimensions';
|
|
||||||
import ServerInput from './ServerInput';
|
|
||||||
import { OutsideParamList } from '../../stacks/types';
|
import { OutsideParamList } from '../../stacks/types';
|
||||||
import { TServerHistory } from '../../definitions/IServerHistory';
|
import { withTheme } from '../../theme';
|
||||||
|
import { isTablet } from '../../utils/deviceInfo';
|
||||||
|
import EventEmitter from '../../utils/events';
|
||||||
|
import { BASIC_AUTH_KEY, setBasicAuth } from '../../utils/fetch';
|
||||||
|
import { showConfirmationAlert } from '../../utils/info';
|
||||||
|
import { events, logEvent } from '../../utils/log';
|
||||||
|
import { moderateScale, verticalScale } from '../../utils/scaling';
|
||||||
|
import SSLPinning from '../../utils/sslPinning';
|
||||||
|
import sharedStyles from '../Styles';
|
||||||
|
import ServerInput from './ServerInput';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
onboardingImage: {
|
onboardingImage: {
|
||||||
|
@ -68,20 +66,14 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
interface INewServerView {
|
interface INewServerViewProps extends IBaseScreen<OutsideParamList, 'NewServerView'> {
|
||||||
navigation: StackNavigationProp<OutsideParamList, 'NewServerView'>;
|
|
||||||
theme: string;
|
|
||||||
connecting: boolean;
|
connecting: boolean;
|
||||||
connectServer(server: string, username?: string, fromServerHistory?: boolean): void;
|
|
||||||
selectServer(server: string): void;
|
|
||||||
previousServer: string;
|
previousServer: string;
|
||||||
inviteLinksClear(): void;
|
|
||||||
serverFinishAdd(): void;
|
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface INewServerViewState {
|
||||||
text: string;
|
text: string;
|
||||||
connectingOpen: boolean;
|
connectingOpen: boolean;
|
||||||
certificate: any;
|
certificate: any;
|
||||||
|
@ -93,8 +85,8 @@ interface ISubmitParams {
|
||||||
username?: string;
|
username?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NewServerView extends React.Component<INewServerView, IState> {
|
class NewServerView extends React.Component<INewServerViewProps, INewServerViewState> {
|
||||||
constructor(props: INewServerView) {
|
constructor(props: INewServerViewProps) {
|
||||||
super(props);
|
super(props);
|
||||||
if (!isTablet) {
|
if (!isTablet) {
|
||||||
Orientation.lockToPortrait();
|
Orientation.lockToPortrait();
|
||||||
|
@ -118,9 +110,9 @@ class NewServerView extends React.Component<INewServerView, IState> {
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
EventEmitter.removeListener('NewServer', this.handleNewServerEvent);
|
EventEmitter.removeListener('NewServer', this.handleNewServerEvent);
|
||||||
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
|
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
|
||||||
const { previousServer, serverFinishAdd } = this.props;
|
const { previousServer, dispatch } = this.props;
|
||||||
if (previousServer) {
|
if (previousServer) {
|
||||||
serverFinishAdd();
|
dispatch(serverFinishAdd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +161,9 @@ class NewServerView extends React.Component<INewServerView, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
close = () => {
|
close = () => {
|
||||||
const { selectServer, previousServer, inviteLinksClear } = this.props;
|
const { dispatch, previousServer } = this.props;
|
||||||
inviteLinksClear();
|
dispatch(inviteLinksClear());
|
||||||
selectServer(previousServer);
|
dispatch(selectServerRequest(previousServer));
|
||||||
};
|
};
|
||||||
|
|
||||||
handleNewServerEvent = (event: { server: string }) => {
|
handleNewServerEvent = (event: { server: string }) => {
|
||||||
|
@ -179,10 +171,10 @@ class NewServerView extends React.Component<INewServerView, IState> {
|
||||||
if (!server) {
|
if (!server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { connectServer } = this.props;
|
const { dispatch } = this.props;
|
||||||
this.setState({ text: server });
|
this.setState({ text: server });
|
||||||
server = this.completeUrl(server);
|
server = this.completeUrl(server);
|
||||||
connectServer(server);
|
dispatch(serverRequest(server));
|
||||||
};
|
};
|
||||||
|
|
||||||
onPressServerHistory = (serverHistory: TServerHistory) => {
|
onPressServerHistory = (serverHistory: TServerHistory) => {
|
||||||
|
@ -192,7 +184,7 @@ class NewServerView extends React.Component<INewServerView, IState> {
|
||||||
submit = async ({ fromServerHistory = false, username }: ISubmitParams = {}) => {
|
submit = async ({ fromServerHistory = false, username }: ISubmitParams = {}) => {
|
||||||
logEvent(events.NS_CONNECT_TO_WORKSPACE);
|
logEvent(events.NS_CONNECT_TO_WORKSPACE);
|
||||||
const { text, certificate } = this.state;
|
const { text, certificate } = this.state;
|
||||||
const { connectServer } = this.props;
|
const { dispatch } = this.props;
|
||||||
|
|
||||||
this.setState({ connectingOpen: false });
|
this.setState({ connectingOpen: false });
|
||||||
|
|
||||||
|
@ -207,9 +199,9 @@ class NewServerView extends React.Component<INewServerView, IState> {
|
||||||
await this.basicAuth(server, text);
|
await this.basicAuth(server, text);
|
||||||
|
|
||||||
if (fromServerHistory) {
|
if (fromServerHistory) {
|
||||||
connectServer(server, username, true);
|
dispatch(serverRequest(server, username, true));
|
||||||
} else {
|
} else {
|
||||||
connectServer(server);
|
dispatch(serverRequest(server));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -217,8 +209,8 @@ class NewServerView extends React.Component<INewServerView, IState> {
|
||||||
connectOpen = () => {
|
connectOpen = () => {
|
||||||
logEvent(events.NS_JOIN_OPEN_WORKSPACE);
|
logEvent(events.NS_JOIN_OPEN_WORKSPACE);
|
||||||
this.setState({ connectingOpen: true });
|
this.setState({ connectingOpen: true });
|
||||||
const { connectServer } = this.props;
|
const { dispatch } = this.props;
|
||||||
connectServer('https://open.rocket.chat');
|
dispatch(serverRequest('https://open.rocket.chat'));
|
||||||
};
|
};
|
||||||
|
|
||||||
basicAuth = async (server: string, text: string) => {
|
basicAuth = async (server: string, text: string) => {
|
||||||
|
@ -283,7 +275,7 @@ class NewServerView extends React.Component<INewServerView, IState> {
|
||||||
await db.write(async () => {
|
await db.write(async () => {
|
||||||
await item.destroyPermanently();
|
await item.destroyPermanently();
|
||||||
});
|
});
|
||||||
this.setState((prevstate: IState) => ({
|
this.setState((prevstate: INewServerViewState) => ({
|
||||||
serversHistory: prevstate.serversHistory.filter((server: TServerHistory) => server.id !== item.id)
|
serversHistory: prevstate.serversHistory.filter((server: TServerHistory) => server.id !== item.id)
|
||||||
}));
|
}));
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -417,12 +409,4 @@ const mapStateToProps = (state: any) => ({
|
||||||
previousServer: state.server.previousServer
|
previousServer: state.server.previousServer
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
export default connect(mapStateToProps)(withDimensions(withTheme(NewServerView)));
|
||||||
connectServer: (server: string, username: string & null, fromServerHistory?: boolean) =>
|
|
||||||
dispatch(serverRequest(server, username, fromServerHistory)),
|
|
||||||
selectServer: (server: string) => dispatch(selectServerRequest(server)),
|
|
||||||
inviteLinksClear: () => dispatch(inviteLinksClearAction()),
|
|
||||||
serverFinishAdd: () => dispatch(serverFinishAddAction())
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(withDimensions(withTheme(NewServerView)));
|
|
||||||
|
|
Loading…
Reference in New Issue