add mapping; prevent upload before mapping office / resource

This commit is contained in:
Bilal Catic
2019-06-10 05:58:09 +02:00
parent c23077d94f
commit 04c9ee3806
7 changed files with 366 additions and 8 deletions

View File

@@ -1 +1,2 @@
export * from './doorLockActions';
export * from './officeRnDActions';

View File

@@ -0,0 +1,34 @@
import {
FETCH_MAPPINGS_PENDING,
FETCH_MAPPINGS_SUCCESS,
FETCH_MAPPINGS_FAILED,
ADD_NEW_MAPPING_PENDING,
ADD_NEW_MAPPING_SUCCESS,
ADD_NEW_MAPPING_FAILED,
} from "../constants";
import API from '../../utilities/api';
export const fetchMappings = (dispatch) => {
dispatch({type: FETCH_MAPPINGS_PENDING});
API.get('doorLock/mappings')
.then(response => {
dispatch({type: FETCH_MAPPINGS_SUCCESS, payload: response.data});
})
.catch(error => {
dispatch({type: FETCH_MAPPINGS_FAILED, payload: error.response});
});
};
export const addNewMapping = (dispatch, mapping) => {
dispatch({type: ADD_NEW_MAPPING_PENDING});
API.post('doorLock/mappings', {
mapping
})
.then(response => {
dispatch({type: ADD_NEW_MAPPING_SUCCESS, payload: response.data});
})
.catch(error => {
dispatch({type: ADD_NEW_MAPPING_FAILED, payload: error.response});
});
};

View File

@@ -0,0 +1,38 @@
import {
ADD_NEW_MAPPING_PENDING,
ADD_NEW_MAPPING_SUCCESS,
ADD_NEW_MAPPING_FAILED,
} from "../constants";
const initialState = {
pending: false,
result: null,
error: null,
};
export const addMapping = (state, action) => {
state = state || initialState;
action = action || {};
switch(action.type){
case ADD_NEW_MAPPING_PENDING:
return Object.assign({}, state, {
pending: true,
error: null,
});
case ADD_NEW_MAPPING_SUCCESS:
return Object.assign({}, state, {
pending: false,
result: action.payload,
error: null,
});
case ADD_NEW_MAPPING_FAILED:
return Object.assign({}, state, {
pending: false,
result: {},
error: action.payload,
});
default:
return state;
}
};

View File

@@ -1,8 +1,12 @@
import { combineReducers } from "redux";
import { doorLockData} from "./doorLockReducers";
import { mappingsData } from "./mappingsReducer";
import { addMapping } from './addMappingReducer';
export const rootReducer = combineReducers({
doorLockData
doorLockData,
mappingsData,
addMapping,
});

View File

@@ -0,0 +1,38 @@
import {
FETCH_MAPPINGS_PENDING,
FETCH_MAPPINGS_SUCCESS,
FETCH_MAPPINGS_FAILED,
} from "../constants";
const initialState = {
pending: false,
result: null,
error: null,
};
export const mappingsData = (state, action) => {
state = state || initialState;
action = action || {};
switch(action.type){
case FETCH_MAPPINGS_PENDING:
return Object.assign({}, state, {
pending: true,
error: null,
});
case FETCH_MAPPINGS_SUCCESS:
return Object.assign({}, state, {
pending: false,
result: action.payload,
error: null,
});
case FETCH_MAPPINGS_FAILED:
return Object.assign({}, state, {
pending: false,
result: {},
error: action.payload,
});
default:
return state;
}
};