2019-10-03 12:30:23 +02:00
|
|
|
import { Spinner } from "qpa-components"
|
2019-08-16 10:30:29 +02:00
|
|
|
import * as React from "react"
|
2019-10-06 17:08:47 +02:00
|
|
|
import {useAppContext} from "../App/Context/AppContext"
|
2019-08-16 10:30:29 +02:00
|
|
|
import removeTypename from "../App/remove-typename"
|
2019-06-04 14:03:51 +02:00
|
|
|
import EditEventMutation from "./EditEventMutation"
|
2019-08-16 10:30:29 +02:00
|
|
|
import EventForm from "./EventForm"
|
|
|
|
import GetEventQuery from "./GetEventQuery"
|
2019-06-04 14:03:51 +02:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
eventId: string
|
|
|
|
}
|
|
|
|
|
2019-10-06 17:08:47 +02:00
|
|
|
const EditEvent = (props: Props) => {
|
2019-10-07 17:06:08 +02:00
|
|
|
const { supportedLocales } = useAppContext()
|
2019-06-05 20:43:08 +02:00
|
|
|
|
2019-10-06 17:08:47 +02:00
|
|
|
return (
|
|
|
|
<EditEventMutation onCompleted={() => {
|
|
|
|
alert("Event edited successfully")
|
|
|
|
}}>
|
|
|
|
{
|
|
|
|
(editEvent, { loading: editLoading }) => (
|
|
|
|
<GetEventQuery skip={!props.eventId} variables={{id: props.eventId}}>
|
|
|
|
{
|
|
|
|
({data, error, loading}) => {
|
|
|
|
if (loading) {
|
|
|
|
return <Spinner />
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
return error.message
|
|
|
|
}
|
|
|
|
const event = removeTypename(data.event)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EventForm
|
|
|
|
loading={editLoading}
|
2019-10-07 17:06:08 +02:00
|
|
|
locales={supportedLocales}
|
2019-10-06 17:08:47 +02:00
|
|
|
onSubmit={(values) => {
|
|
|
|
editEvent({
|
|
|
|
variables: {
|
|
|
|
input: {
|
|
|
|
id: props.eventId,
|
|
|
|
...values,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
values={{
|
|
|
|
meta: {
|
|
|
|
tags: event.meta.tags,
|
|
|
|
},
|
|
|
|
time: event.time,
|
|
|
|
location: event.location,
|
|
|
|
infos: event.infos,
|
|
|
|
status: event.status,
|
|
|
|
}}/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</GetEventQuery>
|
|
|
|
)
|
2019-06-04 14:03:51 +02:00
|
|
|
}
|
2019-10-06 17:08:47 +02:00
|
|
|
</EditEventMutation>
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-04 14:03:51 +02:00
|
|
|
export default EditEvent
|