Skip to content

Commit

Permalink
fix(products): adjusted create products
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseaCodes committed Mar 20, 2022
1 parent 69cdeb3 commit 30eed81
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Components/Product/CreateProduct.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

})
Expand All @@ -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 }

})
Expand All @@ -131,6 +132,7 @@ function CreateProduct() {
const software = {name:"Software"}
const books = {name:"Books"}
const categories = [software, books];
console.log(product)

return (
<>
Expand Down
29 changes: 29 additions & 0 deletions src/Components/Product/LoadMore.jsx
Original file line number Diff line number Diff line change
@@ -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 <div className="products"><Loading /></div>

return (
<>
<div className="load_more">
{
result < page * 9 ? ""
: <button onClick={() => setPage(page + 1)}>Load More</button>
}
</div>
</>
)
}

export default LoadMore;

0 comments on commit 30eed81

Please sign in to comment.