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/#198] 오전 저녁 선택시 오후 시간대 선택 막기 #204

Merged
merged 2 commits into from
Nov 3, 2023
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
Empty file.
1 change: 1 addition & 0 deletions src/components/scheduleComponents/utils/isMorningDinner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//아침 저녁인지를 확인하는 util
29 changes: 26 additions & 3 deletions src/pages/selectSchedule/components/SelectSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ interface PropTypes {
}

function SelectSchedule({ scheduleList, availableDates, preferTimes, setScheduleList, deleteData }: PropTypes) {

// 현재 선택된 가능시간이 아침/저녁 시간대인 경우를 확인하는 함수
const isMorningDinner =
preferTimes.length === 2 && preferTimes.every((time) => time.startTime !== '12:00');

const handleDate = (id: number, date: string) => {

const updateDate: ScheduleStates[] = scheduleList?.map((schedule) => {
Expand All @@ -34,17 +39,25 @@ function SelectSchedule({ scheduleList, availableDates, preferTimes, setSchedule
const updateStartTime: ScheduleStates[] = scheduleList?.map((schedule) =>
{
if (schedule?.id === id) {

if(schedule.endTime==="" ){
return { ...schedule, startTime };
}
else if (compareTime(startTime,schedule.endTime)){

if (isMorningDinner){
//오전,저녁 시간대이므로, 오후 시간대를 선택했는지 아닌지를 판별해야함
//시작 시간이 11:30 이하이면서 종료 시간이 18:00이후인 경우
if (compareTime(startTime, "11:30") && compareTime("18:00", schedule.endTime)) {
alert("12:00 부터 18:00는 선택지에 포함될 수 없습니다.");
return schedule;
}
}

return { ...schedule, startTime };
}
else{
alert("종료 시간은 시작 시간 이후로 설정해주세요!");
}

}
return schedule;
}

Expand All @@ -62,6 +75,16 @@ function SelectSchedule({ scheduleList, availableDates, preferTimes, setSchedule
return { ...schedule, endTime };
}
else if (compareTime(schedule.startTime,endTime)){

if (isMorningDinner){
//오전,저녁 시간대이므로, 오후 시간대를 선택했는지 아닌지를 판별해야함
//시작 시간이 11:30 이하이면서 종료 시간이 18:00이후인 경우
if (compareTime(schedule.startTime, "11:30") && compareTime("18:00", endTime)) {
alert("오후 12시부터 18시는 선택지에 포함될 수 없습니다.");
return schedule;
}
}

return { ...schedule, endTime };
}
else {
Expand Down
Loading