-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23aa835
commit b9ac45e
Showing
23 changed files
with
177 additions
and
15 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,23 @@ | ||
import { fetchSession } from "@/src/auth/ui/fetch/fetch-session"; | ||
import { redirect } from "next/navigation"; | ||
import type { PropsWithChildren } from "react"; | ||
|
||
/** | ||
* Checks that the user is an admin. Otherwise, it redirects to the home page. | ||
*/ | ||
async function adminGuard() { | ||
const result = await fetchSession(); | ||
if (!result.user?.isAdmin) { | ||
redirect("/home"); | ||
} | ||
} | ||
|
||
/** | ||
* Applies the `loginGuard` guard to the pages inside this layout | ||
*/ | ||
export default async function AdminGuardLayout({ | ||
children, | ||
}: PropsWithChildren) { | ||
await adminGuard(); | ||
return <>{children}</>; | ||
} |
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,3 @@ | ||
import { AdminPage } from "@/src/admin/ui/pages/admin-page"; | ||
|
||
export default AdminPage; |
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
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,20 @@ | ||
import { textStyles } from "@/src/common/ui/styles/text-styles"; | ||
import { SlidersHorizontalIcon } from "lucide-react"; | ||
|
||
export function AdminGreeting() { | ||
return ( | ||
<div className="px-4"> | ||
<div className="mx-auto max-w-screen-lg"> | ||
<h1 className={textStyles.h2}> | ||
<SlidersHorizontalIcon className="mr-3 inline size-8 -translate-y-1" /> | ||
Panel de administración | ||
</h1> | ||
<div className="h-2" /> | ||
<p className={textStyles.muted}> | ||
Bienvenido al panel de administración. Desde aquí puedes gestionar los | ||
cursos, usuarios y configuración de la plataforma. | ||
</p> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { textStyles } from "@/src/common/ui/styles/text-styles"; | ||
import Link from "next/link"; | ||
import type { AdminResourceModel } from "../../domain/models/admin-resource-model"; | ||
import { translateAdminKey } from "../i18n/admin-translations"; | ||
import { AdminResourceIcon } from "./admin-resource-icon"; | ||
|
||
interface AdminResourceCardProps { | ||
resource: AdminResourceModel; | ||
} | ||
export function AdminResourceCard({ resource }: AdminResourceCardProps) { | ||
return ( | ||
<Link | ||
href={`/admin/resources/${resource.type}`} | ||
className="block rounded-lg border border-gray-200 p-4 shadow-sm hover:bg-gray-50" | ||
> | ||
<AdminResourceIcon | ||
adminResourceType={resource.type} | ||
className="text-gray-500" | ||
/> | ||
<div className="h-2" /> | ||
<h4 className={textStyles.h4}> | ||
{translateAdminKey(resource.type, "label")} | ||
</h4> | ||
<div className="h-1" /> | ||
<p className={textStyles.muted}> | ||
{translateAdminKey(resource.type, "description")} | ||
</p> | ||
</Link> | ||
); | ||
} |
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,51 @@ | ||
import type { LucideProps } from "lucide-react"; | ||
import { | ||
BanIcon, | ||
BookIcon, | ||
BookUserIcon, | ||
CalendarClockIcon, | ||
IdCardIcon, | ||
KeyRoundIcon, | ||
LogsIcon, | ||
MailCheckIcon, | ||
MailQuestionIcon, | ||
NotebookPenIcon, | ||
TagIcon, | ||
TicketIcon, | ||
UploadIcon, | ||
UserIcon, | ||
} from "lucide-react"; | ||
import type { ForwardRefExoticComponent } from "react"; | ||
import { AdminResourceTypeModel } from "../../domain/models/admin-resource-model"; | ||
|
||
const map: Record< | ||
AdminResourceTypeModel, | ||
ForwardRefExoticComponent<Omit<LucideProps, "ref">> | ||
> = { | ||
[AdminResourceTypeModel.tags]: TagIcon, | ||
[AdminResourceTypeModel.reviewLogs]: LogsIcon, | ||
[AdminResourceTypeModel.rateLimits]: BanIcon, | ||
[AdminResourceTypeModel.courseEnrollments]: TicketIcon, | ||
[AdminResourceTypeModel.coursePermissions]: BookUserIcon, | ||
[AdminResourceTypeModel.courses]: BookIcon, | ||
[AdminResourceTypeModel.emailVerificationCodes]: MailCheckIcon, | ||
[AdminResourceTypeModel.fileUploads]: UploadIcon, | ||
[AdminResourceTypeModel.forgotPasswordTokens]: MailQuestionIcon, | ||
[AdminResourceTypeModel.notes]: NotebookPenIcon, | ||
[AdminResourceTypeModel.practiceCards]: CalendarClockIcon, | ||
[AdminResourceTypeModel.profiles]: UserIcon, | ||
[AdminResourceTypeModel.sessions]: KeyRoundIcon, | ||
[AdminResourceTypeModel.users]: IdCardIcon, | ||
}; | ||
|
||
interface AdminResourceIconProps extends Omit<LucideProps, "ref"> { | ||
adminResourceType: AdminResourceTypeModel; | ||
} | ||
|
||
export const AdminResourceIcon = ({ | ||
adminResourceType, | ||
...props | ||
}: AdminResourceIconProps) => { | ||
const Icon = map[adminResourceType]; | ||
return <Icon {...props} />; | ||
}; |
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,19 @@ | ||
import { textStyles } from "@/src/common/ui/styles/text-styles"; | ||
import { adminResourcesConfig } from "../../domain/config/admin-resources-config"; | ||
import { AdminResourceCard } from "./admin-resource-card"; | ||
|
||
export function AdminResourcesSection() { | ||
return ( | ||
<div className="px-4"> | ||
<div className="mx-auto max-w-screen-lg"> | ||
<h2 className={textStyles.h3}>Gestión de recursos</h2> | ||
<div className="h-3" /> | ||
<div className="grid gap-4 sm:grid-cols-2 md:grid-cols-3"> | ||
{adminResourcesConfig.map((resource) => ( | ||
<AdminResourceCard key={resource.type} resource={resource} /> | ||
))} | ||
</div> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const adminTranslations: Record<string, string> = {}; | ||
|
||
export function translateAdminKey(...keys: string[]): string { | ||
const key = keys.join("."); | ||
return adminTranslations[key] || key; | ||
} |
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,15 @@ | ||
import { AdminGreeting } from "../components/admin-greeting"; | ||
import { AdminResourcesSection } from "../components/admin-resources-section"; | ||
|
||
export function AdminPage() { | ||
return ( | ||
<main> | ||
<div className="h-24" /> | ||
<AdminGreeting /> | ||
|
||
<div className="h-10" /> | ||
|
||
<AdminResourcesSection /> | ||
</main> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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