Skip to content

Commit

Permalink
add sortedStudents function
Browse files Browse the repository at this point in the history
  • Loading branch information
wkim10 authored and nickbar01234 committed Apr 4, 2024
1 parent beef3a0 commit 2e1a2d5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { faArrowUpFromBracket } from "@fortawesome/free-solid-svg-icons";
import { Dropdown } from "@components/selector";
import { Popup } from "@components/container";
import { useRouter } from "next/navigation";
import { sortedStudents } from "@utils";

type MembersHomePageProps = {
members: User[];
Expand Down Expand Up @@ -96,7 +97,7 @@ const MembersHomePage = ({ members }: MembersHomePageProps) => {
)}
<SearchableContainer
display={displayMembers}
elements={members}
elements={sortedStudents(members)}
emptyNode={
<h1 className="text-2xl font-light text-[#000022]">
This chapter has no members.
Expand Down
3 changes: 2 additions & 1 deletion src/components/DisplayChapterInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { UserContext } from "@context/UserProvider";
import PendingCard from "@components/PendingCard";
import { fullName } from "@utils";
import { RoleToUrlSegment } from "@constants/RoleAlias";
import { sortedStudents } from "@utils";

type ChapterWithUser = Prisma.ChapterGetPayload<{
include: { students: true };
Expand Down Expand Up @@ -91,7 +92,7 @@ const DisplayChapterInfo = ({
: "Executive Board"}
</div>
}
tiles={students.map((student) => {
tiles={sortedStudents(students).map((student) => {
const link =
user.role === "USER"
? ""
Expand Down
25 changes: 25 additions & 0 deletions src/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Session } from "next-auth";
import { Resource, Senior, User } from "@prisma/client";
import moment from "moment";

type PositionOrder = {
[position: string]: number;
};

export const formatUserHomeRoute = (user: NonNullable<Session["user"]>) => {
return `/private/${user.id}/${RoleToUrlSegment[user.role]}/home`;
};
Expand Down Expand Up @@ -41,3 +45,24 @@ export const fullName = (user: User) => `${user.firstName} ${user.lastName}`;

export const seniorFullName = (senior: Senior) =>
`${senior.firstname} ${senior.lastname}`;

export const sortedStudents = (students: User[]) => {
const positionOrder: PositionOrder = {
President: 0,
"Social Coordinator": 1,
"Senior Outreach Coordinator": 2,
"Head of Media": 3,
Secretary: 4,
Treasurer: 5,
"Match Coordinator": 6,
};

const comparePositions = (a: User, b: User) => {
const orderA = positionOrder[a.position] || Infinity;
const orderB = positionOrder[b.position] || Infinity;

return orderA - orderB;
};

return students.sort(comparePositions);
};

0 comments on commit 2e1a2d5

Please sign in to comment.