Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”€ λ°•λžŒνšŒ 생성 λΌμš°νŒ… 진행 #50

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading