From 30eed81e9d5b7875c5f66784a411875a97496f5c Mon Sep 17 00:00:00 2001 From: hosead6168 Date: Sun, 20 Mar 2022 02:58:03 -0500 Subject: [PATCH] fix(products): adjusted create products --- src/Components/Product/CreateProduct.jsx | 6 +++-- src/Components/Product/LoadMore.jsx | 29 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Components/Product/LoadMore.jsx diff --git a/src/Components/Product/CreateProduct.jsx b/src/Components/Product/CreateProduct.jsx index 999eaec6..765c1cc1 100644 --- a/src/Components/Product/CreateProduct.jsx +++ b/src/Components/Product/CreateProduct.jsx @@ -85,7 +85,7 @@ function CreateProduct() { try { if (!isAdmin) return alert("You're not an admin") setLoading(true) - await axios.post('/api/destroy', { public_id: images.public_id }, { + await axios.post('/api/destroy', { public_id: images.id }, { headers: { Authorization: token } }) @@ -108,7 +108,8 @@ function CreateProduct() { if (!isAdmin) return alert("You're not an admin") if (!images) return alert("No Image Upload") if (onEdit) { - await axios.put(`/api/products/${product._id}`, { ...products, images }, { + console.log(product) + await axios.put(`/api/products/${product._id}`, { ...product, images }, { headers: { Authorization: token } }) @@ -131,6 +132,7 @@ function CreateProduct() { const software = {name:"Software"} const books = {name:"Books"} const categories = [software, books]; + console.log(product) return ( <> diff --git a/src/Components/Product/LoadMore.jsx b/src/Components/Product/LoadMore.jsx new file mode 100644 index 00000000..abc21baf --- /dev/null +++ b/src/Components/Product/LoadMore.jsx @@ -0,0 +1,29 @@ +import React, { useContext, useState } from 'react'; + +import Loading from '../Loading/Loading' +import { GlobalState } from '../../GlobalState'; +import './Products.css'; + +// Load additional Products for pagination +const LoadMore = () => { + + const state = useContext(GlobalState) + const [page, setPage] = state.productsAPI.page + const [result] = state.productsAPI.result + const [loading] = useState(false) + + if (loading) return
+ + return ( + <> +
+ { + result < page * 9 ? "" + : + } +
+ + ) +} + +export default LoadMore;