update
This commit is contained in:
parent
abc4feee63
commit
7bba1cdc22
@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useState, useEffect, useRef, useCallback } from "react";
|
||||
import axios from "axios";
|
||||
import { isAutheticated } from "src/auth";
|
||||
import {
|
||||
@ -13,7 +13,8 @@ import {
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import { ClipLoader } from "react-spinners";
|
||||
import swal from "sweetalert";
|
||||
|
||||
import { toast } from "react-hot-toast";
|
||||
import debounce from "lodash.debounce";
|
||||
const style = {
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
@ -28,54 +29,65 @@ const style = {
|
||||
|
||||
const Brands = () => {
|
||||
const token = isAutheticated();
|
||||
const nameRef = useRef();
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [updating, setUpdating] = useState(true);
|
||||
const [saveLoding, setSaveLoading] = useState(true);
|
||||
const [saveLoading, setSaveLoading] = useState(true);
|
||||
const [edit, setEdit] = useState(false);
|
||||
const [brandName, setbrandName] = useState("");
|
||||
const [brandId, setbrandId] = useState("");
|
||||
const [brand, setbrand] = useState([]);
|
||||
const [brandName, setBrandName] = useState("");
|
||||
const [brandId, setBrandId] = useState("");
|
||||
const [brands, setBrands] = useState([]);
|
||||
const [itemPerPage, setItemPerPage] = useState(10);
|
||||
const [page, setPage] = useState(1);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [olderbrandName, setOlderBrandName] = useState("");
|
||||
|
||||
const [olderBrandName, setOlderBrandName] = useState("");
|
||||
|
||||
const handleOpen = () => setOpen(true);
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
setEdit(false);
|
||||
setbrandName("");
|
||||
setbrandId("");
|
||||
setBrandName("");
|
||||
setBrandId("");
|
||||
};
|
||||
|
||||
const getBrands = async () => {
|
||||
try {
|
||||
const response = await axios.get("/api/brand/getBrands");
|
||||
setLoading(true); // Set loading to true before fetching
|
||||
const response = await axios.get("/api/brand/getBrands", {
|
||||
params: {
|
||||
page,
|
||||
show: itemPerPage,
|
||||
brandName: nameRef.current?.value || "",
|
||||
}, // Include pagination and search
|
||||
});
|
||||
if (response.status === 200) {
|
||||
setbrand(response.data.brands);
|
||||
setLoading(false);
|
||||
setBrands(response.data.brands);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch brands:", error);
|
||||
} finally {
|
||||
setLoading(false); // Set loading to false after fetching
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getBrands();
|
||||
}, []);
|
||||
}, [page, itemPerPage]); // Trigger fetch when these values change
|
||||
|
||||
const handleEditClick = (_id, brandName) => {
|
||||
setOpen(true);
|
||||
setbrandName(brandName);
|
||||
setbrandId(_id);
|
||||
setBrandName(brandName);
|
||||
setBrandId(_id);
|
||||
setOlderBrandName(brandName);
|
||||
setEdit(true);
|
||||
};
|
||||
|
||||
const handleUpdate = async () => {
|
||||
const filteredBrandNames = brand
|
||||
.filter((brand) => brand.brandName.toLowerCase() !== olderbrandName.toLowerCase())
|
||||
const filteredBrandNames = brands
|
||||
.filter(
|
||||
(brand) =>
|
||||
brand.brandName.toLowerCase() !== olderBrandName.toLowerCase()
|
||||
)
|
||||
.map((brand) => brand.brandName.toLowerCase());
|
||||
|
||||
if (filteredBrandNames.includes(brandName.toLowerCase())) {
|
||||
@ -97,7 +109,7 @@ const Brands = () => {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
handleClose();
|
||||
swal("Success", "The brand was updated successfully!", "success");
|
||||
toast.success("Brand updated successfully");
|
||||
getBrands();
|
||||
} catch (err) {
|
||||
swal("Error", "Failed to update brand", "error");
|
||||
@ -120,7 +132,7 @@ const Brands = () => {
|
||||
await axios.delete(`/api/brand/delete/${_id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
swal("Success", "The brand was deleted successfully!", "success");
|
||||
toast.success("Brand deleted successfully");
|
||||
getBrands();
|
||||
} catch (err) {
|
||||
swal("Error", "Failed to delete brand", "error");
|
||||
@ -129,8 +141,12 @@ const Brands = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleSavebrand = async () => {
|
||||
if (brand.some((brand) => brand.brandName.toLowerCase() === brandName.toLowerCase())) {
|
||||
const handleSaveBrand = async () => {
|
||||
if (
|
||||
brands.some(
|
||||
(brand) => brand.brandName.toLowerCase() === brandName.toLowerCase()
|
||||
)
|
||||
) {
|
||||
swal("Warning", "Brand already exists.", "error");
|
||||
return;
|
||||
}
|
||||
@ -148,7 +164,7 @@ const Brands = () => {
|
||||
await axios.post("/api/brand/add", formData, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "multipart/formdata",
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
handleClose();
|
||||
@ -161,8 +177,19 @@ const Brands = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getPageCount = () => Math.max(1, Math.ceil(brand.length / itemPerPage));
|
||||
const getPageCount = () =>
|
||||
Math.max(1, Math.ceil(brands.length / itemPerPage));
|
||||
const debouncedSearch = useCallback(
|
||||
debounce(() => {
|
||||
setPage(1);
|
||||
getBrands();
|
||||
}, 500),
|
||||
[]
|
||||
);
|
||||
|
||||
const handleSearchChange = () => {
|
||||
debouncedSearch();
|
||||
};
|
||||
return (
|
||||
<div className="main-content">
|
||||
<div className="page-content">
|
||||
@ -191,9 +218,6 @@ const Brands = () => {
|
||||
textTransform: "capitalize",
|
||||
}}
|
||||
onClick={handleOpen}
|
||||
// onClick={() => {
|
||||
// navigate("/testimonial/new", { replace: true });
|
||||
// }}
|
||||
>
|
||||
Add New brand
|
||||
</Button>
|
||||
@ -229,9 +253,9 @@ const Brands = () => {
|
||||
padding: "1rem",
|
||||
}}
|
||||
onChange={(e) =>
|
||||
setbrandName(
|
||||
setBrandName(
|
||||
e.target.value.charAt(0).toUpperCase() +
|
||||
e.target.value.slice(1)
|
||||
e.target.value.slice(1)
|
||||
)
|
||||
}
|
||||
/>
|
||||
@ -249,7 +273,7 @@ const Brands = () => {
|
||||
p={2}
|
||||
display={"flex"}
|
||||
justifyContent={"right"}
|
||||
// width={"500px"}
|
||||
// width={"500px"}
|
||||
>
|
||||
{!edit && (
|
||||
<button
|
||||
@ -257,7 +281,7 @@ const Brands = () => {
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
onClick={() => handleSavebrand()}
|
||||
onClick={() => handleSaveBrand()}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-primary btn-sm
|
||||
@ -267,8 +291,8 @@ const Brands = () => {
|
||||
mt-1
|
||||
"
|
||||
>
|
||||
<ClipLoader loading={!saveLoding} size={18} />
|
||||
{saveLoding && "Save"}
|
||||
<ClipLoader loading={!saveLoading} size={18} />
|
||||
{saveLoading && "Save"}
|
||||
</button>
|
||||
)}
|
||||
{edit && (
|
||||
@ -322,18 +346,17 @@ const Brands = () => {
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="row ml-0 mr-0 mb-10">
|
||||
<div className="col-sm-12 col-md-12">
|
||||
<div className="col-lg-1">
|
||||
<div className="dataTables_length">
|
||||
<label className="w-100">
|
||||
Show
|
||||
<select
|
||||
style={{ width: "10%" }}
|
||||
onChange={(e) => setItemPerPage(e.target.value)}
|
||||
className="
|
||||
select-w
|
||||
custom-select custom-select-sm
|
||||
form-control form-control-sm
|
||||
"
|
||||
onChange={(e) => {
|
||||
setItemPerPage(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="form-control"
|
||||
disabled={loading}
|
||||
>
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
@ -344,6 +367,17 @@ const Brands = () => {
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-lg-3">
|
||||
<label>Brand Name:</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="product name"
|
||||
className="form-control"
|
||||
ref={nameRef}
|
||||
onChange={handleSearchChange}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="table-responsive table-shoot mt-3">
|
||||
@ -356,16 +390,15 @@ const Brands = () => {
|
||||
style={{ background: "rgb(140, 213, 213)" }}
|
||||
>
|
||||
<tr>
|
||||
|
||||
<th> Brand Name</th>
|
||||
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{!loading && brand.length === 0 && (
|
||||
{!loading && brands.length === 0 && (
|
||||
<tr className="text-center">
|
||||
<td colSpan="6">
|
||||
<td colSpan="2">
|
||||
<h5>No Data Available</h5>
|
||||
</td>
|
||||
</tr>
|
||||
@ -377,61 +410,53 @@ const Brands = () => {
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
brand &&
|
||||
brand
|
||||
.slice(
|
||||
(`${page}` - 1) * itemPerPage,
|
||||
`${page}` * itemPerPage
|
||||
)
|
||||
.map((item, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<h5>{item.brandName} </h5>
|
||||
</td>
|
||||
<td className="text-start">
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
brands &&
|
||||
brands.map((item, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<h5>{item.brandName} </h5>
|
||||
</td>
|
||||
<td className="text-start">
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-primary btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
mt-1
|
||||
"
|
||||
onClick={() =>
|
||||
handleEditClick(
|
||||
item._id,
|
||||
item.brandName,
|
||||
)
|
||||
}
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
background: "red",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
onClick={() =>
|
||||
handleEditClick(item._id, item.brandName)
|
||||
}
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
background: "red",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
mt-1
|
||||
"
|
||||
onClick={() => handleDelete(item._id)}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
onClick={() => handleDelete(item._id)}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useState, useEffect, useRef, useCallback } from "react";
|
||||
import axios from "axios";
|
||||
import { isAutheticated } from "src/auth";
|
||||
import {
|
||||
@ -13,7 +13,8 @@ import {
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import { ClipLoader } from "react-spinners";
|
||||
import swal from "sweetalert";
|
||||
|
||||
import { toast } from "react-hot-toast";
|
||||
import debounce from "lodash.debounce";
|
||||
const style = {
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
@ -28,6 +29,7 @@ const style = {
|
||||
|
||||
const Categories = () => {
|
||||
const token = isAutheticated();
|
||||
const nameRef = useRef();
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [updating, setUpdating] = useState(true);
|
||||
const [saveLoding, setSaveLoading] = useState(true);
|
||||
@ -40,7 +42,6 @@ const Categories = () => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [olderCategoryName, setOlderCategoruName] = useState("");
|
||||
|
||||
|
||||
const handleOpen = () => setOpen(true);
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
@ -53,24 +54,28 @@ const Categories = () => {
|
||||
|
||||
const getCategories = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await axios.get("/api/category/getCategories", {
|
||||
// headers: {
|
||||
// Authorization: `Bearer ${token}`,
|
||||
// },
|
||||
params: {
|
||||
page,
|
||||
show: itemPerPage,
|
||||
categoryName: nameRef.current?.value || "",
|
||||
}, // Include pagination and search
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
setCategory(response?.data?.categories);
|
||||
setLoading(false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch brands:", error);
|
||||
} finally {
|
||||
setLoading(false); // Set loading to false after fetching
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getCategories();
|
||||
}, []);
|
||||
}, [page, itemPerPage]);
|
||||
|
||||
const handleEditClick = (_id, categoryName) => {
|
||||
setOpen(true);
|
||||
@ -82,12 +87,14 @@ const Categories = () => {
|
||||
};
|
||||
|
||||
const handleUpdate = async () => {
|
||||
const filteredArrayNames = category.filter(
|
||||
(item) => item.categoryName.toLowerCase() !== olderCategoryName.toLowerCase())
|
||||
.map((item) => item.categoryName.toLowerCase()
|
||||
);
|
||||
const filteredArrayNames = category
|
||||
.filter(
|
||||
(item) =>
|
||||
item.categoryName.toLowerCase() !== olderCategoryName.toLowerCase()
|
||||
)
|
||||
.map((item) => item.categoryName.toLowerCase());
|
||||
// console.log(filteredArrayNames, "filter");
|
||||
if(filteredArrayNames.includes(categoryName.toLowerCase())){
|
||||
if (filteredArrayNames.includes(categoryName.toLowerCase())) {
|
||||
swal({
|
||||
title: "Warning",
|
||||
text: "Category already exists ",
|
||||
@ -109,22 +116,16 @@ const Categories = () => {
|
||||
setUpdating(false);
|
||||
const formData = new FormData();
|
||||
formData.append("categoryName", categoryName);
|
||||
try{
|
||||
await axios
|
||||
.patch(`/api/category/update/${categoryId}`, formData, {
|
||||
try {
|
||||
await axios.patch(`/api/category/update/${categoryId}`, formData, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
handleClose();
|
||||
swal({
|
||||
title: "Congratulations!!",
|
||||
text: "The category was updated successfully!",
|
||||
icon: "success",
|
||||
button: "OK",
|
||||
});
|
||||
getCategories();
|
||||
}catch(err){
|
||||
});
|
||||
handleClose();
|
||||
toast.success("Category updated successfully");
|
||||
getCategories();
|
||||
} catch (err) {
|
||||
swal({
|
||||
title: "",
|
||||
text: "Something went wrong!",
|
||||
@ -132,7 +133,7 @@ try{
|
||||
button: "Retry",
|
||||
dangerMode: true,
|
||||
});
|
||||
}finally{
|
||||
} finally {
|
||||
setUpdating(true);
|
||||
}
|
||||
};
|
||||
@ -148,33 +149,32 @@ try{
|
||||
}).then(async (value) => {
|
||||
if (value === true) {
|
||||
try {
|
||||
await axios
|
||||
.delete(`/api/category/delete/${_id}`, {
|
||||
await axios.delete(`/api/category/delete/${_id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
swal({
|
||||
title: "Congratulations!!",
|
||||
text: "The category was deleted successfully!",
|
||||
icon: "success",
|
||||
button: "OK",
|
||||
});
|
||||
getCategories();
|
||||
}catch(err) {
|
||||
swal({
|
||||
title: "",
|
||||
text: "Something went wrong!",
|
||||
icon: "error",
|
||||
button: "Retry",
|
||||
dangerMode: true,
|
||||
});
|
||||
toast.success("Category deleted successfully");
|
||||
getCategories();
|
||||
} catch (err) {
|
||||
swal({
|
||||
title: "",
|
||||
text: "Something went wrong!",
|
||||
icon: "error",
|
||||
button: "Retry",
|
||||
dangerMode: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}});
|
||||
});
|
||||
};
|
||||
|
||||
const handleSaveCategory = async () => {
|
||||
if(category.some((item) => item.categoryName.toLowerCase() === categoryName.toLowerCase())){
|
||||
if (
|
||||
category.some(
|
||||
(item) => item.categoryName.toLowerCase() === categoryName.toLowerCase()
|
||||
)
|
||||
) {
|
||||
swal({
|
||||
title: "Warning",
|
||||
text: "Category already exists ",
|
||||
@ -198,23 +198,17 @@ try{
|
||||
setLoading(true);
|
||||
const formData = new FormData();
|
||||
formData.append("categoryName", categoryName);
|
||||
try{
|
||||
await axios
|
||||
.post("/api/category/add", formData, {
|
||||
try {
|
||||
await axios.post("/api/category/add", formData, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "multipart/formdata",
|
||||
},
|
||||
})
|
||||
handleClose();
|
||||
swal({
|
||||
title: "Congratulations!!",
|
||||
text: "The category was added successfully!",
|
||||
icon: "success",
|
||||
button: "OK",
|
||||
});
|
||||
handleClose();
|
||||
toast.success("Category added successfully");
|
||||
getCategories();
|
||||
}catch(err){
|
||||
} catch (err) {
|
||||
swal({
|
||||
title: "",
|
||||
text: "Something went wrong!",
|
||||
@ -222,14 +216,24 @@ try{
|
||||
button: "Retry",
|
||||
dangerMode: true,
|
||||
});
|
||||
}finally{
|
||||
} finally {
|
||||
setSaveLoading(true);
|
||||
}
|
||||
};
|
||||
const getPageCount = () => {
|
||||
return Math.max(1, Math.ceil(category.length / itemPerPage));
|
||||
};
|
||||
const debouncedSearch = useCallback(
|
||||
debounce(() => {
|
||||
setPage(1);
|
||||
getCategories();
|
||||
}, 500),
|
||||
[]
|
||||
);
|
||||
|
||||
const handleSearchChange = () => {
|
||||
debouncedSearch();
|
||||
};
|
||||
return (
|
||||
<div className="main-content">
|
||||
<div className="page-content">
|
||||
@ -258,9 +262,6 @@ try{
|
||||
textTransform: "capitalize",
|
||||
}}
|
||||
onClick={handleOpen}
|
||||
// onClick={() => {
|
||||
// navigate("/testimonial/new", { replace: true });
|
||||
// }}
|
||||
>
|
||||
Add New Category
|
||||
</Button>
|
||||
@ -298,7 +299,7 @@ try{
|
||||
onChange={(e) =>
|
||||
setCategoryName(
|
||||
e.target.value.charAt(0).toUpperCase() +
|
||||
e.target.value.slice(1)
|
||||
e.target.value.slice(1)
|
||||
)
|
||||
}
|
||||
/>
|
||||
@ -316,7 +317,7 @@ try{
|
||||
p={2}
|
||||
display={"flex"}
|
||||
justifyContent={"right"}
|
||||
// width={"500px"}
|
||||
// width={"500px"}
|
||||
>
|
||||
{!edit && (
|
||||
<button
|
||||
@ -389,18 +390,17 @@ try{
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="row ml-0 mr-0 mb-10">
|
||||
<div className="col-sm-12 col-md-12">
|
||||
<div className="col-lg-1">
|
||||
<div className="dataTables_length">
|
||||
<label className="w-100">
|
||||
Show
|
||||
<select
|
||||
style={{ width: "10%" }}
|
||||
onChange={(e) => setItemPerPage(e.target.value)}
|
||||
className="
|
||||
select-w
|
||||
custom-select custom-select-sm
|
||||
form-control form-control-sm
|
||||
"
|
||||
onChange={(e) => {
|
||||
setItemPerPage(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="form-control"
|
||||
disabled={loading}
|
||||
>
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
@ -411,6 +411,17 @@ try{
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-lg-3">
|
||||
<label>Category Name:</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="product name"
|
||||
className="form-control"
|
||||
ref={nameRef}
|
||||
onChange={handleSearchChange}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="table-responsive table-shoot mt-3">
|
||||
@ -423,7 +434,6 @@ try{
|
||||
style={{ background: "rgb(140, 213, 213)" }}
|
||||
>
|
||||
<tr>
|
||||
|
||||
<th> Category Name</th>
|
||||
|
||||
<th>Action</th>
|
||||
@ -432,7 +442,7 @@ try{
|
||||
<tbody>
|
||||
{!loading && category.length === 0 && (
|
||||
<tr className="text-center">
|
||||
<td colSpan="6">
|
||||
<td colSpan="">
|
||||
<h5>No Data Available</h5>
|
||||
</td>
|
||||
</tr>
|
||||
@ -445,60 +455,52 @@ try{
|
||||
</tr>
|
||||
) : (
|
||||
category &&
|
||||
category
|
||||
.slice(
|
||||
(`${page}` - 1) * itemPerPage,
|
||||
`${page}` * itemPerPage
|
||||
)
|
||||
.map((item, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<h5>{item.categoryName} </h5>
|
||||
</td>
|
||||
<td className="text-start">
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
category.map((item, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<h5>{item.categoryName} </h5>
|
||||
</td>
|
||||
<td className="text-start">
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-primary btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
mt-1
|
||||
"
|
||||
onClick={() =>
|
||||
handleEditClick(
|
||||
item._id,
|
||||
item.categoryName,
|
||||
)
|
||||
}
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
background: "red",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
onClick={() =>
|
||||
handleEditClick(item._id, item.categoryName)
|
||||
}
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
background: "red",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
mt-1
|
||||
"
|
||||
onClick={() => handleDelete(item._id)}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
onClick={() => handleDelete(item._id)}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom";
|
||||
import { isAutheticated } from "src/auth";
|
||||
import swal from "sweetalert";
|
||||
import debounce from "lodash.debounce";
|
||||
import { toast } from "react-hot-toast";
|
||||
const Products = () => {
|
||||
const token = isAutheticated();
|
||||
const navigate = useNavigate();
|
||||
@ -138,12 +139,7 @@ const Products = () => {
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
swal({
|
||||
title: "Deleted",
|
||||
text: "Product Deleted successfully!",
|
||||
icon: "success",
|
||||
button: "ok",
|
||||
});
|
||||
toast.success("Product deleted successfully!");
|
||||
setSuccess((prev) => !prev);
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -179,12 +175,7 @@ const Products = () => {
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
swal({
|
||||
title: "Changed",
|
||||
text: "Product status changed successfully!",
|
||||
icon: "success",
|
||||
button: "ok",
|
||||
});
|
||||
toast.success("Product status updated successfully!");
|
||||
setSuccess((prev) => !prev);
|
||||
})
|
||||
.catch((err) => {
|
||||
|
Loading…
Reference in New Issue
Block a user