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

[ Refactor ] JuniorPromiseRequest 라우팅 분리 #221

Merged
merged 23 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
511f901
refactor: juniorPromiseRequest 파일 이동
ijieun Aug 12, 2024
89b7e92
refactor: 라우터 분리, 페이지 이동 방식 변경
ijieun Aug 12, 2024
25e8f0b
fix: react-router-dom의 import문 합치기
ijieun Aug 19, 2024
198d605
refactor: state를 사용하지 않고 navigate 이동하도록 코드리뷰 반영
ijieun Aug 19, 2024
fc0f7f4
refactor: state없이 구조분해할당으로 받아오도록 코드리뷰 반영
ijieun Aug 19, 2024
e619cd1
fix: header < 클릭시 이전 페이지 이동
ijieun Aug 19, 2024
4cd44d2
chore: 컴포넌트 제거
ijieun Aug 19, 2024
6c83100
design: 약속 신청 모달 가운데로 정렬
ijieun Aug 19, 2024
b99474d
fix: 이미 있는 약속을 신청할 시에 alert알림
ijieun Aug 19, 2024
90020eb
fix: 변수, 속성 이름 축약
ijieun Aug 23, 2024
d7bd928
refactor: 약속신청 버튼 인라인 조건부 렌더링
ijieun Aug 23, 2024
a3e410b
Merge branch 'develop' into refactor/#218/separateRoute
ijieun Sep 16, 2024
6854730
refactor: isAllSelected 상태 함수 제거
ijieun Sep 17, 2024
96d4527
Merge branch 'refactor/#218/separateRoute' of https://github.com/TEAM…
featuring-sophia Sep 19, 2024
65a9cb8
refactor: isAllSelected 상태 함수 제거
ijieun Sep 19, 2024
cd556c4
Merge branch 'refactor/#218/separateRoute' of https://github.com/TEAM…
ijieun Sep 19, 2024
940f74f
refactor: 에러 핸들링 로직 분리
ijieun Sep 19, 2024
d77d769
Merge branch 'refactor/#218/separateRoute' into fix/#222/patchSelfQA
ijieun Sep 23, 2024
8a7345a
Merge pull request #225 from TEAM-SEONYAK/fix/#222/patchSelfQA
ijieun Sep 23, 2024
3e7f505
fix: 변수 맞춤법 수정
ijieun Sep 23, 2024
163adc4
Merge branch 'develop' into refactor/#218/separateRoute
ijieun Sep 23, 2024
f07cb14
refactor: 중복 코드 합치기
ijieun Sep 23, 2024
d1335ad
refactor: 약속 신청 에러 핸들링 로직 변경
ijieun Sep 25, 2024
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
5 changes: 5 additions & 0 deletions src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import JoinPage from '@pages/join/JoinPage';
import ErrorPage from '@pages/errorPage/ErrorPage';
import StepComplete from '@pages/onboarding/components/juniorOnboarding/StepComplete';
import LoginCallback from '@pages/login/LoginCallback';
import JuniorPromiseRequestPage from '@pages/juniorPromiseRequest/JuniorPromiseRequestPage';

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -153,6 +154,10 @@ const router = createBrowserRouter([
path: 'juniorPromise',
element: <JuniorPromisePage />,
},
{
path: 'juniorPromiseRequest',
element: <JuniorPromiseRequestPage />,
},
{
path: 'error',
element: <ErrorPage />,
Expand Down
17 changes: 11 additions & 6 deletions src/pages/juniorPromise/JuniorPromisePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import { SeniorListBackground } from './components/SeniorListBackground';
import seniorProfileQueries from '../../hooks/seniorProfileQueries';
import PreView from '@pages/seniorProfile/components/preView';
import { FullBtn } from '@components/commons/FullButton';
import PromiseRequestPage from './components/promiseRequest/PromiseRequestPage';
import Loading from '@components/commons/Loading';
import { HbHomeMainSvg } from '@assets/svgs';
import { useNavigate } from 'react-router-dom';

const JuniorPromisePage = () => {

const navigate = useNavigate();

// 바텀 시트 내 버튼& 내용 필터 버튼
const [filterActiveBtn, setFilterActiveBtn] = useState('계열');
// 바텀 시트 여는 동작
Expand Down Expand Up @@ -105,7 +108,6 @@ const JuniorPromisePage = () => {
const myNickname = data?.data.myNickname;

const [isSeniorCardClicked, setIsSeniorCardClicked] = useState(false);
const [isPromiseClicked, setIsPromisedClicked] = useState(false);
const [seniorId, setSeniorId] = useState(0);
const [seniorNickname, setSeniorNickname] = useState('');
const handleSeniorCardClicked = (type: boolean, id: number, name: string) => {
Expand All @@ -115,7 +117,12 @@ const JuniorPromisePage = () => {
};

const handlePromiseClicked = () => {
setIsPromisedClicked(true);
navigate('/juniorPromiseRequest', {
state: {
seniorId,
seniorNickname,
},
});
};

if (isLoading) {
Expand All @@ -128,9 +135,7 @@ const JuniorPromisePage = () => {

return (
<>
{isPromiseClicked ? (
<PromiseRequestPage seniorId={seniorId} seniorNickname={seniorNickname} />
) : isSeniorCardClicked ? (
{isSeniorCardClicked ? (
<>
<Header
LeftSvg={ArrowLeftIc}
Expand Down
38 changes: 0 additions & 38 deletions src/pages/juniorPromise/components/promiseRequest/CheckModal.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import ToggleButton from '@components/commons/ToggleButton';
import styled from '@emotion/styled';
import { useState, useEffect } from 'react';
import CalendarBottomSheet from './CalendarBottomSheet';
import WorryButtons from './WorryButtons';
import WorryTextarea from './WorryTextarea';
import ScheduleSelect from './ScheduleSelect';
import { useState } from 'react';
import { useNavigate, useLocation } from 'react-router-dom';
import { usePostAppointment } from './hooks/queries';

import CalendarBottomSheet from './components/CalendarBottomSheet';
import WorryButtons from './components/WorryButtons';
import WorryTextarea from './components/WorryTextarea';
import ScheduleSelect from './components/ScheduleSelect';
import { BtnCloseModal } from '@components/commons/modal/BtnModal';
import CheckModalContent from './CheckModalContent';
import RequestComplete from './RequestComplete';
import CheckModalContent from './components/CheckModalContent';
import RequestComplete from './components/RequestComplete';
import { ArrowLeftIc, ImgHbpromiseIc } from '@assets/svgs';
import { Header } from '@components/commons/Header';
import { useNavigate } from 'react-router-dom';
import Banner from './Banner';
import { usePostAppointment } from '../../hooks/queries';
import TitleBox from '../../../../components/commons/TitleBox';
import { SELECT_JUNIOR_TITLE } from '@pages/juniorPromise/constants/constants';

interface PromiseRequestPagePropType {
seniorId: number;
seniorNickname: string;
}

const PromiseRequestPage = ({ seniorId, seniorNickname }: PromiseRequestPagePropType) => {
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('선택할래요');
const [isModalOpen, setIsModalOpen] = useState(false);
const [isAllSelected, setIsAllSelected] = useState(false);
const [isAnyWorrySelected, setIsAnyWorrySelected] = useState(false);
const [isTextareaFilled, setIsTextareaFilled] = useState(false);
const [, setUnfilledFields] = useState<number[]>([]);
const navigate = useNavigate();
const location = useLocation();

// 약속 신청하기 눌렸는지 확인
const [isSubmitClicked, setIsSubmitCicked] = useState(false);
const [isSubmitClicked, setIsSubmitClicked] = useState(false);
// 적용할래요 눌렀는지 확인
const [isModalClicked, setIsModalClicked] = useState(false);
// 캘린더 여닫기
Expand All @@ -46,6 +43,8 @@ const PromiseRequestPage = ({ seniorId, seniorNickname }: PromiseRequestPageProp
const [btnId, setBtnId] = useState(0);
// 선택한 고민 리스트
const [selectedButtons, setSelectedButtons] = useState<string[]>([]);
// 선배 Id, 닉네임 useLocation에서 가져오기(구조분해할당)
const { seniorId, seniorNickname } = location.state || {};

// onToggle 함수 정의
const handleToggle = (button: string) => {
Expand Down Expand Up @@ -75,52 +74,41 @@ const PromiseRequestPage = ({ seniorId, seniorNickname }: PromiseRequestPageProp
const handleAppointmentSendSuccess = () => {
setIsModalClicked(true);
};
const { mutate: postAppointment } = usePostAppointment(() => handleAppointmentSendSuccess());

const handlePostAppointment = () => {
if (isAllSelected) {
postAppointment({
seniorId: seniorId,
topic: activeButton === '선택할래요' ? selectedButtons : [],
personalTopic: activeButton === '선택할래요' ? '' : inputVal,
timeList: [
{
date: selectedTime[0].clickedDay,
startTime: selectedTime[0].selectedTime.split('-')[0],
endTime: selectedTime[0].selectedTime.split('-')[1],
},
{
date: selectedTime[1].clickedDay,
startTime: selectedTime[1].selectedTime.split('-')[0],
endTime: selectedTime[1].selectedTime.split('-')[1],
},
{
date: selectedTime[2].clickedDay,
startTime: selectedTime[2].selectedTime.split('-')[0],
endTime: selectedTime[2].selectedTime.split('-')[1],
},
],
});
}
const handleAppointmentSendError = (error: string) => {
alert(error);
};

// 버튼 클릭시 실행 함수
const handleSubmit = (isAllSelected: boolean) => {
setIsSubmitCicked(true);
isAllSelected && handleModalOpen(true);
const { mutate: postAppointment } = usePostAppointment(handleAppointmentSendSuccess, handleAppointmentSendError);

// 적용할래요 누르면 실행되는 함수
const handlePostAppointment = () => {
postAppointment({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p1) 근데 여기 기존에는 isAllSelected일 경우에만 실행되던 로직인 것 같은데, 해당 조건없이 실행되도록 두어도 괜찮은가요?

Copy link
Collaborator Author

@ijieun ijieun Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요게 첫번째 화면을 거쳐서 '적용할래요' 버튼을 누르면 그제서야 '약속 신청 post 요청'이 되는 로직입니다!!
원래 중복 검사를 했지만, 어차피 첫번째 화면처럼 모달이 open 되기 위해서는 isAllSelected 검사를 먼저 수행하고, '적용할래요' 버튼을 누르는 시점에서는 이미 검사를 수행한 이후라 불필요한 검사 과정인 것 같아서 뺐습니당!! 기억력 좋타.. 혹시 중복 검사를 하는게 더 낫다고 생각하시나요 ??!

스크린샷 2024-09-23 오후 11 03 51 스크린샷 2024-09-23 오후 11 06 24

요 화면에서 검사 진행함다
스크린샷 2024-09-23 오후 11 09 21

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 아니요!! 굿입니다~~~ 머지해주세여!!

seniorId,
topic: activeButton === '선택할래요' ? selectedButtons : [],
personalTopic: activeButton === '선택할래요' ? '' : inputVal,
timeList: selectedTime.map((item) => ({
date: item.clickedDay,
startTime: item.selectedTime.split('-')[0],
endTime: item.selectedTime.split('-')[1],
})),
});
};

// isAllSelected 업데이트
useEffect(() => {
setIsAllSelected(
// 버튼 클릭시 실행 함수
const handleSubmit = () => {
setIsSubmitClicked(true);
const isAllSelected =
selectedTime.every((item) => item.selectedTime !== '' && item.clickedDay !== '') &&
(isAnyWorrySelected || isTextareaFilled)
);
}, [selectedTime, isAnyWorrySelected, isTextareaFilled]);
(isAnyWorrySelected || isTextareaFilled);
if (isAllSelected) {
handleModalOpen(true);
}
};

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

Expand All @@ -141,17 +129,6 @@ const PromiseRequestPage = ({ seniorId, seniorNickname }: PromiseRequestPageProp
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 All @@ -175,16 +152,33 @@ const PromiseRequestPage = ({ seniorId, seniorNickname }: PromiseRequestPageProp
<Label>총 결제금액</Label>
<Cost>0원</Cost>
</CostWrapper>
<SubmitBtn type="button" onClick={() => handleSubmit(isAllSelected)} $isAllSelected={isAllSelected}>
<SubmitBtn
type="button"
onClick={handleSubmit}
$isAllSelected={
selectedTime.every((item) => item.selectedTime !== '' && item.clickedDay !== '') &&
(isAnyWorrySelected || isTextareaFilled)
}>
약속 신청하기
</SubmitBtn>
</PageBottomBar>
</Layout>
{isModalOpen && (
<BtnCloseModal
title={'약속 잡기 전 주의해주세요'}
isModalOpen={isModalOpen}
handleModalOpen={handleModalOpen}
handleBtnClick={handlePostAppointment}
btnText={'적용할래요'}>
<CheckModalContent />
</BtnCloseModal>
)}
{isModalClicked && <RequestComplete seniorNickname={seniorNickname} />}
</Wrapper>
);
};

export default PromiseRequestPage;
export default JuniorPromiseRequestPage;

const ImgHbpromiseIcon = styled(ImgHbpromiseIc)`
position: absolute;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReloadIc } from '@assets/svgs';
import styled from '@emotion/styled';
import React, { useEffect, useState } from 'react';
import { formatCalDateToString } from '../../utils/formatCalDateToString';
import { getTomorrow } from '../../utils/getTomorrow';
import { formatCalDateToString } from '../utils/formatCalDateToString';
import { getTomorrow } from '../utils/getTomorrow';

interface CalendarBottomBarPropType {
setIsCalendarOpen: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down Expand Up @@ -47,8 +47,8 @@ const CalendarBottomBar = ({
selectedTime: selectedTimeMent[index],
clickedDay: tomorrow,
}
: time,
),
: time
)
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'react';
import CalendarBottomBar from './CalendarBottomBar';
import CustomCalendar from './CustomCalendar';
import TimeList from './TimeList';
import { useSeniorTimeQuery } from '../../hooks/queries';
import { getDayOfWeek } from '../../utils/getDay';
import { useSeniorTimeQuery } from '../hooks/queries';
import { getDayOfWeek } from '../utils/getDay';
import Loading from '@components/commons/Loading';

interface BottomSheetPropType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import styled from '@emotion/styled';
import React, { useState } from 'react';
import Calendar from 'react-calendar';
import 'react-calendar/dist/Calendar.css';
import { formatCalDateToString } from '../../utils/formatCalDateToString';
import { getTomorrow } from '../../utils/getTomorrow';
import { extractValidKeys } from '../../utils/getSeniorValidWeekOfDay';
import { formatCalDateToString } from '../utils/formatCalDateToString';
import { getTomorrow } from '../utils/getTomorrow';
import { extractValidKeys } from '../utils/getSeniorValidWeekOfDay';

interface CalendarTileProperties {
date: Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from '@emotion/styled';
import { formatBtnDateToString } from '../../utils/formatBtnDateToString';
import { ButtonCheckIc } from '../../../../assets/svgs';
import { TIME_SELECTION_BUTTON } from '../../constants/constants';
import { formatBtnDateToString } from '../utils/formatBtnDateToString';
import { ButtonCheckIc } from '../../../assets/svgs';
import { TIME_SELECTION_BUTTON } from '../constants/constants';
import WarnDescription from '@components/commons/WarnDescription';

interface ScheduleSelectProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from '@emotion/styled';
import React from 'react';
import TimeListBtns from './TimeListBtns';
import { splitTimeRange, isAMTime } from '../../utils/changeFormat30Min';
import { splitTimeRange, isAMTime } from '../utils/changeFormat30Min';

interface TimeListType {
startTime: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import WarnDescription from '@components/commons/WarnDescription';
import styled from '@emotion/styled';
import React, { useEffect } from 'react';
import { ButtonCheckIc } from '../../../../assets/svgs';
import { WORRY_SELECTION_BUTTON } from '../../constants/constants';
import { ButtonCheckIc } from '../../../assets/svgs';
import { WORRY_SELECTION_BUTTON } from '../constants/constants';

interface SelectJuniorWorryButtonProps {
handleCheckWorrySelected: (isSelected: boolean) => void;
Expand All @@ -19,7 +19,7 @@ const SelectJuniorWorryButton = ({
setSelectedButtons((prevSelectedButtons: string[]) =>
prevSelectedButtons.includes(title)
? prevSelectedButtons.filter((buttonTitle) => buttonTitle !== title)
: [...prevSelectedButtons, title],
: [...prevSelectedButtons, title]
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import Textarea from '../../../../components/commons/Textarea';
import Textarea from '../../../components/commons/Textarea';
import styled from '@emotion/styled';

interface SelectJuniorWorryTextareaWrapperProps {
Expand Down
Loading
Loading