Skip to content

Commit

Permalink
Merge branch 'main' into navbar-responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
Aokijiop authored May 20, 2024
2 parents f553ba4 + 0ccb37e commit 85081df
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 232 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@hookform/resolvers": "^3.3.4",
"axios": "^1.6.5",
"csv-writer": "^1.6.0",
"date-fns": "^3.6.0",
"dotenv": "^16.3.1",
"es-abstract": "^1.22.5",
"firebase": "^10.7.1",
Expand Down
6 changes: 3 additions & 3 deletions src/components/Checkin/CheckinStatsDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const CheckinStatsDashboard = ({ event, registered, checkin, isPastEvent = false
// formats dbms date into Month Day, Year
const getDateString = () => {
const dateObject = new Date(Date.parse(event['date']));
const dateString = `${[
dateObject.getMonth(),
]}/${dateObject.getDate()}/${dateObject.getFullYear()}`;

if (isNaN(dateObject)) {
// on page load, prevents displaying "Undefined" as date
return '';
}

const dateString = `${dateObject.getMonth() + 1}/${dateObject.getDate()}/${dateObject.getFullYear()}`;

return dateString;
};

Expand Down
1 change: 1 addition & 0 deletions src/components/Dropzone.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import axios from 'axios';
import React, { useMemo } from 'react';
import Backend from '../utils/utils';
Expand Down
50 changes: 50 additions & 0 deletions src/components/EventRegistration/CancelFlowController.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Button,
Text,
Stack,
Modal,
ModalContent,
ModalBody,
ModalOverlay,
ModalCloseButton,
} from '@chakra-ui/react';
import Backend from '../../utils/utils';
import PropTypes from 'prop-types';

const CancelFlowController = ({id, isOpen, onClose}) => {
const unregisterFromEvent = async (id) => {
console.log(id)
// Register for event
try {
const route = '/data/' + id
await Backend.delete(route);
onClose();
} catch (e) {
console.log('Error deleting event data entry', e);
}
// Added this to update the page / no longer show unregistered events
window.location.reload(false);
};
return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalCloseButton />
<ModalBody>
<Stack align="center" padding="1rem" gap="2rem">
<Text fontSize="2xl" align="center">Are you sure you want to cancel your registration?</Text>
<Button onClick={() => unregisterFromEvent(id)}>Confirm Cancellation</Button>
</Stack>
</ModalBody>
</ModalContent>
</Modal>
);
}

CancelFlowController.propTypes = {
isOpen: PropTypes.bool,
onClose: PropTypes.func,
id: PropTypes.number,
};

export default CancelFlowController;
36 changes: 26 additions & 10 deletions src/components/Events/EventCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ import { useState, useRef, useEffect } from 'react';
import { putEvent } from '../../utils/eventsUtils.js';
import Dropzone from '../Dropzone.tsx';
import HappeningInChip from '../HappeningInChip/HappeningInChip.jsx';
import HappeningNowChip from '../HappeningNowChip/HappeningNowChip.jsx';
import RegistrationFlowController from '../EventRegistration/RegistrationFlowController.jsx';

