diff --git a/package.json b/package.json index fc22d67..f009926 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@coreui/react-chartjs": "^2.0.0", "@coreui/utils": "^1.3.1", "@material-ui/core": "^4.12.4", - "@reduxjs/toolkit": "^1.8.2", + "@reduxjs/toolkit": "^1.9.2", "@wojtekmaj/enzyme-adapter-react-17": "^0.6.5", "axios": "^0.25.0", "bootstrap": "^5.1.3", @@ -57,9 +57,10 @@ "react-date-picker": "^8.4.0", "react-datepicker": "^4.8.0", "react-dom": "^18.0.0", + "react-hot-toast": "^2.4.0", "react-paginate": "^8.1.3", "react-qr-code": "^2.0.11", - "react-redux": "^7.2.6", + "react-redux": "^7.2.9", "react-router-dom": "^6.7.0", "react-spinners": "^0.11.0", "react-time-picker": "^4.5.0", diff --git a/src/App.js b/src/App.js index 2850d67..705bff4 100644 --- a/src/App.js +++ b/src/App.js @@ -2,6 +2,7 @@ import React, { Component, Suspense } from 'react' import axios from 'axios'; import { Router, Route, Routes, HashRouter } from 'react-router-dom' import { useState, useEffect } from 'react'; +import { Toaster } from "react-hot-toast"; import './scss/style.scss' import ForgotPassword from './views/pages/register/ForgotPassword' import NewRegister from './views/pages/register/NewRegister' @@ -81,7 +82,9 @@ const App = () => { } /> + + ) diff --git a/src/_nav.js b/src/_nav.js index c3267c7..64bc615 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -13,6 +13,7 @@ import { cilDrop, cilFace, cilFilterSquare, + cilLoopCircular, cilMedicalCross, cilMoney, cilMugTea, @@ -24,6 +25,7 @@ import { cilSpeedometer, cilStar, cilTablet, + cilTags, cilTennisBall, cilUser, @@ -48,7 +50,7 @@ const _nav = [ }, { component: CNavItem, - name: 'Temples', + name: 'Franchisee', icon: , to: '/temples', }, @@ -112,7 +114,7 @@ const _nav = [ { component: CNavItem, name: 'Cities', - icon: , + icon: , to: '/cities', }, { @@ -139,12 +141,12 @@ const _nav = [ // icon: , // to: '/pincode', // }, - // { - // component: CNavItem, - // name: 'Tax Rates', - // icon: , - // to: '/tax', - // }, + { + component: CNavItem, + name: 'Tax Rates', + icon: , + to: '/tax', + }, // { // component: CNavItem, // name: 'Pages', diff --git a/src/components/AppContent.js b/src/components/AppContent.js index 7a03fe5..f3c74be 100644 --- a/src/components/AppContent.js +++ b/src/components/AppContent.js @@ -30,4 +30,6 @@ const AppContent = () => { ) } + + export default React.memo(AppContent) diff --git a/src/index.js b/src/index.js index bc52aee..527691f 100644 --- a/src/index.js +++ b/src/index.js @@ -7,8 +7,8 @@ import ReactDOM from 'react-dom' import App from './App' import * as serviceWorker from './serviceWorker' import { Provider } from 'react-redux' -import store from './store' import axios from 'axios' +import { store } from './redux/store'; const setupAxios = () => { axios.defaults.baseURL = 'https://atpapi.checkapp.one' diff --git a/src/redux/Actions/cartAction.js b/src/redux/Actions/cartAction.js new file mode 100644 index 0000000..c3fac4d --- /dev/null +++ b/src/redux/Actions/cartAction.js @@ -0,0 +1,71 @@ +import axios from "axios"; + +// Add to Cart +// export const addItemsToCart = (id, quantity) => async (dispatch, getState) => { +// const { productData } = await axios.get(`/api/v1/product/${id}`); + +// dispatch({ +// type: ADD_TO_CART, +// payload: { +// product: productData.product._id, +// name: productData.product.name, +// price: productData.product.price, +// image: productData.product.images[0].url, +// stock: productData.product.Stock, +// quantity, +// }, +// }); + +// localStorage.setItem("cartItems", JSON.stringify(getState().cart.cartItems)); +// }; +export const addItemsToCart = (id) => async (dispatch, getState) => { + console.log(id) + try { + dispatch({ + type: "ADD_TO_CART_REQUIST", + }); + + const productData = await axios.get(`/api/product/getOne/${id}`); + console.log(productData.data.product) + + dispatch({ + type: "ADD_TO_CART_SUCCESS", + payload: { + product: productData?.data?.product?._id, + name: productData?.data?.product?.name, + price: productData?.data?.product?.base_Price, + image: productData?.data?.product?.image.url, + // stock: productData.product.Stock, + // quantity, + }, + }); + localStorage.setItem("cartItems", JSON.stringify(getState().cart.cartItems)); + + } catch (error) { + console.log(error) + dispatch({ + type: "ADD_TO_CART_FAILURE", + payload: error.response.data.message, + }); + } +}; + +// REMOVE FROM CART +export const removeItemsFromCart = (id) => async (dispatch, getState) => { + dispatch({ + type: REMOVE_CART_ITEM, + payload: id, + }); + + localStorage.setItem("cartItems", JSON.stringify(getState().cart.cartItems)); +}; + +// SAVE SHIPPING INFO +// export const saveShippingInfo = (productData) => async (dispatch) => { +// dispatch({ +// type: SAVE_SHIPPING_INFO, +// payload: productData, +// }); + +// localStorage.setItem("shippingInfo", JSON.stringify(productData)); +// }; \ No newline at end of file diff --git a/src/redux/reducers/cartReducer.js b/src/redux/reducers/cartReducer.js new file mode 100644 index 0000000..8366656 --- /dev/null +++ b/src/redux/reducers/cartReducer.js @@ -0,0 +1,85 @@ +import { createReducer } from "@reduxjs/toolkit"; +let initialState = localStorage.getItem("cartItems") ? JSON.parse(localStorage.getItem("cartItems")) : ({ + cartItems: [], + subTotal: 0, + shipping: 0, + tax: 0, + total: 0, +}) + + + + +export const cartReducer = createReducer( + initialState, + { + addToCart: (state, action) => { + const item = action.payload; + const isItemExist = state.cartItems.find((i) => i.id === item.id); + + if (isItemExist) { + state.cartItems.forEach((i) => { + if (i.id === item.id) i.quantity += 1; + }); + } else { + state.cartItems.push(item); + } + }, + + decrement: (state, action) => { + const item = state.cartItems.find((i) => i.id === action.payload); + if (item.quantity > 1) { + state.cartItems.forEach((i) => { + if (i.id === item.id) i.quantity -= 1; + }); + } + }, + + deleteFromCart: (state, action) => { + state.cartItems = state.cartItems.filter((i) => i.id !== action.payload); + }, + calculatePrice: (state) => { + let sum = 0; + state.cartItems.forEach((i) => (sum += i.price * i.quantity)); + state.subTotal = sum; + // state.shipping = state.subTotal > 1000 ? 0 : 200; + // state.tax = +(state.subTotal * 0.18).toFixed(); + state.total = state.subTotal + // + state.tax + state.shipping; + }, + + } +); + + + + +let initialInfo = localStorage.getItem("shippingInfo") ? JSON.parse(localStorage.getItem("shippingInfo")) : ({ + franchisees: [], + +}) + + +export const shipingReducer = createReducer( + initialInfo, + { + addShippingInfo: (state, action) => { + const item = action.payload; + const isItemExist = state.franchisees.find((i) => i.id === item.id); + + if (isItemExist) { + // state.cartItems.forEach((i) => { + // if (i.id === item.id) i.quantity += 1; + // }); + return; + } else { + state.franchisees.push(item); + } + }, + + deleteFromshippingInfo: (state, action) => { + state.franchisees = state.franchisees.filter((i) => i.id !== action.payload); + + }, + } +) \ No newline at end of file diff --git a/src/redux/store.js b/src/redux/store.js new file mode 100644 index 0000000..b68631c --- /dev/null +++ b/src/redux/store.js @@ -0,0 +1,28 @@ +import { configureStore } from "@reduxjs/toolkit" +import { cartReducer, shipingReducer } from "./reducers/cartReducer" + + + +// let initialState = { +// cart: { +// cartItems: localStorage.getItem("cartItems") +// ? JSON.parse(localStorage.getItem("cartItems")) +// : [], +// subTotal: 0, +// shipping: 0, +// tax: 0, +// total: 0, +// // shippingInfo: localStorage.getItem("shippingInfo") +// // ? JSON.parse(localStorage.getItem("shippingInfo")) +// // : {}, +// }, +// }; + +export const store = configureStore({ + reducer: { + cart: cartReducer, + shipingInfo: shipingReducer + }, + // initialState + +}) \ No newline at end of file diff --git a/src/routes.js b/src/routes.js index 483b6aa..2ad63f9 100644 --- a/src/routes.js +++ b/src/routes.js @@ -39,7 +39,12 @@ import DispatchedOrders from './views/orders/DispatchedOrders.js' import DeliveredOrders from './views/orders/DeliveredOrders.js' import CancelledOrders from './views/orders/CancelledOrders.js' import ReturnedOrders from './views/orders/ReturnedOrders.js' -import ViewOrder from './views/orders/ViewOrder.js' +import ViewOrder from './views/orders/ViewOrder' +import AddOrder from './views/orders/AddOrder' +//Taxes +import Tax from './views/configuration/tax/Tax' +import Addtax from './views/configuration/tax/Addtax' +import Edittax from './views/configuration/tax/Edittax' const routes = [ { path: '/', exact: true, name: 'Home' }, @@ -54,13 +59,16 @@ const routes = [ { path: '/product/edit/:id', name: 'Edit products', element: EditProduct }, { path: '/product/view/:id', name: 'view products', element: ViewProduct }, //Order Management + + { path: '/orders/new', name: 'New Orders', element: NewOrders }, + { path: '/order/add', name: 'add Order', element: AddOrder }, // { path: '/orders/processing', name: 'Processing Orders', element: ProcessingOrders }, // { path: '/orders/dispatched', name: 'Dispatched Orders', element: DispatchedOrders }, // { path: '/orders/delivered', name: 'Delivered Orders', element: DeliveredOrders }, // { path: '/orders/cancelled', name: 'Cancelled Orders', element: CancelledOrders }, // { path: '/orders/returned', name: 'Returned Orders', element: ReturnedOrders }, - // { path: '/orders/:status/:id', name: 'View Order', element: ViewOrder }, + { path: '/order/:status/:id', name: 'View Order', element: ViewOrder }, //Temple @@ -87,6 +95,11 @@ const routes = [ { path: '/socialmedia', name: 'Social Media', element: Socialmedia }, { path: '/address', name: 'Address', element: Address }, { path: '/logo', name: 'Logo', element: Logo }, + + //Taxes + { path: '/tax', name: 'Tax Rates', element: Tax }, + { path: '/tax/add', name: 'Add Tax', element: Addtax }, + { path: '/tax/edit/:id', name: 'Edit Tax', element: Edittax }, // -------------------------------------------// diff --git a/src/store.js b/src/store.js index 81c401c..b6efad1 100644 --- a/src/store.js +++ b/src/store.js @@ -1,20 +1,4 @@ -import { createStore } from 'redux' -const initialState = { - sidebarShow: true, -} - -const changeState = (state = initialState, { type, ...rest }) => { - switch (type) { - case 'set': - return { ...state, ...rest } - default: - return state - } -} - -const store = createStore(changeState) -export default store // import { configureStore } from "@reduxjs/toolkit"; // import { newCategoryReducer, AllcategoryReducer } from "./reducers/categoryReducer.js"; // import { loginReducer } from "./reducers/directoryReducer.js"; diff --git a/src/views/Products/EditProduct.js b/src/views/Products/EditProduct.js index 1091b1b..9e6f411 100644 --- a/src/views/Products/EditProduct.js +++ b/src/views/Products/EditProduct.js @@ -128,7 +128,7 @@ const EditProduct = () => { axios - .put(`/api//product/update/${id}`, formData, { + .put(`/api/product/update/${id}`, formData, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'multipart/formdata', diff --git a/src/views/Temples/AddTemple.js b/src/views/Temples/AddTemple.js index 491ffa3..5e50489 100644 --- a/src/views/Temples/AddTemple.js +++ b/src/views/Temples/AddTemple.js @@ -22,6 +22,8 @@ const AddTemple = () => { city: '', state_name: '', short_url: '', + contact_Number: '', + contact_Person_Name: '' // pan: '', // business_name: '', // gstin: '', @@ -102,10 +104,11 @@ const AddTemple = () => { const handleSubmit = () => { if ( data.name.trim() === '' || + // data.pan.trim() === '' || - // data.business_name.trim() === '' || - // data.gstin.trim() === '' || - // data.option.trim() === '' || + data.contact_Number === '' || + + data.contact_Person_Name === '' || data.address_line_1.trim() === '' || data.address_line_2.trim() === '' || data.city === '' || @@ -133,6 +136,9 @@ const AddTemple = () => { formData.set('address_line_2', data.address_line_2) formData.set('city', data.city) formData.set('state_name', data.state_name) + formData.set('contact_Number', data.contact_Number) + formData.set('contact_Person_Name', data.contact_Person_Name) + formData.set('url', WebsiteURL + data.short_url + '/login') formData.set('short_url', data.short_url) formData.append('image', data.image) @@ -180,7 +186,7 @@ const AddTemple = () => { " >
- Add Temple + Add Franchisee

@@ -219,12 +225,12 @@ const AddTemple = () => {
-
+
{ />

Remaining characters : {limiter.nameHas}

- {/*
- - handleChange(e)} - /> -
*/} +
- {/*
- - handleChange(e)} - /> -
*/} - {/*
- - handleChange(e)} - /> -
*/} +
-
+
+ +
+ + handleChange(e)} + /> +
+
+ + handleChange(e)} + /> +
- {/*
- - -
*/} + +