source: CookCraft-FrontEnd/CookCraft-FrontEnd-master/cookcraft-app/src/components/ShoppingCartComponents/OrderNotification.jsx@ f08e256

Last change on this file since f08e256 was d7b7f00, checked in by Gorazd Biskoski <gorazdbiskoskii@…>, 4 weeks ago

Add project

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import React, { useContext, useState, useEffect, useRef } from 'react';
2import { useNavigate } from 'react-router-dom';
3import { OrderContext } from './OrderContext';
4import { FaBiking } from 'react-icons/fa';
5import styles from '../../css/ShoppingCartCss/order-notification.module.css';
6
7const OrderNotification = () => {
8 const { isOrderInProgress, itemsWithQuantities } = useContext(OrderContext);
9 const [showPopup, setShowPopup] = useState(false);
10 const navigate = useNavigate();
11 const popupRef = useRef(null);
12
13 const handleNotificationClick = () => {
14 setShowPopup(!showPopup);
15 };
16
17 const handleGoToOrder = () => {
18 navigate('/delivery-details', { state: { itemsWithQuantities } });
19 };
20
21 useEffect(() => {
22 const handleClickOutside = (event) => {
23 if (popupRef.current && !popupRef.current.contains(event.target)) {
24 setShowPopup(false);
25 }
26 };
27
28 if (showPopup) {
29 document.addEventListener('mousedown', handleClickOutside);
30 } else {
31 document.removeEventListener('mousedown', handleClickOutside);
32 }
33
34 return () => {
35 document.removeEventListener('mousedown', handleClickOutside);
36 };
37 }, [showPopup]);
38
39 return (
40 <>
41 {isOrderInProgress && (
42 <div className={styles.notificationCircle} onClick={handleNotificationClick}>
43 <FaBiking className={styles.notificationIcon} />
44 <span className={styles.exclamationMark}>!</span>
45 </div>
46 )}
47
48 {showPopup && (
49 <div ref={popupRef} className={styles.notificationPopup}>
50 <p>Active Order</p>
51 <button onClick={handleGoToOrder}>Go to Order</button>
52 </div>
53 )}
54 </>
55 );
56};
57
58export default OrderNotification;
Note: See TracBrowser for help on using the repository browser.