1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 15:14:23 +00:00
festa/components/events/actions/edit.tsx

72 lines
2.5 KiB
TypeScript
Raw Normal View History

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"
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,
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
}
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={<>
<h1>
{useMemo(
() => (
<input
type="text"
value={name}
onChange={e => setData(prev => ({ ...prev!, name: e.target.value }))}
placeholder={t("eventNamePlaceholder")}
/>
),
[t, setData, name]
)}
</h1>
2022-07-20 11:26:34 +00:00
{useMemo(
() => (
<textarea
rows={12}
value={description}
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
/>
),
[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 ?? ""}
onChange={e => setData(prev => ({ ...prev!, postcard: e.target.value || null }))}
2022-07-20 19:34:27 +00:00
placeholder={t("eventPostcardPlaceholder")}
/>
),
[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
)
}