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

Redirect to the event page after creation

This commit is contained in:
Steffo 2022-07-27 01:36:33 +02:00
parent 9d18308642
commit 9a51764c0d
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -4,11 +4,11 @@ import classNames from "classnames"
import { useTranslation } from "next-i18next" import { useTranslation } from "next-i18next"
import Link from "next/link" import Link from "next/link"
import { useRouter } from "next/router" import { useRouter } from "next/router"
import { useState } from "react" import { useEffect, useState } from "react"
import { default as useSWR } from "swr" import { default as useSWR } from "swr"
import { useAxiosRequest } from "../../auth/requests" import { useAxiosRequest } from "../../auth/requests"
import { ErrorBlock } from "../../generic/errors/renderers" import { ErrorBlock } from "../../generic/errors/renderers"
import { promiseMultiplexer } from "../../generic/loading/promise" import { promiseMultiplexer, UsePromiseStatus } from "../../generic/loading/promise"
import { swrMultiplexer } from "../../generic/loading/swr" import { swrMultiplexer } from "../../generic/loading/swr"
import { LoadingInline } from "../../generic/loading/renderers" import { LoadingInline } from "../../generic/loading/renderers"
import { FestaIcon } from "../../generic/renderers/fontawesome" import { FestaIcon } from "../../generic/renderers/fontawesome"
@ -73,6 +73,16 @@ const LandingActionEventsFormCreate = () => {
const createHook = useAxiosRequest<Event, Partial<Event>>({ method: "POST", url: "/api/events/" }) const createHook = useAxiosRequest<Event, Partial<Event>>({ method: "POST", url: "/api/events/" })
useEffect(
() => {
if (createHook.status === UsePromiseStatus.FULFILLED) {
console.debug(`[LandingActionEventsFormCreate] Moving you to /events/${createHook.data!.slug}`)
router.push(`/events/${createHook.data!.slug}`)
}
},
[router]
)
return promiseMultiplexer({ return promiseMultiplexer({
hook: createHook, hook: createHook,
ready: ({ run }) => ( ready: ({ run }) => (
@ -109,13 +119,11 @@ const LandingActionEventsFormCreate = () => {
<ErrorBlock text={t("landingEventsCreateRejected")} error={error} /> <ErrorBlock text={t("landingEventsCreateRejected")} error={error} />
</p> </p>
), ),
fulfilled: ({ result }) => { fulfilled: ({ result }) => (
return ( <p>
<p> <LoadingInline text={t("landingEventsCreateFulfilled", name)} />
<LoadingInline text={t("landingEventsCreateFulfilled", name)} /> </p>
</p> )
)
},
}) })
} }