Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource Page #119

Merged
merged 1 commit into from
Mar 11, 2024
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
2 changes: 1 addition & 1 deletion src/app/private/[uid]/admin/home/resources/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { prisma } from "@server/db/client";
const AdminResourcesPage = async () => {
const resources = await prisma.resource.findMany();

return <DisplayResources showRole={true} resources={resources} />;
return <DisplayResources showRole={true} resources={resources} editable />;
};

export default AdminResourcesPage;
16 changes: 9 additions & 7 deletions src/app/private/[uid]/chapter-leader/home/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const Layout = async ({ children }: LayoutProps) => {
headerIcon={faHouse}
showHorizontalLine={false}
>
<TabButtons
queries={[
{ segment: "home", name: "My Chapter" },
{ segment: "home/resources", name: "resources" },
]}
/>
{children}
<div className="flex flex-col gap-y-6">
<TabButtons
queries={[
{ segment: "home", name: "My Chapter" },
{ segment: "home/resources", name: "resources" },
]}
/>
{children}
</div>
</HeaderContainer>
);
};
Expand Down
17 changes: 17 additions & 0 deletions src/app/private/[uid]/chapter-leader/home/resources/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import DisplayResources from "@components/DisplayResources";
import { prisma } from "@server/db/client";

const ChapterLeaderResourcesPage = async () => {
const resources = await prisma.resource.findMany({
where: {
access: {
has: "CHAPTER_LEADER",
},
},
});
return (
<DisplayResources showRole={false} resources={resources} editable={false} />
);
};

export default ChapterLeaderResourcesPage;
16 changes: 9 additions & 7 deletions src/app/private/[uid]/user/home/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ const Layout = async ({ children, params, joinChapter }: LayoutProps) => {
headerIcon={faHouse}
showHorizontalLine={false}
>
<TabButtons
queries={[
{ segment: "home", name: "My Chapter" },
{ segment: "home/resources", name: "resources" },
]}
/>
{children}
<div className="flex flex-col gap-y-6">
<TabButtons
queries={[
{ segment: "home", name: "My Chapter" },
{ segment: "home/resources", name: "resources" },
]}
/>
{children}
</div>
</HeaderContainer>
);
} else {
Expand Down
17 changes: 17 additions & 0 deletions src/app/private/[uid]/user/home/resources/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import DisplayResources from "@components/DisplayResources";
import { prisma } from "@server/db/client";

const UserResourcesPage = async () => {
const resources = await prisma.resource.findMany({
where: {
access: {
isEmpty: true,
},
},
});
return (
<DisplayResources showRole={false} resources={resources} editable={false} />
);
};

export default UserResourcesPage;
57 changes: 30 additions & 27 deletions src/components/DisplayResources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { createResourceSchema } from "@api/resources/route.schema";
interface IDisplayResources {
resources: Resource[];
showRole: boolean;
editable: boolean;
}

interface ResourceState extends Resource {
Expand Down Expand Up @@ -127,41 +128,43 @@ const DisplayResources = (props: IDisplayResources) => {
}, [stateResources, setCanSubmit]);

return (
<div>
<div className="flex justify-between">
<button
className="flex w-44 items-center justify-between rounded-xl border border-dark-teal px-4 py-2.5"
onClick={onAddResource}
>
<p className="text-base font-normal">Add resource</p>
<FontAwesomeIcon icon={faPlus} className="h-5 w-5" />
</button>
{edit ? (
<div className="flex flex-col gap-y-6">
{props.editable && (
<div className="flex justify-between">
<button
className={`rounded-xl ${
canSubmit ? "bg-dark-teal" : "bg-[#A6A6A6]"
} px-6 py-2 text-white`}
onClick={onSaveResources}
disabled={!canSubmit}
className="flex w-44 items-center justify-between rounded-xl border border-dark-teal px-4 py-2.5"
onClick={onAddResource}
>
Save
<p className="text-base font-normal">Add resource</p>
<FontAwesomeIcon icon={faPlus} className="h-5 w-5" />
</button>
) : (
<button
className="cursor-pointer text-dark-teal"
onClick={() => setEdit(true)}
>
<span className="mr-2 text-base font-normal">Edit</span>
<FontAwesomeIcon icon={faPencil} className="inline h-5 w-5" />
</button>
)}
</div>
{edit ? (
<button
className={`rounded-xl ${
canSubmit ? "bg-dark-teal" : "bg-[#A6A6A6]"
} px-6 py-2 text-white`}
onClick={onSaveResources}
disabled={!canSubmit}
>
Save
</button>
) : (
<button
className="cursor-pointer text-dark-teal"
onClick={() => setEdit(true)}
>
<span className="mr-2 text-base font-normal">Edit</span>
<FontAwesomeIcon icon={faPencil} className="inline h-5 w-5" />
</button>
)}
</div>
)}
{loading ? (
<div className="flex h-full w-full flex-col items-center justify-center py-64">
<Spinner />
</div>
) : (
<div className="mt-6 grid items-start gap-6 self-stretch md:grid-cols-2 ">
<div className="grid items-start gap-6 self-stretch md:grid-cols-2 ">
{stateResources
.filter((resource) => resource.state !== "DELETED")
.map((eachResource) => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TabButtons = ({ queries }: TabButtonsProps) => {
<div className="flex gap-6">
{queries.map(({ segment, name }, index) => {
const isTabSelected =
pathName.includes(segment) || (urlSegment === null && index === 0);
pathName.endsWith(segment) || (urlSegment === null && index === 0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simplifies our logic. If we use include, we have to account for overlaps.


const base = pathName.match(
new RegExp(
Expand Down
3 changes: 1 addition & 2 deletions src/components/admin/DisplayChapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ const DisplayChapter = (props: DisplayChapterProps) => {
dateCreated={chapter.dateCreated}
/>
<CardGrid
column_count={2}
title={<div className=" text-xl font-bold">Executive Board</div>}
title={<div className="text-xl font-bold">Executive Board</div>}
tiles={eboardMembers.map((user) => (
<UserTile
key={user.id}
Expand Down
Loading