Migrate actions,reducers and action types to TS #15
This commit is contained in:
40
app/reducers/authorize/AuthorizeState.ts
Normal file
40
app/reducers/authorize/AuthorizeState.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Post state
|
||||
*
|
||||
* @export
|
||||
* @class AuthorizeState
|
||||
*/
|
||||
export class AuthorizeState {
|
||||
|
||||
/**
|
||||
* Authorized user identifier
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
uid: number = 0;
|
||||
|
||||
/**
|
||||
* If user is authed {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
authed: Boolean = false;
|
||||
|
||||
/**
|
||||
* If user password is updated {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
updatePassword: Boolean = false;
|
||||
|
||||
/**
|
||||
* If the user is guest {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
guest: Boolean = false;
|
||||
}
|
||||
15
app/reducers/authorize/IAuthorizeAction.ts
Normal file
15
app/reducers/authorize/IAuthorizeAction.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// - Import action types
|
||||
import {AuthorizeActionType} from 'constants/authorizeActionType'
|
||||
|
||||
|
||||
/**
|
||||
* Authorize action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IAuthorizeAction
|
||||
*/
|
||||
export interface IAuthorizeAction {
|
||||
payload: any;
|
||||
type: AuthorizeActionType;
|
||||
|
||||
}
|
||||
50
app/reducers/authorize/authorizeReducer.ts
Normal file
50
app/reducers/authorize/authorizeReducer.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
// - Import react components
|
||||
import {Reducer, Action} from "redux";
|
||||
|
||||
// - Import action types
|
||||
import {AuthorizeActionType} from 'constants/authorizeActionType'
|
||||
|
||||
import { IAuthorizeAction } from "./IAuthorizeAction";
|
||||
import { AuthorizeState } from "./AuthorizeState";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Authorize reducer
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export var authorizeReducer = (state : AuthorizeState = new AuthorizeState(), action: IAuthorizeAction) =>{
|
||||
const { payload } = action;
|
||||
switch (action.type) {
|
||||
case AuthorizeActionType.LOGIN:
|
||||
return{
|
||||
...state,
|
||||
uid: payload.uid,
|
||||
authed: true,
|
||||
guest:false
|
||||
}
|
||||
case AuthorizeActionType.LOGOUT:
|
||||
return{
|
||||
...state,
|
||||
uid: 0,
|
||||
authed: false,
|
||||
guest:true
|
||||
}
|
||||
|
||||
case AuthorizeActionType.SIGNUP:
|
||||
return{
|
||||
...state,
|
||||
uid: payload.userId
|
||||
}
|
||||
case AuthorizeActionType.UPDATE_PASSWORD:
|
||||
return{
|
||||
...state,
|
||||
updatePassword: payload.updatePassword
|
||||
}
|
||||
default:
|
||||
return state
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
3
app/reducers/authorize/index.ts
Normal file
3
app/reducers/authorize/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { authorizeReducer } from "./authorizeReducer";
|
||||
|
||||
export {authorizeReducer};
|
||||
Reference in New Issue
Block a user