|
@@ -1,125 +0,0 @@
|
|
-import { isEqual, has, isString } from 'lodash'
|
|
|
|
-import { setToken } from '../utils/auth'
|
|
|
|
-import {
|
|
|
|
- REQUEST_START,
|
|
|
|
- REQUEST_KO,
|
|
|
|
- SHOW_SPINNER,
|
|
|
|
- HIDE_SPINNER,
|
|
|
|
- SHOW_NOTIFICATION,
|
|
|
|
- HIDE_NOTIFICATION,
|
|
|
|
- REQUEST_OK
|
|
|
|
-} from '../constants/ActionTypes';
|
|
|
|
-
|
|
|
|
-const initialState = {
|
|
|
|
- spinner: {
|
|
|
|
- isOpen: false,
|
|
|
|
- message: null,
|
|
|
|
- },
|
|
|
|
- notification: {
|
|
|
|
- isOpen: false,
|
|
|
|
- message: null
|
|
|
|
- },
|
|
|
|
- dialog: {
|
|
|
|
- isOpen: false,
|
|
|
|
- message: null
|
|
|
|
- },
|
|
|
|
- isAuthenticated: true
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- *
|
|
|
|
- * @param {*} state
|
|
|
|
- * @param {*} action
|
|
|
|
- */
|
|
|
|
-export const app = (state = initialState, action) => {
|
|
|
|
- if (isEqual(action.type, SHOW_SPINNER) || isEqual(action.type, REQUEST_START)) {
|
|
|
|
- state = {
|
|
|
|
- ...state,
|
|
|
|
- spinner: {
|
|
|
|
- isOpen: true,
|
|
|
|
- message: action.payload
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (isEqual(action.type, HIDE_SPINNER) || isEqual(action.type, REQUEST_OK)) {
|
|
|
|
- // Response is auth
|
|
|
|
- if (has(action.payload, 'auth')) {
|
|
|
|
- state = {
|
|
|
|
- ...state,
|
|
|
|
- isAuthenticated: action.payload.auth
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Response has token
|
|
|
|
- if (has(action.payload, 'token')) {
|
|
|
|
- setToken(action.payload.token)
|
|
|
|
-
|
|
|
|
- state = {
|
|
|
|
- ...state,
|
|
|
|
- isAuthenticated: true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Response is action
|
|
|
|
- if (has(action.payload, 'action')) {
|
|
|
|
- if (isEqual(action.payload.action.type, 'redirect')) {
|
|
|
|
- const params = {
|
|
|
|
- ip: action.payload.action.ip,
|
|
|
|
- port: action.payload.action.port
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- window.open(`${window.location.protocol}//${params.ip}:${params.port}`, '_blank')
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Hide spinner
|
|
|
|
- state = {
|
|
|
|
- ...state,
|
|
|
|
- spinner: {
|
|
|
|
- isOpen: false,
|
|
|
|
- message: isString(action.payload) ? action.payload : null
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // if (isEqual(action.type, REQUEST_KO)) {
|
|
|
|
- // const status = action.payload.status
|
|
|
|
-
|
|
|
|
- // if (status === 401) {
|
|
|
|
- // return {
|
|
|
|
- // ...state,
|
|
|
|
- // spinner: {
|
|
|
|
- // isOpen: false
|
|
|
|
- // },
|
|
|
|
- // isAuthenticated: false
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- if (isEqual(action.type, SHOW_NOTIFICATION)) {
|
|
|
|
- state = {
|
|
|
|
- ...state,
|
|
|
|
- spinner: {
|
|
|
|
- isOpen: false,
|
|
|
|
- message: null
|
|
|
|
- },
|
|
|
|
- notification: {
|
|
|
|
- isOpen: true,
|
|
|
|
- message: isString(action.payload) ? action.payload : 'No se pudo terminar la petición'
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (isEqual(action.type, HIDE_NOTIFICATION)) {
|
|
|
|
- state = {
|
|
|
|
- ...state,
|
|
|
|
- notification: {
|
|
|
|
- isOpen: false,
|
|
|
|
- message: null
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return state
|
|
|
|
-}
|
|
|