mirror of
https://github.com/Steffo99/festa.git
synced 2025-01-09 15:29:44 +00:00
62 lines
No EOL
1.7 KiB
TypeScript
62 lines
No EOL
1.7 KiB
TypeScript
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";
|
|
import { useEffect } from "react";
|
|
import useSWR from "swr";
|
|
import { ErrorInline } from "../../components/ErrorInline";
|
|
import { Loading } from "../../components/Loading";
|
|
import { PostcardContext } from "../../contexts/postcard";
|
|
import {useEventDetail} from "../../hooks/useEventDetail"
|
|
import { useDefinedContext } from "../../utils/definedContext";
|
|
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()
|
|
const [_, setPostcard] = useDefinedContext(PostcardContext)
|
|
|
|
useEffect(
|
|
() => {
|
|
console.debug(event.postcard)
|
|
if(event.postcard) {
|
|
setPostcard(event.postcard)
|
|
}
|
|
},
|
|
[event]
|
|
)
|
|
|
|
return (
|
|
<main id="page-event-detail" className="page">
|
|
<h1>
|
|
{event.name}
|
|
</h1>
|
|
</main>
|
|
)
|
|
} |