2022-07-19 18:25:11 +00:00
|
|
|
import { Event } from "@prisma/client"
|
2022-07-20 19:34:27 +00:00
|
|
|
import { useTranslation } from "next-i18next"
|
2022-07-26 23:46:09 +00:00
|
|
|
import { Dispatch, SetStateAction, useMemo } from "react"
|
2022-07-19 18:25:11 +00:00
|
|
|
import { KeyedMutator } from "swr"
|
2022-07-20 11:26:34 +00:00
|
|
|
import { UsePromise } from "../../generic/loading/promise"
|
2022-07-19 18:25:11 +00:00
|
|
|
import { ViewContent } from "../../generic/views/content"
|
|
|
|
|
|
|
|
|
|
|
|
export type EventsActionViewProps = {
|
|
|
|
data: Event,
|
2022-07-26 23:46:09 +00:00
|
|
|
setData: Dispatch<SetStateAction<Event>>,
|
2022-07-20 11:26:34 +00:00
|
|
|
save: UsePromise<void, void>,
|
|
|
|
setEditing: Dispatch<boolean>,
|
2022-07-19 18:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-26 23:46:09 +00:00
|
|
|
export const EventsActionEdit = ({ data, setData, save, setEditing }: EventsActionViewProps) => {
|
2022-07-20 19:34:27 +00:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2022-07-19 18:32:13 +00:00
|
|
|
const name = data.name
|
|
|
|
const description = data.description
|
2022-07-20 19:34:27 +00:00
|
|
|
const postcard = data.postcard
|
2022-07-19 18:32:13 +00:00
|
|
|
|
2022-07-19 18:25:11 +00:00
|
|
|
return (
|
2022-07-20 11:26:34 +00:00
|
|
|
<form onSubmit={e => {
|
|
|
|
e.preventDefault()
|
|
|
|
save.run()
|
|
|
|
setEditing(false)
|
|
|
|
}}>
|
|
|
|
<ViewContent
|
|
|
|
content={<>
|
2022-07-21 16:19:14 +00:00
|
|
|
<h1>
|
|
|
|
{useMemo(
|
|
|
|
() => (
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value={name}
|
2022-07-26 23:46:09 +00:00
|
|
|
onChange={e => setData(prev => ({ ...prev!, name: e.target.value }))}
|
2022-07-21 16:19:14 +00:00
|
|
|
placeholder={t("eventNamePlaceholder")}
|
|
|
|
/>
|
|
|
|
),
|
2022-07-26 23:46:09 +00:00
|
|
|
[t, setData, name]
|
2022-07-21 16:19:14 +00:00
|
|
|
)}
|
|
|
|
</h1>
|
2022-07-20 11:26:34 +00:00
|
|
|
{useMemo(
|
|
|
|
() => (
|
|
|
|
<textarea
|
|
|
|
rows={12}
|
|
|
|
value={description}
|
2022-07-26 23:46:09 +00:00
|
|
|
onChange={e => setData(prev => ({ ...prev!, description: e.target.value }))}
|
2022-07-20 19:34:27 +00:00
|
|
|
placeholder={t("eventDescriptionPlaceholder")}
|
2022-07-20 11:26:34 +00:00
|
|
|
/>
|
|
|
|
),
|
2022-07-26 23:46:09 +00:00
|
|
|
[t, setData, description]
|
2022-07-20 11:26:34 +00:00
|
|
|
)}
|
2022-07-20 19:34:27 +00:00
|
|
|
{useMemo(
|
|
|
|
() => (
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value={postcard ?? ""}
|
2022-07-26 23:46:09 +00:00
|
|
|
onChange={e => setData(prev => ({ ...prev!, postcard: e.target.value || null }))}
|
2022-07-20 19:34:27 +00:00
|
|
|
placeholder={t("eventPostcardPlaceholder")}
|
|
|
|
/>
|
|
|
|
),
|
2022-07-26 23:46:09 +00:00
|
|
|
[t, setData, postcard]
|
2022-07-20 19:34:27 +00:00
|
|
|
)}
|
2022-07-20 11:26:34 +00:00
|
|
|
</>}
|
|
|
|
/>
|
|
|
|
</form>
|
2022-07-19 18:25:11 +00:00
|
|
|
)
|
|
|
|
}
|