From 6f99ba55410c935e5a68d66db9aba2d837185fbe Mon Sep 17 00:00:00 2001
From: "[Diksha]" <[diksha39511@gmail.com]>
Date: Wed, 2 Feb 2022 14:45:41 +0530
Subject: [PATCH] warehouse api integration
---
src/components/TileBasic/index.js | 51 ++++++++++----------
src/constant/Endpoints.js | 3 +-
src/pages/setup/index.js | 29 ++++++-----
src/pages/warehouse/index.js | 80 +++++++------------------------
src/redux/WarehouseRedux.js | 53 ++++++++++++++++++++
src/redux/index.js | 4 +-
src/sagas/Warehouse.js | 31 ++++++++++++
src/sagas/index.js | 4 ++
8 files changed, 154 insertions(+), 101 deletions(-)
create mode 100644 src/redux/WarehouseRedux.js
create mode 100644 src/sagas/Warehouse.js
diff --git a/src/components/TileBasic/index.js b/src/components/TileBasic/index.js
index 026850a..79c61fc 100644
--- a/src/components/TileBasic/index.js
+++ b/src/components/TileBasic/index.js
@@ -3,8 +3,14 @@ import PropTypes from 'prop-types';
import MDBox from 'components/MDBox';
import { makeStyles } from '@mui/styles';
import { Grid } from '@mui/material';
+import SetupIcon from 'assets/images/SetupIcon';
const useStyles = makeStyles({
+ iconSize: {
+ width: '50%',
+ height: '50%',
+ marginBottom: '10px'
+ },
centerContent: {
display: 'flex',
alignItems: 'center',
@@ -31,30 +37,27 @@ export default function TileBasic({ tiles }) {
const classes = useStyles();
return (
<>
-
-
- {tiles &&
- tiles.map((tile) => (
- <>
-
- white.main,
- padding: '32px 40px'
- }}
- >
- {tile.icon}
- {tile.name}
-
-
- >
- ))}
-
-
+
+ {tiles &&
+ tiles.map((tile) => (
+ <>
+
+ white.main,
+ padding: '32px 40px'
+ }}
+ >
+
+ {tile.name}
+
+
+ >
+ ))}
+
>
);
}
diff --git a/src/constant/Endpoints.js b/src/constant/Endpoints.js
index 4e526c5..26b116b 100644
--- a/src/constant/Endpoints.js
+++ b/src/constant/Endpoints.js
@@ -1,3 +1,4 @@
export default {
- LOGIN_USER: '/user/login'
+ LOGIN_USER: '/user/login',
+ GET_WAREHOUSE_DATA: '/warehouse/all'
};
diff --git a/src/pages/setup/index.js b/src/pages/setup/index.js
index 9771941..96e87dd 100644
--- a/src/pages/setup/index.js
+++ b/src/pages/setup/index.js
@@ -7,6 +7,7 @@ import WarehouseIcon from 'assets/images/WarehouseIcon';
import InventoryIcon from 'assets/images/InventoryIcon';
import ProfileCircleIcon from 'assets/images/ProfileCircleIcon';
import LabelIcon from 'assets/images/LabelIcon';
+import { Link } from 'react-router-dom';
const useStyles = makeStyles({
iconSize: {
@@ -77,19 +78,21 @@ function SetupHome() {
{data.map((items) => (
<>
- white.main,
- padding: '32px 40px'
- }}
- >
- {items.icon}
- {items.name}
-
+
+ white.main,
+ padding: '32px 40px'
+ }}
+ >
+ {items.icon}
+ {items.name}
+
+
>
))}
diff --git a/src/pages/warehouse/index.js b/src/pages/warehouse/index.js
index 5a24340..6cac45b 100644
--- a/src/pages/warehouse/index.js
+++ b/src/pages/warehouse/index.js
@@ -2,76 +2,32 @@ import MDBox from 'components/MDBox';
import DashboardNavbar from 'components/DashboardNavbar';
import Footer from 'components/Footer';
import DashboardLayout from 'layouts/DashboardLayout';
-import SetupIcon from 'assets/images/SetupIcon';
import TileBasic from 'components/TileBasic';
-import { makeStyles } from '@mui/styles';
-
-const useStyles = makeStyles({
- iconSize: {
- width: '50%',
- height: '50%',
- marginBottom: '10px'
- },
- margin: {
- marginBottom: '20px'
- }
-});
+import { API } from 'constant';
+import WarehouseActions from 'redux/WarehouseRedux';
+import { useEffect } from 'react';
+import { useDispatch, useSelector } from 'react-redux';
+import { WarehouseSelectors } from 'redux/WarehouseRedux';
function WarehouseScreen() {
- const classes = useStyles();
- const data = [
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- },
- {
- name: 'Warehouse 1',
- path: '/',
- icon:
- }
- ];
+ const dispatch = useDispatch();
+ const warehouseData = useSelector(WarehouseSelectors.getWarehouseDetail);
+
+ useEffect(() => {
+ dispatch(
+ WarehouseActions.warehouseDataAction({
+ loader: 'loading-request',
+ slug: API.GET_WAREHOUSE_DATA,
+ method: 'get'
+ })
+ );
+ }, []);
return (
-
+
diff --git a/src/redux/WarehouseRedux.js b/src/redux/WarehouseRedux.js
new file mode 100644
index 0000000..9f9f339
--- /dev/null
+++ b/src/redux/WarehouseRedux.js
@@ -0,0 +1,53 @@
+import { createActions, createReducer } from 'reduxsauce';
+import Immutable from 'seamless-immutable';
+import _ from 'underscore';
+import { getFetchingValue, getErrorValue } from '../services/Utils';
+
+/* ------------- Types and Action Creators ------------- */
+const { Types, Creators } = createActions({
+ warehouseDataAction: ['payload'],
+ warehouseDataSuccess: ['data'],
+ warehouseDataFailure: ['error']
+});
+
+export const WarehouseTypes = Types;
+const WarehouseActions = Creators;
+export default WarehouseActions;
+
+/* ------------- Initial State ------------- */
+export const INITIAL_STATE = Immutable({
+ warehouseDetail: null,
+ error: {}
+});
+
+/* ------------- Selectors ------------- */
+export const WarehouseSelectors = {
+ getWarehouseDetail: (state) => state.warehouse.warehouseDetail
+};
+
+/* ------------- Reducers ------------- */
+export const onWarehouseDataAction = (state, { payload }) =>
+ state.merge({
+ fetching: _.uniq([state.fetching, payload?.loader]),
+ error: getErrorValue(state?.error, payload?.loader)
+ });
+
+export const onWarehouseDataSuccess = (state, { data }) =>
+ state.merge({
+ fetching: getFetchingValue(state.fetching, data?.loader),
+ error: getErrorValue(state?.error, data?.loader),
+ warehouseDetail: data.warehouseDetail
+ });
+
+export const onWarehouseDataFailure = (state, { error }) =>
+ state.merge({
+ fetching: _.without(state.fetching, error?.loader),
+ error: { ...state.error, [error?.loader]: error?.error }
+ });
+
+/* ------------- Hookup Reducers To Types ------------- */
+export const warehouseReducer = createReducer(INITIAL_STATE, {
+ [Types.WAREHOUSE_DATA_ACTION]: onWarehouseDataAction,
+ [Types.WAREHOUSE_DATA_SUCCESS]: onWarehouseDataSuccess,
+ [Types.WAREHOUSE_DATA_FAILURE]: onWarehouseDataFailure
+});
diff --git a/src/redux/index.js b/src/redux/index.js
index d46bc25..c2bd4a7 100644
--- a/src/redux/index.js
+++ b/src/redux/index.js
@@ -1,9 +1,11 @@
import { combineReducers } from 'redux';
import { authReducer } from './AuthRedux';
+import { warehouseReducer } from './WarehouseRedux';
// Combine all reducers.
const appReducer = combineReducers({
- auth: authReducer
+ auth: authReducer,
+ warehouse: warehouseReducer
});
const rootReducer = (state, action) => {
diff --git a/src/sagas/Warehouse.js b/src/sagas/Warehouse.js
new file mode 100644
index 0000000..40c7b3e
--- /dev/null
+++ b/src/sagas/Warehouse.js
@@ -0,0 +1,31 @@
+import { AuthorizedAPI } from 'config';
+import { takeLatest, call, put } from 'redux-saga/effects';
+import WarehouseActions, { WarehouseTypes } from '../redux/WarehouseRedux';
+import ApiServices from 'services/API/ApiServices';
+
+export function* onRequestWarehouseData({ payload }) {
+ const response = yield call(
+ ApiServices[payload?.method],
+ AuthorizedAPI,
+ payload?.slug,
+ payload?.data
+ );
+ if (response?.status === 200) {
+ yield put(
+ WarehouseActions.warehouseDataSuccess({
+ loader: payload?.loader,
+ warehouseDetail: response?.data?.data
+ })
+ );
+ } else {
+ payload.onFailedWarehouseData(response.data.error);
+ yield put(
+ WarehouseActions.warehouseDataFailure({
+ loader: payload?.loader,
+ error: response?.data
+ })
+ );
+ }
+}
+
+export default [takeLatest(WarehouseTypes.WAREHOUSE_DATA_ACTION, onRequestWarehouseData)];
diff --git a/src/sagas/index.js b/src/sagas/index.js
index 92cc761..30ff8dc 100644
--- a/src/sagas/index.js
+++ b/src/sagas/index.js
@@ -1,6 +1,10 @@
import { all } from 'redux-saga/effects';
import AuthSaga from './Auth';
+import WarehouseSaga from './Warehouse';
+
export default function* rootSaga() {
yield all([...AuthSaga]);
+ yield all([...WarehouseSaga]);
+
}