Fixes/ll inventory (#69)
* inventory data changes * update Inventory changes * Fixed: removed unnecessary imports * Disabled: cycle count * Added: Inventory types sagas * Fix: null check * Updated: policies * Fixed: formik values * update: allow single image * Update: Policies control * Updated: new inventory add form * Update: new inventory conditional render * Update: populate formik fields * Added: Validation * Added: edit functionality, disabled fields * Update: housekeeping * Fix: iconslug and key * Update: route handling * Added: endpoints * Added: widget nested page * Added: sagas * Added: redux handling * Update: new product page functionality * Added: inventory page functionality * Fixed: form validation * Fix: route handling Co-authored-by: evdigitech <evdigitech@gmail.com> Co-authored-by: Llewellyn Dsouza <lledsouza2209@gmail.com>
This commit is contained in:
@@ -5,9 +5,18 @@ import { getFetchingValue, getErrorValue } from '../services/Utils';
|
||||
|
||||
/* ------------- Types and Action Creators ------------- */
|
||||
const { Types, Creators } = createActions({
|
||||
getInventoryAction: ['payload'],
|
||||
getInventorySuccess: ['data'],
|
||||
getInventoryFailure: ['error'],
|
||||
addInventoryAction: ['payload'],
|
||||
addInventorySuccess: ['data'],
|
||||
addInventoryFailure: ['error']
|
||||
addInventoryFailure: ['error'],
|
||||
updateInventoryAction: ['payload'],
|
||||
updateInventorySuccess: ['data'],
|
||||
updateInventoryFailure: ['error'],
|
||||
getInventoryTypesAction: ['payload'],
|
||||
getInventoryTypesSuccess: ['data'],
|
||||
getInventoryTypesFailure: ['error']
|
||||
});
|
||||
|
||||
export const InventoryTypes = Types;
|
||||
@@ -16,17 +25,44 @@ export default InventoryActions;
|
||||
|
||||
/* ------------- Initial State ------------- */
|
||||
export const INITIAL_STATE = Immutable({
|
||||
getInventoryDetail: [],
|
||||
addInventoryDetail: [],
|
||||
updateInventoryDetail: [],
|
||||
addInventoryLoading: false,
|
||||
addInventoryerror: {}
|
||||
addInventoryerror: {},
|
||||
inventoryTypes: []
|
||||
});
|
||||
|
||||
/* ------------- Selectors ------------- */
|
||||
export const InventorySelectors = {
|
||||
addInventoryDetail: (state) => state.inventory.inventoryDetail
|
||||
addInventoryDetail: (state) => state.inventory.inventoryDetail,
|
||||
getInventoryDetail: (state) => state.inventory.getInventoryDetail,
|
||||
getInventoryDetailById: (id) => (state) =>
|
||||
state.inventory.getInventoryDetail.find((x) => x._id === id),
|
||||
getInventoryTypes: (state) => state.inventory.inventoryTypes,
|
||||
updateInventoryDetail: (state) => state.inventory.updateInventoryDetail
|
||||
};
|
||||
|
||||
/* ------------- Reducers ------------- */
|
||||
export const onGetInventoryAction = (state, { payload }) =>
|
||||
state.merge({
|
||||
fetching: _.uniq([state.fetching, payload?.loader]),
|
||||
error: getErrorValue(state?.error, payload?.loader)
|
||||
});
|
||||
|
||||
export const onGetInventorySuccess = (state, { data }) =>
|
||||
state.merge({
|
||||
fetching: getFetchingValue(state.fetching, data?.loader),
|
||||
error: getErrorValue(state?.error, data?.loader),
|
||||
getInventoryDetail: data.getInventoryDetail
|
||||
});
|
||||
|
||||
export const onGetInventoryFailure = (state, { error }) =>
|
||||
state.merge({
|
||||
fetching: _.without(state.fetching, error?.loader),
|
||||
error: { ...state.error, [error?.loader]: error?.error }
|
||||
});
|
||||
|
||||
export const onAddInventoryAction = (state, { payload }) =>
|
||||
state.merge({
|
||||
fetching: _.uniq([state.fetching, payload?.loader]),
|
||||
@@ -37,7 +73,7 @@ export const onAddInventorySuccess = (state, { data }) =>
|
||||
state.merge({
|
||||
fetching: getFetchingValue(state.fetching, data?.loader),
|
||||
error: getErrorValue(state?.error, data?.loader),
|
||||
addInventoryDetail: data.addInventoryDetail
|
||||
getInventoryDetail: [...state.getInventoryDetail, data.newInventory]
|
||||
});
|
||||
|
||||
export const onAddInventoryFailure = (state, { error }) =>
|
||||
@@ -46,9 +82,59 @@ export const onAddInventoryFailure = (state, { error }) =>
|
||||
error: { ...state.error, [error?.loader]: error?.error }
|
||||
});
|
||||
|
||||
export const onUpdateInventoryAction = (state, { payload }) =>
|
||||
state.merge({
|
||||
fetching: _.uniq([state.fetching, payload?.loader]),
|
||||
error: getErrorValue(state?.error, payload?.loader)
|
||||
});
|
||||
|
||||
export const onUpdateInventorySuccess = (state, { data }) =>
|
||||
state.merge({
|
||||
fetching: getFetchingValue(state.fetching, data?.loader),
|
||||
error: getErrorValue(state?.error, data?.loader),
|
||||
getInventoryDetail: [
|
||||
...state.getInventoryDetail.filter((x) => x._id !== data.newInventory._id),
|
||||
data.newInventory
|
||||
]
|
||||
});
|
||||
|
||||
export const onUpdateInventoryFailure = (state, { error }) =>
|
||||
state.merge({
|
||||
fetching: _.without(state.fetching, error?.loader),
|
||||
error: { ...state.error, [error?.loader]: error?.error }
|
||||
});
|
||||
|
||||
export const onGetInventoryTypesAction = (state, { payload }) =>
|
||||
state.merge({
|
||||
fetching: _.uniq([state.fetching, payload?.loader]),
|
||||
error: getErrorValue(state?.error, payload?.loader)
|
||||
});
|
||||
|
||||
export const onGetInventoryTypesSuccess = (state, { data }) =>
|
||||
state.merge({
|
||||
fetching: getFetchingValue(state.fetching, data?.loader),
|
||||
error: getErrorValue(state?.error, data?.loader),
|
||||
inventoryTypes: data.inventoryTypes
|
||||
});
|
||||
|
||||
export const onGetInventoryTypesFailure = (state, { error }) =>
|
||||
state.merge({
|
||||
fetching: _.without(state.fetching, error?.loader),
|
||||
error: { ...state.error, [error?.loader]: error?.error }
|
||||
});
|
||||
|
||||
/* ------------- Hookup Reducers To Types ------------- */
|
||||
export const inventoryReducer = createReducer(INITIAL_STATE, {
|
||||
[Types.GET_INVENTORY_ACTION]: onGetInventoryAction,
|
||||
[Types.GET_INVENTORY_SUCCESS]: onGetInventorySuccess,
|
||||
[Types.GET_INVENTORY_FAILURE]: onGetInventoryFailure,
|
||||
[Types.ADD_INVENTORY_ACTION]: onAddInventoryAction,
|
||||
[Types.ADD_INVENTORY_SUCCESS]: onAddInventorySuccess,
|
||||
[Types.ADD_INVENTORY_FAILURE]: onAddInventoryFailure
|
||||
[Types.ADD_INVENTORY_FAILURE]: onAddInventoryFailure,
|
||||
[Types.UPDATE_INVENTORY_ACTION]: onUpdateInventoryAction,
|
||||
[Types.UPDATE_INVENTORY_SUCCESS]: onUpdateInventorySuccess,
|
||||
[Types.UPDATE_INVENTORY_FAILURE]: onUpdateInventoryFailure,
|
||||
[Types.GET_INVENTORY_TYPES_ACTION]: onGetInventoryTypesAction,
|
||||
[Types.GET_INVENTORY_TYPES_SUCCESS]: onGetInventoryTypesSuccess,
|
||||
[Types.GET_INVENTORY_TYPES_FAILURE]: onGetInventoryTypesFailure
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user