Skip to content

Commit

Permalink
♻️Add: create-exhibition routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethen1264 committed Dec 3, 2024
1 parent 65e0a59 commit 3335bba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/widgets/create-exhibition/model/exhibitionFormHandler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRouter } from 'next/navigation';
import { toast } from 'react-toastify';
import { convertAddressToCoordinates } from '../api/convertAddressToCoordinates';
import { createExhibition } from '../api/createExhibition';
Expand All @@ -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<typeof useRouter>,
) => {
try {
const coordinates = await convertAddressToCoordinates(data.address);
if (!coordinates) {
Expand Down Expand Up @@ -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('박람회 생성에 실패했습니다.');
}
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/create-exhibition/ui/ExhibitionForm/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -21,6 +22,7 @@ const ExhibitionForm = () => {
setValue,
watch,
} = useForm<ExhibitionFormData>();
const router = useRouter();

const trainingFields = useFieldArray<ExhibitionFormData>({
control,
Expand All @@ -33,7 +35,7 @@ const ExhibitionForm = () => {
});

const onSubmit = (data: ExhibitionFormData) => {
handleExhibitionFormSubmit(data);
handleExhibitionFormSubmit(data, router);
};

const showError = (message: string) => {
Expand Down

0 comments on commit 3335bba

Please sign in to comment.