forked from epicweb-dev/epic-stack
-
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
Showing
11 changed files
with
150 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type MetaFunction } from '@remix-run/react' | ||
import { PageContentIndex } from '#app/components/templates/index.ts' | ||
|
||
export default function AdminIndexRoute() { | ||
return <PageContentIndex message="Hello admin" /> | ||
} | ||
|
||
export const meta: MetaFunction = () => { | ||
return [ | ||
{ title: `Admin | Epic Notes` }, | ||
{ | ||
name: 'description', | ||
content: `Admin page for Epic Notes`, | ||
}, | ||
] | ||
} |
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,54 @@ | ||
import { json, type DataFunctionArgs } from '@remix-run/node' | ||
import { Outlet, useLoaderData } from '@remix-run/react' | ||
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx' | ||
import { | ||
Main, | ||
MainContainer, | ||
MainContent, | ||
} from '#app/components/layout/index.ts' | ||
import { PageSidebar } from '#app/components/templates/index.ts' | ||
import { requireAdminUserId } from '#app/utils/auth.server.ts' | ||
import { prisma } from '#app/utils/db.server.ts' | ||
import { invariantResponse } from '#app/utils/misc.tsx' | ||
|
||
export async function loader({ request }: DataFunctionArgs) { | ||
const userId = await requireAdminUserId(request) | ||
const user = await prisma.user.findUnique({ | ||
where: { id: userId }, | ||
select: { | ||
id: true, | ||
name: true, | ||
username: true, | ||
image: { select: { id: true } }, | ||
}, | ||
}) | ||
invariantResponse(user, 'User not found', { status: 404 }) | ||
return json({ user }) | ||
} | ||
|
||
export default function AdminRoute() { | ||
const data = useLoaderData<typeof loader>() | ||
const { user } = data | ||
return ( | ||
<Main> | ||
<MainContainer> | ||
<PageSidebar owner={user} title="Admin" list={[]} /> | ||
<MainContent> | ||
<Outlet /> | ||
</MainContent> | ||
</MainContainer> | ||
</Main> | ||
) | ||
} | ||
|
||
export function ErrorBoundary() { | ||
return ( | ||
<GeneralErrorBoundary | ||
statusHandlers={{ | ||
404: ({ params }) => ( | ||
<p>No user with the username "{params.username}" exists</p> | ||
), | ||
}} | ||
/> | ||
) | ||
} |
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,11 @@ | ||
import { type Page } from '@playwright/test' | ||
import { goTo } from '#tests/utils/page-utils.ts' | ||
import { expectUrl } from '#tests/utils/url-utils.ts' | ||
|
||
export async function goToAdminPage(page: Page) { | ||
await goTo(page, '/admin') | ||
} | ||
|
||
export async function expectAdminPage(page: Page) { | ||
await expectUrl({ page, url: '/admin' }) | ||
} |
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,24 @@ | ||
import { test } from '#tests/playwright-utils.ts' | ||
import { expectLoginUrl, expectUrl } from '#tests/utils/url-utils.ts' | ||
import { expectAdminPage, goToAdminPage } from './admin-utils.ts' | ||
|
||
test.describe('User cannot view Admin', () => { | ||
test('when not logged in', async ({ page }) => { | ||
await goToAdminPage(page) | ||
await expectLoginUrl({ page, redirectTo: '/admin' }) | ||
}) | ||
|
||
test('when logged in as user', async ({ page, login }) => { | ||
await login() | ||
await goToAdminPage(page) | ||
await expectUrl({ page, url: '/' }) | ||
}) | ||
}) | ||
|
||
test.describe('User can view Admin', () => { | ||
test('when logged in as admin', async ({ page, login }) => { | ||
await login({ roles: ['user', 'admin'] }) | ||
await goToAdminPage(page) | ||
await expectAdminPage(page) | ||
}) | ||
}) |
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