Chore: Migrate redux module share to typescript (#3612)
* chore: migrate redux module share to typescript * chore: fix types * chore: update types * chore: migrate redux module share to typescript * remove double import * chore: fix import
This commit is contained in:
parent
03459147ed
commit
c442a8473d
|
@ -1,22 +0,0 @@
|
|||
import { SHARE } from './actionsTypes';
|
||||
|
||||
export function shareSelectServer(server) {
|
||||
return {
|
||||
type: SHARE.SELECT_SERVER,
|
||||
server
|
||||
};
|
||||
}
|
||||
|
||||
export function shareSetSettings(settings) {
|
||||
return {
|
||||
type: SHARE.SET_SETTINGS,
|
||||
settings
|
||||
};
|
||||
}
|
||||
|
||||
export function shareSetUser(user) {
|
||||
return {
|
||||
type: SHARE.SET_USER,
|
||||
user
|
||||
};
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import { Action } from 'redux';
|
||||
|
||||
import { IShareServer, IShareUser, TShareSettings } from '../reducers/share';
|
||||
import { SHARE } from './actionsTypes';
|
||||
|
||||
interface IShareSelectServer extends Action {
|
||||
server: IShareServer;
|
||||
}
|
||||
|
||||
interface IShareSetSettings extends Action {
|
||||
settings: TShareSettings;
|
||||
}
|
||||
|
||||
interface IShareSetUser extends Action {
|
||||
user: IShareUser;
|
||||
}
|
||||
|
||||
export type TActionsShare = IShareSelectServer & IShareSetSettings & IShareSetUser;
|
||||
|
||||
export function shareSelectServer(server: IShareServer): IShareSelectServer {
|
||||
return {
|
||||
type: SHARE.SELECT_SERVER,
|
||||
server
|
||||
};
|
||||
}
|
||||
|
||||
export function shareSetSettings(settings: TShareSettings): IShareSetSettings {
|
||||
return {
|
||||
type: SHARE.SET_SETTINGS,
|
||||
settings
|
||||
};
|
||||
}
|
||||
|
||||
export function shareSetUser(user: IShareUser): IShareSetUser {
|
||||
return {
|
||||
type: SHARE.SET_USER,
|
||||
user
|
||||
};
|
||||
}
|
|
@ -1,23 +1,25 @@
|
|||
// ACTIONS
|
||||
import { TActionServer } from '../../actions/server';
|
||||
import { TActionActiveUsers } from '../../actions/activeUsers';
|
||||
import { TActionCustomEmojis } from '../../actions/customEmojis';
|
||||
import { TActionEncryption } from '../../actions/encryption';
|
||||
import { TActionInviteLinks } from '../../actions/inviteLinks';
|
||||
import { IActionRoles } from '../../actions/roles';
|
||||
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
||||
import { TActionServer } from '../../actions/server';
|
||||
import { IActionSettings } from '../../actions/settings';
|
||||
import { TActionsShare } from '../../actions/share';
|
||||
import { TActionSortPreferences } from '../../actions/sortPreferences';
|
||||
import { TActionUserTyping } from '../../actions/usersTyping';
|
||||
// REDUCERS
|
||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||
import { IConnect } from '../../reducers/connect';
|
||||
import { IEncryption } from '../../reducers/encryption';
|
||||
import { IInviteLinks } from '../../reducers/inviteLinks';
|
||||
import { IRoles } from '../../reducers/roles';
|
||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||
import { IServer } from '../../reducers/server';
|
||||
import { IConnect } from '../../reducers/connect';
|
||||
import { ISettings } from '../../reducers/settings';
|
||||
import { IShare } from '../../reducers/share';
|
||||
|
||||
export interface IApplicationState {
|
||||
settings: ISettings;
|
||||
|
@ -30,7 +32,7 @@ export interface IApplicationState {
|
|||
room: any;
|
||||
rooms: any;
|
||||
sortPreferences: any;
|
||||
share: any;
|
||||
share: IShare;
|
||||
customEmojis: any;
|
||||
activeUsers: IActiveUsers;
|
||||
usersTyping: any;
|
||||
|
@ -52,4 +54,5 @@ export type TApplicationActions = TActionActiveUsers &
|
|||
TActionEncryption &
|
||||
TActionSortPreferences &
|
||||
TActionUserTyping &
|
||||
TActionsShare &
|
||||
TActionServer;
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
import { SHARE } from '../actions/actionsTypes';
|
||||
|
||||
const initialState = {
|
||||
user: {},
|
||||
server: {},
|
||||
settings: {}
|
||||
};
|
||||
|
||||
export default function share(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case SHARE.SELECT_SERVER:
|
||||
return {
|
||||
...state,
|
||||
server: action.server
|
||||
};
|
||||
case SHARE.SET_USER:
|
||||
return {
|
||||
...state,
|
||||
user: action.user
|
||||
};
|
||||
case SHARE.SET_SETTINGS:
|
||||
return {
|
||||
...state,
|
||||
settings: action.settings
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
import { shareSelectServer, shareSetSettings, shareSetUser } from '../actions/share';
|
||||
import { mockedStore } from './mockedStore';
|
||||
import { initialState } from './share';
|
||||
|
||||
describe('test share reducer', () => {
|
||||
it('should return initial state', () => {
|
||||
const state = mockedStore.getState().share;
|
||||
expect(state).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('should return modified store after shareSelectServer', () => {
|
||||
const server = {
|
||||
server: 'https://open.rocket.chat',
|
||||
version: '4.4.0'
|
||||
};
|
||||
mockedStore.dispatch(shareSelectServer(server));
|
||||
const state = mockedStore.getState().share.server;
|
||||
expect(state).toEqual(server);
|
||||
});
|
||||
|
||||
it('should return modified store after shareSetSettings', () => {
|
||||
const settings = {
|
||||
Admin: false
|
||||
};
|
||||
mockedStore.dispatch(shareSetSettings(settings));
|
||||
const state = mockedStore.getState().share.settings;
|
||||
expect(state).toEqual(settings);
|
||||
});
|
||||
|
||||
it('should return modified store after shareSetUser', () => {
|
||||
const user = {
|
||||
id: 'dig-joy',
|
||||
token: 'token',
|
||||
username: 'rocket.chat',
|
||||
roles: ['admin']
|
||||
};
|
||||
mockedStore.dispatch(shareSetUser(user));
|
||||
const state = mockedStore.getState().share.user;
|
||||
expect(state).toEqual(user);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,50 @@
|
|||
import { TActionsShare } from '../actions/share';
|
||||
import { SHARE } from '../actions/actionsTypes';
|
||||
|
||||
export interface IShareServer {
|
||||
server: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
export type TShareSettings = Record<string, string | number | boolean>;
|
||||
|
||||
export interface IShareUser {
|
||||
id: string;
|
||||
token: string;
|
||||
username: string;
|
||||
roles: string[];
|
||||
}
|
||||
|
||||
export interface IShare {
|
||||
user: IShareUser | {};
|
||||
server: IShareServer | {};
|
||||
settings: TShareSettings;
|
||||
}
|
||||
|
||||
export const initialState: IShare = {
|
||||
user: {},
|
||||
server: {},
|
||||
settings: {}
|
||||
};
|
||||
|
||||
export default function share(state = initialState, action: TActionsShare): IShare {
|
||||
switch (action.type) {
|
||||
case SHARE.SELECT_SERVER:
|
||||
return {
|
||||
...state,
|
||||
server: action.server
|
||||
};
|
||||
case SHARE.SET_USER:
|
||||
return {
|
||||
...state,
|
||||
user: action.user
|
||||
};
|
||||
case SHARE.SET_SETTINGS:
|
||||
return {
|
||||
...state,
|
||||
settings: action.settings
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue