Skip to content

Commit

Permalink
Extract isCartempty into the cart module
Browse files Browse the repository at this point in the history
  • Loading branch information
bespoyasov committed Jan 21, 2022
1 parent 138ccd2 commit e3b760c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ export function useCartStore() {
const [cart, setCart] = useState(cart_);
return { cart, setCart };
}

export function isCartEmpty(cart) {
return !cart.products.length;
}
5 changes: 1 addition & 4 deletions src/order.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { totalPrice } from "./product";
import { isCartEmpty } from "./cart";
import { callApi } from "./api";

function selectDiscount(total, coupon) {
Expand All @@ -16,10 +17,6 @@ function selectDiscount(total, coupon) {
return discount;
}

function isCartEmpty(cart) {
return !cart.products.length;
}

function userHasEnoughMoney(user, cart) {
return user.account >= totalPrice(cart.products);
}
Expand Down

0 comments on commit e3b760c

Please sign in to comment.