From 4ca7f525d67897d3668443bcaf40933da517c044 Mon Sep 17 00:00:00 2001
From: pawan-dot <71133473+pawan-dot@users.noreply.github.com>
Date: Wed, 29 Nov 2023 16:02:06 +0530
Subject: [PATCH] show order
---
package.json | 2 +-
src/views/orders/EditOrder.js | 1469 ++++++++++++++++----------------
src/views/orders/NewOrders.js | 224 ++---
src/views/orders/ViewOrders.js | 946 ++++++++++----------
4 files changed, 1311 insertions(+), 1330 deletions(-)
diff --git a/package.json b/package.json
index d4d6b74..434b89e 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
"license": "MIT",
"author": "The CoreUI Team (https://github.com/orgs/coreui/people)",
"scripts": {
- "dev": "react-scripts --openssl-legacy-provider start",
+ "dev": "react-scripts start",
"build": "react-scripts build",
"build:n17": "react-scripts --openssl-legacy-provider build",
"changelog": "auto-changelog --starting-version 4.1.0 --commit-limit false --hide-credit",
diff --git a/src/views/orders/EditOrder.js b/src/views/orders/EditOrder.js
index c407c4c..1b5d147 100644
--- a/src/views/orders/EditOrder.js
+++ b/src/views/orders/EditOrder.js
@@ -1,779 +1,760 @@
-
-
-
-
-import React, { useState, useEffect, useRef } from 'react'
-import axios from 'axios'
-import { Link, useNavigate, useParams } from 'react-router-dom'
-import QRCode from 'react-qr-code'
-import { isAutheticated } from 'src/auth'
-import { useDispatch, useSelector } from 'react-redux'
-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 React, { useState, useEffect, useRef } from "react";
+import axios from "axios";
+import { Link, useNavigate, useParams } from "react-router-dom";
+import QRCode from "react-qr-code";
+import { isAutheticated } from "src/auth";
+import { useDispatch, useSelector } from "react-redux";
+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";
function EditOrder() {
- const { status, id } = useParams()
+ const { status, id } = useParams();
- const { cartItems, subTotal, shippingCharge, tax, shipingInfo, total } = useSelector(
- (state) => state.cart
- );
+ const { cartItems, subTotal, shippingCharge, tax, shipingInfo, total } =
+ useSelector((state) => state.cart);
+ const AllStates = useSelector((state) => state);
+ const getValue = useRef();
+ const getFranchiseeID = useRef();
+ const dispatch = useDispatch();
+ const navigate = useNavigate();
+ const printOrderRef = useRef();
+ const token = isAutheticated();
+ const [productData, setProductData] = useState([]);
+ const [allFranchisee, setAllFranchisee] = useState([]);
+ const [allTax, setAllTax] = useState([]);
- const AllStates = useSelector(
- (state) => state
- );
- const getValue = useRef()
- const getFranchiseeID = useRef()
- const dispatch = useDispatch();
- const navigate = useNavigate()
- const printOrderRef = useRef()
- 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 [orderId, setOrderId] = useState(null);
+ const [orderStatus, setOrderStatus] = useState("");
+ // 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) {
+ setOrderId(res.data?.order?.order_id);
+ let options = {
+ Franchisee: res.data?.order?.shippingInfo?.Franchisee?._id,
+ name: res.data?.order?.shippingInfo?.name,
-
-
- const [productDetails, setProductDetails] = useState()
- const [loading, setLoading] = useState(true)
- const [orderId, setOrderId] = useState(null)
- const [orderStatus, setOrderStatus] = useState('')
- // 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) {
- setOrderId(res.data?.order?.order_id)
- 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" });
-
- })
- }
-
- }
+ 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() {
- setLoading(true)
- axios
- .get(`/api/product/getAll/`, {
- headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
- })
- .then((res) => {
- setLoading(false)
- // console.log(res.data.product)
- setProductData(res.data.product)
- })
- .catch((err) => {
- setLoading(false)
- // getBack()
- })
- }
- function getFranchiseeDetails() {
- setLoading(true)
- axios
- .get(`/api/franchisee`, {
- headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
- })
- .then((res) => {
- setLoading(false)
- // console.log(res.data.data)
- setAllFranchisee(res.data.data)
- })
- .catch((err) => {
- setLoading(false)
- // getBack()
- })
- }
- getProductDetails()
- getFranchiseeDetails()
- }, [])
-
- const handleChange = (e) => {
- if (e.target.type === 'text') {
- setData((prev) => ({ ...prev, [e.target.id]: e.target.value }))
- } else {
- setOrderStatus(e.target.value)
- }
- }
- const handleQuantityChange = (e) => {
-
- setData((prev) => ({
- ...prev,
- quantity: e.target.value,
- total_Price: (productDetails?.base_Price * e.target.value)
- }))
-
- }
-
- // ------------------------Frenchisee handle------------------------------//
-
- const handleGetSingleFrenchisee = async () => {
- console.log(getFranchiseeID.current.value)
-
- axios
- .get(`/api/franchisee/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) => {
-
-
- axios
- .get(`/api/product/getOne/${getValue.current.value}`, {
- headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
- })
- .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");
+ 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);
+ }
};
- //increase qty
- const increaseQuantity = (id) => {
+ getAllTax();
+ }, [token]);
- dispatch({
- type: "addToCart",
- payload: { product: id },
+ useEffect(() => {
+ function getProductDetails() {
+ setLoading(true);
+ axios
+ .get(`/api/product/getAll/`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ Authorization: `Bearer ${token}`,
+ },
+ })
+ .then((res) => {
+ setLoading(false);
+ // console.log(res.data.product)
+ setProductData(res.data.product);
+ })
+ .catch((err) => {
+ setLoading(false);
+ // getBack()
});
- dispatch({ type: "calculatePrice" });
- // localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
-
}
-
-
- const decreaseQuantity = (id) => {
-
- dispatch({
- type: "decrement",
- payload: { product: id },
+ function getFranchiseeDetails() {
+ setLoading(true);
+ axios
+ .get(`/api/franchisee`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ Authorization: `Bearer ${token}`,
+ },
+ })
+ .then((res) => {
+ setLoading(false);
+ // console.log(res.data.data)
+ setAllFranchisee(res.data.data);
+ })
+ .catch((err) => {
+ setLoading(false);
+ // getBack()
});
+ }
+ getProductDetails();
+ getFranchiseeDetails();
+ }, []);
+
+ const handleChange = (e) => {
+ if (e.target.type === "text") {
+ setData((prev) => ({ ...prev, [e.target.id]: e.target.value }));
+ } else {
+ setOrderStatus(e.target.value);
+ }
+ };
+ const handleQuantityChange = (e) => {
+ setData((prev) => ({
+ ...prev,
+ quantity: e.target.value,
+ total_Price: productDetails?.base_Price * e.target.value,
+ }));
+ };
+
+ // ------------------------Frenchisee handle------------------------------//
+
+ const handleGetSingleFrenchisee = async () => {
+ console.log(getFranchiseeID.current.value);
+
+ axios
+ .get(`/api/franchisee/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) => {
+ axios
+ .get(`/api/product/getOne/${getValue.current.value}`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ Authorization: `Bearer ${token}`,
+ },
+ })
+ .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" });
- };
- // ------------------------product handle End------------------------------//
+ 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));
+ };
- function handleSubmit() {
- if (
- shipingInfo === null) {
- swal({
- title: 'Warning',
- text: 'Please select Franchisee ',
- icon: 'error',
- button: 'Close',
- dangerMode: true,
- })
- return
- }
+ const decreaseQuantity = (id) => {
+ dispatch({
+ type: "decrement",
+ payload: { product: id },
+ });
- else if (cartItems.length < 1) {
- swal({
- title: 'Warning',
- text: 'Please select atleast one product',
- icon: 'error',
- button: 'Close',
- dangerMode: true,
- })
- return
- }
+ dispatch({ type: "calculatePrice" });
+ };
+ // ------------------------product handle End------------------------------//
-
- else if (
- tax === '' ||
- shippingCharge === '' ||
- total === ''
-
- ) {
- swal({
- title: 'Warning',
- text: 'Fill all mandatory fields',
- icon: 'error',
- button: 'Close',
- dangerMode: true,
- })
- return
- }
-
-
-
- setLoading(true)
-
-
-
-
- setLoading(true)
- axios
- .put(
- `/api/order/edit/${id}`,
- {
- orderItems: cartItems,
- shippingInfo: shipingInfo,
- shipping_charge: shippingCharge,
- tax_amount: tax,
- total_amount: total
-
-
- },
-
- {
- headers: {
- 'Access-Control-Allow-Origin': '*',
- Authorization: `Bearer ${token}`,
- },
- },
- )
- .then((res) => {
- swal({
- title: 'Updated',
- text: res.data.message ? res.data.message : 'Order Updated!',
- icon: 'success',
- button: 'ok',
- })
- setLoading(false)
- navigate('/orders/new')
- })
- .catch((error) => {
- setLoading(false)
- console.log(error)
- swal({
- title: 'Warning',
- text: error.response.data.message ? error.response.data.message : 'Something went wrong!',
- icon: 'error',
- button: 'Retry',
- dangerMode: true,
- })
- })
+ function handleSubmit() {
+ if (shipingInfo === null) {
+ swal({
+ title: "Warning",
+ text: "Please select Franchisee ",
+ icon: "error",
+ button: "Close",
+ dangerMode: true,
+ });
+ return;
+ } 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 === "") {
+ swal({
+ title: "Warning",
+ text: "Fill all mandatory fields",
+ icon: "error",
+ button: "Close",
+ dangerMode: true,
+ });
+ return;
}
+ setLoading(true);
- function getBack() {
- navigate(`/orders/${status}`, { replace: true })
- }
+ setLoading(true);
+ axios
+ .put(
+ `/api/order/edit/${id}`,
+ {
+ orderItems: cartItems,
+ shippingInfo: shipingInfo,
+ shipping_charge: shippingCharge,
+ tax_amount: tax,
+ total_amount: total,
+ },
- return (
- <>
- {' '}
-
-
-
-
-
-
{
+ swal({
+ title: "Updated",
+ text: res.data.message ? res.data.message : "Order Updated!",
+ icon: "success",
+ button: "ok",
+ });
+ setLoading(false);
+ navigate("/orders/new");
+ })
+ .catch((error) => {
+ setLoading(false);
+ console.log(error);
+ swal({
+ title: "Warning",
+ text: error.response.data.message
+ ? error.response.data.message
+ : "Something went wrong!",
+ icon: "error",
+ button: "Retry",
+ dangerMode: true,
+ });
+ });
+ }
+
+ function getBack() {
+ navigate(`/orders/${status}`, { replace: true });
+ }
+
+ return (
+ <>
+ {" "}
+
+
+
+
+
+
-
-
-
Edit Order
- {orderId &&
Order ID : {orderId} }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {
- shipingInfo !== null &&
-
-
-
-

-
-
-
{shipingInfo?.name}
-
- Address. : {shipingInfo?.address}
-
-
- Contact No. : {shipingInfo?.contact_Number}
-
-
- Contact Person Name : {shipingInfo?.contact_Person_Name}
-
-
- Price Lable : {shipingInfo?.price_Lable}
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
{' '}
-
-
-
-
-
-
-
-
-
-
- {shipingInfo !== null &&
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {
- cartItems && cartItems.map((productDetails, i) =>
-
-
-
-

-
-
-
{productDetails?.name}
-
-
-
-
-
-
- {productDetails?.quantity}
-
-
-
-
-
- Price With Tax: ₹{productDetails?.price_With_Tax}
-
-
-
-
-
- Price: ₹{productDetails?.price}
-
-
-
-
-
-
-
-
-
-
-
-
- )
- }
- {subTotal &&
- Total Order Value: ₹{subTotal}
-
}
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- Order Placed On |
- : |
-
- {productData?.status_timeline?.new
- ? new Date(productData?.status_timeline?.new).toLocaleString('en-IN', {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: 'numeric',
- hour12: true,
- })
- : new Date(productData?.placed_on).toLocaleString('en-IN', {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: 'numeric',
- hour12: true,
- })}
- |
-
-
- Processing Started |
- : |
-
- {productData?.status_timeline?.processing
- ? new Date(productData?.status_timeline?.processing).toLocaleString(
- 'en-IN',
- {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: 'numeric',
- hour12: true,
- },
- )
- : '-'}
- |
-
-
- Dispatched On |
- : |
-
- {productData?.status_timeline?.dispatched
- ? new Date(productData?.status_timeline?.dispatched).toLocaleString(
- 'en-IN',
- {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: 'numeric',
- hour12: true,
- },
- )
- : '-'}
- |
-
-
- Delivered On |
- : |
-
- {productData?.status_timeline?.delivered
- ? new Date(productData?.status_timeline?.delivered).toLocaleString(
- 'en-IN',
- {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: 'numeric',
- hour12: true,
- },
- )
- : '-'}
- |
-
-
- Cancelled On |
- : |
-
- {productData?.status_timeline?.cancelled
- ? new Date(productData?.status_timeline?.cancelled).toLocaleString(
- 'en-IN',
- {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: 'numeric',
- hour12: true,
- },
- )
- : '-'}
- |
-
-
- Returned On |
- : |
-
- {productData?.status_timeline?.returned
- ? new Date(productData?.status_timeline?.returned).toLocaleString(
- 'en-IN',
- {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: 'numeric',
- hour12: true,
- },
- )
- : '-'}
- |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ >
+
+
Edit Order
+ {orderId && (
+
+ Order ID : {orderId}{" "}
+
+ )}
+
+
+
+
+
+
+
+
-
- {/*
*/}
+
+
+
+
+
+
+
+
+
+
+
+
+ {shipingInfo !== null && (
+
+
+
+

+
+
+
{shipingInfo?.name}
+
+ Address. : {shipingInfo?.address}
+
+
+ Contact No. : {shipingInfo?.contact_Number}
+
+
+ Contact Person Name :{" "}
+ {shipingInfo?.contact_Person_Name}
+
+
+ Price Lable : {shipingInfo?.price_Lable}
+
+
+
+
+
+
+
+ )}
+
+
+
{" "}
+
+
+
+
+
+
+
+ {shipingInfo !== null && (
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {cartItems &&
+ cartItems.map((productDetails, i) => (
+
+
+
+

+
+
+
+ {productDetails?.name}
+
+
+
+
+
+
+ {productDetails?.quantity}
+
+
+
+
+
+ Total Price: $
+ {productDetails?.quantity *
+ productDetails?.price}
+
+
+
+
+
+ Price: $
+ {productDetails?.price}
+
+
+
+
+
+
+
+ ))}
+ {subTotal && (
+
+ Total Order Value: ₹{subTotal}
+
+ )}
+
+
+
+ )}
+
+
+
+
+
+
+
+ Order Placed On |
+ : |
+
+ {productData?.status_timeline?.new
+ ? new Date(
+ productData?.status_timeline?.new
+ ).toLocaleString("en-IN", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "numeric",
+ hour12: true,
+ })
+ : new Date(productData?.placed_on).toLocaleString(
+ "en-IN",
+ {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "numeric",
+ hour12: true,
+ }
+ )}
+ |
+
+
+ Processing Started |
+ : |
+
+ {productData?.status_timeline?.processing
+ ? new Date(
+ productData?.status_timeline?.processing
+ ).toLocaleString("en-IN", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "numeric",
+ hour12: true,
+ })
+ : "-"}
+ |
+
+
+ Dispatched On |
+ : |
+
+ {productData?.status_timeline?.dispatched
+ ? new Date(
+ productData?.status_timeline?.dispatched
+ ).toLocaleString("en-IN", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "numeric",
+ hour12: true,
+ })
+ : "-"}
+ |
+
+
+ Delivered On |
+ : |
+
+ {productData?.status_timeline?.delivered
+ ? new Date(
+ productData?.status_timeline?.delivered
+ ).toLocaleString("en-IN", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "numeric",
+ hour12: true,
+ })
+ : "-"}
+ |
+
+
+ Cancelled On |
+ : |
+
+ {productData?.status_timeline?.cancelled
+ ? new Date(
+ productData?.status_timeline?.cancelled
+ ).toLocaleString("en-IN", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "numeric",
+ hour12: true,
+ })
+ : "-"}
+ |
+
+
+ Returned On |
+ : |
+
+ {productData?.status_timeline?.returned
+ ? new Date(
+ productData?.status_timeline?.returned
+ ).toLocaleString("en-IN", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "numeric",
+ hour12: true,
+ })
+ : "-"}
+ |
+
+
+
+
+
+
- >
- )
+
+
+
+
+ >
+ );
}
-export default EditOrder
+export default EditOrder;
diff --git a/src/views/orders/NewOrders.js b/src/views/orders/NewOrders.js
index 56aa6ee..485cf2a 100644
--- a/src/views/orders/NewOrders.js
+++ b/src/views/orders/NewOrders.js
@@ -1,84 +1,91 @@
-import React, { useState, useEffect } from 'react'
-import { Link } from 'react-router-dom'
-import axios from 'axios'
+import React, { useState, useEffect } from "react";
+import { Link } from "react-router-dom";
+import axios from "axios";
-import { isAutheticated } from 'src/auth'
-import Button from '@material-ui/core/Button'
+import { isAutheticated } from "src/auth";
+import Button from "@material-ui/core/Button";
function NewOrders() {
- const token = isAutheticated()
- const [loading, setLoading] = useState(true)
- const [success, setSuccess] = useState(true)
- const [newOrdersData, setNewOrdersData] = useState([])
+ const token = isAutheticated();
+ const [loading, setLoading] = useState(true);
+ const [success, setSuccess] = useState(true);
+ const [newOrdersData, setNewOrdersData] = useState([]);
- const [currentPage, setCurrentPage] = useState(1)
- const [itemPerPage, setItemPerPage] = useState(10)
- const [showData, setShowData] = useState(newOrdersData)
+ const [currentPage, setCurrentPage] = useState(1);
+ const [itemPerPage, setItemPerPage] = useState(10);
+ const [showData, setShowData] = useState(newOrdersData);
const handleShowEntries = (e) => {
- setCurrentPage(1)
- setItemPerPage(e.target.value)
- }
+ setCurrentPage(1);
+ setItemPerPage(e.target.value);
+ };
useEffect(() => {
function getNewOrder() {
axios
- .get(`/api/order/getAll`, {
- headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
+ .get(`/api/order/getAll/:new`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ Authorization: `Bearer ${token}`,
+ },
})
.then((res) => {
- setNewOrdersData(res.data.order)
- // console.log(res.data.order)
- setLoading(false)
+ setNewOrdersData(res.data.order);
+ console.log(res.data);
+ setLoading(false);
})
.catch((err) => {
- console.log(err)
- setLoading(false)
- })
+ console.log(err);
+ setLoading(false);
+ });
}
- getNewOrder()
- }, [success])
+ getNewOrder();
+ }, [success]);
useEffect(() => {
const loadData = () => {
- const indexOfLastPost = currentPage * itemPerPage
- const indexOfFirstPost = indexOfLastPost - itemPerPage
- setShowData(newOrdersData.slice(indexOfFirstPost, indexOfLastPost))
- }
- loadData()
- }, [currentPage, itemPerPage, newOrdersData])
-
+ const indexOfLastPost = currentPage * itemPerPage;
+ const indexOfFirstPost = indexOfLastPost - itemPerPage;
+ setShowData(newOrdersData.slice(indexOfFirstPost, indexOfLastPost));
+ };
+ loadData();
+ }, [currentPage, itemPerPage, newOrdersData]);
const handleDelete = (id) => {
- console.log(id)
+ console.log(id);
swal({
- title: 'Are you sure?',
- icon: 'error',
- buttons: { Yes: { text: 'Yes', value: true }, Cancel: { text: 'Cancel', value: 'cancel' } },
+ title: "Are you sure?",
+ icon: "error",
+ buttons: {
+ Yes: { text: "Yes", value: true },
+ Cancel: { text: "Cancel", value: "cancel" },
+ },
}).then((value) => {
if (value === true) {
axios
.delete(`/api/order/delete/${id}`, {
headers: {
- 'Access-Control-Allow-Origin': '*',
+ "Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
})
.then((res) => {
- setSuccess((prev) => !prev)
+ setSuccess((prev) => !prev);
})
.catch((err) => {
swal({
- title: 'Warning',
- text: err.response.data.message ? err.response.data.message : 'Something went wrong!',
- icon: 'error',
- button: 'Retry',
+ title: "Warning",
+ text: err.response.data.message
+ ? err.response.data.message
+ : "Something went wrong!",
+ icon: "error",
+ button: "Retry",
dangerMode: true,
- })
- })
+ });
+ });
}
- })
- }
+ });
+ };
return (
@@ -94,26 +101,25 @@ function NewOrders() {
justify-content-between
"
>
-
@@ -127,7 +133,7 @@ function NewOrders() {