mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
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:
@@ -47,16 +47,6 @@ const BeerPage: NextPage = () => {
|
||||
<h1 className="text-4xl font-bold lg:text-6xl">The Biergarten App</h1>
|
||||
<h2 className="text-2xl font-bold lg:text-4xl">Beers</h2>
|
||||
</div>
|
||||
{!!user && (
|
||||
<div
|
||||
className="tooltip tooltip-left h-full"
|
||||
data-tip="Create a new beer post"
|
||||
>
|
||||
<Link href="/beers/create" className="btn-ghost btn-sm btn">
|
||||
<FaPlus />
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</header>
|
||||
<div className="grid gap-6 xl:grid-cols-2">
|
||||
{!!beerPosts.length && !isLoading && (
|
||||
|
||||
@@ -3,19 +3,19 @@ import FormPageLayout from '@/components/ui/forms/FormPageLayout';
|
||||
|
||||
import withPageAuthRequired from '@/util/withPageAuthRequired';
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import getAllBreweryPosts from '@/services/BreweryPost/getAllBreweryPosts';
|
||||
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 {
|
||||
breweries: z.infer<typeof BreweryPostQueryResult>[];
|
||||
brewery: z.infer<typeof BreweryPostQueryResult>;
|
||||
types: BeerType[];
|
||||
}
|
||||
|
||||
const CreateBeerPost: NextPage<CreateBeerPageProps> = ({ breweries, types }) => {
|
||||
const CreateBeerPost: NextPage<CreateBeerPageProps> = ({ brewery, types }) => {
|
||||
return (
|
||||
<FormPageLayout
|
||||
headingText="Create a new beer"
|
||||
@@ -23,21 +23,26 @@ const CreateBeerPost: NextPage<CreateBeerPageProps> = ({ breweries, types }) =>
|
||||
backLink="/beers"
|
||||
backLinkText="Back to beers"
|
||||
>
|
||||
<CreateBeerPostForm breweries={breweries} types={types} />
|
||||
<CreateBeerPostForm brewery={brewery} types={types} />
|
||||
</FormPageLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = withPageAuthRequired<CreateBeerPageProps>(async () => {
|
||||
const breweryPosts = await getAllBreweryPosts();
|
||||
const beerTypes = await DBClient.instance.beerType.findMany();
|
||||
export const getServerSideProps = withPageAuthRequired<CreateBeerPageProps>(
|
||||
async (context) => {
|
||||
const id = context.params?.id as string;
|
||||
|
||||
return {
|
||||
props: {
|
||||
breweries: JSON.parse(JSON.stringify(breweryPosts)),
|
||||
types: JSON.parse(JSON.stringify(beerTypes)),
|
||||
},
|
||||
};
|
||||
});
|
||||
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;
|
||||
Reference in New Issue
Block a user