From 6f6a884c54876e865e8487b987d6a207b0ecb9d2 Mon Sep 17 00:00:00 2001
From: pawan-dot <71133473+pawan-dot@users.noreply.github.com>
Date: Thu, 27 Oct 2022 12:02:33 +0530
Subject: [PATCH] add category banner image
---
src/index.js | 2 +-
src/views/Category/AddCategory.js | 22 ++++++++++++++++++++--
src/views/Category/Category.js | 18 ++++++++++++++----
src/views/Category/EditCategory.js | 27 ++++++++++++++++++++++++---
4 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/src/index.js b/src/index.js
index 05329e4..dc6683f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -12,7 +12,7 @@ import axios from 'axios'
const setupAxios = () => {
axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/';
- // axios.defaults.baseURL = 'http://localhost:5000'
+ //axios.defaults.baseURL = 'http://localhost:5000'
axios.defaults.headers = {
'Cache-Control': 'no-cache,no-store',
'Pragma': 'no-cache',
diff --git a/src/views/Category/AddCategory.js b/src/views/Category/AddCategory.js
index 5ecb8d8..200a4bb 100644
--- a/src/views/Category/AddCategory.js
+++ b/src/views/Category/AddCategory.js
@@ -26,12 +26,13 @@ const AddProduct = () => {
const token = isAutheticated();
let history = useHistory();
const [image, setImage] = useState("");
+ const [ctegoryBannerImage, setCtegoryBannerImage] = useState("");
const [name, setName] = useState("");
const [loading, setLoading] = useState(false);
const handleSubmit = async () => {
- if (!(name && image)) {
+ if (!(name && image && ctegoryBannerImage)) {
return swal('Error!', 'All fields are required', 'error')
}
@@ -41,6 +42,7 @@ const AddProduct = () => {
myForm.set("image", image);
+ myForm.set("category_banner", ctegoryBannerImage);
setLoading({ loading: true });
// console.log(image)
try {
@@ -103,8 +105,9 @@ const AddProduct = () => {
value={name}
placeholder="Name" />
+
category image *
-
+
{/* */}
@@ -116,6 +119,21 @@ const AddProduct = () => {
onChange={handleImage}
+ />
+
+ category Banner image *
+
+
+
+
+ setCtegoryBannerImage(e.target.files[0])}
+
+
/>
diff --git a/src/views/Category/Category.js b/src/views/Category/Category.js
index 1085f63..db65f7a 100644
--- a/src/views/Category/Category.js
+++ b/src/views/Category/Category.js
@@ -33,7 +33,7 @@ function Products() {
},
}
);
- // console.log(res.data.category[0].image.url)
+ // console.log(res.data.category)
setCategory(res.data.category)
// console.log(category[0].addedOn)
changeState({
@@ -62,12 +62,16 @@ function Products() {
Authorization: `Bearer ${token}`,
},
});
- console.log(res)
+ // console.log(res)
if (res.data.success == true) {
swal("success!", "Category Deleted Successfully!", "success");
window.location.reload();
// if (res.status === 200) window.location.reload();
}
+ else {
+ swal("error!", "failled!", "error");
+
+ }
};
@@ -119,7 +123,8 @@ function Products() {
Name |
- Image |
+ Category Image |
+ Category Banner |
Added On |
Actions |
@@ -129,7 +134,12 @@ function Products() {
{item?.name} |
-  |
+
+
+
+
+ {item.category_banner && }
+ |
{/* {item?.addedOn} */}
{new Date(`${item?.addedOn}`).toDateString()} , {`${formatAMPM(item?.addedOn)}`}
diff --git a/src/views/Category/EditCategory.js b/src/views/Category/EditCategory.js
index bab5e68..50e209a 100644
--- a/src/views/Category/EditCategory.js
+++ b/src/views/Category/EditCategory.js
@@ -29,6 +29,8 @@ const AddProduct = () => {
// console.log(id)
const [image, setImage] = useState("");
const [name, setName] = useState("");
+ const [ctegoryBannerImage, setCtegoryBannerImage] = useState("");
+
const [loading, setLoading] = useState(false);
useEffect(async () => {
const res = await axios.get(`/api/category/getOne/${id}`, {
@@ -43,8 +45,8 @@ const AddProduct = () => {
const handleSubmit = async () => {
- if (!(name && image)) {
- return swal('Error!', 'All fields are required', 'error')
+ if (!(name)) {
+ return swal('Error!', 'Name fields are required', 'error')
}
const myForm = new FormData();
@@ -53,6 +55,8 @@ const AddProduct = () => {
myForm.set("image", image);
+ myForm.set("category_banner", ctegoryBannerImage);
+
setLoading({ loading: true });
// console.log(image)
try {
@@ -112,7 +116,9 @@ const AddProduct = () => {
placeholder="Name" />
-
+ category image *
+
+
{/* */}
@@ -124,6 +130,21 @@ const AddProduct = () => {
onChange={handleImage}
+ />
+
+ category Banner image *
+
+
+
+
+ setCtegoryBannerImage(e.target.files[0])}
+
+
/>
|