Update: beer post form now connected to a specific brewery.

This commit eliminates the brewery selector in the create beer post form, and reroutes the form page to /breweries/[id]/beers/create.

This commit also introduces the use of turbopack for `next dev`.
This commit is contained in:
Aaron William Po
2023-05-12 20:20:52 -04:00
parent 5c9970a045
commit 99c57d88c7
8 changed files with 76 additions and 97 deletions

View File

@@ -0,0 +1,48 @@
import CreateBeerPostForm from '@/components/CreateBeerPostForm';
import FormPageLayout from '@/components/ui/forms/FormPageLayout';
import withPageAuthRequired from '@/util/withPageAuthRequired';
import DBClient from '@/prisma/DBClient';
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
import { BeerType } from '@prisma/client';
import { NextPage } from 'next';
import { BiBeer } from 'react-icons/bi';
import { z } from 'zod';
import getBreweryPostById from '@/services/BreweryPost/getBreweryPostById';
interface CreateBeerPageProps {
brewery: z.infer<typeof BreweryPostQueryResult>;
types: BeerType[];
}
const CreateBeerPost: NextPage<CreateBeerPageProps> = ({ brewery, types }) => {
return (
<FormPageLayout
headingText="Create a new beer"
headingIcon={BiBeer}
backLink="/beers"
backLinkText="Back to beers"
>
<CreateBeerPostForm brewery={brewery} types={types} />
</FormPageLayout>
);
};
export const getServerSideProps = withPageAuthRequired<CreateBeerPageProps>(
async (context) => {
const id = context.params?.id as string;
const breweryPost = await getBreweryPostById(id);
const beerTypes = await DBClient.instance.beerType.findMany();
return {
props: {
brewery: JSON.parse(JSON.stringify(breweryPost)),
types: JSON.parse(JSON.stringify(beerTypes)),
},
};
},
);
export default CreateBeerPost;