diff --git a/src/widgets/create-exhibition/model/exhibitionFormHandler.ts b/src/widgets/create-exhibition/model/exhibitionFormHandler.ts index ad44ce4..aedaa16 100644 --- a/src/widgets/create-exhibition/model/exhibitionFormHandler.ts +++ b/src/widgets/create-exhibition/model/exhibitionFormHandler.ts @@ -1,3 +1,4 @@ +import { useRouter } from 'next/navigation'; import { toast } from 'react-toastify'; import { convertAddressToCoordinates } from '../api/convertAddressToCoordinates'; import { createExhibition } from '../api/createExhibition'; @@ -6,7 +7,10 @@ import { createTraining } from '../api/createTraining'; import { uploadImage } from '../api/uploadImage'; import { ExhibitionFormData } from '../types/type'; -export const handleExhibitionFormSubmit = async (data: ExhibitionFormData) => { +export const handleExhibitionFormSubmit = async ( + data: ExhibitionFormData, + router: ReturnType, +) => { try { const coordinates = await convertAddressToCoordinates(data.address); if (!coordinates) { @@ -34,6 +38,7 @@ export const handleExhibitionFormSubmit = async (data: ExhibitionFormData) => { await createTraining(response.expoId, data.trainings); await createStandard(response.expoId, data.standard); toast.success('박람회가 생성되었습니다.'); + router.push('/'); } else { toast.error('박람회 생성에 실패했습니다.'); } diff --git a/src/widgets/create-exhibition/ui/ExhibitionForm/index.tsx b/src/widgets/create-exhibition/ui/ExhibitionForm/index.tsx index 1c6f3db..ccd1297 100644 --- a/src/widgets/create-exhibition/ui/ExhibitionForm/index.tsx +++ b/src/widgets/create-exhibition/ui/ExhibitionForm/index.tsx @@ -1,5 +1,6 @@ 'use client'; +import { useRouter } from 'next/navigation'; import { useFieldArray, useForm } from 'react-hook-form'; import { toast } from 'react-toastify'; import { ImageInput } from '@/entities/create-exhibition'; @@ -21,6 +22,7 @@ const ExhibitionForm = () => { setValue, watch, } = useForm(); + const router = useRouter(); const trainingFields = useFieldArray({ control, @@ -33,7 +35,7 @@ const ExhibitionForm = () => { }); const onSubmit = (data: ExhibitionFormData) => { - handleExhibitionFormSubmit(data); + handleExhibitionFormSubmit(data, router); }; const showError = (message: string) => {