1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2025-01-09 23:39:44 +00:00
festa/pages/events/[slug].tsx

62 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-06-03 01:55:02 +00:00
import { Event } from "@prisma/client";
import { NextPageContext } from "next";
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { useRouter } from "next/router";
2022-06-03 02:07:12 +00:00
import { useEffect } from "react";
2022-06-03 01:55:02 +00:00
import useSWR from "swr";
import { ErrorInline } from "../../components/ErrorInline";
import { Loading } from "../../components/Loading";
2022-06-03 02:07:12 +00:00
import { PostcardContext } from "../../contexts/postcard";
2022-06-03 01:55:02 +00:00
import {useEventDetail} from "../../hooks/useEventDetail"
2022-06-03 02:07:12 +00:00
import { useDefinedContext } from "../../utils/definedContext";
2022-06-03 01:55:02 +00:00
import { database } from "../../utils/prismaClient";
export async function getServerSideProps(context: NextPageContext) {
const slug = context.query.slug as string
if(typeof slug === "object") {
return {notFound: true}
}
const event = await database.event.findUnique({where: {slug}})
if(!event) {
return {notFound: true}
}
return {
props: {
event,
...(await serverSideTranslations(context.locale ?? "it-IT", ["common"]))
}
}
}
type PageEventDetailProps = {
event: Event
}
export default function PageEventDetail({event}: PageEventDetailProps) {
const {t} = useTranslation()
2022-06-03 02:07:12 +00:00
const [_, setPostcard] = useDefinedContext(PostcardContext)
useEffect(
() => {
console.debug(event.postcard)
if(event.postcard) {
setPostcard(event.postcard)
}
},
[event]
)
2022-06-03 01:55:02 +00:00
return (
<main id="page-event-detail" className="page">
<h1>
{event.name}
</h1>
</main>
)
}