mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Add beer post, brewery post GET service and page
Add prettier, eslint config
This commit is contained in:
27
pages/beers/[id].tsx
Normal file
27
pages/beers/[id].tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { GetServerSideProps, NextPage } from 'next';
|
||||
import BeerPostQueryResult from '@/services/BeerPost/types/BeerPostQueryResult';
|
||||
import getBeerPostById from '@/services/BeerPost/getBeerPostById';
|
||||
import Layout from '@/components/Layout';
|
||||
|
||||
interface BeerPageProps {
|
||||
beerPost: BeerPostQueryResult;
|
||||
}
|
||||
|
||||
const BeerByIdPage: NextPage<BeerPageProps> = ({ beerPost }) => {
|
||||
return (
|
||||
<Layout>
|
||||
<main>
|
||||
<h1 className="text-3xl font-bold underline">{beerPost.name}</h1>
|
||||
</main>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<BeerPageProps> = async (context) => {
|
||||
const beerPost = await getBeerPostById(context.params!.id! as string);
|
||||
return !beerPost
|
||||
? { notFound: true }
|
||||
: { props: { beerPost: JSON.parse(JSON.stringify(beerPost)) } };
|
||||
};
|
||||
|
||||
export default BeerByIdPage;
|
||||
Reference in New Issue
Block a user