From 210947f4a188ca96da468e5a486a01f5fe879a23 Mon Sep 17 00:00:00 2001 From: happytaeyoon Date: Tue, 3 Dec 2024 10:01:41 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Add=20toast=20and=20router?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/ApplicationForm/standard/index.tsx | 13 +++-- .../ui/form/ApplicationForm/trainee/index.tsx | 57 ++++++++++++------- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/widgets/application/ui/form/ApplicationForm/standard/index.tsx b/src/widgets/application/ui/form/ApplicationForm/standard/index.tsx index e157125..6dce5ab 100644 --- a/src/widgets/application/ui/form/ApplicationForm/standard/index.tsx +++ b/src/widgets/application/ui/form/ApplicationForm/standard/index.tsx @@ -5,6 +5,9 @@ import { Input, RadioGroup } from '@/entities/application'; import { Button } from '@/shared/ui'; import { handleStandardFormsSubmit } from '@/widgets/application/model/applicationFormHandler'; import { StandardForms } from '../../../../types/type'; +import { toast } from 'react-toastify'; +import { useRouter } from 'next/navigation'; + // import TrainingRadioGroup from '@/entities/application/ui/TrainingRadioGroup'; const StandardForm = ({ params }: { params: number }) => { @@ -22,6 +25,7 @@ const StandardForm = ({ params }: { params: number }) => { informationStatus: false, }, }); + const router = useRouter(); const yesNoOptions = [ { value: 'yes', label: '예' }, @@ -31,6 +35,7 @@ const StandardForm = ({ params }: { params: number }) => { const onSubmit = async (data: StandardForms) => { try { await handleStandardFormsSubmit(data, params); + toast.success('신청 되었습니다.'); const qrBody = { phoneNumber: data.phoneNumber, @@ -38,18 +43,18 @@ const StandardForm = ({ params }: { params: number }) => { }; const response = await axios.post('/api/sms/qr', qrBody); - console.log('QR SMS API Response:', response.data); - alert('QR SMS 요청이 성공적으로 처리되었습니다.'); + toast.success('QR이 발송 되었습니다. 문자를 확인 해 주세요.'); + router.back(); } catch (error) { if (axios.isAxiosError(error)) { const errorMessage = error.response?.data?.message || '알 수 없는 오류가 발생했습니다.'; console.error('QR SMS API Error:', errorMessage); - alert(`QR SMS API 호출에 실패했습니다: ${errorMessage}`); + toast.error(`QR SMS API 호출에 실패했습니다: ${errorMessage}`); } else { console.error('폼 제출 중 에러 발생:', error); - alert('폼 제출에 실패했습니다. 다시 시도해주세요.'); + toast.error('폼 제출에 실패했습니다. 다시 시도해주세요.'); } } }; diff --git a/src/widgets/application/ui/form/ApplicationForm/trainee/index.tsx b/src/widgets/application/ui/form/ApplicationForm/trainee/index.tsx index c5f6784..3192326 100644 --- a/src/widgets/application/ui/form/ApplicationForm/trainee/index.tsx +++ b/src/widgets/application/ui/form/ApplicationForm/trainee/index.tsx @@ -7,6 +7,8 @@ import TrainingRadioGroup from '@/entities/application/ui/TrainingRadioGroup'; import { Button } from '@/shared/ui'; import { handleTraineeFormsSubmit } from '@/widgets/application/model/applicationFormHandler'; import { TraineeForms } from '../../../../types/type'; +import { toast } from 'react-toastify'; +import { useRouter } from 'next/navigation'; const TraineeForm = ({ params }: { params: number }) => { const [trainingId, setTrainingId] = useState(''); @@ -28,13 +30,14 @@ const TraineeForm = ({ params }: { params: number }) => { informationStatus: false, }, }); + const router = useRouter(); const schoolLevelOptions = [ - { value: '초등학교', label: '초등학교' }, - { value: '중학교', label: '중학교' }, - { value: '고등학교', label: '고등학교' }, - { value: '교육청', label: '교육청' }, - { value: '기타', label: '기타' }, + { value: 'elementary', label: '초등학교' }, + { value: 'middle', label: '중학교' }, + { value: 'high', label: '고등학교' }, + { value: 'education', label: '교육청' }, + { value: 'other', label: '기타' }, ]; const yesNoOptions = [ @@ -43,24 +46,38 @@ const TraineeForm = ({ params }: { params: number }) => { ]; const onSubmit = async (data: TraineeForms) => { - await handleTraineeFormsSubmit(data, params); - if (trainingId && selectedValue) { - const result = await TrainingRadioGroup.handleTrainingSubmit( - selectedValue, - trainingId, - ); - console.log('Training Submit Result:', result); - } + try { + await handleTraineeFormsSubmit(data, params); + toast.success('신청 되었습니다.'); - const qrBody = { - phoneNumber: data.phoneNumber, - authority: 'ROLE_TRAINEE', - }; + if (trainingId && selectedValue) { + const result = await TrainingRadioGroup.handleTrainingSubmit( + selectedValue, + trainingId, + ); + console.log('Training Submit Result:', result); + } - const response = await axios.post('/api/sms/qr', qrBody); + const qrBody = { + phoneNumber: data.phoneNumber, + authority: 'ROLE_TRAINEE', + }; - console.log('QR SMS API Response:', response.data); - alert('QR SMS 요청이 성공적으로 처리되었습니다.'); + const response = await axios.post('/api/sms/qr', qrBody); + console.log('QR SMS API Response:', response.data); + toast.success('QR이 발송 되었습니다. 문자를 확인 해 주세요.'); + router.back(); + } catch (error) { + if (axios.isAxiosError(error)) { + const errorMessage = + error.response?.data?.message || '알 수 없는 오류가 발생했습니다.'; + console.error('API Error:', errorMessage); + toast.error(`오류가 발생했습니다: ${errorMessage}`); + } else { + console.error('폼 제출 중 에러 발생:', error); + toast.error('폼 제출에 실패했습니다. 다시 시도해주세요.'); + } + } }; const handleTrainingIdChange = (