product update
This commit is contained in:
parent
ae473a0c48
commit
810d5770b5
14
src/_nav.js
14
src/_nav.js
@ -60,13 +60,13 @@ const _nav = [
|
|||||||
to: "/categories",
|
to: "/categories",
|
||||||
group: "Product Management",
|
group: "Product Management",
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// component: CNavItem,
|
component: CNavItem,
|
||||||
// name: "Products",
|
name: "Products",
|
||||||
// icon: <CIcon icon={cilClipboard} customClassName="nav-icon" />,
|
icon: <CIcon icon={cilClipboard} customClassName="nav-icon" />,
|
||||||
// to: "/products",
|
to: "/products",
|
||||||
// group: "Product Management",
|
group: "Product Management",
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
component: CNavItem,
|
component: CNavItem,
|
||||||
name: "GST",
|
name: "GST",
|
||||||
|
@ -1,23 +1,11 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { Button } from "@mui/material";
|
import { Button } from "@mui/material";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
// import { API } from "src/API";
|
|
||||||
// import { isAutheticated } from "../../components/auth/authhelper";
|
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import {
|
import { CCard, CCardBody, CCardGroup, CCol, CContainer, CRow } from "@coreui/react";
|
||||||
CCard,
|
|
||||||
CCardBody,
|
|
||||||
CCardGroup,
|
|
||||||
CCol,
|
|
||||||
CContainer,
|
|
||||||
CRow,
|
|
||||||
} from "@coreui/react";
|
|
||||||
import ProductDetails from "./Productcomponents/ProductDetails.js";
|
import ProductDetails from "./Productcomponents/ProductDetails.js";
|
||||||
import ProductVarients from "./Productcomponents/ProductVarients.js";
|
|
||||||
import ProductsImages from "./Productcomponents/ProductImages.js";
|
import ProductsImages from "./Productcomponents/ProductImages.js";
|
||||||
import { isAutheticated } from "src/auth.js";
|
import { isAutheticated } from "src/auth.js";
|
||||||
// import ReleventProduct from "./Productcomponents/ReleventProduct";
|
|
||||||
// import ProductFabric from "./Productcomponents/ProductFabric.js";
|
|
||||||
|
|
||||||
const AddProduct = () => {
|
const AddProduct = () => {
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
@ -26,68 +14,19 @@ const AddProduct = () => {
|
|||||||
const [images, setImages] = useState([]);
|
const [images, setImages] = useState([]);
|
||||||
const [categories, setCategories] = useState([]);
|
const [categories, setCategories] = useState([]);
|
||||||
const [taxes, setTaxes] = useState([]);
|
const [taxes, setTaxes] = useState([]);
|
||||||
const [sizes, setSizes] = useState([]);
|
|
||||||
const [relevantProduct, setRelevantProduct] = useState([]);
|
|
||||||
const [allreleventSelectedProduct, setallReleventSelectedProduct] = useState(
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const [data, setData] = useState({
|
const [data, setData] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
category: "",
|
category: "",
|
||||||
// sku: "",
|
|
||||||
description: "",
|
description: "",
|
||||||
master_price: "",
|
price: "",
|
||||||
master_GST: "",
|
GST: "",
|
||||||
|
|
||||||
// discontinue_on: "",
|
|
||||||
// hsn_code: "",
|
|
||||||
product_Status: "",
|
product_Status: "",
|
||||||
|
|
||||||
special_instructions: "",
|
special_instructions: "",
|
||||||
// productImages.length == 0 ||
|
|
||||||
// gst_amount === "" ||
|
|
||||||
// price === "" ||
|
|
||||||
// totalAmt === "" ||
|
|
||||||
// gst_amount === "" ||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [varients, setVarients] = useState([
|
const navigate = useNavigate();
|
||||||
{
|
|
||||||
variant_Name: "",
|
|
||||||
weight: "",
|
|
||||||
volume: "",
|
|
||||||
price: "",
|
|
||||||
|
|
||||||
gst_Id: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
variant_Name: "",
|
|
||||||
weight: "",
|
|
||||||
volume: "",
|
|
||||||
price: "",
|
|
||||||
|
|
||||||
gst_Id: "",
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
variant_Name: "",
|
|
||||||
weight: "",
|
|
||||||
volume: "",
|
|
||||||
price: "",
|
|
||||||
|
|
||||||
gst_Id: "",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
const [allFabrics, setAllFabrics] = useState([]);
|
|
||||||
const [fabrics, setFabrics] = useState([
|
|
||||||
{ _id: "", fabric_Name: "", for_Part: "" },
|
|
||||||
{ _id: "", fabric_Name: "", for_Part: "" },
|
|
||||||
{ _id: "", fabric_Name: "", for_Part: "" },
|
|
||||||
]);
|
|
||||||
|
|
||||||
const getCategories = () => {
|
const getCategories = () => {
|
||||||
axios
|
axios
|
||||||
@ -101,7 +40,7 @@ const AddProduct = () => {
|
|||||||
setCategories(res?.data?.categories);
|
setCategories(res?.data?.categories);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -119,57 +58,11 @@ const AddProduct = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// const getSizes = () => {
|
|
||||||
// axios
|
|
||||||
// .get(`/api/erp/sizemaster/size`, {
|
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// setSizes(res.data?.data);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// const getItemWhichcontaiNameFabric = () => {
|
|
||||||
// axios
|
|
||||||
// .get(`/api/erp/item/name_contain_fabric`, {
|
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// console.log(res?.data);
|
|
||||||
// // setSizes(res.data?.data)
|
|
||||||
// setAllFabrics(res?.data?.data);
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// console.log(err);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const getProductsData = async () => {
|
|
||||||
// axios
|
|
||||||
// .get(`/api/product`, {
|
|
||||||
// headers: {
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// setRelevantProduct(res.data?.data);
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// console.log(err);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCategories();
|
getCategories();
|
||||||
getTaxes();
|
getTaxes();
|
||||||
// getSizes();
|
|
||||||
// getProductsData();
|
|
||||||
// getItemWhichcontaiNameFabric();
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleView = (n) => {
|
const handleView = (n) => {
|
||||||
if (viewState === n) return;
|
if (viewState === n) return;
|
||||||
setViewState(n);
|
setViewState(n);
|
||||||
@ -179,14 +72,7 @@ const AddProduct = () => {
|
|||||||
<CContainer>
|
<CContainer>
|
||||||
<CRow className="mt-3">
|
<CRow className="mt-3">
|
||||||
<CCol md={12}>
|
<CCol md={12}>
|
||||||
<div
|
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||||
className="
|
|
||||||
page-title-box
|
|
||||||
d-flex
|
|
||||||
align-items-center
|
|
||||||
justify-content-between
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<div style={{ fontSize: "22px" }} className="fw-bold">
|
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||||
Add Product : {data?.name && data?.name}
|
Add Product : {data?.name && data?.name}
|
||||||
</div>
|
</div>
|
||||||
@ -195,11 +81,7 @@ const AddProduct = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
style={{
|
style={{ fontWeight: "bold", marginBottom: "1rem", textTransform: "capitalize" }}
|
||||||
fontWeight: "bold",
|
|
||||||
marginBottom: "1rem",
|
|
||||||
textTransform: "capitalize",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Back
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
@ -222,15 +104,6 @@ const AddProduct = () => {
|
|||||||
loading={{ loading, setLoading }}
|
loading={{ loading, setLoading }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{viewState === 2 && (
|
|
||||||
<ProductVarients
|
|
||||||
productId={productId}
|
|
||||||
data={{ varients, setVarients }}
|
|
||||||
taxes={taxes}
|
|
||||||
sizes={sizes}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{viewState === 3 && (
|
{viewState === 3 && (
|
||||||
<ProductsImages
|
<ProductsImages
|
||||||
productId={productId}
|
productId={productId}
|
||||||
@ -238,38 +111,6 @@ const AddProduct = () => {
|
|||||||
loading={{ loading, setLoading }}
|
loading={{ loading, setLoading }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{/* {viewState === 4 && (
|
|
||||||
<ProductFabric
|
|
||||||
productId={productId}
|
|
||||||
data={{ fabrics, setFabrics }}
|
|
||||||
allFabrics={allFabrics}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{viewState === 5 && (
|
|
||||||
<ReleventProduct
|
|
||||||
data={{ data, setData }}
|
|
||||||
ProductId={productId}
|
|
||||||
AllreleventSelectedPro={{
|
|
||||||
allreleventSelectedProduct,
|
|
||||||
setallReleventSelectedProduct,
|
|
||||||
}}
|
|
||||||
ReleventProduct={relevantProduct}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)} */}
|
|
||||||
{/* {viewState === 5 && (
|
|
||||||
<ProductFabric
|
|
||||||
data={{ data, setData }}
|
|
||||||
ProductId={productId}
|
|
||||||
AllreleventSelectedPro={{
|
|
||||||
allreleventSelectedProduct,
|
|
||||||
setallReleventSelectedProduct,
|
|
||||||
}}
|
|
||||||
ReleventProduct={relevantProduct}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)} */}
|
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
</CCard>
|
</CCard>
|
||||||
</CCardGroup>
|
</CCardGroup>
|
||||||
@ -280,60 +121,19 @@ const AddProduct = () => {
|
|||||||
<CCardBody>
|
<CCardBody>
|
||||||
<div className="d-grid gap-2">
|
<div className="d-grid gap-2">
|
||||||
<button
|
<button
|
||||||
className={
|
className={viewState === 1 ? "btn btn-light" : "btn btn-info text-white"}
|
||||||
viewState === 1
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleView(1)}
|
onClick={() => handleView(1)}
|
||||||
>
|
>
|
||||||
Product Details
|
Product Details
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={
|
className={viewState === 3 ? "btn btn-light" : "btn btn-info text-white"}
|
||||||
viewState === 2
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleView(2)}
|
|
||||||
>
|
|
||||||
Variants
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className={
|
|
||||||
viewState === 3
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleView(3)}
|
onClick={() => handleView(3)}
|
||||||
>
|
>
|
||||||
Images
|
Images
|
||||||
</button>
|
</button>
|
||||||
{/* <button
|
|
||||||
className={
|
|
||||||
viewState === 4
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleView(4)}
|
|
||||||
>
|
|
||||||
Fabric
|
|
||||||
</button> */}
|
|
||||||
{/* <button
|
|
||||||
className={
|
|
||||||
viewState === 5
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleView(5)}
|
|
||||||
>
|
|
||||||
+ Relevent Product
|
|
||||||
</button> */}
|
|
||||||
</div>
|
</div>
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
</CCard>
|
</CCard>
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { Button } from "@mui/material";
|
import { Button } from "@mui/material";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
// import { API } from "src/API";
|
|
||||||
// import { isAutheticated } from "../../components/auth/authhelper";
|
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom";
|
import { Link, useNavigate, useParams } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
CCard,
|
CCard,
|
||||||
@ -13,26 +11,18 @@ import {
|
|||||||
CRow,
|
CRow,
|
||||||
} from "@coreui/react";
|
} from "@coreui/react";
|
||||||
import ProductDetails from "./Productcomponents/ProductDetails.js";
|
import ProductDetails from "./Productcomponents/ProductDetails.js";
|
||||||
import ProductVarients from "./Productcomponents/ProductVarients.js";
|
|
||||||
import ProductsImages from "./Productcomponents/ProductImages.js";
|
import ProductsImages from "./Productcomponents/ProductImages.js";
|
||||||
import { isAutheticated } from "src/auth.js";
|
import { isAutheticated } from "src/auth.js";
|
||||||
// import ReleventProduct from "./Productcomponents/ReleventProduct";
|
|
||||||
// import ProductFabric from "./Productcomponents/ProductFabric.js";
|
|
||||||
|
|
||||||
const EditProduct = () => {
|
const EditProduct = () => {
|
||||||
const id = useParams()?.id;
|
const id = useParams()?.id;
|
||||||
console.log("id", id);
|
// console.log("id", id);
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
const [productId, setProductId] = useState("");
|
const [productId, setProductId] = useState("");
|
||||||
const [viewState, setViewState] = useState(1);
|
const [viewState, setViewState] = useState(1);
|
||||||
const [images, setImages] = useState([]);
|
const [images, setImages] = useState([]);
|
||||||
const [categories, setCategories] = useState([]);
|
const [categories, setCategories] = useState([]);
|
||||||
const [taxes, setTaxes] = useState([]);
|
const [taxes, setTaxes] = useState([]);
|
||||||
const [sizes, setSizes] = useState([]);
|
|
||||||
const [relevantProduct, setRelevantProduct] = useState([]);
|
|
||||||
const [allreleventSelectedProduct, setallReleventSelectedProduct] = useState(
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@ -40,46 +30,13 @@ const EditProduct = () => {
|
|||||||
const [data, setData] = useState({
|
const [data, setData] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
category: "",
|
category: "",
|
||||||
// sku: "",
|
|
||||||
description: "",
|
description: "",
|
||||||
master_price: "",
|
price: "",
|
||||||
master_GST: "",
|
GST: "",
|
||||||
// discontinue_on: "",
|
|
||||||
// hsn_code: "",
|
|
||||||
product_Status: "",
|
product_Status: "",
|
||||||
|
|
||||||
special_instructions: "",
|
special_instructions: "",
|
||||||
// productImages.length == 0 ||
|
|
||||||
// gst_amount === "" ||
|
|
||||||
// price === "" ||
|
|
||||||
// totalAmt === "" ||
|
|
||||||
// gst_amount === "" ||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [varients, setVarients] = useState([
|
|
||||||
{
|
|
||||||
variant_Name: "",
|
|
||||||
weight: "",
|
|
||||||
volume: "",
|
|
||||||
price: "",
|
|
||||||
gst_Id: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
variant_Name: "",
|
|
||||||
weight: "",
|
|
||||||
volume: "",
|
|
||||||
price: "",
|
|
||||||
gst_Id: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
variant_Name: "",
|
|
||||||
weight: "",
|
|
||||||
volume: "",
|
|
||||||
price: "",
|
|
||||||
gst_Id: "",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
const getProduct = () => {
|
const getProduct = () => {
|
||||||
axios
|
axios
|
||||||
@ -90,31 +47,22 @@ const EditProduct = () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
// console.log("res", res.data);
|
||||||
setData((prev) => ({
|
setData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
...res.data?.data,
|
...res.data?.data,
|
||||||
category: res.data?.data?.category?._id,
|
category: res.data?.data?.category?._id,
|
||||||
master_GST: res.data?.data?.master_GST?._id,
|
GST: res.data?.data?.GST?._id,
|
||||||
product_Status: res.data?.data?.product_Status,
|
product_Status: res.data?.data?.product_Status,
|
||||||
// discontinue_on: res.data?.data?.discontinue_on?.slice(0, 10),
|
|
||||||
}));
|
}));
|
||||||
setProductId(res.data?.data?._id);
|
setProductId(res.data?.data?._id);
|
||||||
setImages([...res.data?.data?.image]);
|
setImages([...res.data?.data?.image]);
|
||||||
setVarients([...res.data.data?.variants]);
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
/////////////////
|
|
||||||
const [allFabrics, setAllFabrics] = useState([]);
|
|
||||||
const [fabrics, setFabrics] = useState([
|
|
||||||
{ _id: "", fabric_Name: "", for_Part: "" },
|
|
||||||
{ _id: "", fabric_Name: "", for_Part: "" },
|
|
||||||
{ _id: "", fabric_Name: "", for_Part: "" },
|
|
||||||
]);
|
|
||||||
|
|
||||||
const getCategories = () => {
|
const getCategories = () => {
|
||||||
axios
|
axios
|
||||||
.get(`/api/category/getCategories`, {
|
.get(`/api/category/getCategories`, {
|
||||||
@ -141,62 +89,14 @@ const EditProduct = () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
// console.log("tax", res.data);
|
|
||||||
setTaxes(res.data);
|
setTaxes(res.data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// const getSizes = () => {
|
|
||||||
// axios
|
|
||||||
// .get(`/api/erp/sizemaster/size`, {
|
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// setSizes(res.data?.data);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// const getItemWhichcontaiNameFabric = () => {
|
|
||||||
// axios
|
|
||||||
// .get(`/api/erp/item/name_contain_fabric`, {
|
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// console.log(res?.data);
|
|
||||||
// // setSizes(res.data?.data)
|
|
||||||
// setAllFabrics(res?.data?.data);
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// console.log(err);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const getProductsData = async () => {
|
|
||||||
// axios
|
|
||||||
// .get(`/api/product`, {
|
|
||||||
// headers: {
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// setRelevantProduct(res.data?.data);
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// console.log(err);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getProduct();
|
getProduct();
|
||||||
getCategories();
|
getCategories();
|
||||||
getTaxes();
|
getTaxes();
|
||||||
// getSizes();
|
|
||||||
// getProductsData();
|
|
||||||
// getItemWhichcontaiNameFabric();
|
|
||||||
}, []);
|
}, []);
|
||||||
const handleView = (n) => {
|
const handleView = (n) => {
|
||||||
if (viewState === n) return;
|
if (viewState === n) return;
|
||||||
@ -250,15 +150,6 @@ const EditProduct = () => {
|
|||||||
loading={{ loading, setLoading }}
|
loading={{ loading, setLoading }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{viewState === 2 && (
|
|
||||||
<ProductVarients
|
|
||||||
productId={productId}
|
|
||||||
data={{ varients, setVarients }}
|
|
||||||
taxes={taxes}
|
|
||||||
sizes={sizes}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{viewState === 3 && (
|
{viewState === 3 && (
|
||||||
<ProductsImages
|
<ProductsImages
|
||||||
productId={productId}
|
productId={productId}
|
||||||
@ -266,38 +157,6 @@ const EditProduct = () => {
|
|||||||
loading={{ loading, setLoading }}
|
loading={{ loading, setLoading }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{/* {viewState === 4 && (
|
|
||||||
<ProductFabric
|
|
||||||
productId={productId}
|
|
||||||
data={{ fabrics, setFabrics }}
|
|
||||||
allFabrics={allFabrics}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{viewState === 5 && (
|
|
||||||
<ReleventProduct
|
|
||||||
data={{ data, setData }}
|
|
||||||
ProductId={productId}
|
|
||||||
AllreleventSelectedPro={{
|
|
||||||
allreleventSelectedProduct,
|
|
||||||
setallReleventSelectedProduct,
|
|
||||||
}}
|
|
||||||
ReleventProduct={relevantProduct}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)} */}
|
|
||||||
{/* {viewState === 5 && (
|
|
||||||
<ProductFabric
|
|
||||||
data={{ data, setData }}
|
|
||||||
ProductId={productId}
|
|
||||||
AllreleventSelectedPro={{
|
|
||||||
allreleventSelectedProduct,
|
|
||||||
setallReleventSelectedProduct,
|
|
||||||
}}
|
|
||||||
ReleventProduct={relevantProduct}
|
|
||||||
loading={{ loading, setLoading }}
|
|
||||||
/>
|
|
||||||
)} */}
|
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
</CCard>
|
</CCard>
|
||||||
</CCardGroup>
|
</CCardGroup>
|
||||||
@ -318,17 +177,6 @@ const EditProduct = () => {
|
|||||||
>
|
>
|
||||||
Product Details
|
Product Details
|
||||||
</button>
|
</button>
|
||||||
<button
|
|
||||||
className={
|
|
||||||
viewState === 2
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleView(2)}
|
|
||||||
>
|
|
||||||
Variants
|
|
||||||
</button>
|
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
viewState === 3
|
viewState === 3
|
||||||
@ -340,28 +188,6 @@ const EditProduct = () => {
|
|||||||
>
|
>
|
||||||
Images
|
Images
|
||||||
</button>
|
</button>
|
||||||
{/* <button
|
|
||||||
className={
|
|
||||||
viewState === 4
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleView(4)}
|
|
||||||
>
|
|
||||||
Fabric
|
|
||||||
</button> */}
|
|
||||||
{/* <button
|
|
||||||
className={
|
|
||||||
viewState === 5
|
|
||||||
? "btn btn-light"
|
|
||||||
: "btn btn-info text-white"
|
|
||||||
}
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleView(5)}
|
|
||||||
>
|
|
||||||
+ Relevent Product
|
|
||||||
</button> */}
|
|
||||||
</div>
|
</div>
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
</CCard>
|
</CCard>
|
||||||
@ -373,617 +199,3 @@ const EditProduct = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default EditProduct;
|
export default EditProduct;
|
||||||
// import React, { useEffect, useState } from "react";
|
|
||||||
// import Button from "@material-ui/core/Button";
|
|
||||||
// import { Link, useNavigate, useParams } from "react-router-dom";
|
|
||||||
// import swal from "sweetalert";
|
|
||||||
// import axios from "axios";
|
|
||||||
// import { isAutheticated } from "src/auth";
|
|
||||||
|
|
||||||
// import CloudUploadIcon from "@mui/icons-material/CloudUpload";
|
|
||||||
// import DeleteSharpIcon from "@mui/icons-material/DeleteSharp";
|
|
||||||
// import {
|
|
||||||
// Box,
|
|
||||||
// FormControl,
|
|
||||||
// IconButton,
|
|
||||||
// MenuItem,
|
|
||||||
// Select,
|
|
||||||
// TextField,
|
|
||||||
// } from "@mui/material";
|
|
||||||
// // import { WebsiteURL } from '../WebsiteURL'
|
|
||||||
|
|
||||||
// const EditProduct = () => {
|
|
||||||
// const id = useParams()?.id;
|
|
||||||
|
|
||||||
// const token = isAutheticated();
|
|
||||||
// const navigate = useNavigate();
|
|
||||||
|
|
||||||
// const [loading, setLoading] = useState(false);
|
|
||||||
// const [allTax, setAllTax] = useState([]);
|
|
||||||
// const [categories, setCatgories] = useState([]);
|
|
||||||
// const [imagesPreview, setImagesPreview] = useState([]);
|
|
||||||
// const [name, setName] = useState("");
|
|
||||||
// const [description, setDescription] = useState("");
|
|
||||||
// const [productImages, setProductImages] = useState([]);
|
|
||||||
// const [price, setPrice] = useState("");
|
|
||||||
// const [category, setCategoryName] = useState("");
|
|
||||||
// const [error, setError] = useState("");
|
|
||||||
// const [initTax, setInitTax] = useState();
|
|
||||||
// const [selectedTax, setselectedTax] = useState();
|
|
||||||
// const [product_Status, setproduct_Status] = useState("");
|
|
||||||
|
|
||||||
// const [totalAmt, setTotalAmt] = useState(0);
|
|
||||||
// const [gst_amount, setGst_amount] = useState(0);
|
|
||||||
// const [newUpdatedImages, setNewUpdatedImages] = useState([]);
|
|
||||||
|
|
||||||
// //get Productdata
|
|
||||||
// const getProduct = async () => {
|
|
||||||
// axios
|
|
||||||
// .get(`/api/product/getOne/${id}`, {
|
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// setName(res?.data?.product.name);
|
|
||||||
// setDescription(res.data.product.description);
|
|
||||||
// setProductImages(res.data.product.image);
|
|
||||||
// setPrice(res.data.product.price);
|
|
||||||
// setCategoryName(res.data.product?.category?._id);
|
|
||||||
// setselectedTax(res.data.product?.gst);
|
|
||||||
// setInitTax(res.data.product?.gst?._id);
|
|
||||||
// setTotalAmt(res.data.product?.total_amount);
|
|
||||||
// setGst_amount(res.data.product?.gst_amount);
|
|
||||||
// setproduct_Status(res.data.product?.product_Status);
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// swal({
|
|
||||||
// title: error,
|
|
||||||
// text: " Can not fetch the product ",
|
|
||||||
// icon: "error",
|
|
||||||
// button: "Retry",
|
|
||||||
// dangerMode: true,
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// // console.log(selectedTax, "selectedTax");
|
|
||||||
|
|
||||||
// const getCategories = async () => {
|
|
||||||
// try {
|
|
||||||
// const response = await axios.get("/api/category/getCategories", {
|
|
||||||
// headers: {
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if (response.status === 200) {
|
|
||||||
// setCatgories(response?.data?.categories);
|
|
||||||
// }
|
|
||||||
// } catch (error) {
|
|
||||||
// swal({
|
|
||||||
// title: error,
|
|
||||||
// text: " please login to access the resource ",
|
|
||||||
// icon: "error",
|
|
||||||
// button: "Retry",
|
|
||||||
// dangerMode: true,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// useEffect(() => {
|
|
||||||
// getProduct();
|
|
||||||
// getCategories();
|
|
||||||
// }, []);
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// const getAllTax = async () => {
|
|
||||||
// const res = await axios.get(`/api/tax/view_tax`, {
|
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// if (res.data) {
|
|
||||||
// setAllTax(res.data);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// getAllTax();
|
|
||||||
// }, [token]);
|
|
||||||
// const TaxRatechange = async (e) => {
|
|
||||||
// let m = JSON.parse(e.target.value);
|
|
||||||
// setInitTax("");
|
|
||||||
// if (m?.tax) {
|
|
||||||
// let totalprice = Number(price) + Number((price * m?.tax) / 100);
|
|
||||||
// setGst_amount(Number((price * m?.tax) / 100)?.toFixed(2));
|
|
||||||
// setTotalAmt(totalprice?.toFixed(2));
|
|
||||||
// setselectedTax(m?._id);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// // console.log(selectedTax, "inisele");
|
|
||||||
// const handlePriceChange = (e) => {
|
|
||||||
// const newPrice = e.target.value;
|
|
||||||
|
|
||||||
// setPrice(newPrice);
|
|
||||||
// const selectedTaxObj = allTax.find(
|
|
||||||
// (t) =>
|
|
||||||
// t._id ===
|
|
||||||
// (typeof selectedTax === "object" ? selectedTax._id : selectedTax)
|
|
||||||
// );
|
|
||||||
// // console.log(selectedTax);
|
|
||||||
// // console.log(selectedTaxObj, "this is ", selectedTax);
|
|
||||||
|
|
||||||
// if (selectedTaxObj && !isNaN(newPrice)) {
|
|
||||||
// const gstAmount = (newPrice * selectedTaxObj.tax) / 100;
|
|
||||||
// const totalAmount = Number(newPrice) + gstAmount;
|
|
||||||
|
|
||||||
// setGst_amount(gstAmount.toFixed(2));
|
|
||||||
// setTotalAmt(totalAmount.toFixed(2));
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// const handleSubmit = () => {
|
|
||||||
// // console.log("selected Tax", selectedTax);
|
|
||||||
// if (
|
|
||||||
// name === "" ||
|
|
||||||
// description === "" ||
|
|
||||||
// productImages.length == 0 ||
|
|
||||||
// category === "" ||
|
|
||||||
// selectedTax === "" ||
|
|
||||||
// gst_amount === "" ||
|
|
||||||
// price === "" ||
|
|
||||||
// product_Status === "" ||
|
|
||||||
// totalAmt === "" ||
|
|
||||||
// gst_amount === "" ||
|
|
||||||
// (productImages.length == 0 && newUpdatedImages.length == 0)
|
|
||||||
// ) {
|
|
||||||
// swal({
|
|
||||||
// title: "Warning",
|
|
||||||
// text: "Fill all mandatory fields",
|
|
||||||
// icon: "error",
|
|
||||||
// button: "Close",
|
|
||||||
// dangerMode: true,
|
|
||||||
// });
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// setLoading(true);
|
|
||||||
// const formData = new FormData();
|
|
||||||
// formData.append("name", name);
|
|
||||||
|
|
||||||
// formData.append("description", description);
|
|
||||||
// formData.append("price", price);
|
|
||||||
// formData.append("category", category);
|
|
||||||
// formData.append("total_amount", totalAmt);
|
|
||||||
// formData.append("gst_amount", gst_amount);
|
|
||||||
// formData.append("product_Status", product_Status);
|
|
||||||
|
|
||||||
// formData.append("gst", initTax === "" ? selectedTax : initTax);
|
|
||||||
|
|
||||||
// newUpdatedImages.length > 0 &&
|
|
||||||
// newUpdatedImages.forEach((Singleimage) => {
|
|
||||||
// formData.append("newImages", Singleimage);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// formData.append("image", JSON.stringify(productImages));
|
|
||||||
|
|
||||||
// axios
|
|
||||||
// .patch(`/api/product/update/${id}`, formData, {
|
|
||||||
// headers: {
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// "Content-Type": "multipart/form-data",
|
|
||||||
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// swal({
|
|
||||||
// title: "Updated",
|
|
||||||
// text: "Product Updated successfully!",
|
|
||||||
// icon: "success",
|
|
||||||
// button: "ok",
|
|
||||||
// });
|
|
||||||
// setLoading(false);
|
|
||||||
// navigate("/products", { replace: true });
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// setLoading(false);
|
|
||||||
|
|
||||||
// const message = err.response?.data?.message
|
|
||||||
// ? err.response?.data?.message
|
|
||||||
// : "Something went wrong!";
|
|
||||||
// swal({
|
|
||||||
// title: "Warning",
|
|
||||||
// text: message,
|
|
||||||
// icon: "error",
|
|
||||||
// button: "Retry",
|
|
||||||
// dangerMode: true,
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// const handleFileChange = (e) => {
|
|
||||||
// const files = e.target.files;
|
|
||||||
|
|
||||||
// // Check the total number of selected files
|
|
||||||
// if (newUpdatedImages.length + files.length > 4 - productImages.length) {
|
|
||||||
// setError("You can only upload up to 4 images.");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Check file types and append to selectedFiles
|
|
||||||
// const allowedTypes = ["image/jpeg", "image/png", "image/jpg"];
|
|
||||||
// const selected = [];
|
|
||||||
|
|
||||||
// for (let i = 0; i < files.length; i++) {
|
|
||||||
// if (
|
|
||||||
// newUpdatedImages.length + selected.length >=
|
|
||||||
// 4 - productImages.length
|
|
||||||
// ) {
|
|
||||||
// break; // Don't allow more than 4 images
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (allowedTypes.includes(files[i].type)) {
|
|
||||||
// selected.push(files[i]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (selected.length === 0) {
|
|
||||||
// setError("Please upload only PNG, JPEG, or JPG files.");
|
|
||||||
// } else {
|
|
||||||
// setError("");
|
|
||||||
// setNewUpdatedImages([...newUpdatedImages, ...selected]);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const handelDelete = async (public_id) => {
|
|
||||||
// const ary = public_id.split("/");
|
|
||||||
|
|
||||||
// const res = await axios.delete(
|
|
||||||
// `/api/product/deleteImage/jatinMor/product/${ary[2]}`,
|
|
||||||
// {
|
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// if (res) {
|
|
||||||
// const filtered = productImages.filter(
|
|
||||||
// (item) => item.public_id !== public_id
|
|
||||||
// );
|
|
||||||
// setProductImages(filtered);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// const handellocalDelete = (image) => {
|
|
||||||
// const filtered = productImages.filter((item) => item !== image);
|
|
||||||
// setProductImages(filtered);
|
|
||||||
// };
|
|
||||||
// return (
|
|
||||||
// <div className="container">
|
|
||||||
// <div className="row">
|
|
||||||
// <div className="col-12">
|
|
||||||
// <div
|
|
||||||
// className="
|
|
||||||
// page-title-box
|
|
||||||
// d-flex
|
|
||||||
// align-items-center
|
|
||||||
// justify-content-between
|
|
||||||
// "
|
|
||||||
// >
|
|
||||||
// <div style={{ fontSize: "22px" }} className="fw-bold">
|
|
||||||
// Edit Product
|
|
||||||
// </div>
|
|
||||||
// <div style={{ display: "flex", gap: "1rem" }}>
|
|
||||||
// <h4 className="mb-0"></h4>
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <div className="page-title-right">
|
|
||||||
// <Button
|
|
||||||
// variant="contained"
|
|
||||||
// color="primary"
|
|
||||||
// style={{
|
|
||||||
// fontWeight: "bold",
|
|
||||||
// marginBottom: "1rem",
|
|
||||||
// textTransform: "capitalize",
|
|
||||||
// marginRight: "5px",
|
|
||||||
// }}
|
|
||||||
// onClick={() => handleSubmit()}
|
|
||||||
// disabled={loading}
|
|
||||||
// >
|
|
||||||
// {loading ? "Loading" : "Save"}
|
|
||||||
// </Button>
|
|
||||||
// <Link to="/products">
|
|
||||||
// <Button
|
|
||||||
// variant="contained"
|
|
||||||
// color="secondary"
|
|
||||||
// style={{
|
|
||||||
// fontWeight: "bold",
|
|
||||||
// marginBottom: "1rem",
|
|
||||||
// textTransform: "capitalize",
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// Back
|
|
||||||
// </Button>
|
|
||||||
// </Link>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// <div className="row">
|
|
||||||
// <div className="col-lg-6 col-md-6 col-sm-12 my-1">
|
|
||||||
// <div className="card h-100">
|
|
||||||
// <div className="card-body px-5">
|
|
||||||
// <div className="mb-3">
|
|
||||||
// <label htmlFor="title" className="form-label">
|
|
||||||
// Product Name*
|
|
||||||
// </label>
|
|
||||||
// <input
|
|
||||||
// type="text"
|
|
||||||
// className="form-control"
|
|
||||||
// id="name"
|
|
||||||
// value={name}
|
|
||||||
// maxLength={35}
|
|
||||||
// onChange={(e) => setName(e.target.value)}
|
|
||||||
// />
|
|
||||||
// {name ? (
|
|
||||||
// <>
|
|
||||||
// <small className="charLeft mt-4 fst-italic">
|
|
||||||
// {35 - name.length} characters left
|
|
||||||
// </small>
|
|
||||||
// </>
|
|
||||||
// ) : (
|
|
||||||
// <></>
|
|
||||||
// )}{" "}
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <div className="mb-3">
|
|
||||||
// <label htmlFor="title" className="form-label">
|
|
||||||
// Description*
|
|
||||||
// </label>
|
|
||||||
// <textarea
|
|
||||||
// type="text"
|
|
||||||
// className="form-control"
|
|
||||||
// id="description"
|
|
||||||
// rows="8"
|
|
||||||
// value={description}
|
|
||||||
// maxLength="400"
|
|
||||||
// onChange={(e) => setDescription(e.target.value)}
|
|
||||||
// />
|
|
||||||
// {description ? (
|
|
||||||
// <>
|
|
||||||
// <small className="charLeft mt-4 fst-italic">
|
|
||||||
// {400 - description.length} characters left
|
|
||||||
// </small>
|
|
||||||
// </>
|
|
||||||
// ) : (
|
|
||||||
// <></>
|
|
||||||
// )}
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <Box>
|
|
||||||
// <label htmlFor="upload-Image">
|
|
||||||
// <TextField
|
|
||||||
// style={{
|
|
||||||
// display: "none",
|
|
||||||
// width: "350px",
|
|
||||||
// height: "350px",
|
|
||||||
// borderRadius: "10%",
|
|
||||||
// }}
|
|
||||||
// fullWidth
|
|
||||||
// id="upload-Image"
|
|
||||||
// type="file"
|
|
||||||
// accept=".jpg , .png ,.jpeg"
|
|
||||||
// label="file"
|
|
||||||
// multiple
|
|
||||||
// variant="outlined"
|
|
||||||
// onChange={(e) => handleFileChange(e)}
|
|
||||||
// />
|
|
||||||
// <Box
|
|
||||||
// style={{ borderRadius: "10%" }}
|
|
||||||
// sx={{
|
|
||||||
// margin: "1rem 0rem",
|
|
||||||
// cursor: "pointer",
|
|
||||||
// width: "140px",
|
|
||||||
// height: "140px",
|
|
||||||
// border: "2px solid grey",
|
|
||||||
// // borderRadius: '50%',
|
|
||||||
|
|
||||||
// "&:hover": {
|
|
||||||
// background: "rgba(112,112,112,0.5)",
|
|
||||||
// },
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// <CloudUploadIcon
|
|
||||||
// style={{
|
|
||||||
// color: "grey",
|
|
||||||
// margin: "auto",
|
|
||||||
// fontSize: "5rem",
|
|
||||||
// }}
|
|
||||||
// fontSize="large"
|
|
||||||
// />
|
|
||||||
// </Box>
|
|
||||||
// </label>
|
|
||||||
// </Box>
|
|
||||||
// {error && <p style={{ color: "red" }}>{error}</p>}
|
|
||||||
// <div>
|
|
||||||
// <strong className="fs-6 fst-italic">
|
|
||||||
// *You cannot upload more than 4 images
|
|
||||||
// </strong>
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// <Box style={{ display: "flex" }}>
|
|
||||||
// {productImages &&
|
|
||||||
// productImages.map((image, i) => (
|
|
||||||
// <Box marginRight={"2rem"}>
|
|
||||||
// <img
|
|
||||||
// src={image.url}
|
|
||||||
// alt="profileImage"
|
|
||||||
// style={{
|
|
||||||
// width: 70,
|
|
||||||
// height: 70,
|
|
||||||
|
|
||||||
// marginBottom: "1rem",
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// {productImages.length + newUpdatedImages.length > 1 && (
|
|
||||||
// <DeleteSharpIcon
|
|
||||||
// onClick={() => handelDelete(image.public_id)}
|
|
||||||
// fontSize="small"
|
|
||||||
// sx={{
|
|
||||||
// color: "white",
|
|
||||||
// position: "absolute",
|
|
||||||
// cursor: "pointer",
|
|
||||||
// padding: "0.2rem",
|
|
||||||
// background: "black",
|
|
||||||
// borderRadius: "50%",
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// )}
|
|
||||||
// {/* </IconButton> */}
|
|
||||||
// </Box>
|
|
||||||
// ))}
|
|
||||||
// {newUpdatedImages &&
|
|
||||||
// newUpdatedImages.map((image, i) => (
|
|
||||||
// <Box marginRight={"2rem"}>
|
|
||||||
// <img
|
|
||||||
// src={URL.createObjectURL(image)}
|
|
||||||
// alt="profileImage"
|
|
||||||
// style={{
|
|
||||||
// width: 70,
|
|
||||||
// height: 70,
|
|
||||||
|
|
||||||
// marginBottom: "1rem",
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// {productImages.length + newUpdatedImages.length > 1 && (
|
|
||||||
// <DeleteSharpIcon
|
|
||||||
// onClick={() => handellocalDelete(image)}
|
|
||||||
// fontSize="small"
|
|
||||||
// sx={{
|
|
||||||
// color: "white",
|
|
||||||
// position: "absolute",
|
|
||||||
// cursor: "pointer",
|
|
||||||
// padding: "0.2rem",
|
|
||||||
// background: "black",
|
|
||||||
// borderRadius: "50%",
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// )}
|
|
||||||
// {/* </IconButton> */}
|
|
||||||
// </Box>
|
|
||||||
// ))}
|
|
||||||
// </Box>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// <div className="col-lg-6 col-md-6 col-sm-12 my-1">
|
|
||||||
// <div className="card h-100">
|
|
||||||
// <div className="card-body px-5">
|
|
||||||
// <div className="mb-3 me-3">
|
|
||||||
// <label htmlFor="title" className="form-label">
|
|
||||||
// Price(Rs)*
|
|
||||||
// </label>
|
|
||||||
// <input
|
|
||||||
// type="number"
|
|
||||||
// className="form-control"
|
|
||||||
// id="price"
|
|
||||||
// value={price}
|
|
||||||
// onChange={(e) => handlePriceChange(e)}
|
|
||||||
// />
|
|
||||||
// </div>
|
|
||||||
// <div>
|
|
||||||
// <label htmlFor="categorySelect">Select a Category *:</label>
|
|
||||||
// <select
|
|
||||||
// id="category"
|
|
||||||
// className="form-control"
|
|
||||||
// style={{ width: "100%" }}
|
|
||||||
// value={category}
|
|
||||||
// onChange={(e) => setCategoryName(e.target.value)}
|
|
||||||
// >
|
|
||||||
// <option value={""}>None</option>
|
|
||||||
// {categories.map((category, index) => (
|
|
||||||
// <option key={index} value={category?._id}>
|
|
||||||
// {category.categoryName}
|
|
||||||
// </option>
|
|
||||||
// ))}
|
|
||||||
// </select>
|
|
||||||
// </div>
|
|
||||||
|
|
||||||
// {allTax.length > 0 && (
|
|
||||||
// <div className=" mb-3">
|
|
||||||
// <label htmlFor="title" className="form-label">
|
|
||||||
// GST*
|
|
||||||
// </label>{" "}
|
|
||||||
// <select
|
|
||||||
// className=" form-control"
|
|
||||||
// name=""
|
|
||||||
// id=""
|
|
||||||
// value={JSON.stringify(selectedTax?._id)}
|
|
||||||
// onChange={(e) => TaxRatechange(e)}
|
|
||||||
// >
|
|
||||||
// {selectedTax?.tax && (
|
|
||||||
// <option
|
|
||||||
// value={selectedTax && JSON.stringify(selectedTax)}
|
|
||||||
// >
|
|
||||||
// {selectedTax?.tax}% {selectedTax?.name}
|
|
||||||
// </option>
|
|
||||||
// )}
|
|
||||||
// {allTax.map((t, i) => (
|
|
||||||
// <option key={i} value={JSON.stringify(t)}>
|
|
||||||
// {t.tax}% {t.name}
|
|
||||||
// </option>
|
|
||||||
// ))}
|
|
||||||
// </select>
|
|
||||||
// </div>
|
|
||||||
// )}
|
|
||||||
|
|
||||||
// <div className="mb-3 me-3">
|
|
||||||
// <label htmlFor="title" className="form-label">
|
|
||||||
// GST Amount (Rs) *
|
|
||||||
// </label>
|
|
||||||
// <input
|
|
||||||
// disabled
|
|
||||||
// type="number"
|
|
||||||
// name="gst_amount"
|
|
||||||
// className="form-control"
|
|
||||||
// id="gst_amount"
|
|
||||||
// value={gst_amount}
|
|
||||||
// // onChange={(e) => setPrice(e.target.value)}
|
|
||||||
// />
|
|
||||||
// </div>
|
|
||||||
// <div className="mb-3 me-3">
|
|
||||||
// <label htmlFor="title" className="form-label">
|
|
||||||
// Total Amount(Rs)*
|
|
||||||
// </label>
|
|
||||||
// <input
|
|
||||||
// disabled
|
|
||||||
// type="number"
|
|
||||||
// name="total_amount"
|
|
||||||
// className="form-control"
|
|
||||||
// id="total_amount"
|
|
||||||
// value={totalAmt}
|
|
||||||
// // onChange={(e) => setPrice(e.target.value)}
|
|
||||||
// />
|
|
||||||
// </div>
|
|
||||||
// <div className=" mb-3">
|
|
||||||
// <label htmlFor="title" className="form-label">
|
|
||||||
// Product Status *
|
|
||||||
// </label>{" "}
|
|
||||||
// <select
|
|
||||||
// className="form-control"
|
|
||||||
// name="product_Status"
|
|
||||||
// id="product_Status"
|
|
||||||
// value={product_Status}
|
|
||||||
// onChange={(e) => setproduct_Status(e.target.value)}
|
|
||||||
// >
|
|
||||||
// <option value="">--Select--</option>
|
|
||||||
// <option value="Active">Active</option>
|
|
||||||
// <option value="Inactive">Inactive</option>
|
|
||||||
// </select>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// export default EditProduct;
|
|
||||||
|
@ -33,8 +33,6 @@ const ProductDetails = (props) => {
|
|||||||
data.category === "" ||
|
data.category === "" ||
|
||||||
data.description === "" ||
|
data.description === "" ||
|
||||||
data.product_Status === ""
|
data.product_Status === ""
|
||||||
// data.sku === "" ||
|
|
||||||
// data.hsn_code === ""
|
|
||||||
) {
|
) {
|
||||||
swal({
|
swal({
|
||||||
title: "Warning",
|
title: "Warning",
|
||||||
@ -143,36 +141,36 @@ const ProductDetails = (props) => {
|
|||||||
>
|
>
|
||||||
<option value="">--Select--</option>
|
<option value="">--Select--</option>
|
||||||
<option value="Active">Active</option>
|
<option value="Active">Active</option>
|
||||||
<option value="Inactive">Inactive</option>
|
<option value="inActive">inActive</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-3 row">
|
<div className="mb-3 row">
|
||||||
<div className="col-lg-6">
|
<div className="col-lg-6">
|
||||||
<label htmlFor="product" className="form-label">
|
<label htmlFor="product" className="form-label">
|
||||||
Master Price*
|
Price*
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
id="master_price"
|
id="price"
|
||||||
name="master_price"
|
name="price"
|
||||||
value={data.master_price}
|
value={data.price}
|
||||||
maxLength="6"
|
maxLength="6"
|
||||||
onChange={(e) => handleChange(e)}
|
onChange={(e) => handleChange(e)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-lg-6 ">
|
<div className="col-lg-6 ">
|
||||||
<label htmlFor="product" className="form-label">
|
<label htmlFor="product" className="form-label">
|
||||||
Master GST *
|
GST *
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
name="master_GST"
|
name="GST"
|
||||||
// value={r.gst_Id?._id ? r.gst_Id?._id : r.gst_Id}
|
// value={r.gst_Id?._id ? r.gst_Id?._id : r.gst_Id}
|
||||||
value={data?.master_GST}
|
value={data?.GST}
|
||||||
onChange={(e) => handleChange(e)}
|
onChange={(e) => handleChange(e)}
|
||||||
id="master_GST"
|
id="GST"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
>
|
>
|
||||||
<option value="">---select---</option>
|
<option value="">---select---</option>
|
||||||
@ -197,21 +195,6 @@ const ProductDetails = (props) => {
|
|||||||
onChange={(e) => handleChange(e)}
|
onChange={(e) => handleChange(e)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="mb-3 row">
|
|
||||||
<div className="col-6">
|
|
||||||
<label htmlFor="hsc_code" className="form-label">
|
|
||||||
HSN Code*
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control"
|
|
||||||
id="hsn_code"
|
|
||||||
value={data.hsn_code}
|
|
||||||
maxLength="50"
|
|
||||||
onChange={(e) => handleChange(e)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div> */}
|
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
<label htmlFor="product" className="form-label">
|
<label htmlFor="product" className="form-label">
|
||||||
Special Instructions
|
Special Instructions
|
||||||
@ -229,34 +212,6 @@ const ProductDetails = (props) => {
|
|||||||
id="special_instructions"
|
id="special_instructions"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="mb-3">
|
|
||||||
<label>Discontinue On*</label>
|
|
||||||
<input
|
|
||||||
type="date"
|
|
||||||
value={data.discontinue_on}
|
|
||||||
id="discontinue_on"
|
|
||||||
onChange={(e) => handleChange(e)}
|
|
||||||
className="form-control"
|
|
||||||
min={new Date().toISOString().slice(0, 10)}
|
|
||||||
/>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
{/* <div className=" mb-3">
|
|
||||||
<label htmlFor="title" className="form-label">
|
|
||||||
Product Status *
|
|
||||||
</label>{" "}
|
|
||||||
<select
|
|
||||||
className="form-control"
|
|
||||||
name="product_Status"
|
|
||||||
id="product_Status"
|
|
||||||
value={data.product_Status}
|
|
||||||
onChange={(e) => handleChange(e)}
|
|
||||||
>
|
|
||||||
<option value="">--Select--</option>
|
|
||||||
<option value="Active">Active</option>
|
|
||||||
<option value="Inactive">Inactive</option>
|
|
||||||
</select>
|
|
||||||
</div> */}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -8,201 +8,88 @@ const ProductsImages = (props) => {
|
|||||||
const productId = props.productId;
|
const productId = props.productId;
|
||||||
const { images, setImages } = props.data;
|
const { images, setImages } = props.data;
|
||||||
const { loading, setLoading } = props.loading;
|
const { loading, setLoading } = props.loading;
|
||||||
const [deleting, setDeleting] = useState(false);
|
|
||||||
const [imagePreview, setImagePreview] = useState({ preview: "", image: "" });
|
|
||||||
const [imagesPreview, setImagesPreview] = useState([]);
|
|
||||||
const [allimage, setAllImage] = useState([]);
|
|
||||||
//
|
|
||||||
|
|
||||||
const [data, setData] = useState({
|
const [imagePreview, setImagePreview] = useState([]);
|
||||||
image: [],
|
const [localImages, setLocalImages] = useState([]);
|
||||||
imageURL: [],
|
const [removedImages, setRemovedImages] = useState([]);
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (images?.length > 0) {
|
if (images?.length > 0) {
|
||||||
setData((prev) => ({
|
setImagePreview(images.map((img) => ({ url: img.url, public_id: img.public_id })));
|
||||||
...prev,
|
|
||||||
imageURL: images?.url,
|
|
||||||
}));
|
|
||||||
setImagesPreview(images);
|
|
||||||
}
|
}
|
||||||
}, []);
|
}, [images]);
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
if (e.target.id === "image") {
|
const files = Array.from(e.target.files);
|
||||||
if (
|
const imagePreviews = files.map((file) => {
|
||||||
e.target.files[0]?.type === "image/jpeg" ||
|
return {
|
||||||
e.target.files[0]?.type === "image/png" ||
|
url: URL.createObjectURL(file),
|
||||||
e.target.files[0]?.type === "image/jpg"
|
file,
|
||||||
) {
|
};
|
||||||
if (imagesPreview.length > 3) {
|
|
||||||
swal({
|
|
||||||
title: "Warning",
|
|
||||||
text: "maximum Four image Upload ",
|
|
||||||
icon: "error",
|
|
||||||
button: "Close",
|
|
||||||
dangerMode: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// only for file preview------------------------------------
|
|
||||||
const files = Array.from(e.target.files);
|
|
||||||
files.forEach((file) => {
|
|
||||||
const reader = new FileReader();
|
|
||||||
|
|
||||||
reader.onload = () => {
|
|
||||||
if (reader.readyState === 2) {
|
|
||||||
setImagesPreview((old) => [...old, reader.result]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
});
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
setData((prev) => ({
|
|
||||||
...prev,
|
|
||||||
|
|
||||||
image: [...data.image, ...e.target.files],
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
swal({
|
|
||||||
title: "Warning",
|
|
||||||
text: "Upload jpg, jpeg, png only.",
|
|
||||||
icon: "error",
|
|
||||||
button: "Close",
|
|
||||||
dangerMode: true,
|
|
||||||
});
|
|
||||||
setData((prev) => ({
|
|
||||||
...prev,
|
|
||||||
imageURL: "",
|
|
||||||
image: "",
|
|
||||||
}));
|
|
||||||
e.target.value = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setData((prev) => ({ ...prev, [e.target.id]: e.target.value }));
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// const handleChange = (e) => {
|
|
||||||
// if (
|
|
||||||
// e.target.files[0]?.type === "image/jpeg" ||
|
|
||||||
// e.target.files[0]?.type === "image/png" ||
|
|
||||||
// e.target.files[0]?.type === "image/jpg"
|
|
||||||
// ) {
|
|
||||||
// setImagePreview((prev) => ({
|
|
||||||
// ...prev,
|
|
||||||
// preview: URL.createObjectURL(e.target.files[0]),
|
|
||||||
// image: e.target.files[0],
|
|
||||||
// }));
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
// swal({
|
|
||||||
// title: "Warning",
|
|
||||||
// text: "Upload jpg, jpeg, png only.",
|
|
||||||
// icon: "error",
|
|
||||||
// button: "Close",
|
|
||||||
// dangerMode: true,
|
|
||||||
// });
|
|
||||||
// setImagePreview((prev) => ({
|
|
||||||
// ...prev,
|
|
||||||
// preview: "",
|
|
||||||
// image: "",
|
|
||||||
// }));
|
|
||||||
// e.target.value = null;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
const handleDelete = (id) => {
|
|
||||||
swal({
|
|
||||||
title: "Are you sure?",
|
|
||||||
icon: "error",
|
|
||||||
buttons: {
|
|
||||||
Yes: { text: "Yes", value: true },
|
|
||||||
Cancel: { text: "Cancel", value: "cancel" },
|
|
||||||
},
|
|
||||||
}).then((value) => {
|
|
||||||
if (value === true) {
|
|
||||||
setDeleting(true);
|
|
||||||
axios
|
|
||||||
.delete(`/api/product/image/${productId}/${id}`, {
|
|
||||||
headers: {
|
|
||||||
"Access-Control-Allow-Origin": "*",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
setDeleting(false);
|
|
||||||
const filteredImages = images.filter((e) => e._id !== id);
|
|
||||||
setImages(filteredImages);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
setDeleting(false);
|
|
||||||
swal({
|
|
||||||
title: "Warning",
|
|
||||||
text: "Something went wrong!",
|
|
||||||
icon: "error",
|
|
||||||
button: "Retry",
|
|
||||||
dangerMode: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
setLocalImages((prevImages) => [...prevImages, ...imagePreviews]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeleteImage = (url, public_id) => {
|
||||||
|
if (public_id) {
|
||||||
|
// Mark image for removal
|
||||||
|
setRemovedImages((prevRemoved) => [...prevRemoved, public_id]);
|
||||||
|
const encodedPublicId = encodeURIComponent(public_id);
|
||||||
|
|
||||||
|
// Retrieve the authentication token
|
||||||
|
const token = isAutheticated(); // Ensure this function correctly retrieves the token
|
||||||
|
|
||||||
|
// console.log("public_id:", public_id); // Log to debug
|
||||||
|
// console.log("encodedPublicId:", encodedPublicId); // Log to debug
|
||||||
|
|
||||||
|
// Delete image from Cloudinary
|
||||||
|
axios.delete(`/api/product/deleteImage/${encodedPublicId}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}` // Include the token in the headers
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
setImagePreview((prevImages) => prevImages.filter((img) => img.url !== url));
|
||||||
|
swal("Success", "Image deleted successfully", "success");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err.response?.data); // Log error for debugging
|
||||||
|
swal("Error", "Failed to delete image", "error");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Delete local image
|
||||||
|
setLocalImages((prevImages) => prevImages.filter((img) => img.url !== url));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
// if (!imagePreview.image) return;
|
|
||||||
if (data.image?.length < 1) {
|
|
||||||
swal({
|
|
||||||
title: "Warning",
|
|
||||||
text: "PLease select Product Image",
|
|
||||||
icon: "warning",
|
|
||||||
button: "ok",
|
|
||||||
dangerMode: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
data.image.forEach((Singleimage) => {
|
|
||||||
// console.log(Singleimage)
|
// Append local images to formData
|
||||||
formData.append("image", Singleimage);
|
localImages.forEach((img) => formData.append('images', img.file));
|
||||||
});
|
|
||||||
axios
|
// Append removedImages as a JSON string
|
||||||
.patch(`/api/product/update/${productId}`, formData, {
|
formData.append('removedImages', JSON.stringify(removedImages));
|
||||||
headers: {
|
|
||||||
"Content-Type": "multipart/form-data",
|
axios.patch(`/api/product/update/${productId}`, formData, {
|
||||||
Authorization: `Bearer ${token}`,
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
'Content-Type': 'multipart/form-data',
|
||||||
},
|
Authorization: `Bearer ${token}`
|
||||||
})
|
}
|
||||||
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
swal({
|
setImages(res.data.images);
|
||||||
title: "Saved",
|
setLocalImages([]);
|
||||||
text: "Product image saved successfully!",
|
setRemovedImages([]);
|
||||||
icon: "success",
|
swal("Success", "Product updated successfully", "success");
|
||||||
button: "Close",
|
|
||||||
});
|
|
||||||
setImages((prev) => [...prev, res.data?.image]);
|
|
||||||
setImagePreview({ preview: "", image: "" });
|
|
||||||
setLoading(false);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
// console.log(err);
|
console.error(err.response.data); // Log the error for debugging
|
||||||
const msg = err?.response?.data?.message || "Something went wrong!";
|
swal("Error", "Failed to update product", "error");
|
||||||
swal({
|
})
|
||||||
title: "Warning",
|
.finally(() => setLoading(false));
|
||||||
text: msg,
|
|
||||||
icon: "warning",
|
|
||||||
button: "Close",
|
|
||||||
});
|
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -219,13 +106,13 @@ const ProductsImages = (props) => {
|
|||||||
id="image"
|
id="image"
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
multiple
|
multiple
|
||||||
onChange={(e) => handleChange(e)}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-lg-3">
|
<div className="col-lg-3">
|
||||||
<button
|
<button
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
onClick={() => handleSubmit()}
|
onClick={handleSubmit}
|
||||||
disabled={!productId || loading}
|
disabled={!productId || loading}
|
||||||
>
|
>
|
||||||
{productId
|
{productId
|
||||||
@ -237,64 +124,33 @@ const ProductsImages = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className="pt-1 pl-2 text-secondary">
|
<p className="pt-1 pl-2 text-secondary">
|
||||||
Upload jpg, jpeg and png only*
|
Upload jpg, jpeg, and png only*
|
||||||
</p>
|
</p>
|
||||||
<div>
|
|
||||||
<strong className="fs-6 fst-italic">
|
|
||||||
*Please Upload maximum four images
|
|
||||||
</strong>
|
|
||||||
</div>
|
|
||||||
<div className="mb-3" style={{ height: "100px", maxWdth: "100%" }}>
|
|
||||||
{/* <img
|
|
||||||
src={imagePreview.preview}
|
|
||||||
alt="Uploaded Image will be shown here"
|
|
||||||
style={{ maxHeight: "100px", maxWidth: "100%" }}
|
|
||||||
/> */}
|
|
||||||
{imagesPreview.map((image, index) => (
|
|
||||||
<img
|
|
||||||
className="p-1"
|
|
||||||
key={index}
|
|
||||||
src={image?.url ? image?.url : image}
|
|
||||||
alt="Uploaded Image will be shown here"
|
|
||||||
style={{ maxHeight: "100px", maxWidth: "100%" }}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{/* <table className="table">
|
<div className="row">
|
||||||
<thead>
|
{imagePreview.map((img) => (
|
||||||
<tr>
|
<div key={img.url} className="col-lg-3 mb-3 position-relative">
|
||||||
<th scope="col">Preview</th>
|
<img src={img.url} alt="Preview" className="img-thumbnail" />
|
||||||
<th scope="col">Actions</th>
|
<button
|
||||||
</tr>
|
className="btn btn-danger position-absolute top-0 end-0 m-2"
|
||||||
</thead>
|
onClick={() => handleDeleteImage(img.url, img.public_id)}
|
||||||
<tbody>
|
>
|
||||||
{images.length !== 0 ? (
|
×
|
||||||
images.map((r, idx) => (
|
</button>
|
||||||
<tr key={idx}>
|
</div>
|
||||||
<td>
|
))}
|
||||||
<img src={r.url} alt="preview" height="100px" />
|
{localImages.map((img) => (
|
||||||
</td>
|
<div key={img.url} className="col-lg-3 mb-3 position-relative">
|
||||||
<td>
|
<img src={img.url} alt="Preview" className="img-thumbnail" />
|
||||||
<button
|
<button
|
||||||
className="btn btn-danger btn-sm text-white"
|
className="btn btn-danger position-absolute top-0 end-0 m-2"
|
||||||
onClick={() => handleDelete(r._id)}
|
onClick={() => handleDeleteImage(img.url)}
|
||||||
disabled={deleting}
|
>
|
||||||
>
|
×
|
||||||
Delete
|
</button>
|
||||||
</button>
|
</div>
|
||||||
</td>
|
))}
|
||||||
</tr>
|
</div>
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<tr>
|
|
||||||
<td colSpan={6} className="text-center fw-bold">
|
|
||||||
No Image Added
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
</tbody>
|
|
||||||
</table> */}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,249 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import React from "react";
|
|
||||||
import swal from "sweetalert";
|
|
||||||
import { isAutheticated } from "src/auth";
|
|
||||||
|
|
||||||
const ProductVarients = (props) => {
|
|
||||||
const token = isAutheticated();
|
|
||||||
const productId = props.productId;
|
|
||||||
|
|
||||||
const taxes = props.taxes;
|
|
||||||
const sizes = props.sizes;
|
|
||||||
const { varients, setVarients } = props.data;
|
|
||||||
const { loading, setLoading } = props.loading;
|
|
||||||
const addVarientRow = () => {
|
|
||||||
setVarients((prev) => [
|
|
||||||
...prev,
|
|
||||||
{
|
|
||||||
variant_Name: "",
|
|
||||||
weight: "",
|
|
||||||
volume: "",
|
|
||||||
price: "",
|
|
||||||
gst_Id: "",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (e, idx) => {
|
|
||||||
if (
|
|
||||||
e.target.name === "weight" &&
|
|
||||||
e.target.value !== "" &&
|
|
||||||
!/^[0-9.]+$/.test(e.target.value)
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
if (
|
|
||||||
e.target.name === "price" &&
|
|
||||||
e.target.value !== "" &&
|
|
||||||
!/^[0-9.]+$/.test(e.target.value)
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
let clone = [...varients];
|
|
||||||
let obj = clone[idx];
|
|
||||||
// if (e.target.name === "gst_Id") {
|
|
||||||
// }
|
|
||||||
obj[e.target.name] = e.target.value;
|
|
||||||
clone[idx] = obj;
|
|
||||||
setVarients([...clone]);
|
|
||||||
};
|
|
||||||
// variant_Name: "",
|
|
||||||
// weight: "",
|
|
||||||
// volume: "",
|
|
||||||
// price: "",
|
|
||||||
// gst_Name: "",
|
|
||||||
// gst_Rate: "",
|
|
||||||
// gst_Id: "",
|
|
||||||
const handleSubmit = () => {
|
|
||||||
const emptyVarients = varients.filter(
|
|
||||||
(e) =>
|
|
||||||
!(e.variant_Name === "" && e.price === "" && e.gst_Id === "") &&
|
|
||||||
(e.variant_Name === "" || e.price === "" || e.gst_Id === "")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (emptyVarients.length !== 0) {
|
|
||||||
swal({
|
|
||||||
title: "Warning",
|
|
||||||
text: "Fill all fields of a row",
|
|
||||||
icon: "warning",
|
|
||||||
button: "Return",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// const variant_Name = [];
|
|
||||||
// varients.map((e) => e.variant_Name && variant_Name.push(e.variant_Name));
|
|
||||||
// const duplicate = variant_Name.filter(
|
|
||||||
// (e) => sizes.indexOf(e) !== sizes.lastIndexOf(e)
|
|
||||||
// );
|
|
||||||
// if (duplicate.length !== 0) {
|
|
||||||
// swal({
|
|
||||||
// title: "Warning",
|
|
||||||
// text: "Duplicate sizes selected!",
|
|
||||||
// icon: "warning",
|
|
||||||
// button: "Return",
|
|
||||||
// });
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const varientData = varients.filter((e) => e.variant_Name !== "");
|
|
||||||
const emptyVariants = varients.reduce(
|
|
||||||
(arr, e) =>
|
|
||||||
e.gst_Id !== "" && e.variant_Name === "" && e.price === ""
|
|
||||||
? [...arr, e._id]
|
|
||||||
: arr,
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
setLoading(true);
|
|
||||||
axios
|
|
||||||
.patch(
|
|
||||||
`/api/product/update/${productId}`,
|
|
||||||
{ variants: varientData, delete_variants: emptyVariants },
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then((res) => {
|
|
||||||
swal({
|
|
||||||
title: "Saved",
|
|
||||||
text: "Product variants saved successfully!",
|
|
||||||
icon: "success",
|
|
||||||
button: "Close",
|
|
||||||
});
|
|
||||||
setVarients((prev) =>
|
|
||||||
res?.data?.variants?.length > 0 ? [...res?.data?.variants] : prev
|
|
||||||
);
|
|
||||||
setLoading(false);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
const msg = err?.response?.data?.message || "Something went wrong!";
|
|
||||||
swal({
|
|
||||||
title: "Warning",
|
|
||||||
text: msg,
|
|
||||||
icon: "warning",
|
|
||||||
button: "Close",
|
|
||||||
});
|
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="d-flex justify-content-between">
|
|
||||||
<h5>Product Variants</h5>
|
|
||||||
<button
|
|
||||||
className="btn btn-primary btn-sm"
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleSubmit()}
|
|
||||||
disabled={!productId || loading}
|
|
||||||
>
|
|
||||||
{productId
|
|
||||||
? loading
|
|
||||||
? "Loading"
|
|
||||||
: "Save Varients"
|
|
||||||
: "First Save Product Details then Save Varients"}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<table className="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
{/* <th scope="col">Size</th> */}
|
|
||||||
<th scope="col">Variant Name</th>
|
|
||||||
<th scope="col">Price</th>
|
|
||||||
|
|
||||||
{/* <th scope="col">Weight (in Grams)</th> */}
|
|
||||||
{/* <th scope="col">Show in E-store</th> */}
|
|
||||||
<th scope="col">Tax</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{varients.map((r, idx) => (
|
|
||||||
<tr key={idx}>
|
|
||||||
{/* <td>
|
|
||||||
<select
|
|
||||||
name="size"
|
|
||||||
value={r.size}
|
|
||||||
onChange={(e) => handleChange(e, idx)}
|
|
||||||
className="form-control"
|
|
||||||
>
|
|
||||||
<option value="">---select---</option>
|
|
||||||
{sizes &&
|
|
||||||
sizes.map((item, index) => (
|
|
||||||
<option value={item._id} key={index}>
|
|
||||||
{item.size}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</td> */}
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control"
|
|
||||||
name="variant_Name"
|
|
||||||
value={r.variant_Name}
|
|
||||||
onChange={(e) => handleChange(e, idx)}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
className="form-control"
|
|
||||||
name="price"
|
|
||||||
value={r.price}
|
|
||||||
onChange={(e) => handleChange(e, idx)}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
{/* <td>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control"
|
|
||||||
name="weight"
|
|
||||||
value={r.weight}
|
|
||||||
onChange={(e) => handleChange(e, idx)}
|
|
||||||
/>
|
|
||||||
</td> */}
|
|
||||||
{/* <td>
|
|
||||||
<select
|
|
||||||
name="show_in_estore"
|
|
||||||
value={r.show_in_estore}
|
|
||||||
onChange={(e) => handleChange(e, idx)}
|
|
||||||
className="form-control"
|
|
||||||
>
|
|
||||||
<option value={true}>Yes</option>
|
|
||||||
<option value={false}>No</option>
|
|
||||||
</select>
|
|
||||||
</td> */}
|
|
||||||
<td>
|
|
||||||
<select
|
|
||||||
name="gst_Id"
|
|
||||||
value={r.gst_Id?._id ? r.gst_Id?._id : r.gst_Id}
|
|
||||||
onChange={(e) => handleChange(e, idx)}
|
|
||||||
className="form-control"
|
|
||||||
>
|
|
||||||
<option value="">---select---</option>
|
|
||||||
{taxes &&
|
|
||||||
taxes.map((item, index) => (
|
|
||||||
<option value={item._id} key={index}>
|
|
||||||
{item.tax} %{item.name}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div className="text-center">
|
|
||||||
<button
|
|
||||||
className="btn btn-primary btn-sm"
|
|
||||||
onClick={() => addVarientRow()}
|
|
||||||
>
|
|
||||||
Add another variant
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ProductVarients;
|
|
@ -42,8 +42,8 @@ const Products = () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log("res.data?.data", res.data?.product);
|
// console.log(res.data);
|
||||||
setProductsData(res.data?.product);
|
setProductsData(res.data?.products);
|
||||||
setTotalData(res.data?.total_data);
|
setTotalData(res.data?.total_data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
@ -71,6 +71,7 @@ const Products = () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
// console.log(res?.data?.categories);
|
||||||
setCategories(res?.data?.categories);
|
setCategories(res?.data?.categories);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -220,7 +221,7 @@ const Products = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
console.log("currencyDetails", currencyDetails);
|
// console.log("currencyDetails", currencyDetails);
|
||||||
return (
|
return (
|
||||||
<div className="main-content">
|
<div className="main-content">
|
||||||
<div className="page-content">
|
<div className="page-content">
|
||||||
@ -415,9 +416,7 @@ const Products = () => {
|
|||||||
</td>
|
</td>
|
||||||
<th className="text-start">
|
<th className="text-start">
|
||||||
{currencyDetails?.CurrencySymbol}
|
{currencyDetails?.CurrencySymbol}
|
||||||
{product?.variants?.length > 0
|
{product?.price}
|
||||||
? product?.variants[0]?.price
|
|
||||||
: product?.master_price}
|
|
||||||
</th>
|
</th>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
<span className=""></span>
|
<span className=""></span>
|
||||||
@ -450,25 +449,9 @@ const Products = () => {
|
|||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
{/* <Link to={`/products/variants/${product._id}`}>
|
|
||||||
<button
|
|
||||||
style={{ color: 'white', marginRight: '1rem' }}
|
|
||||||
type="button"
|
|
||||||
className="
|
|
||||||
btn btn-primary btn-sm
|
|
||||||
waves-effect waves-light
|
|
||||||
btn-table
|
|
||||||
mx-1
|
|
||||||
mt-1
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Variants
|
|
||||||
</button>
|
|
||||||
</Link> */}
|
|
||||||
<Link
|
<Link
|
||||||
to={`/product/view/${product._id}`}
|
to={`/product/view/${product._id}`}
|
||||||
state={{ currencyDetails }}
|
state={{ currencyDetails }}
|
||||||
// to={`/product/view/${product._id}`}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
style={{
|
style={{
|
||||||
|
@ -13,13 +13,6 @@ const ViewProduct = () => {
|
|||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
|
|
||||||
const [productData, setProductData] = useState({});
|
const [productData, setProductData] = useState({});
|
||||||
const [SAW, setSAW] = useState([
|
|
||||||
{ volume: "", weight: "" },
|
|
||||||
{ volume: "", weight: "" },
|
|
||||||
{ volume: "", weight: "" },
|
|
||||||
{ volume: "", weight: "" },
|
|
||||||
{ volume: "", weight: "" },
|
|
||||||
]);
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const getProductData = async () => {
|
const getProductData = async () => {
|
||||||
@ -30,11 +23,8 @@ const ViewProduct = () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.data.data);
|
// console.log(res.data.data);
|
||||||
setProductData(res.data.data);
|
setProductData(res.data.data);
|
||||||
if (res.data.data?.variants) {
|
|
||||||
setSAW((prev) => [...res.data.data?.variants]);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err) => {});
|
.catch((err) => {});
|
||||||
};
|
};
|
||||||
@ -102,32 +92,32 @@ const ViewProduct = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{productData?.master_price && (
|
{productData?.price && (
|
||||||
<tr>
|
<tr>
|
||||||
<th>Master Price</th>
|
<th>Price</th>
|
||||||
<td>
|
<td>
|
||||||
{currencyDetails?.CurrencySymbol}
|
{currencyDetails?.CurrencySymbol}
|
||||||
{productData?.master_price}
|
{productData?.price}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
{productData?.master_GST && (
|
{productData?.GST && (
|
||||||
<tr>
|
<tr>
|
||||||
<th>Master GST</th>
|
<th>Master GST</th>
|
||||||
<td>
|
<td>
|
||||||
{productData?.master_GST?.tax}%{" "}
|
{productData?.GST?.tax}%{" "}
|
||||||
{productData?.master_GST?.name}
|
{productData?.GST?.name}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
{productData?.master_GST && (
|
{productData?.GST && (
|
||||||
<tr>
|
<tr>
|
||||||
<th>Master GST Price</th>
|
<th>GST Price</th>
|
||||||
<td>
|
<td>
|
||||||
{currencyDetails?.CurrencySymbol}
|
{currencyDetails?.CurrencySymbol}
|
||||||
{(
|
{(
|
||||||
(Number(productData?.master_price) *
|
(Number(productData?.price) *
|
||||||
Number(productData?.master_GST?.tax)) /
|
Number(productData?.GST?.tax)) /
|
||||||
100
|
100
|
||||||
)?.toFixed(2)}
|
)?.toFixed(2)}
|
||||||
</td>
|
</td>
|
||||||
@ -165,118 +155,6 @@ const ViewProduct = () => {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
</table>
|
</table>
|
||||||
<table className="table table-primary mt-3">
|
|
||||||
<caption
|
|
||||||
style={{ captionSide: "top" }}
|
|
||||||
className="text-dark fw-bold"
|
|
||||||
>
|
|
||||||
Varients:
|
|
||||||
</caption>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th className="text-center">Variant Name</th>
|
|
||||||
<th className="text-center">Price</th>
|
|
||||||
|
|
||||||
<th className="text-center">GST</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{SAW.map(
|
|
||||||
(r, i) =>
|
|
||||||
r.variant_Name !== "" && (
|
|
||||||
<tr key={i}>
|
|
||||||
<td className="text-center">
|
|
||||||
{r?.variant_Name}
|
|
||||||
</td>
|
|
||||||
<td className="text-center">
|
|
||||||
{currencyDetails?.CurrencySymbol}
|
|
||||||
{r?.price}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td className="text-center">
|
|
||||||
{r?.gst_Id?.name + " " + r?.gst_Id?.tax + "%"}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
{SAW.filter((e) => e.variant_Name !== "").length ===
|
|
||||||
0 && (
|
|
||||||
<tr>
|
|
||||||
<td colSpan={"6"} className="text-center">
|
|
||||||
No data available
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{/* <div className="mb-2">
|
|
||||||
<table className="table table-secondary mt-3">
|
|
||||||
<caption
|
|
||||||
style={{ captionSide: "top" }}
|
|
||||||
className="text-dark fw-bold"
|
|
||||||
>
|
|
||||||
Product Fabric:
|
|
||||||
</caption>
|
|
||||||
{productData?.product_Fabric?.length > 0 ? (
|
|
||||||
<>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th className="text-center">S. No.</th>
|
|
||||||
<th className="text-center"> Name</th>
|
|
||||||
<th className="text-center"> Use For Part</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{productData?.product_Fabric?.map((r, i) => (
|
|
||||||
<tr key={i}>
|
|
||||||
<td className="text-center">{++i}</td>
|
|
||||||
<td className="text-center">
|
|
||||||
{r?.fabric_Name}
|
|
||||||
</td>
|
|
||||||
<td className="text-center">{r?.for_Part}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<h5>No Fabric Allotted for this product!</h5>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</table>
|
|
||||||
</div> */}
|
|
||||||
{/* <div className="mb-2">
|
|
||||||
<table className="table table-info mt-3">
|
|
||||||
<caption
|
|
||||||
style={{ captionSide: "top" }}
|
|
||||||
className="text-dark fw-bold"
|
|
||||||
>
|
|
||||||
Relevent Product:
|
|
||||||
</caption>
|
|
||||||
{productData?.relevent_product?.length > 0 ? (
|
|
||||||
<>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th className="text-center">S. No.</th>
|
|
||||||
<th className="text-center">Product Name</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{productData?.relevent_product?.map((r, i) => (
|
|
||||||
<tr key={i}>
|
|
||||||
<td className="text-center">{count++}</td>
|
|
||||||
<td className="text-center">{r?.name}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<h5>No relevent item for this product !</h5>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</table>
|
|
||||||
</div> */}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* <!-- end table-responsive --> */}
|
{/* <!-- end table-responsive --> */}
|
||||||
|
Loading…
Reference in New Issue
Block a user