소스 검색

[ADD] task reducer

Gogs 7 년 전
부모
커밋
4dccca3431
6개의 변경된 파일47개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 3
      src/components/pages/TasksList.js
  2. 0 0
      src/reducers/app.js
  3. 2 0
      src/reducers/index.js
  4. 8 2
      src/reducers/notification.js
  5. 36 0
      src/reducers/task.js
  6. 0 12
      src/reducers/user.js

+ 1 - 3
src/components/pages/TasksList.js

@@ -179,9 +179,7 @@ const mapDispatchToProps = (dispatch, props) => ({
      * 
      */
     createOdoo(name) {
-        dispatch(post(`${ODOO}create/`, {
-            name
-        }))
+        dispatch(post(`${ODOO}create/`, { name }))
     }
 })
 

+ 0 - 0
src/reducers/app.js


+ 2 - 0
src/reducers/index.js

@@ -8,6 +8,7 @@ import { auth } from './auth'
 import { spinner } from './spinner'
 import { notification } from './notification'
 import { containers } from './containers'
+import { task } from './task'
 import { requests } from './requests'
 
 const history = createBrowserHistory()
@@ -17,6 +18,7 @@ const rootReducer = combineReducers({
     spinner,
     notification,
     containers,
+    task,
     requests,
     router: routerReducer
 })

+ 8 - 2
src/reducers/notification.js

@@ -29,7 +29,8 @@ const hideNotification = () => {
 const notificationVisibilityReducer = createReducer(false, {
     'LOGIN_FAILURE': showNotification,
     'CHECK_TOKEN_FAILURE': hideNotification,
-    'HIDE_NOTIFICATION': hideNotification
+    'HIDE_NOTIFICATION': hideNotification,
+    'REQUEST_KO': showNotification
 })
 
 /**
@@ -46,6 +47,10 @@ const setNotificationMessage = (message, action) => {
         return null
     }
 
+    if (action.type === 'REQUEST_KO' && action.payload !== 401) {
+        return 'No se pudo procesar su petición, intente nuevamente'
+    }
+
     return null
 }
 
@@ -55,7 +60,8 @@ const setNotificationMessage = (message, action) => {
 const notificationMessageReducer = createReducer(null, {
     'LOGIN_FAILURE': setNotificationMessage,
     'CHECK_TOKEN_FAILURE': setNotificationMessage,
-    'HIDE_NOTIFICATION': setNotificationMessage
+    'HIDE_NOTIFICATION': setNotificationMessage,
+    'REQUEST_KO': setNotificationMessage
 })
 
 /**

+ 36 - 0
src/reducers/task.js

@@ -0,0 +1,36 @@
+import { createReducer } from '../utils/reducer'
+import { has } from 'lodash'
+
+const initialState = {
+    running: false
+}
+
+const executePosAction = (running, action) => {
+    if (!has(action.payload, 'action')) {
+        return running
+    }
+
+    if (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')
+    }
+
+    return running
+}
+
+const taskReducer = createReducer(false, {
+    'REQUEST_OK': executePosAction
+})
+
+/**
+ * 
+ * @param {*} state 
+ * @param {*} action 
+ */
+export const task = (state = initialState, action) => {
+    return taskReducer(state.running, action)
+}

+ 0 - 12
src/reducers/user.js

@@ -1,12 +0,0 @@
-const initialState = {
-    username: null
-}
-
-/**
- * 
- * @param {*} state 
- * @param {*} payload 
- */
-export const user = (state = initialState, payload) => {
-
-}