From 60a9afce0c55aa36008a615a6c493c3e1507e991 Mon Sep 17 00:00:00 2001 From: Monika Krella Date: Sun, 19 Jun 2022 18:50:22 +0200 Subject: [PATCH] -created modal to show after delete all products from cart as "universalModal" - possible to use in other places --- public/locales/en/deletecartmodal.json | 3 ++ public/locales/pl/deletecartmodal.json | 3 ++ src/features/cartPage/Cart.tsx | 13 +++--- src/features/cartPage/CartPage.tsx | 25 +++++++++-- src/features/cartPage/CartRemoveButton.tsx | 14 ++++-- .../universalModal/UniversalModal.tsx | 44 +++++++++++++++++++ 6 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 public/locales/en/deletecartmodal.json create mode 100644 public/locales/pl/deletecartmodal.json create mode 100644 src/features/universalModal/UniversalModal.tsx diff --git a/public/locales/en/deletecartmodal.json b/public/locales/en/deletecartmodal.json new file mode 100644 index 0000000..4856e2e --- /dev/null +++ b/public/locales/en/deletecartmodal.json @@ -0,0 +1,3 @@ +{ + "info": "Your cart is empty" +} diff --git a/public/locales/pl/deletecartmodal.json b/public/locales/pl/deletecartmodal.json new file mode 100644 index 0000000..f7e002e --- /dev/null +++ b/public/locales/pl/deletecartmodal.json @@ -0,0 +1,3 @@ +{ + "info": "Twój koszyk jest pusty" +} diff --git a/src/features/cartPage/Cart.tsx b/src/features/cartPage/Cart.tsx index 718bb82..a9e929f 100644 --- a/src/features/cartPage/Cart.tsx +++ b/src/features/cartPage/Cart.tsx @@ -1,11 +1,14 @@ -import CartTableHeading from './CartTableHeading'; import CartDeliveries from './CartDeliveries'; -import CartTableBody from './CartTableBody'; import CartRemoveButton from './CartRemoveButton'; - import CartSummaryRow from './CartTableSummaryRow'; +import CartTableBody from './CartTableBody'; +import CartTableHeading from './CartTableHeading'; + +interface CartTypes { + openModalHandler: () => void; +} -const Cart = () => { +const Cart = (prop: CartTypes) => { return (
@@ -14,7 +17,7 @@ const Cart = () => {
- +
diff --git a/src/features/cartPage/CartPage.tsx b/src/features/cartPage/CartPage.tsx index e6c8eed..addce5d 100644 --- a/src/features/cartPage/CartPage.tsx +++ b/src/features/cartPage/CartPage.tsx @@ -1,16 +1,18 @@ import { useDispatch, useSelector } from 'react-redux'; -import Cart from './Cart'; -import { RootState } from '../../app/store'; - import { useNavigate } from 'react-router-dom'; +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; +import Cart from './Cart'; +import DeleteCartModal from '../universalModal/UniversalModal'; +import { RootState } from '../../app/store'; import { fetchDeliveryId, fetchOrderDetails, } from '../../app/slices/orderSlice'; const CartPage = () => { + const [showModal, setShowModal] = useState(false); const { t } = useTranslation('cart'); const navigate = useNavigate(); const dispatch = useDispatch(); @@ -44,6 +46,14 @@ const CartPage = () => { } }; + const openModalHandler = () => { + setShowModal(true); + }; + + const closeModalHandler = () => { + setShowModal(false); + }; + return (
{cart.counter !== 0 ? ( @@ -52,7 +62,7 @@ const CartPage = () => { {t('cartOpenerText')}

- + {Object.keys(chosenDelivery).length > 0 && (
); }; diff --git a/src/features/cartPage/CartRemoveButton.tsx b/src/features/cartPage/CartRemoveButton.tsx index abdfacd..d2b902f 100644 --- a/src/features/cartPage/CartRemoveButton.tsx +++ b/src/features/cartPage/CartRemoveButton.tsx @@ -1,11 +1,16 @@ +//import toast from 'react-hot-toast'; + import { useDispatch } from 'react-redux'; +import { useTranslation } from 'react-i18next'; import { AppDispatch } from '../../app/store'; import { clear } from '../../app/slices/cartSlice'; -import { useTranslation } from 'react-i18next'; -import toast from 'react-hot-toast'; -const CartRemoveButton = () => { +interface CartRemoveButtonTypes { + openModalHandler: () => void; +} + +const CartRemoveButton = (prop: CartRemoveButtonTypes) => { const dispatch: AppDispatch = useDispatch(); const { t } = useTranslation('cart'); @@ -13,7 +18,8 @@ const CartRemoveButton = () => { +
+
+ ); +} + +export default DeleteCartModal;