2022-06-03 02:54:09 +00:00
|
|
|
import { Event, User } from "@prisma/client";
|
2022-06-03 01:55:02 +00:00
|
|
|
import { NextPageContext } from "next";
|
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
2022-06-04 03:13:19 +00:00
|
|
|
import Head from "next/head";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { ToolBar } from "../../components/tools/ToolBar";
|
|
|
|
import { EditableMarkdown } from "../../components/editable/EditableMarkdown";
|
|
|
|
import { EditableText } from "../../components/editable/EditableText";
|
|
|
|
import { ToolToggleEditing } from "../../components/tools/ToolToggleEditing";
|
|
|
|
import { EditingContext } from "../../contexts/editing";
|
2022-06-03 01:55:02 +00:00
|
|
|
import { database } from "../../utils/prismaClient";
|
2022-06-04 03:13:19 +00:00
|
|
|
import { Postcard } from "../../components/postcard/Postcard";
|
|
|
|
import { ViewContent } from "../../components/view/ViewContent";
|
2022-06-03 01:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
export async function getServerSideProps(context: NextPageContext) {
|
|
|
|
const slug = context.query.slug as string
|
|
|
|
if(typeof slug === "object") {
|
|
|
|
return {notFound: true}
|
|
|
|
}
|
|
|
|
|
2022-06-03 02:54:09 +00:00
|
|
|
const event = await database.event.findUnique({
|
|
|
|
where: {slug},
|
|
|
|
include: {creator: true}
|
|
|
|
})
|
2022-06-03 01:55:02 +00:00
|
|
|
if(!event) {
|
|
|
|
return {notFound: true}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
event,
|
|
|
|
...(await serverSideTranslations(context.locale ?? "it-IT", ["common"]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type PageEventDetailProps = {
|
2022-06-03 02:54:09 +00:00
|
|
|
event: Event & {creator: User}
|
2022-06-03 01:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function PageEventDetail({event}: PageEventDetailProps) {
|
|
|
|
const {t} = useTranslation()
|
2022-06-04 03:13:19 +00:00
|
|
|
const editState = useState<boolean>(false)
|
|
|
|
const [description, setDescription] = useState<string>("")
|
|
|
|
|
|
|
|
return <>
|
|
|
|
<Head>
|
|
|
|
<title key="title">{event.name} - {t("siteTitle")}</title>
|
|
|
|
</Head>
|
|
|
|
<Postcard
|
|
|
|
src={event.postcard ?? undefined}
|
|
|
|
/>
|
|
|
|
<EditingContext.Provider value={editState}>
|
|
|
|
<ToolBar vertical="top" horizontal="right">
|
|
|
|
<ToolToggleEditing/>
|
|
|
|
</ToolBar>
|
|
|
|
<ViewContent
|
|
|
|
title={
|
|
|
|
<EditableText value={event.name}/>
|
|
|
|
}
|
|
|
|
content={<>
|
|
|
|
<EditableMarkdown
|
|
|
|
value={description}
|
|
|
|
onChange={e => setDescription((e.target as HTMLTextAreaElement).value)}
|
|
|
|
/>
|
|
|
|
</>}
|
|
|
|
/>
|
|
|
|
</EditingContext.Provider>
|
|
|
|
</>
|
2022-06-03 01:55:02 +00:00
|
|
|
}
|