From afe20466e52fbc04b33ef6153afdfee0d05de34c Mon Sep 17 00:00:00 2001 From: KimiaMontazeri Date: Thu, 30 Nov 2023 20:10:28 +0330 Subject: [PATCH 1/2] feat(my-account): add 25% discount if total price is more than 200 --- frontend/src/pages/my-account/MyAccount.jsx | 48 +++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/my-account/MyAccount.jsx b/frontend/src/pages/my-account/MyAccount.jsx index 8881fed..9bce866 100644 --- a/frontend/src/pages/my-account/MyAccount.jsx +++ b/frontend/src/pages/my-account/MyAccount.jsx @@ -1,10 +1,12 @@ import React, { useState } from 'react'; -import { Box, Button, CircularProgress, Divider, Stack, Tab, Tabs, Typography } from '@mui/material'; +import { Box, Button, Chip, CircularProgress, Divider, Stack, Tab, Tabs, Typography } from '@mui/material'; import ItemCard from '../../components/item-card/item-card.jsx'; import Toast from '../../components/toast/Toast.jsx'; import useMyAccount from './useMyAccount.js'; const TAB_ITEMS = ['Workshops', 'Presentations', 'Cart']; +const DISCOUNT = 0.25; +const MIN_TOTAL_PRICE_TO_GET_DISCOUNT = 200000; const MyAccount = () => { const { @@ -101,7 +103,47 @@ const MyAccount = () => { cart.forEach(({ cost }) => { total += cost; }); - return total; + + if (total >= MIN_TOTAL_PRICE_TO_GET_DISCOUNT) { + const orgPrice = total; + total -= DISCOUNT * total; + + return { + total: orgPrice, + discountedPrice: total, + }; + } + + return { + total, + discountedPrice: null, + }; + }; + + const renderTotalPrice = () => { + const { total, discountedPrice } = calculateTotalCost(); + if (discountedPrice) { + return ( + + + Total:{' '} + + + {total} T + + + + {discountedPrice} T + + + ); + } + + return ( + + Total: {total} T + + ); }; return ( @@ -129,7 +171,7 @@ const MyAccount = () => { <> - Total: {calculateTotalCost()} T + {renderTotalPrice()}