const EventCard = ({
id,
name,
end_time,
start_time,
date,
showSelect,
image_url,
Expand All @@ -41,8 +44,6 @@ const EventCard = ({
hasBorder = false,
isFeatured = false,
}) => {
const { onOpen, onClose } = useDisclosure();

// Placeholder for testing a high-res image
// image_url =
// 'https://s3-alpha-sig.figma.com/img/4683/1e77/df1444c9bf86d4882d7252f8c2939d3f?Expires=1713139200&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=o5biccW0iouIqgojcte5OMBpWeqQBhdUheAzCF5dUsHGLEYO8lWMb9df75l8NeItiYS93QbY-ZMSRTotplxK2OkExz9nI1Iwy8~HBEZp3cVR9j16wsLAXgB8Vb7GwMCK9d4eFILp6yydgRfr8~Dhd7SwwjCYSgGx94czHpMdLTC231Ss1WmOJiy5PsvfnytNOE3FxumVN95mZ5s-tB5ywvh3h8zqj6-d8FBI2NZG5vd0KqJeiahVxBJQtHxoxmJk1MXrBaQiXuG8aNlUwjGl~wdsqzQ7Aq2~A0x6BfrZUNbVsmmFowD4cdmTPuRTyex4Gc1IjR7AtrAdp2P48iSBTQ__';
Expand All @@ -59,12 +60,6 @@ const EventCard = ({
const breakpoint = 400;
const [containerWidth, setContainerWidth] = useState(0);

const selectEventForSidebar = () => {
console.log("Hit");
onClose();
onOpen();
}

const {
isOpen: isRegistrationFlowOpen,
onOpen: onRegistrationFlowOpen,
Expand All @@ -81,6 +76,25 @@ const EventCard = ({

const sideBySideCard = containerWidth >= breakpoint && isFeatured;

const checkDate = () => {
const todayDate = new Date();
console.log(`TODAY DATE HOURS: ${todayDate.getHours()} MINUTE: ${todayDate.getMinutes()}`);

// Convert start_time, end_time, and eventDate to Date objects
const eventStartHour = start_time.split(':')[0];
const eventStartMin = start_time.split(':')[1];

const eventEndHour = end_time.split(':')[0];
const eventEndMin = end_time.split(':')[1];

return (
todayDate.getHours() >= eventStartHour &&
todayDate.getHours() <= eventEndHour &&
todayDate.getMinutes() >= eventStartMin &&
todayDate.getMinutes() <= eventEndMin
);
};

return (
<>
<Box
Expand All @@ -89,7 +103,7 @@ const EventCard = ({
flexDir="column"
cursor={'pointer'}
justifyContent={sideBySideCard ? 'center' : 'start'}
onClick={() => (showSelect ? handleCheckboxChange(id) : selectEventForSidebar())}
onClick={() => (showSelect ? handleCheckboxChange(id) : handleCheckboxChange(id))}
border={hasBorder ? '2px solid var(--Secondary-Button-Color, #EFEFEF)' : ''}
borderRadius="18px"
width={'Fill (674px)'}
Expand Down Expand Up @@ -138,7 +152,7 @@ const EventCard = ({
mt={sideBySideCard ? 0 : 5}
mb={sideBySideCard ? 0 : 5}
>
<HappeningInChip date={dateObj} mb={5} />
{checkDate() ? <HappeningNowChip mb={5} /> : <HappeningInChip date={dateObj} mb={5} />}

{name.length > 30 ? (
<Text
Expand Down Expand Up @@ -286,6 +300,8 @@ EventCard.propTypes = {
getEvents: PropTypes.func,
hasBorder: PropTypes.bool,
isFeatured: PropTypes.bool,
start_time: PropTypes.string,
end_time: PropTypes.string,
};

export default EventCard;
Expand Down
24 changes: 17 additions & 7 deletions src/components/Events/EventFilteredGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import {
Heading,
HStack,
} from '@chakra-ui/react';
import { useEffect, useState, useCallback } from 'react';
import { useEffect, useState, useContext, useCallback } from 'react';
import { SearchIcon } from '@chakra-ui/icons';
import PropTypes from 'prop-types';

import EventCard from '../../components/Events/EventCard';
import Backend from '../../utils/utils';
import Fuse from 'fuse.js';

const EventFilteredGrid = ({ setCurrentEventId, setIsOpen, setShowOpenDrawerButton, isOpen }) => {
import UserContext from '../../utils/UserContext';

const EventFilteredGrid = ({ setCurrentEventId, setIsOpen, setShowOpenDrawerButton, isOpen, onlyUnregistered=false }) => {
const [events, setEvents] = useState([]);
const [displayEvents, setDisplayEvents] = useState([]);

Expand All @@ -30,11 +32,21 @@ const EventFilteredGrid = ({ setCurrentEventId, setIsOpen, setShowOpenDrawerButt
const [date, setDate] = useState('');
const [fuse, setFuse] = useState();


const { user } = useContext(UserContext);

const getEvents = useCallback(async () => {

try {
const eventsData = await Backend.get('/events/currentEvents');
let eventsData;
if (onlyUnregistered) {
// Will show only registered events
eventsData = await Backend.get(`data/unregistered/${user.id}`);
} else {
// Will show all events, default / previous behavior
eventsData = await Backend.get('/events/currentEvents');
}
setEvents(eventsData.data);
// setDates();
setLocations(getLocation(eventsData.data));
setDates(getDate(eventsData.data));
const options = { keys: ['name', 'date', 'location'], includeScore: true }; //use date and locaiton selected
Expand Down Expand Up @@ -119,7 +131,6 @@ const EventFilteredGrid = ({ setCurrentEventId, setIsOpen, setShowOpenDrawerButt
// result = fuseResult.filter(item => item.score <= 0.5).map(item => item.item);
result = fuseResult.map(item => item.item);
} else result = events;
// result.map((e) -> e.)
setDisplayEvents(result);
}, [name, location, date, fuse, events]);

Expand Down Expand Up @@ -197,7 +208,6 @@ const EventFilteredGrid = ({ setCurrentEventId, setIsOpen, setShowOpenDrawerButt
</Select>
<Select
bg={'white'}
// icon={<Icon as={CalendarIcon}/>}
onChange={handleDateChange}
placeholder="Select Date"
border={'2px solid var(--Secondary-Button-Color, #EFEFEF)'}
Expand Down Expand Up @@ -237,7 +247,6 @@ const EventFilteredGrid = ({ setCurrentEventId, setIsOpen, setShowOpenDrawerButt
<EventCard
{...element}
isSelected={selectedEvents.includes(element.id)}
// showSelect={showSelect}
handleCheckboxChange={handleCheckboxChange}
getEvents={getEvents}
hasBorder={true}
Expand All @@ -257,6 +266,7 @@ EventFilteredGrid.propTypes = {
setIsOpen: PropTypes.func.isRequired,
setShowOpenDrawerButton: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired,
onlyUnregistered: PropTypes.bool
};

export default EventFilteredGrid;
14 changes: 13 additions & 1 deletion src/components/Events/FeaturedDashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Heading, Flex, Grid, GridItem, IconButton, useBreakpointValue } from '@chakra-ui/react';
import { useState, useEffect } from 'react';
import { useState, useEffect, useContext } from 'react';
import Backend from '../../utils/utils';
import EventCard from './EventCard';
import { RxCaretLeft } from 'react-icons/rx';
import PropTypes from 'prop-types';

import UserContext from '../../utils/UserContext';

const FeaturedDashboard = ({
setCurrentEventId,
setIsOpen,
Expand All @@ -16,6 +18,16 @@ const FeaturedDashboard = ({
const [featuredEvents, setFeaturedEvents] = useState([]);
const numEvents = useBreakpointValue({ base: 1, md: 2, xl: 2 });

const { user } = useContext(UserContext);

const getEvents = async () => {
try {
const eventsData = await Backend.get(`/data/unregistered/${user.id}`);
setFeaturedEvents(eventsData.data.slice(0, numEvents));
} catch (err) {
console.log(`Error getting events: `, err.message);
}
};

useEffect(() => {
const getEvents = async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/components/EventsModal/AddEventsModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const AddEventsModal = () => {
isClosable: true,
});
// TODO: API request is comment out for now due to form change
await postEvent(eventData);
const res = await postEvent(eventData);
console.log(res);
toast.close(toastIdRef.current);
toast({
title: 'Event Created.',
Expand All @@ -65,7 +66,7 @@ const AddEventsModal = () => {
isClosable: true,
});
onClose();
window.location.reload();
// window.location.reload();
} catch (err) {
console.log(err);
toast({
Expand Down Expand Up @@ -215,6 +216,7 @@ const AddEventsModal = () => {
size="lg"
borderRadius="8px"
onChange={e => {
console.log(`date: ${e.target.value}`);
setEventData({ ...eventData, date: e.target.value });
}}
/>
Expand Down
Loading

0 comments on commit 85081df

Please sign in to comment.