-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): added permissions for the platform
- Loading branch information
Showing
11 changed files
with
153 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
apps/nextjs/src/app/(home)/guides/action-guides/_components/GuideCardSkeleton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from "react"; | ||
|
||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@amaxa/ui/card"; | ||
import { Input } from "@amaxa/ui/input"; | ||
import { Skeleton } from "@amaxa/ui/skeleton"; | ||
|
||
const GuidesSkeleton = () => { | ||
return ( | ||
<div className="mx-auto px-4 py-8 md:px-6"> | ||
<h1 className="mb-6 text-3xl font-bold">Action Guides</h1> | ||
<div className="mb-6 flex flex-row justify-between"> | ||
<Input | ||
placeholder="Search action guides..." | ||
className="w-full max-w-md" | ||
disabled | ||
/> | ||
<Skeleton className="h-10 w-32" /> | ||
</div> | ||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3"> | ||
{[...Array(6)].map((_, index) => ( | ||
<Skeleton key={index} className="h-[200px]"> | ||
<Card className="h-full"> | ||
<CardHeader> | ||
<CardTitle> | ||
<Skeleton className="h-6 w-2/3" /> | ||
</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<Skeleton className="mb-2 h-4 w-full" /> | ||
<Skeleton className="h-4 w-4/5" /> | ||
</CardContent> | ||
<CardFooter> | ||
<Skeleton className="h-4 w-1/4" /> | ||
</CardFooter> | ||
</Card> | ||
</Skeleton> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GuidesSkeleton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import { Suspense } from "react"; | ||
|
||
import { checkAuth } from "~/lib/auth"; | ||
import { api, HydrateClient } from "~/trpc/server"; | ||
import Guides from "./_components/GuideCard"; | ||
import GuidesSkeleton from "./_components/GuideCardSkeleton"; | ||
|
||
export default async function Page() { | ||
await checkAuth(); | ||
void api.actionGuides.getActionGuides.prefetch(); | ||
|
||
export default function Page() { | ||
return ( | ||
<div className="w-full"> | ||
<Guides /> | ||
<HydrateClient> | ||
<Suspense fallback={<GuidesSkeleton />}> | ||
<Guides /> | ||
</Suspense> | ||
</HydrateClient> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { Session } from "@amaxa/auth"; | ||
|
||
export function isProjectStudent(projectId: string, session: Session | null) { | ||
if (!session) return false; | ||
if (session.user.role === "Admin") return true; | ||
const projectPermissions = session.user.project_permissions; | ||
if (!projectPermissions) return false; | ||
return ( | ||
projectPermissions[projectId] === "admin" || | ||
projectPermissions[projectId] === "coach" || | ||
projectPermissions[projectId] === "student" | ||
); | ||
} | ||
|
||
/* | ||
param projectId: string | ||
@param session: Session | null | ||
@returns boolean | ||
Returns true if the user has admin or coach privileges for the project | ||
*/ | ||
export function isProjectPrivileged( | ||
projectId: string, | ||
session: Session | null, | ||
) { | ||
if (!session) return false; | ||
if (session.user.role === "Admin") return true; | ||
const projectPermissions = session.user.project_permissions; | ||
if (!projectPermissions) return false; | ||
return ( | ||
projectPermissions[projectId] === "admin" || | ||
projectPermissions[projectId] === "coach" | ||
); | ||
} | ||
|
||
export function isProjectAdmin(projectId: string, session: Session | null) { | ||
if (!session) return false; | ||
if (session.user.role === "Admin") return true; | ||
const projectPermissions = session.user.project_permissions; | ||
if (!projectPermissions) return false; | ||
return projectPermissions[projectId] === "admin"; | ||
} | ||
|
||
export function isAdmin(session: Session | null) { | ||
if (!session) return false; | ||
if (session.user.role === "Admin") return true; | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters