1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 14:44:21 +00:00

Add support for postcard feature

This commit is contained in:
Steffo 2022-06-03 04:07:12 +02:00
parent c708201379
commit d431540e4d
Signed by: steffo
GPG key ID: 6965406171929D01
5 changed files with 33 additions and 4 deletions

View file

@ -18,10 +18,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
}
const which = {
slug: req.query.slug
slug: req.query.slug,
}
const update = {
name: req.body.name
name: req.body.name,
postcard: req.body.postcard ?? null,
}
await restInPeace(req, res, {

View file

@ -19,7 +19,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const create = {
slug: cryptoRandomString({ length: 12, type: "url-safe" }),
creatorId: user.id,
name: req.body.name
name: req.body.name,
postcard: req.body.postcard ?? null,
}
await restInPeace(req, res, {

View file

@ -3,10 +3,13 @@ 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";
@ -37,6 +40,17 @@ type PageEventDetailProps = {
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">

View file

@ -5,6 +5,9 @@ import { LoginContext } from '../contexts/login';
import { useDefinedContext } from '../utils/definedContext';
import { ActionLoginTelegram } from '../components/ActionLoginTelegram';
import { ActionEventList } from '../components/ActionEventList';
import { PostcardContext } from '../contexts/postcard';
import defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg"
import { useEffect } from 'react';
export async function getStaticProps(context: NextPageContext) {
@ -18,7 +21,15 @@ export async function getStaticProps(context: NextPageContext) {
export default function PageIndex() {
const { t } = useTranslation()
const [login, _] = useDefinedContext(LoginContext)
const [login, ] = useDefinedContext(LoginContext)
const [, setPostcard] = useDefinedContext(PostcardContext)
useEffect(
() => {
setPostcard(defaultPostcard)
},
[]
)
return (
<main id="page-index" className="page">

View file

@ -83,4 +83,6 @@ model Event {
creator User @relation(fields: [creatorId], references: [id])
/// The name of the event.
name String
/// The URL to the postcard of the event.
postcard String?
}