Skip to content

Commit

Permalink
♻️ Add toast and router
Browse files Browse the repository at this point in the history
  • Loading branch information
happytaeyoon committed Dec 3, 2024
1 parent 65e0a59 commit 210947f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -22,6 +25,7 @@ const StandardForm = ({ params }: { params: number }) => {
informationStatus: false,
},
});
const router = useRouter();

const yesNoOptions = [
{ value: 'yes', label: '예' },
Expand All @@ -31,25 +35,26 @@ const StandardForm = ({ params }: { params: number }) => {
const onSubmit = async (data: StandardForms) => {
try {
await handleStandardFormsSubmit(data, params);
toast.success('신청 되었습니다.');

const qrBody = {
phoneNumber: data.phoneNumber,
authority: 'ROLE_STANDARD',
};

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('폼 제출에 실패했습니다. 다시 시도해주세요.');
}
}
};
Expand Down
57 changes: 37 additions & 20 deletions src/widgets/application/ui/form/ApplicationForm/trainee/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand All @@ -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 = [
Expand All @@ -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 = (
Expand Down

0 comments on commit 210947f

Please sign in to comment.