mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 22:54:22 +00:00
Create event page
This commit is contained in:
parent
33efdd3c44
commit
5e1ff05c0a
6 changed files with 65 additions and 3 deletions
6
hooks/useEventDetail.ts
Normal file
6
hooks/useEventDetail.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { Event } from "@prisma/client";
|
||||||
|
import useSWR, { SWRResponse } from "swr";
|
||||||
|
|
||||||
|
export function useEventDetail(slug: string): SWRResponse<Event> {
|
||||||
|
return useSWR(`/api/events/${slug}`)
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import useSWR from "swr";
|
import { Event } from "@prisma/client";
|
||||||
|
import useSWR, { SWRResponse } from "swr";
|
||||||
|
|
||||||
export function useMyEvents() {
|
export function useMyEvents(): SWRResponse<Event[]> {
|
||||||
return useSWR("/api/events/mine")
|
return useSWR("/api/events/mine")
|
||||||
}
|
}
|
||||||
|
|
48
pages/events/[slug].tsx
Normal file
48
pages/events/[slug].tsx
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
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 useSWR from "swr";
|
||||||
|
import { ErrorInline } from "../../components/ErrorInline";
|
||||||
|
import { Loading } from "../../components/Loading";
|
||||||
|
import {useEventDetail} from "../../hooks/useEventDetail"
|
||||||
|
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()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main id="page-event-detail" className="page">
|
||||||
|
<h1>
|
||||||
|
{event.name}
|
||||||
|
</h1>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ export async function getStaticProps(context: NextPageContext) {
|
||||||
|
|
||||||
|
|
||||||
export default function PageIndex() {
|
export default function PageIndex() {
|
||||||
const { t } = useTranslation("common")
|
const { t } = useTranslation()
|
||||||
const [login, _] = useDefinedContext(LoginContext)
|
const [login, _] = useDefinedContext(LoginContext)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -211,3 +211,7 @@ input.negative, button.negative {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#page-event-detail h1 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
|
@ -11,6 +11,9 @@ export async function handleInterrupts(res: NextApiResponse, f: () => Promise<vo
|
||||||
if(e instanceof Interrupt) {
|
if(e instanceof Interrupt) {
|
||||||
return res.status(e.status).json(e.response)
|
return res.status(e.status).json(e.response)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue