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"
2022-07-20 11:26:34 +00:00
import { Dispatch, 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,
mutate: KeyedMutator<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-20 11:26:34 +00:00
export const EventsActionEdit = ({ data, mutate, 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
title={
useMemo(
() => (
<input
type="text"
value={name}
onChange={e => mutate((prev) => ({ ...prev!, name: e.target.value }), { revalidate: false })}
2022-07-20 19:34:27 +00:00
placeholder={t("eventNamePlaceholder")}
2022-07-20 11:26:34 +00:00
/>
),
[mutate, name]
)
}
content={<>
{useMemo(
() => (
<textarea
rows={12}
value={description}
onChange={e => mutate((prev) => ({ ...prev!, description: e.target.value }), { revalidate: false })}
2022-07-20 19:34:27 +00:00
placeholder={t("eventDescriptionPlaceholder")}
2022-07-20 11:26:34 +00:00
/>
),
[mutate, description]
)}
2022-07-20 19:34:27 +00:00
{useMemo(
() => (
<input
type="text"
value={postcard ?? ""}
onChange={e => mutate((prev) => ({ ...prev!, postcard: e.target.value || null }), { revalidate: false })}
placeholder={t("eventPostcardPlaceholder")}
/>
),
[mutate, postcard]
)}
2022-07-20 11:26:34 +00:00
</>}
/>
</form>
2022-07-19 18:25:11 +00:00
)
}