|
| 1 | +import { useState } from 'react'; |
| 2 | +import { useSelector } from 'react-redux'; |
| 3 | +import './Participation.css'; |
| 4 | +import mockEvents from './mockData'; |
| 5 | + |
| 6 | +function DropOffTracking() { |
| 7 | + const [selectedEvent, setSelectedEvent] = useState('All Events'); |
| 8 | + const [selectedTime, setSelectedTime] = useState('All Time'); |
| 9 | + |
| 10 | + const getDateRange = () => { |
| 11 | + const today = new Date(); |
| 12 | + let startDate; |
| 13 | + let endDate; |
| 14 | + |
| 15 | + if (selectedTime === 'Today') { |
| 16 | + startDate = new Date(today); |
| 17 | + // Start of the day |
| 18 | + startDate.setHours(0, 0, 0, 0); |
| 19 | + endDate = new Date(today); |
| 20 | + // End of the day |
| 21 | + endDate.setHours(23, 59, 59, 999); |
| 22 | + } else if (selectedTime === 'This Week') { |
| 23 | + startDate = new Date(today); |
| 24 | + startDate.setDate(today.getDate() - today.getDay()); |
| 25 | + // Start of the week |
| 26 | + startDate.setHours(0, 0, 0, 0); |
| 27 | + endDate = new Date(startDate); |
| 28 | + endDate.setDate(startDate.getDate() + 6); |
| 29 | + // End of the week |
| 30 | + endDate.setHours(23, 59, 59, 999); |
| 31 | + } else if (selectedTime === 'This Month') { |
| 32 | + // Start of the month |
| 33 | + startDate = new Date(today.getFullYear(), today.getMonth(), 1); |
| 34 | + // End of the month |
| 35 | + endDate = new Date(today.getFullYear(), today.getMonth() + 1, 0); |
| 36 | + endDate.setHours(23, 59, 59, 999); |
| 37 | + } |
| 38 | + |
| 39 | + return { startDate, endDate }; |
| 40 | + }; |
| 41 | + |
| 42 | + // Filter events based on selected filters |
| 43 | + const filteredEvents = mockEvents.filter(event => { |
| 44 | + // Filter by event type |
| 45 | + if (selectedEvent !== 'All Events' && event.eventType !== selectedEvent) { |
| 46 | + return false; |
| 47 | + } |
| 48 | + |
| 49 | + // Filter by date range |
| 50 | + if (selectedTime !== 'All Time') { |
| 51 | + const { startDate, endDate } = getDateRange(); |
| 52 | + const eventDate = new Date(event.eventTime.split(' pm ')[1]); |
| 53 | + if (startDate && endDate) { |
| 54 | + return eventDate >= startDate && eventDate <= endDate; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return true; |
| 59 | + }); |
| 60 | + |
| 61 | + const darkMode = useSelector(state => state.theme.darkMode); |
| 62 | + |
| 63 | + return ( |
| 64 | + <div className={`tracking-container ${darkMode ? 'tracking-container-dark' : ''}`}> |
| 65 | + <div className={`tracking-header ${darkMode ? 'tracking-header-dark' : ''}`}> |
| 66 | + <h3>Drop-off and no-show rate tracking</h3> |
| 67 | + <div className="tracking-filters"> |
| 68 | + <select value={selectedEvent} onChange={e => setSelectedEvent(e.target.value)}> |
| 69 | + <option value="All Events">All Events</option> |
| 70 | + <option value="Yoga Class">Yoga Class</option> |
| 71 | + <option value="Cooking Workshop">Cooking Workshop</option> |
| 72 | + <option value="Dance Class">Dance Class</option> |
| 73 | + <option value="Fitness Bootcamp">Fitness Bootcamp</option> |
| 74 | + </select> |
| 75 | + <select value={selectedTime} onChange={e => setSelectedTime(e.target.value)}> |
| 76 | + <option value="All Time">All Time</option> |
| 77 | + <option value="Today">Today</option> |
| 78 | + <option value="This Week">This Week</option> |
| 79 | + <option value="This Month">This Month</option> |
| 80 | + </select> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + <div className="tracking-summary"> |
| 84 | + <div className={`tracking-rate ${darkMode ? 'tracking-rate-dark' : ''}`}> |
| 85 | + <p className="tracking-rate-value"> |
| 86 | + +5% |
| 87 | + <span className={darkMode ? 'span-dark' : ''}>Last week</span> |
| 88 | + </p> |
| 89 | + <p>Drop-off rate</p> |
| 90 | + </div> |
| 91 | + <div className={`tracking-rate ${darkMode ? 'tracking-rate-dark' : ''}`}> |
| 92 | + <p className="tracking-rate-value"> |
| 93 | + +5% <span className={darkMode ? 'span-dark' : ''}>Last week</span> |
| 94 | + </p> |
| 95 | + <p>No-show rate</p> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + <div className={`tracking-list-container ${darkMode ? 'tracking-list-container-dark' : ''}`}> |
| 99 | + <table className={`tracking-table ${darkMode ? 'tracking-table-dark' : ''}`}> |
| 100 | + <thead> |
| 101 | + <tr> |
| 102 | + <th>Event name</th> |
| 103 | + <th>No-show rate</th> |
| 104 | + <th>Drop-off rate</th> |
| 105 | + <th>Attendees</th> |
| 106 | + </tr> |
| 107 | + </thead> |
| 108 | + <tbody> |
| 109 | + {filteredEvents.map(event => ( |
| 110 | + <tr key={event.id}> |
| 111 | + <td>{event.eventName}</td> |
| 112 | + <td className="tracking-rate-green">{event.noShowRate}</td> |
| 113 | + <td className="tracking-rate-red">{event.dropOffRate}</td> |
| 114 | + <td>{event.attendees}</td> |
| 115 | + </tr> |
| 116 | + ))} |
| 117 | + </tbody> |
| 118 | + </table> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + ); |
| 122 | +} |
| 123 | + |
| 124 | +export default DropOffTracking; |
0 commit comments