Skip to content

Commit

Permalink
Merge pull request #79 from fac29/comment-out-unused-code
Browse files Browse the repository at this point in the history
comment out unused code for build
  • Loading branch information
halimahexe authored Jun 26, 2024
2 parents db2dbd7 + f354b90 commit 5f50c9a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 68 deletions.
125 changes: 67 additions & 58 deletions src/pages/ShoppingCart/ShoppingCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,80 @@ import { useCart } from '../../ShoppingCartContext';
import PlusMinusButton from '../../components/PlusMinusButton/PlusMinusButton';
import { Modal } from '../../components/Modal/Modal';
import { useState } from 'react';
const requestUrl = import.meta.env.VITE_REQUEST_URL;
// const requestUrl = import.meta.env.VITE_REQUEST_URL;

function ShoppingCart() {
const navigate = useNavigate();
const [isOpen, setIsOpen] = useState(false);
const {
cart,
total,
handleRemoveFromCart,
handleAddToCart,
loggedIn,
userID,
} = useCart();
const navigate = useNavigate();
const [isOpen, setIsOpen] = useState(false);
const {
cart,
total,
handleRemoveFromCart,
handleAddToCart,
loggedIn,
// userID,
} = useCart();

function handleBack() {
navigate('/');
}
function handleBack() {
navigate('/');
}

function goToCheckout() {
if (loggedIn) {
navigate('/checkout');
} else {
setIsOpen(true);
}
}
function goToCheckout() {
if (loggedIn) {
navigate('/checkout');
} else {
setIsOpen(true);
}
}

async function handleCheckout() {
const response = await fetch(`${requestUrl}/checkout`, {
method: 'POST',
});
}
// async function handleCheckout() {
// const response = await fetch(`${requestUrl}/checkout`, {
// method: "POST",
// });
// }

return (
<div>
<h2>Cart Items</h2>
<button onClick={handleBack}>Back to Products</button>
<ul>
{cart.length ? (
cart.map((item) => (
<li key={item.product_id}>
<p>{item.product_name}</p>
<PlusMinusButton
buttonText='-'
buttonClick={() => handleRemoveFromCart(item.product_id)}
/>
<PlusMinusButton
buttonText='+'
buttonClick={() => handleAddToCart(item.product_id)}
/>
return (
<div>
<h2>Cart Items</h2>
<button onClick={handleBack}>Back to Products</button>
<ul>
{cart.length ? (
cart.map((item) => (
<li key={item.product_id}>
<p>{item.product_name}</p>
<PlusMinusButton
buttonText='-'
buttonClick={() =>
handleRemoveFromCart(item.product_id)
}
/>
<PlusMinusButton
buttonText='+'
buttonClick={() =>
handleAddToCart(item.product_id)
}
/>

<p>{item.quantity}</p>
<p>£{(item.price * item.quantity) / 100}</p>
</li>
))
) : (
<h2>You don't have any items in your cart!</h2>
)}
</ul>
{cart.length ? <p>Total: £{total ? total / 100 : null}</p> : null}
{isOpen && (
<Modal textModal='Please Log In to Checkout' setIsOpen={setIsOpen} />
)}
{cart.length ? <button onClick={goToCheckout}>Checkout</button> : null}
</div>
);
<p>{item.quantity}</p>
<p>£{(item.price * item.quantity) / 100}</p>
</li>
))
) : (
<h2>You don't have any items in your cart!</h2>
)}
</ul>
{cart.length ? <p>Total: £{total ? total / 100 : null}</p> : null}
{isOpen && (
<Modal
textModal='Please Log In to Checkout'
setIsOpen={setIsOpen}
/>
)}
{cart.length ? (
<button onClick={goToCheckout}>Checkout</button>
) : null}
</div>
);
}

export default ShoppingCart;
20 changes: 10 additions & 10 deletions src/utils/fetchSession/fetchSession.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const requestUrl = import.meta.env.VITE_REQUEST_URL;

export async function fetchSessionById() {
const response = await fetch(`${requestUrl}/session`, {
credentials: 'include',
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
} else {
const data = await response.json();
return data;
}
const response = await fetch(`${requestUrl}/session`, {
credentials: "include",
});
console.log(response);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
} else {
const data = await response.json();
return data;
}
}

0 comments on commit 5f50c9a

Please sign in to comment.