Skip to content

Modal confirmation of adding and removing item to/from cart resp. #27

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"react-currency-format": "^1.0.0",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3"
"react-scripts": "3.4.3",
"sweetalert": "^2.1.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down
9 changes: 9 additions & 0 deletions src/CheckoutProduct.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import React from 'react';
import './CheckoutProduct.css'
import { useStateValue } from "./StateProvider";
import swal from 'sweetalert';


function CheckoutProduct({ id, image, title, price, rating, hideButton }) {
const [{ basket }, dispatch] = useStateValue();

const removeFromBasket = () => {

swal({
title: "Product has been removed from the cart.",
icon: "success",
dangerMode: true,
})

// remove the item from the basket
dispatch({
type: 'REMOVE_FROM_BASKET',
Expand Down
9 changes: 9 additions & 0 deletions src/Orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ function Orders() {

return (
<div className='orders'>
{orders ? (
<div>
<h1>Your Orders</h1>

<div className='orders__order'>
{orders?.map(order => (
<Order order={order} />
))}
</div>
</div>

) : (
<h2>No orders</h2>
)
}

</div>
)
}
Expand Down
10 changes: 10 additions & 0 deletions src/Product.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import React from "react";
import "./Product.css";
import { useStateValue } from "./StateProvider";
import swal from 'sweetalert';


function Product({ id, title, image, price, rating }) {
const [{ basket }, dispatch] = useStateValue();

const addToBasket = () => {

swal({
title: "Product Added to cart.",
icon: "success",
dangerMode: false,
})


// dispatch the item into the data layer
dispatch({
type: "ADD_TO_BASKET",
Expand Down