Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
akinfelami committed May 7, 2024
2 parents 281ed02 + e70c9f3 commit 41ddc57
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 49 deletions.
27 changes: 25 additions & 2 deletions backend/src/events/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const getEvents = async (
pagination: {
after: string;
limit: string;
},
include: {
attendees: boolean;
}
) => {
/* SORTING */
Expand Down Expand Up @@ -116,7 +119,7 @@ const getEvents = async (
/* FILTERING */

let whereDict: { [key: string]: any } = {};
let includeDict: { [key: string]: any } = {};
let includeDict: { [key: string]: any } = include;

// Handles GET /events?date=upcoming and GET /events?date=past
// TODO: Investigate creating events that occur in a few minutes into the future
Expand Down Expand Up @@ -272,6 +275,18 @@ const getEvent = async (eventID: string) => {
});
};

/**
* Returns a boleean indicating whether event is past or not
* @param eventID (String)
* @returns promise with boolean or error
*/
export const isEventPast = async (eventID: string) => {
const currentDateTime = new Date();
const event = (await getEvent(eventID)) as Event;
const eventDate = new Date(event.startDate);
return eventDate < currentDateTime;
};

/**
* Gets all attendees registered for an event
* @param eventID (String)
Expand Down Expand Up @@ -341,8 +356,9 @@ const addAttendee = async (eventID: string, userID: string) => {
var eventDateTimeUnknown = event?.startDate as unknown;
var eventDateTimeString = eventDateTimeUnknown as string;
var textBody = "Your registration was successful.";
const eventIsInThePast = await isEventPast(eventID);

if (process.env.NODE_ENV != "test") {
if (process.env.NODE_ENV != "test" && !eventIsInThePast) {
// creates updated html path with the changed inputs
const updatedHtml = replaceEventInputs(
stringEventUpdate,
Expand All @@ -358,6 +374,9 @@ const addAttendee = async (eventID: string, userID: string) => {
updatedHtml
);
}
if (eventIsInThePast) {
return Promise.reject("Event is past, cannot enroll new user");
}
return await prisma.eventEnrollment.create({
data: {
event: {
Expand Down Expand Up @@ -435,6 +454,10 @@ const deleteAttendee = async (
* @returns promise with event or error
*/
const updateEventStatus = async (eventID: string, status: string) => {
if (await isEventPast(eventID)) {
return Promise.reject("Event is past, cannot update status");
}

return await prisma.event.update({
where: {
id: eventID,
Expand Down
8 changes: 7 additions & 1 deletion backend/src/events/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ eventRouter.get("/", useAuth, async (req: Request, res: Response) => {
limit: req.query.limit as string,
};

attempt(res, 200, () => eventController.getEvents(filter, sort, pagination));
const include = {
attendees: req.query.include === "attendees" ? true : false,
};

attempt(res, 200, () =>
eventController.getEvents(filter, sort, pagination, include)
);
});

eventRouter.get("/upcoming", useAuth, async (req: Request, res: Response) => {
Expand Down
38 changes: 17 additions & 21 deletions backend/src/users/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,23 @@ userRouter.get(
}
);

userRouter.get(
"/search",
useAdminAuth || useSupervisorAuth,
async (req: Request, res: Response) => {
// #swagger.tags = ['Users']
const { email, firstName, lastName, role, status, hours, nickname } =
req.body;
attempt(res, 200, () =>
userController.getSearchedUser(
req,
email,
firstName,
lastName,
role,
status,
hours,
nickname
)
);
}
);
userRouter.get("/search", useAuth, async (req: Request, res: Response) => {
// #swagger.tags = ['Users']
const { email, firstName, lastName, role, status, hours, nickname } =
req.body;
attempt(res, 200, () =>
userController.getSearchedUser(
req,
email,
firstName,
lastName,
role,
status,
hours,
nickname
)
);
});

userRouter.get(
"/sorting",
Expand Down
1 change: 1 addition & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
transpilePackages: ["@mdxeditor/editor"],
};

module.exports = nextConfig;
6 changes: 1 addition & 5 deletions frontend/src/components/organisms/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import Markdown from "react-markdown";
import UploadIcon from "@mui/icons-material/Upload";
import EditIcon from "@mui/icons-material/Edit";
import { useAuth } from "@/utils/AuthContext";
import dynamic from "next/dynamic";

const EditorComp = dynamic(() => import("@/components/atoms/Editor"), {
ssr: false,
});
import EditorComp from "@/components/atoms/Editor";

type modalBodyProps = {
handleModal: () => void;
Expand Down
26 changes: 21 additions & 5 deletions frontend/src/components/organisms/EventCardCancel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useForm, SubmitHandler } from "react-hook-form";
interface EventCardCancelProps {
attendeeId: string;
eventId: string;
date: Date;
}

interface modalProps {
Expand Down Expand Up @@ -58,7 +59,11 @@ const ModalBody = ({ handleClose, mutateFn }: modalProps) => {
);
};

const EventCardCancel = ({ eventId, attendeeId }: EventCardCancelProps) => {
const EventCardCancel = ({
eventId,
attendeeId,
date,
}: EventCardCancelProps) => {
const { user } = useAuth();
const queryClient = useQueryClient();

Expand Down Expand Up @@ -110,6 +115,10 @@ const EventCardCancel = ({ eventId, attendeeId }: EventCardCancelProps) => {
setOpen(!open);
};

/** Register button should be disabled if event is in the past */
const currentDate = new Date();
const disableCancelEvent = date < currentDate;

return (
<>
<Modal
Expand All @@ -121,7 +130,9 @@ const EventCardCancel = ({ eventId, attendeeId }: EventCardCancelProps) => {
<Card>
<div className="font-semibold text-2xl">You're registered</div>
<div className="mt-5" />
<div className="font-semibold text-lg">No longer able to attend?</div>
<div className="font-semibold text-lg mb-2">
No longer able to attend?
</div>
<IconText icon={<AccessTimeFilledIcon />}>
{/* TODO: Update how many hours left */}
<div>4 hours left to cancel registration</div>
Expand All @@ -142,12 +153,17 @@ const EventCardCancel = ({ eventId, attendeeId }: EventCardCancelProps) => {
{...register("cancelReason", {
required: { value: true, message: "Required" },
})}
disabled={disableCancelEvent}
onChange={(e: any) => setCancelationMessage(e.target.value)}
/>
<div className="mt-3" />
<Button type="submit" variety="error">
Cancel registration
</Button>
{disableCancelEvent ? (
<Button disabled>The event has concluded.</Button>
) : (
<Button type="submit" variety="error">
Cancel registration
</Button>
)}
</form>
</Card>
</>
Expand Down
31 changes: 23 additions & 8 deletions frontend/src/components/organisms/EventCardRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import Button from "../atoms/Button";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { api } from "@/utils/api";
import { useAuth } from "@/utils/AuthContext";
import Alert from "../atoms/Alert";

interface EventRegisterCardProps {
attendeeId: string;
eventId: string;
date: Date;
}

const EventCardRegister = ({ eventId, attendeeId }: EventRegisterCardProps) => {
const EventCardRegister = ({
eventId,
attendeeId,
date,
}: EventRegisterCardProps) => {
const { user } = useAuth();
const queryClient = useQueryClient();

Expand All @@ -35,6 +41,10 @@ const EventCardRegister = ({ eventId, attendeeId }: EventRegisterCardProps) => {
},
});

/** Register button should be disabled if event is in the past */
const currentDate = new Date();
const disableRegisterEvent = date < currentDate;

return (
<Card>
<div className="font-semibold text-2xl">Register for this event</div>
Expand All @@ -48,16 +58,21 @@ const EventCardRegister = ({ eventId, attendeeId }: EventRegisterCardProps) => {
<div className="mt-3" />
<CustomCheckbox
label="I agree to the terms and conditions"
disabled={disableRegisterEvent}
onChange={() => setIsChecked(!isChecked)}
/>
<div className="mt-3" />
<Button
onClick={handleEventResgistration}
disabled={!isChecked}
loading={isPending}
>
Register
</Button>
{disableRegisterEvent ? (
<Button disabled>The event has concluded.</Button>
) : (
<Button
onClick={handleEventResgistration}
disabled={!isChecked}
loading={isPending}
>
Register
</Button>
)}
</Card>
);
};
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/components/organisms/EventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ import {
import { api } from "@/utils/api";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import Dropzone from "../atoms/Dropzone";
import dynamic from "next/dynamic";
import Alert from "../atoms/Alert";

const EditorComp = dynamic(() => import("@/components/atoms/Editor"), {
ssr: false,
});
import EditorComp from "@/components/atoms/Editor";

interface EventFormProps {
eventId?: string | string[] | undefined;
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/components/organisms/ViewEventDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import EventCardCancel from "./EventCardCancel";
import Markdown from "react-markdown";
import DefaultTemplate from "../templates/DefaultTemplate";
import FetchDataError from "./FetchDataError";
import EventDetails from "./EventDetails";

interface ViewEventDetailsProps {}

Expand Down Expand Up @@ -132,9 +133,17 @@ const ViewEventDetails = () => {
{userHasCanceledAttendance ? (
<EventCardCancelConfirmation />
) : eventAttendance ? (
<EventCardCancel eventId={eventid} attendeeId={userid} />
<EventCardCancel
eventId={eventid}
attendeeId={userid}
date={new Date(eventData.startDate)}
/>
) : (
<EventCardRegister eventId={eventid} attendeeId={userid} />
<EventCardRegister
eventId={eventid}
attendeeId={userid}
date={new Date(eventData.startDate)}
/>
)}
</div>
)
Expand Down

0 comments on commit 41ddc57

Please sign in to comment.