Skip to content

Commit

Permalink
collapsible items in univ home page and chapter requests (#145)
Browse files Browse the repository at this point in the history
* collapsible items in univ home page and chapter requests

* Incorporate PR feedback

---------

Co-authored-by: nickbar01234 <[email protected]>
  • Loading branch information
tylerrlin and nickbar01234 authored Apr 9, 2024
1 parent 2ec1fc3 commit 8ab1f3e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 73 deletions.
133 changes: 69 additions & 64 deletions src/components/DisplayChapterInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { sortedStudents } from "@utils";
import { Dropdown } from "./selector";
import { editRole } from "@api/admin/edit-role/route.client";
import { useRouter } from "next/navigation";
import DropDownContainer from "@components/container/DropDownContainer";

type ChapterWithUser = Prisma.ChapterGetPayload<{
include: { students: true };
Expand Down Expand Up @@ -103,73 +104,77 @@ const DisplayChapterInfo = ({
</div>
))}
</div>
{userRequests && (
<div className="mb-12">
<h1 className="mb-6 text-xl">{`Pending (${userRequests.length})`}</h1>
{userRequests.length > 0 ? (
<CardGrid
column_count={2}
tiles={userRequests.map((user, index) => {
return (
<PendingCard
key={index}
name={fullName(user.user)}
uid={user.user.id}
/>
);
})}
/>
) : (
<h1 className="font-light">
{"This chapter has no pending members."}
</h1>
)}
</div>
)}

<div className="mb-12">
<CardGrid
<div className="flex flex-col gap-y-12">
{userRequests && (
<DropDownContainer
title={
<div className="mb-6 text-xl">{`Pending (${userRequests.length})`}</div>
}
>
{userRequests.length > 0 ? (
<CardGrid
column_count={2}
tiles={userRequests.map((user) => {
return (
<PendingCard
key={user.id}
name={fullName(user.user)}
uid={user.id}
/>
);
})}
/>
) : (
<h1 className="font-light">
{"This chapter has no pending members."}
</h1>
)}
</DropDownContainer>
)}
<DropDownContainer
title={
<div className="flex justify-between">
<span className="text-xl text-[#000022]">
{user.role === "ADMIN"
? `Members (${chapter.students.length})`
: "Executive Board"}
</span>
{user.role === "ADMIN" && (
<div
className="cursor-pointer rounded-lg bg-dark-teal px-4 py-3 text-white"
onClick={(e) => {
e.stopPropagation();
setDisplayAssignPresident(true);
}}
>
Assign President
</div>
)}
<div className="mb-6 flex justify-between text-xl text-[#000022]">
{user.role === "ADMIN"
? `Members (${chapter.students.length})`
: "Executive Board"}
</div>
}
tiles={sortedStudents(students).map((student) => {
const link =
user.role === "USER"
? ""
: `/private/${user.id}/${RoleToUrlSegment[user.role]}` +
`${
user.role === "ADMIN" ? `/home/chapters/${chapter.id}` : ""
}` +
`/users/${student.id}`;
return <UserTile key={student.id} student={student} link={link} />;
})}
/>
</div>
<div className="flex flex-col gap-y-6">
<div className="text-xl text-[#000022]">Resources</div>
<DisplayResources
resources={resources}
showRole={false}
editable={false}
column={3}
/>
>
<div className="flex flex-col gap-y-6">
{user.role === "ADMIN" && (
<div
className="w-fit cursor-pointer rounded-lg bg-dark-teal px-4 py-3 text-white"
onClick={(e) => {
e.stopPropagation();
setDisplayAssignPresident(true);
}}
>
Assign President
</div>
)}
<CardGrid
tiles={sortedStudents(students).map((student) => (
<UserTile
key={student.id}
student={student}
link={`/private/${user.id}/${
RoleToUrlSegment[user.role]
}/users/${student.id}`}
/>
))}
/>
</div>
</DropDownContainer>
<DropDownContainer
title={<div className="mb-6 text-xl">Resources</div>}
>
<DisplayResources
resources={resources}
showRole={false}
editable={false}
column={3}
/>
</DropDownContainer>
</div>
</div>
);
Expand Down
17 changes: 8 additions & 9 deletions src/components/TileGrid/InfoTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Link from "next/link";
import React from "react";
import DropDownContainer from "@components/container/DropDownContainer";

interface Information {
key: string;
Expand Down Expand Up @@ -54,17 +55,15 @@ const InfoTile = (params: InfoTileProps) => {
</div>
))}
</div>
{moreInformation != undefined ? (
<div>
<p
className="mb-6 w-fit cursor-pointer text-dark-teal underline"
onClick={onToggleShouldShowMore}
>
<DropDownContainer
title={
<p className="mb-6 w-fit cursor-pointer text-dark-teal underline">
{!shouldShowMore ? "Show more" : "Show less"}
</p>
{shouldShowMore ? moreInformation : null}
</div>
) : null}
}
>
{moreInformation}
</DropDownContainer>
</div>
);
};
Expand Down
44 changes: 44 additions & 0 deletions src/components/container/DropDownContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use client";

import React from "react";
import { faCaretDown, faCaretRight } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

interface DropDownContainerProps {
classname?: string;
title?: React.ReactNode;
children?: React.ReactNode;
}

const DropDownContainer = (props: DropDownContainerProps) => {
const [showItems, setShowItems] = React.useState(false);

const handleClick = () => {
setShowItems(!showItems);
};

return (
<div className={props.classname ?? ""}>
<div className="flex cursor-pointer" onClick={handleClick}>
<div className="h-full pr-2">
<FontAwesomeIcon icon={showItems ? faCaretDown : faCaretRight} />
</div>
{props.title}
</div>
<div
className={`overflow-scroll ${
showItems ? "max-h-[512px] md:max-h-[1024px]" : "max-h-0"
}`}
style={
showItems
? { transition: "max-height 1s ease" }
: { transition: "max-height 0.3s ease" }
}
>
{props.children}
</div>
</div>
);
};

export default DropDownContainer;

0 comments on commit 8ab1f3e

Please sign in to comment.