1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 15:14:23 +00:00
festa/pages/events/[slug].tsx

77 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-06-11 03:08:49 +00:00
import { NextPage, NextPageContext } from 'next'
import { useTranslation } from 'next-i18next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { default as Head } from 'next/head'
2022-06-09 21:43:38 +00:00
import defaultPostcard from "../../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg"
2022-06-11 03:08:49 +00:00
import { Postcard } from '../../components/postcard/changer'
import { ViewEvent } from '../../components/events/views/event'
import useSWR from 'swr'
import { Event } from '@prisma/client'
2022-07-16 16:18:41 +00:00
import { EditableText } from '../../components/generic/editable/inputs'
import { EditingContext, EditingMode } from '../../components/generic/editable/base'
import { useState } from 'react'
import { ToolBar } from '../../components/generic/toolbar/bar'
import { ToolToggleEditing } from '../../components/events/toolbar/toolToggleEditing'
import { ToolToggleVisibility } from '../../components/postcard/toolbar/toolToggleVisibility'
import { WIPBanner } from '../../components/generic/wip/banner'
2022-06-03 01:55:02 +00:00
export async function getServerSideProps(context: NextPageContext) {
return {
props: {
2022-06-11 03:08:49 +00:00
slug: context.query.slug,
2022-06-03 01:55:02 +00:00
...(await serverSideTranslations(context.locale ?? "it-IT", ["common"]))
}
}
}
2022-06-11 03:08:49 +00:00
type PageEventProps = {
slug: string
2022-06-03 01:55:02 +00:00
}
2022-06-11 03:08:49 +00:00
const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
2022-06-08 17:14:00 +00:00
const { t } = useTranslation()
2022-06-11 03:08:49 +00:00
const { data, error } = useSWR<Event>(`/api/events/${slug}`)
2022-06-10 03:21:02 +00:00
2022-07-16 16:18:41 +00:00
const displayTitle = data?.name ?? slug
const displayPostcard = data?.postcard ?? defaultPostcard
const displayDescription = data?.description ?? ""
2022-06-04 03:13:19 +00:00
return <>
<Head>
2022-07-16 16:18:41 +00:00
<title key="title">{displayTitle} - {t("siteTitle")}</title>
2022-06-11 03:08:49 +00:00
<link rel="preload" href={`/api/events/${slug}`} as="fetch" />
2022-06-04 03:13:19 +00:00
</Head>
2022-06-11 03:08:49 +00:00
<Postcard
2022-07-16 16:18:41 +00:00
src={displayPostcard}
2022-06-11 03:08:49 +00:00
/>
2022-07-16 16:18:41 +00:00
<WIPBanner />
<EditingContext.Provider value={useState<EditingMode>(EditingMode.VIEW)}>
<ViewEvent
title={<>
<EditableText
value={displayTitle}
/>
</>}
postcard={<></>}
description={<>
<EditableText
value={displayDescription}
/>
</>}
daterange={<></>}
/>
<ToolBar vertical="vadapt" horizontal="right">
<ToolToggleEditing />
<ToolToggleVisibility />
</ToolBar>
</EditingContext.Provider>
2022-06-04 03:13:19 +00:00
</>
2022-06-11 03:08:49 +00:00
}
export default PageEvent