Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/app/auth/sign_in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import z from "zod";
import { zodResolver } from "@hookform/resolvers/zod";

const formSchema = z.object({
email: z.email(),
email: z.email({
pattern: /^[aA]\d{6}@alunos\.uminho\.pt$/,
message: "Email must be in the format a123456@alunos.uminho.pt",
}),
password: z.string().min(1, "Password is required"),
});

Expand Down Expand Up @@ -80,7 +83,7 @@ export default function SignIn() {
{...register("email")}
id="email"
className="bg-dark/5 border-0 placeholder:text-black/50"
placeholder="Email"
placeholder="a123456@alunos.uminho.pt"
/>
<span className="text-danger pl-2">{errors.email?.message}</span>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/components/calendar/event-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventProps } from "react-big-calendar";
import { editColor } from "@/lib/utils";

export default function EventCard({ event }: EventProps) {
const id = event.resource?.id;
const building = event.resource?.building;
const room = event.resource?.room;
const textColor = event.resource?.textColor;
Expand All @@ -10,6 +11,7 @@ export default function EventCard({ event }: EventProps) {

return (
<div
id={id}
className="h-full w-full px-1.5 py-0.5"
style={{
backgroundImage:
Expand Down
1 change: 1 addition & 0 deletions src/components/calendarOptions/common/item-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function ShiftTag({
}) {
return (
<div
id={id}
className={twMerge(
clsx(
"bg-dark/5 inline-flex w-fit items-center gap-2.5 rounded-2xl py-1.5 select-none",
Expand Down
46 changes: 33 additions & 13 deletions src/contexts/schedule-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,42 @@ function addShiftById(
originalShifts: IShift[],
id: string,
): IShift[] {
const newShift = allShifts.find((shift) => shift.id === id);
const isOriginal = originalShifts.some(
(shift) =>
shift.id === id &&
(shift.status === "inactive" || shift.status === "active"),
const newShifts = allShifts.filter((shift) => shift.id === id);

const shiftsToAdd = newShifts.filter(
(newShift) =>
!shifts.some((s) => s.id === newShift.id && s.slotId === newShift.slotId),
);
if (newShift && !shifts.some((s) => s.id === id)) {
return [
...shifts,
{ ...newShift, status: isOriginal ? "active" : "override" },
];
}
return shifts;

const mappedShifts = shiftsToAdd.map((newShift) => {
const isOriginal = originalShifts.some(
(shift) =>
shift.id === id &&
(shift.status === "inactive" || shift.status === "active"),
);
return {
...newShift,
status: (isOriginal ? "active" : "override") as
| "active"
| "override"
| "inactive"
| null,
};
});

return [...shifts, ...mappedShifts];
}

function sortShiftsByYearCourse(mixedShifts: IShift[]): IShiftsSorted {
const byYearSemester = mixedShifts.reduce(
// remove duplicates since timeslots are previously converted to shifts
const seen = new Set<string>();
const uniqueShifts = mixedShifts.filter((shift) => {
if (seen.has(shift.id)) return false;
seen.add(shift.id);
return true;
});

const byYearSemester = uniqueShifts.reduce(
(acc, shift) => {
if (!acc[shift.year]) acc[shift.year] = {};

Expand Down Expand Up @@ -171,6 +190,7 @@ function extractShifts(courses: ICourse[]): IShift[] {

return {
id: shiftGroup.id,
slotId: shift.id,
courseName: course.name,
courseId: course.id,
shortCourseName: course.shortname,
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ICourse {

export interface IShift {
id: string;
slotId: string;
courseName: string;
courseId: string;
shortCourseName: string;
Expand Down