From 46ed77392a831007e566509c7f9b20ef8cb86c51 Mon Sep 17 00:00:00 2001
From: pawan-dot <71133473+pawan-dot@users.noreply.github.com>
Date: Tue, 7 Feb 2023 18:12:08 +0530
Subject: [PATCH] product change and edit order
---
src/index.js | 2 +-
src/redux/reducers/cartReducer.js | 76 ++--
src/redux/store.js | 2 +-
src/views/orders/AddOrder.js | 580 +++++++++++-------------------
src/views/orders/EditOrder.js | 558 +++++++++++++---------------
src/views/orders/NewOrders.js | 2 +-
6 files changed, 495 insertions(+), 725 deletions(-)
diff --git a/src/index.js b/src/index.js
index 527691f..c7cc467 100644
--- a/src/index.js
+++ b/src/index.js
@@ -12,7 +12,7 @@ import { store } from './redux/store';
const setupAxios = () => {
axios.defaults.baseURL = 'https://atpapi.checkapp.one'
- // axios.defaults.baseURL = 'http://localhost:5000'
+ //axios.defaults.baseURL = 'http://localhost:5000'
axios.defaults.headers = {
'Cache-Control': 'no-cache,no-store',
'Pragma': 'no-cache',
diff --git a/src/redux/reducers/cartReducer.js b/src/redux/reducers/cartReducer.js
index 8fab70d..8a625a6 100644
--- a/src/redux/reducers/cartReducer.js
+++ b/src/redux/reducers/cartReducer.js
@@ -2,9 +2,10 @@ import { createReducer } from "@reduxjs/toolkit";
let initialState = localStorage.getItem("cartItems") ? JSON.parse(localStorage.getItem("cartItems")) : ({
cartItems: [],
subTotal: 0,
- shipping: 0,
+ shippingCharge: 0,
tax: 0,
total: 0,
+ shipingInfo: null,
})
@@ -15,11 +16,12 @@ export const cartReducer = createReducer(
{
addToCart: (state, action) => {
const item = action.payload;
- const isItemExist = state.cartItems.find((i) => i.id === item.id);
+
+ const isItemExist = state.cartItems.find((i) => i.product === item.product);
if (isItemExist) {
state.cartItems.forEach((i) => {
- if (i.id === item.id) i.quantity += 1;
+ if (i.product === item.product) i.quantity += 1;
});
} else {
state.cartItems.push(item);
@@ -27,27 +29,33 @@ export const cartReducer = createReducer(
},
decrement: (state, action) => {
- const item = state.cartItems.find((i) => i.id === action.payload);
- if (item.quantity > 1) {
+ const item = action.payload;
+ const pro = state.cartItems.find((i) => i.product === item.product);
+
+ if (pro.quantity > 1) {
state.cartItems.forEach((i) => {
- if (i.id === item.id) i.quantity -= 1;
+ if (i.product === item.product) i.quantity -= 1;
});
}
},
deleteFromCart: (state, action) => {
- state.cartItems = state.cartItems.filter((i) => i.id !== action.payload);
+ const item = action.payload;
+
+
+
+ state.cartItems = state.cartItems.filter((i) => i.product !== item.product);
},
// selectTax: (state, action) => {
// const tax = action.payload;
- // const item = state.cartItems.find((i) => i.id === tax.productId);
+ // const item = state.cartItems.find((i) => i.product === tax.productId);
// if (item) {
// state.cartItems.forEach((i) => {
- // if (i.id === item.id) {
+ // if (i.product === item.product) {
// i.taxName = tax.name;
// i.taxRate = tax.rate;
@@ -64,14 +72,28 @@ export const cartReducer = createReducer(
calculatePrice: (state) => {
let sum = 0;
- state.cartItems.forEach((i) => (sum += i.PriceWithTax * i.quantity));
+ state.cartItems.forEach((i) => (sum += i.price_With_Tax * i.quantity));
state.subTotal = sum;
- // state.shipping = state.subTotal > 1000 ? 0 : 200;
+ // state.shippingCharge = state.subTotal > 1000 ? 0 : 200;
// state.tax = +(state.subTotal * 0.18).toFixed();
state.total = state.subTotal
- // + state.tax + state.shipping;
+ // + state.tax + state.shippingCharge;
+ },
+ addShippingInfo: (state, action) => {
+ const item = action.payload;
+
+ state.shipingInfo = item;
+
},
+ deleteFromshippingInfo: (state, action) => {
+
+ state.shipingInfo = null
+ state.total = 0
+ state.subTotal = 0
+ state.cartItems = []
+
+ },
}
);
@@ -79,33 +101,3 @@ export const cartReducer = createReducer(
-let initialInfo = localStorage.getItem("shippingInfo") ? JSON.parse(localStorage.getItem("shippingInfo")) : ({
- franchisees: null,
-
-})
-
-
-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 = item;
- // }
- },
-
- deleteFromshippingInfo: (state, action) => {
- state.franchisees = null
- // 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
index b68631c..1091d97 100644
--- a/src/redux/store.js
+++ b/src/redux/store.js
@@ -21,7 +21,7 @@ import { cartReducer, shipingReducer } from "./reducers/cartReducer"
export const store = configureStore({
reducer: {
cart: cartReducer,
- shipingInfo: shipingReducer
+ // shipingInfo: shipingReducer
},
// initialState
diff --git a/src/views/orders/AddOrder.js b/src/views/orders/AddOrder.js
index d81192d..e2a544a 100644
--- a/src/views/orders/AddOrder.js
+++ b/src/views/orders/AddOrder.js
@@ -11,18 +11,15 @@ import { addItemsToCart } from 'src/redux/Actions/cartAction'
import toast from 'react-hot-toast'
import { cibBlackberry } from '@coreui/icons'
import Button from '@material-ui/core/Button'
-// import PrintOrderDetails from './PrintOrderDetails.js'
function AddOrder() {
const { status, id } = useParams()
- const { cartItems, subTotal, tax, shipping, total } = useSelector(
+ const { cartItems, subTotal, shippingCharge, tax, shipingInfo, total } = useSelector(
(state) => state.cart
);
- // const { cart, shippingInfo } = useSelector(
- // (state) => state
- // );
+
const AllStates = useSelector(
(state) => state
);
@@ -115,120 +112,6 @@ function AddOrder() {
}))
}
- // ------------------------product handle------------------------------//
-
- const handleGetSingleProduct = async (e) => {
-
-
- axios
- .get(`/api/product/getOne/${getValue.current.value}`, {
- headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
- })
- .then((res) => {
- setLoading(false)
- let options = {
- name: res?.data?.product?.name,
- price: res?.data?.product?.base_Price,
- id: res?.data?.product?._id,
- quantity: 1,
-
- image: res?.data?.product?.image?.url,
- taxRate: 0.0,
- taxName: '',
- taxId: '',
- PriceWithTax: res?.data?.product?.base_Price,
- }
- dispatch({ type: "addToCart", payload: options });
-
- dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
-
- toast.success("Product Added");
-
- })
- .catch((err) => {
- setLoading(false)
-
- })
- }
-
- // const TaxRatechange = async (id, e) => {
- // // console.log(e.target.value)
- // // console.log(e.target.value.slice(4, 6))
- // // console.log(e.target.value.slice(12, 16))
- // // console.log(e.target.value.slice(23))
-
-
- // let taxDetails = {
- // name: e.target.value.slice(12, 16),
- // rate: e.target.value.slice(4, 6),
- // productId: id,
- // taxId: e.target.value.slice(24)
-
- // }
- // dispatch({ type: "selectTax", payload: taxDetails });
-
- // dispatch({ type: "calculatePrice" });
- // localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
-
- // toast.success("Tax Added");
-
- // }
- const handleRemove = (id) => {
- dispatch({
- type: "deleteFromCart",
- payload: id,
- });
- dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
- toast.success("Item Removed");
-
- };
- //increase qty
- const increaseQuantity = (id) => {
- if (
- tax === 1) {
- swal({
- title: 'Warning',
- text: 'Please select Tax Rate ',
- icon: 'error',
- button: 'Close',
- dangerMode: true,
- })
- return
- }
- dispatch({
- type: "addToCart",
- payload: { id },
- });
- dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
-
- }
-
-
- const decreaseQuantity = (id) => {
- if (
- tax === 1) {
- swal({
- title: 'Warning',
- text: 'Please select Tax Rate ',
- icon: 'error',
- button: 'Close',
- dangerMode: true,
- })
- return
- }
- dispatch({
- type: "decrement",
- payload: id,
- });
-
- dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
-
- };
- // ------------------------product handle End------------------------------//
// ------------------------Frenchisee handle------------------------------//
@@ -244,9 +127,9 @@ function AddOrder() {
})
.then((res) => {
setLoading(false)
- // console.log(res.data.data)
+ console.log(res.data.data)
let options = {
- id: res?.data?.data?._id,
+ Franchisee: res?.data?.data?._id,
name: res?.data?.data?.name,
@@ -254,6 +137,7 @@ function AddOrder() {
contact_Person_Name: res?.data?.data?.contact_Person_Name,
address: (res?.data?.data?.address_line_1 + ' ' + res?.data?.data?.address_line_2),
city: res?.data?.data?.city?.city_name,
+ price_Lable: res?.data?.data?.price_Lable,
state: res?.data?.data?.city?.state?.state_name,
banner: res?.data?.data?.banner?.url,
Franchisee_Url: res?.data?.data?.url
@@ -261,7 +145,7 @@ function AddOrder() {
dispatch({ type: "addShippingInfo", payload: options });
- localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
+ // localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
toast.success("Franchisee Added");
@@ -274,40 +158,93 @@ function AddOrder() {
const FranchiseeRemove = (id) => {
dispatch({
type: "deleteFromshippingInfo",
- payload: id,
+ payload: { Franchisee: id },
});
- localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
toast.success("Franchisee Removed");
};
// ------------------------Frenchisee handle End------------------------------//
- console.log(AllStates.shipingInfo.franchisees)
- // cartItems.map(i => console.log(i.taxName))
- function handleSubmit() {
+ // ------------------------product handle------------------------------//
+
+ const handleGetSingleProduct = async (e) => {
- if (cartItems.length < 1) {
- swal({
- title: 'Warning',
- text: 'Please select atleast one product',
- icon: 'error',
- button: 'Close',
- dangerMode: true,
+ axios
+ .get(`/api/product/getOne/${getValue.current.value}`, {
+ headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
})
- return
- }
- // else if (cartItems.find(i => i.taxName === '')) {
- // swal({
- // title: 'Warning',
- // text: 'Please select tax rate for every Product',
- // icon: 'error',
- // button: 'Close',
- // dangerMode: true,
- // })
- // return
- // }
- else if (
- AllStates.shipingInfo.franchisees === null) {
+ .then((res) => {
+ setLoading(false)
+ const productAllkey = Object.keys(res?.data?.product);
+ const productAllValue = Object.values(res?.data?.product);
+ const findIndex1 = (productAllkey.indexOf(shipingInfo?.price_Lable))
+ const findIndex2 = (productAllkey.indexOf(`${shipingInfo?.price_Lable}_With_Tax`))
+
+
+
+ let options = {
+ name: res?.data?.product?.name,
+ price: productAllValue[findIndex1],
+ product: res?.data?.product?._id,
+ quantity: 1,
+
+ image: res?.data?.product?.image?.url,
+
+ taxId: res?.data?.product?.taxId,
+ price_With_Tax: productAllValue[findIndex2],
+ }
+ dispatch({ type: "addToCart", payload: options });
+
+ dispatch({ type: "calculatePrice" });
+
+ toast.success("Product Added");
+
+ })
+ .catch((err) => {
+ setLoading(false)
+
+ })
+ }
+
+
+ const handleRemove = (id) => {
+ dispatch({
+ type: "deleteFromCart",
+ payload: { product: id },
+ });
+ dispatch({ type: "calculatePrice" });
+ toast.success("Item Removed");
+
+ };
+ //increase qty
+ const increaseQuantity = (id) => {
+
+ dispatch({
+ type: "addToCart",
+ payload: { product: id },
+ });
+ dispatch({ type: "calculatePrice" });
+ // localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
+
+ }
+
+
+ const decreaseQuantity = (id) => {
+
+ dispatch({
+ type: "decrement",
+ payload: { product: id },
+ });
+
+ dispatch({ type: "calculatePrice" });
+
+ };
+ // ------------------------product handle End------------------------------//
+
+
+ function handleSubmit() {
+ if (
+ shipingInfo === null) {
swal({
title: 'Warning',
text: 'Please select Franchisee ',
@@ -317,10 +254,22 @@ function AddOrder() {
})
return
}
- else if (
- shipping === '' ||
+ else if (cartItems.length < 1) {
+ swal({
+ title: 'Warning',
+ text: 'Please select atleast one product',
+ icon: 'error',
+ button: 'Close',
+ dangerMode: true,
+ })
+ return
+ }
+
+
+ else if (
tax === '' ||
+ shippingCharge === '' ||
total === ''
) {
@@ -337,15 +286,8 @@ function AddOrder() {
setLoading(true)
- // const formData = new FormData()
- // formData.set('orderItems', cartItems)
- // formData.set('shippingInfo', AllStates.shipingInfo.franchisees)
- // formData.set('shipping_charge', shipping)
- // formData.set('tax_amount', tax)
- // formData.set('total_amount', total)
-
setLoading(true)
@@ -354,8 +296,8 @@ function AddOrder() {
`/api/order/create`,
{
orderItems: cartItems,
- shippingInfo: AllStates.shipingInfo.franchisees,
- shipping_charge: shipping,
+ shippingInfo: shipingInfo,
+ shipping_charge: shippingCharge,
tax_amount: tax,
total_amount: total
@@ -373,18 +315,18 @@ function AddOrder() {
// console.log(res)
swal({
title: 'Created',
- text: 'Order Created!',
+ text: res.data.message ? res.data.message : 'Order created!',
icon: 'success',
button: 'ok',
})
setLoading(false)
navigate('/orders/new')
})
- .catch((err) => {
+ .catch((error) => {
setLoading(false)
swal({
title: 'Warning',
- text: 'Something went wrong!',
+ text: error.response.data.message ? error.response.data.message : 'Something went wrong!',
icon: 'error',
button: 'Retry',
dangerMode: true,
@@ -453,8 +395,92 @@ function AddOrder() {
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ shipingInfo !== null &&
+
+
+
+

+
+
+
{shipingInfo?.name}
+
+ Address. : {shipingInfo?.address}
+
+
+ Contact No. : {shipingInfo?.contact_Number}
+
+
+ contact Person Name. : {shipingInfo?.contact_Person_Name}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
{' '}
+
+
+
+
+
+
+
+
+
+
+ {shipingInfo !== null &&
@@ -510,34 +536,22 @@ function AddOrder() {
}}>
-
+
{productDetails?.quantity}
-
+
- {productDetails?.PriceWithTax &&
- Price With Tax: ₹{productDetails?.PriceWithTax}
-
}
-
+
+ Price With Tax: ₹{productDetails?.price_With_Tax}
+
+
Price: ₹{productDetails?.price}
- {/* {allTax.length > 0 &&
-
Tax:
-
-
- } */}
@@ -556,124 +570,8 @@ function AddOrder() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {
- AllStates?.shipingInfo?.franchisees !== null &&
-
-
-
-

-
-
-
{AllStates.shipingInfo.franchisees?.name}
-
- Address. : {AllStates.shipingInfo.franchisees?.address}
-
-
- Contact No. : {AllStates.shipingInfo.franchisees?.contact_Number}
-
-
- contact Person Name. : {AllStates.shipingInfo.franchisees?.contact_Person_Name}
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- {/*
-
-
-
-
-
*/}
- {/*
-
-
*/}
-
- {/*
- {productData?.order_id && (
-
- )}
-
*/}
- {/* {productData.status === 'processing' && (
- <>
-
-
-
-
-
-
-
-
- >
- )} */}
- {/*
-
-
*/}
+ }
@@ -681,86 +579,6 @@ function AddOrder() {
-
- {/* {productData?.address && (
- <>
-
-
-
-
-
-
- >
- )} */}
-
-
-
-
-
-
- {/* {productData?.courier_name && (
-
-
-
- )}
- {productData?.tracking_id && (
-
-
-
- )} */}
-
-
-
-
-
-
-
-
- {/*
-
-
*/}
-
-
-
{' '}
-
-
-
-
-
@@ -895,6 +713,12 @@ function AddOrder() {
+
+
+
+
+
+
diff --git a/src/views/orders/EditOrder.js b/src/views/orders/EditOrder.js
index 5ecdc68..8727453 100644
--- a/src/views/orders/EditOrder.js
+++ b/src/views/orders/EditOrder.js
@@ -2,8 +2,6 @@
-
-
import React, { useState, useEffect, useRef } from 'react'
import axios from 'axios'
import { Link, useNavigate, useParams } from 'react-router-dom'
@@ -14,21 +12,18 @@ import { addItemsToCart } from 'src/redux/Actions/cartAction'
import toast from 'react-hot-toast'
import { cibBlackberry } from '@coreui/icons'
import Button from '@material-ui/core/Button'
-// import PrintOrderDetails from './PrintOrderDetails.js'
function EditOrder() {
const { status, id } = useParams()
- const { cartItems, subTotal, tax, shipping, total } = useSelector(
+ const { cartItems, subTotal, shippingCharge, tax, shipingInfo, total } = useSelector(
(state) => state.cart
);
- // const { cart, shippingInfo } = useSelector(
- // (state) => state
- // );
+
+
const AllStates = useSelector(
(state) => state
);
- console.log(AllStates.shipingInfo.franchisees)
const getValue = useRef()
const getFranchiseeID = useRef()
const dispatch = useDispatch();
@@ -37,18 +32,70 @@ function EditOrder() {
const token = isAutheticated()
const [productData, setProductData] = useState([])
const [allFranchisee, setAllFranchisee] = useState([])
+ const [allTax, setAllTax] = useState([])
+
const [productDetails, setProductDetails] = useState()
const [loading, setLoading] = useState(true)
const [orderStatus, setOrderStatus] = useState('')
- const [data, setData] = useState({
- product_Name: '',
- address: '',
- quantity: '',
- contact_Number: '',
- total_Price: '',
- })
+ // const [data, setData] = useState({
+ // product_Name: '',
+ // address: '',
+ // quantity: '',
+ // contact_Number: '',
+ // total_Price: '',
+ // })
+ useEffect(() => {
+ const getSingleOrder = async () => {
+ const res = await axios.get(`/api/order/getOne/${id}`, {
+ headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
+ })
+ if (res.data) {
+ // console.log(res.data?.order?.shippingInfo)
+
+ let options = {
+ Franchisee: res.data?.order?.shippingInfo?.Franchisee?._id,
+ name: res.data?.order?.shippingInfo?.name,
+
+
+ contact_Number: res.data?.order?.shippingInfo?.contact_Number,
+ contact_Person_Name: res.data?.order?.shippingInfo?.contact_Person_Name,
+ address: res.data?.order?.shippingInfo?.address,
+ city: res.data?.order?.shippingInfo?.city,
+ price_Lable: res.data?.order?.shippingInfo?.Franchisee?.price_Lable,
+ state: res.data?.order?.shippingInfo?.state,
+ banner: res.data?.order?.shippingInfo?.Franchisee?.banner?.url,
+ // Franchisee_Url: res?.data?.data?.url
+ }
+ dispatch({ type: "addShippingInfo", payload: options });
+ if (res.data?.order?.orderItems) {
+ res.data?.order?.orderItems.map((i, ind) => {
+ dispatch({ type: "addToCart", payload: i });
+ dispatch({ type: "calculatePrice" });
+
+ })
+ }
+
+ }
+ }
+ getSingleOrder()
+
+ }, [token])
+
+ useEffect(() => {
+ const getAllTax = async () => {
+ const res = await axios.get(`/api/tax/view_tax`, {
+ headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
+ })
+ if (res.data) {
+ // console.log(res.data)
+ setAllTax(res.data)
+ }
+ }
+ getAllTax()
+
+ }, [token])
useEffect(() => {
function getProductDetails() {
@@ -75,7 +122,7 @@ function EditOrder() {
})
.then((res) => {
setLoading(false)
- // console.log(res.data.product)
+ // console.log(res.data.data)
setAllFranchisee(res.data.data)
})
.catch((err) => {
@@ -103,7 +150,60 @@ function EditOrder() {
}))
}
+
+ // ------------------------Frenchisee handle------------------------------//
+
+ const handleGetSingleFrenchisee = async () => {
+ console.log(getFranchiseeID.current.value)
+
+ axios
+ .get(`/api/Temple/arrayspopulate/${getFranchiseeID.current.value}`, {
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ Authorization: `Bearer ${token}`,
+ },
+ })
+ .then((res) => {
+ setLoading(false)
+ console.log(res.data.data)
+ let options = {
+ Franchisee: res?.data?.data?._id,
+ name: res?.data?.data?.name,
+
+
+ contact_Number: res?.data?.data?.contact_Number,
+ contact_Person_Name: res?.data?.data?.contact_Person_Name,
+ address: (res?.data?.data?.address_line_1 + ' ' + res?.data?.data?.address_line_2),
+ city: res?.data?.data?.city?.city_name,
+ price_Lable: res?.data?.data?.price_Lable,
+ state: res?.data?.data?.city?.state?.state_name,
+ banner: res?.data?.data?.banner?.url,
+ Franchisee_Url: res?.data?.data?.url
+ }
+
+ dispatch({ type: "addShippingInfo", payload: options });
+
+ // localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
+
+ toast.success("Franchisee Added");
+
+ })
+ .catch((err) => {
+ setLoading(false)
+
+ })
+ }
+ const FranchiseeRemove = (id) => {
+ dispatch({
+ type: "deleteFromshippingInfo",
+ payload: { Franchisee: id },
+ });
+ toast.success("Franchisee Removed");
+
+ };
+ // ------------------------Frenchisee handle End------------------------------//
// ------------------------product handle------------------------------//
+
const handleGetSingleProduct = async (e) => {
@@ -113,17 +213,27 @@ function EditOrder() {
})
.then((res) => {
setLoading(false)
+ const productAllkey = Object.keys(res?.data?.product);
+ const productAllValue = Object.values(res?.data?.product);
+ const findIndex1 = (productAllkey.indexOf(shipingInfo?.price_Lable))
+ const findIndex2 = (productAllkey.indexOf(`${shipingInfo?.price_Lable}_With_Tax`))
+
+
+
let options = {
name: res?.data?.product?.name,
- price: res?.data?.product?.base_Price,
- id: res?.data?.product?._id,
+ price: productAllValue[findIndex1],
+ product: res?.data?.product?._id,
quantity: 1,
- image: res?.data?.product?.image?.url
+
+ image: res?.data?.product?.image?.url,
+
+ taxId: res?.data?.product?.taxId,
+ price_With_Tax: productAllValue[findIndex2],
}
dispatch({ type: "addToCart", payload: options });
dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
toast.success("Product Added");
@@ -138,92 +248,41 @@ function EditOrder() {
const handleRemove = (id) => {
dispatch({
type: "deleteFromCart",
- payload: id,
+ payload: { product: id },
});
dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
toast.success("Item Removed");
};
//increase qty
const increaseQuantity = (id) => {
+
dispatch({
type: "addToCart",
- payload: { id },
+ payload: { product: id },
});
dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
+ // localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
}
const decreaseQuantity = (id) => {
+
dispatch({
type: "decrement",
- payload: id,
+ payload: { product: id },
});
dispatch({ type: "calculatePrice" });
- localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
};
// ------------------------product handle End------------------------------//
- // ------------------------Frenchisee handle------------------------------//
- const handleGetSingleFrenchisee = async () => {
-
- axios
- .get(`/api/Temple/arrayspopulate/${getFranchiseeID.current.value}`, {
- headers: {
- 'Access-Control-Allow-Origin': '*',
- Authorization: `Bearer ${token}`,
- },
- })
- .then((res) => {
- setLoading(false)
- console.log(res.data.data)
- let options = {
- id: res?.data?.data?._id,
- name: res?.data?.data?.name,
-
-
- contact_Number: res?.data?.data?.contact_Number,
- contact_Person_Name: res?.data?.data?.contact_Person_Name,
- address: (res?.data?.data?.address_line_1 + ' ' + res?.data?.data?.address_line_2),
- city: res?.data?.data?.city?.city_name,
- state: res?.data?.data?.city?.state?.state_name,
- banner: res?.data?.data?.banner?.url,
- Franchisee_Url: res?.data?.data?.url
- }
-
- dispatch({ type: "addShippingInfo", payload: options });
-
- localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
-
- toast.success("Franchisee Added");
-
- })
- .catch((err) => {
- setLoading(false)
-
- })
- }
- const FranchiseeRemove = (id) => {
- dispatch({
- type: "deleteFromshippingInfo",
- payload: id,
- });
- localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
- toast.success("Franchisee Removed");
-
- };
- // ------------------------Frenchisee handle End------------------------------//
- console.log(AllStates.shipingInfo.franchisees.length)
- console.log(cartItems)
function handleSubmit() {
if (
- AllStates.shipingInfo.franchisees.length < 1) {
+ shipingInfo === null) {
swal({
title: 'Warning',
text: 'Please select Franchisee ',
@@ -233,6 +292,7 @@ function EditOrder() {
})
return
}
+
else if (cartItems.length < 1) {
swal({
title: 'Warning',
@@ -242,10 +302,12 @@ function EditOrder() {
dangerMode: true,
})
return
- } else if (
- shipping === '' ||
+ }
+
+ else if (
tax === '' ||
+ shippingCharge === '' ||
total === ''
) {
@@ -260,26 +322,20 @@ function EditOrder() {
}
+
setLoading(true)
- // const formData = new FormData()
- // formData.set('orderItems', cartItems)
- // formData.set('shippingInfo', AllStates.shipingInfo.franchisees)
- // formData.set('shipping_charge', shipping)
- // formData.set('tax_amount', tax)
- // formData.set('total_amount', total)
-
setLoading(true)
axios
- .post(
- `/api/order/create`,
+ .put(
+ `/api/order/edit/${id}`,
{
orderItems: cartItems,
- shippingInfo: AllStates.shipingInfo.franchisees,
- shipping_charge: shipping,
+ shippingInfo: shipingInfo,
+ shipping_charge: shippingCharge,
tax_amount: tax,
total_amount: total
@@ -294,21 +350,21 @@ function EditOrder() {
},
)
.then((res) => {
- console.log(res)
swal({
- title: 'Created',
- text: 'Order Created!',
+ title: 'Updated',
+ text: res.data.message ? res.data.message : 'Order Updated!',
icon: 'success',
button: 'ok',
})
setLoading(false)
navigate('/orders/new')
})
- .catch((err) => {
+ .catch((error) => {
setLoading(false)
+ console.log(error)
swal({
title: 'Warning',
- text: 'Something went wrong!',
+ text: error.response.data.message ? error.response.data.message : 'Something went wrong!',
icon: 'error',
button: 'Retry',
dangerMode: true,
@@ -353,7 +409,7 @@ function EditOrder() {
onClick={() => handleSubmit()}
disabled={loading}
>
- {loading ? 'Loading' : ' Edit Order'}
+ {loading ? 'Loading' : 'Update'}