-
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.
- Loading branch information
1 parent
537ed9b
commit 9006fdf
Showing
6 changed files
with
94 additions
and
50 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
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,53 @@ | ||
import { Link, useLoaderData } from 'remix' | ||
import type { LoaderFunction, MetaFunction, HeadersFunction } from 'remix' | ||
|
||
import { db } from '~/utils/prisma.server' | ||
import type { User } from '@prisma/client' | ||
|
||
export let meta: MetaFunction = ({ data }: { data: User | undefined }) => { | ||
if (!data) { | ||
return { | ||
title: 'User not found', | ||
description: 'User not found', | ||
} | ||
} | ||
|
||
return { | ||
title: `User ${data.name}`, | ||
description: `User ${data.name} details`, | ||
} | ||
} | ||
|
||
export let loader: LoaderFunction = async ({ params }) => { | ||
try { | ||
const user = await db.user.findUnique({ | ||
where: { | ||
id: params.id, | ||
}, | ||
}) | ||
|
||
return user | ||
} catch (error) { | ||
throw new Response('Not Found', { | ||
status: 404, | ||
}) | ||
} | ||
} | ||
|
||
export let headers: HeadersFunction = () => { | ||
return { | ||
'Cache-Control': 'max-age=60', | ||
} | ||
} | ||
|
||
export default function Index() { | ||
const user = useLoaderData<User>() | ||
|
||
return ( | ||
<div style={{ fontFamily: 'system-ui, sans-serif', lineHeight: '1.4' }}> | ||
<h1>{user.name}</h1> | ||
<p>{user.email}</p> | ||
<Link to='/'>Back to users</Link> | ||
</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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
const db = new PrismaClient(); | ||
import { PrismaClient } from '@prisma/client' | ||
const db = new PrismaClient() | ||
|
||
export { db } | ||
export { db } |
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