mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Implement edit beer post functionality. Register, edit and create beer post forms are now using the same layout found in components/ui/forms/BeerPostFormPageLayout. All forms are now extracted into their own components and are now found in components. Added redirectIfLoggedIn getServerSidesProp fn for login and register pages.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import CreateBeerPostForm from '@/components/CreateBeerPostForm';
|
|
import FormPageLayout from '@/components/ui/forms/BeerPostFormPageLayout';
|
|
import Layout from '@/components/ui/Layout';
|
|
import withPageAuthRequired from '@/getServerSideProps/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';
|
|
|
|
interface CreateBeerPageProps {
|
|
breweries: BreweryPostQueryResult[];
|
|
types: BeerType[];
|
|
}
|
|
|
|
const Create: NextPage<CreateBeerPageProps> = ({ breweries, types }) => {
|
|
return (
|
|
<Layout>
|
|
<FormPageLayout headingText="Create a new beer" headingIcon={BiBeer}>
|
|
<CreateBeerPostForm breweries={breweries} types={types} />
|
|
</FormPageLayout>
|
|
</Layout>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = withPageAuthRequired<CreateBeerPageProps>(async () => {
|
|
const breweryPosts = await getAllBreweryPosts();
|
|
const beerTypes = await DBClient.instance.beerType.findMany();
|
|
|
|
return {
|
|
props: {
|
|
breweries: JSON.parse(JSON.stringify(breweryPosts)),
|
|
types: JSON.parse(JSON.stringify(beerTypes)),
|
|
},
|
|
};
|
|
});
|
|
|
|
export default Create;
|