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

[ Fix ] self QA - 뒤로가기 버튼 수정, 약속신청 모달 위치 조정, 이미 있는 약속 신청시 alert #225

Open
wants to merge 5 commits into
base: refactor/#218/separateRoute
Choose a base branch
from
Open
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
36 changes: 21 additions & 15 deletions src/pages/juniorPromiseRequest/JuniorPromiseRequestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Header } from '@components/commons/Header';
import Banner from './components/Banner';
import TitleBox from '@components/commons/TitleBox';
import { SELECT_JUNIOR_TITLE } from './constants/constants';
import axios from 'axios';

const JuniorPromiseRequestPage = () => {
const [activeButton, setActiveButton] = useState('선택할래요');
Expand All @@ -28,7 +29,7 @@ const JuniorPromiseRequestPage = () => {
const location = useLocation();

// 약속 신청하기 눌렸는지 확인
const [isSubmitClicked, setIsSubmitCicked] = useState(false);
const [isSubmitClicked, setIsSubmitClicked] = useState(false);
// 적용할래요 눌렀는지 확인
const [isModalClicked, setIsModalClicked] = useState(false);
// 캘린더 여닫기
Expand Down Expand Up @@ -74,7 +75,12 @@ const JuniorPromiseRequestPage = () => {
const handleAppointmentSendSuccess = () => {
setIsModalClicked(true);
};
const { mutate: postAppointment } = usePostAppointment(() => handleAppointmentSendSuccess());

const handleAppointmentSendError = (error: string) => {
alert(error);
};

const { mutate: postAppointment } = usePostAppointment(handleAppointmentSendSuccess, handleAppointmentSendError);

const handlePostAppointment = () => {
if (isAllSelected) {
Expand Down Expand Up @@ -105,7 +111,7 @@ const JuniorPromiseRequestPage = () => {

// 버튼 클릭시 실행 함수
const handleSubmit = (isAllSelected: boolean) => {
setIsSubmitCicked(true);
setIsSubmitClicked(true);
isAllSelected && handleModalOpen(true);
};

Expand All @@ -119,7 +125,7 @@ const JuniorPromiseRequestPage = () => {

return (
<Wrapper>
<Header LeftSvg={ArrowLeftIc} onClickLeft={() => navigate('/')} title={'약속 신청하기'} />
<Header LeftSvg={ArrowLeftIc} onClickLeft={() => navigate(-1)} title={'약속 신청하기'} />
<Banner senior={`${seniorNickname} 선배`} />
<ImgHbpromiseIcon />

Expand All @@ -140,17 +146,6 @@ const JuniorPromiseRequestPage = () => {
activeButton={activeButton}
onSetActiveButtonHandler={handleToggle}
/>
{isModalOpen && (
<BtnCloseModal
title={'약속 잡기 전 주의해주세요'}
isModalOpen={isModalOpen}
handleModalOpen={handleModalOpen}
handleBtnClick={handlePostAppointment}
btnText={'적용할래요'}>
<CheckModalContent />
</BtnCloseModal>
)}
{isModalClicked && <RequestComplete seniorNickname={seniorNickname} />}
{activeButton === '선택할래요' ? (
<WorryButtons
selectedButtons={selectedButtons}
Expand Down Expand Up @@ -179,6 +174,17 @@ const JuniorPromiseRequestPage = () => {
</SubmitBtn>
</PageBottomBar>
</Layout>
{isModalOpen && (
<BtnCloseModal
title={'약속 잡기 전 주의해주세요'}
isModalOpen={isModalOpen}
handleModalOpen={handleModalOpen}
handleBtnClick={handlePostAppointment}
btnText={'적용할래요'}>
<CheckModalContent />
</BtnCloseModal>
)}
{isModalClicked && <RequestComplete seniorNickname={seniorNickname} />}
</Wrapper>
);
};
Expand Down
38 changes: 0 additions & 38 deletions src/pages/juniorPromiseRequest/components/CheckModal.tsx

This file was deleted.

16 changes: 15 additions & 1 deletion src/pages/juniorPromiseRequest/hooks/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { useMutation, useQuery } from '@tanstack/react-query';
import { postAppointment } from '../apis/postAppointment';
import { postAppointmentType } from '../apis/postAppointment';
import { getSeniorTimeAxios } from '../apis/getSeniorTimeAxios';
import axios from 'axios';

export const QUERY_KEY_JUNIOR_PROMISE_SEND = {
postAppointment: postAppointment,
getSeniorTimeAxios: getSeniorTimeAxios,
};

export const usePostAppointment = (onSuccessCallback?: () => void) => {
export const usePostAppointment = (onSuccessCallback?: () => void, onErrorCallback?: (error: string) => void) => {
const { mutate, data } = useMutation({
mutationKey: [QUERY_KEY_JUNIOR_PROMISE_SEND.postAppointment],
mutationFn: ({ seniorId, topic, personalTopic, timeList }: postAppointmentType) =>
Expand All @@ -19,6 +20,19 @@ export const usePostAppointment = (onSuccessCallback?: () => void) => {
onSuccessCallback();
}
},
onError: (error) => {
let errorMessage = '알 수 없는 오류가 발생했습니다.';
if (axios.isAxiosError(error) && error.response) {
if (error.response?.status === 403 || error.response?.status === 400) {
errorMessage = '이미 약속을 신청한 선배입니다.';
} else {
errorMessage = '약속 신청에 실패했습니다.';
}
}
if (onErrorCallback) {
onErrorCallback(errorMessage);
}
},
});

return { mutate, data };
Expand Down