From 7f3b27dce64cf26e3cee37233b6e2d145f7a8116 Mon Sep 17 00:00:00 2001 From: Sang <128155681+ChoEun-Sang@users.noreply.github.com> Date: Tue, 3 Oct 2023 13:53:56 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=98=A4=EB=8A=98=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=93=B1=EB=A1=9D=20=EC=B2=B4=ED=81=AC=20=EB=B0=8F?= =?UTF-8?q?=20=EA=B8=B0=ED=83=80=20=EC=88=98=EC=A0=95=20(#183)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: reset 추가 * refactor: 오늘 리뷰 등록 체크 구현 * chore: 불필요한 api 삭제 * chore: 불필요한 스타일 삭제 * chore: ErrorIcon import 위치 변경 --- src/assets/icons/index.ts | 4 ++-- .../lunch/calendar/LunchCalendarCafeteria.tsx | 6 +++-- .../lunch/calendar/LunchCalendarEatOut.tsx | 6 +++-- .../lunch/calendar/LunchCalendarForm.tsx | 22 +++++++---------- .../lunch/calendar/LunchCalendarLunchBox.tsx | 6 +++-- .../lunch/calendar/LunchCalendarMain.tsx | 24 ++++++++++++++----- src/pages/api/lunch/calendarRequests.ts | 6 ----- 7 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/assets/icons/index.ts b/src/assets/icons/index.ts index 2ce1ecd4..32e9558a 100644 --- a/src/assets/icons/index.ts +++ b/src/assets/icons/index.ts @@ -16,7 +16,6 @@ import Right from '@/assets/icons/Right.svg'; import Seminar from '@/assets/icons/seminar.svg'; import Up from '@/assets/icons/Up.svg'; import Info from '@/assets/icons/Info.svg'; -import ErrorIcon from '@/assets/icons/Erroricon.svg'; import PlusBig from '@/assets/icons/Plus=big.svg'; import PlusSmall from '@/assets/icons/Plus=small.svg'; import ExitSmall from '@/assets/icons/Exit=small.svg'; @@ -108,6 +107,7 @@ import HomeActive from '@/assets/icons/HomeActive.svg'; import LunchActive from '@/assets/icons/LunchActive.svg'; import MyActive from '@/assets/icons/MyActive.svg'; import PlateSmall from '@/assets/icons/plateSmall.svg'; +import ErrorIcon from '@/assets/icons/Erroricon.svg'; export { As, @@ -128,7 +128,6 @@ export { Send, Up, Info, - ErrorIcon, PlusBig, PlusSmall, ExitSmall, @@ -220,4 +219,5 @@ export { LunchActive, MyActive, PlateSmall, + ErrorIcon, }; diff --git a/src/components/lunch/calendar/LunchCalendarCafeteria.tsx b/src/components/lunch/calendar/LunchCalendarCafeteria.tsx index 3c76ce4c..8b550347 100644 --- a/src/components/lunch/calendar/LunchCalendarCafeteria.tsx +++ b/src/components/lunch/calendar/LunchCalendarCafeteria.tsx @@ -24,7 +24,7 @@ import Alert from '@/components/common/Alert'; function LunchCalendarCafeteria() { const [searchText, setSearchText] = useState(''); - const { setNextComponent } = usePagesStore(); + const { setNextComponent, reset } = usePagesStore(); const { bottomSheetState, openBottomSheet, closeBottomSheet } = useBottomSheetStore(); const { isSave } = useSaveStore(); @@ -56,8 +56,10 @@ function LunchCalendarCafeteria() { if (imageFiles.length === 0) { router.replace('/lunch/calendar'); + reset(); + } else { + setNextComponent(calendar.Inform); } - setNextComponent(calendar.Inform); } catch (err) { const error = err as ErrorProps; openAlert('📢', error.message || '리뷰 등록 오류'); diff --git a/src/components/lunch/calendar/LunchCalendarEatOut.tsx b/src/components/lunch/calendar/LunchCalendarEatOut.tsx index 3dbef89f..11889453 100644 --- a/src/components/lunch/calendar/LunchCalendarEatOut.tsx +++ b/src/components/lunch/calendar/LunchCalendarEatOut.tsx @@ -24,7 +24,7 @@ import Alert from '@/components/common/Alert'; function LunchCalenderEatOut() { const [searchText, setSearchText] = useState(''); - const { setNextComponent, goBack } = usePagesStore(); + const { setNextComponent, goBack, reset } = usePagesStore(); const { bottomSheetState, openBottomSheet, closeBottomSheet } = useBottomSheetStore(); const { @@ -80,8 +80,10 @@ function LunchCalenderEatOut() { if (imageFiles.length === 0) { router.replace('/lunch/calendar'); + reset(); + } else { + setNextComponent(calendar.Inform); } - setNextComponent(calendar.Inform); } catch (err) { const error = err as ErrorProps; openAlert('📢', error.message || '리뷰 등록 오류'); diff --git a/src/components/lunch/calendar/LunchCalendarForm.tsx b/src/components/lunch/calendar/LunchCalendarForm.tsx index f2565870..741b5460 100644 --- a/src/components/lunch/calendar/LunchCalendarForm.tsx +++ b/src/components/lunch/calendar/LunchCalendarForm.tsx @@ -76,9 +76,6 @@ const CalendarStyles = css` width: 350px; max-width: 100%; background: white; - border: 1px solid #a0a096; - font-family: Arial, Helvetica, sans-serif; - line-height: 1.125em; } .react-calendar--doubleView { @@ -126,13 +123,12 @@ const CalendarStyles = css` } .react-calendar__navigation button:disabled { - // background-color: #f0f0f0; - // pointer-events: none; + } .react-calendar__navigation button:enabled:hover, .react-calendar__navigation button:enabled:focus { - // background-color: #e6e6e6; + } // 요일 section @@ -200,21 +196,19 @@ const CalendarStyles = css` .react-calendar__tile:disabled { color: ${theme.palette.greyscale.grey40}; - // pointer-events: none; } .react-calendar__tile:enabled:hover, .react-calendar__tile:enabled:focus { - // background-color: #e6e6e6; + } // 오늘 날짜 .react-calendar__tile--now { - color: ${theme.palette.bluescale.blue50}; } .react-calendar__tile--now:enabled:hover, .react-calendar__tile--now:enabled:focus { - // background: #ffffa9; + } .react-calendar__tile--hasActive { @@ -223,23 +217,23 @@ const CalendarStyles = css` .react-calendar__tile--hasActive:enabled:hover, .react-calendar__tile--hasActive:enabled:focus { - // background: #a9d4ff; + } // 선택한 날짜 .react-calendar__tile--active { .react-calendar__tile--active:enabled:hover, .react-calendar__tile--active:enabled:focus { - // background: #1087ff; + } .react-calendar--selectRange .react-calendar__tile--hover { - // background-color: #e6e6e6; + } // 네비게이션 레이블 - button 태그 .react-calendar__navigation__label { - // pointer-events: none; + } // 네비게이션 레이블 - span 태그 .react-calendar__navigation__label__labelText.react-calendar__navigation__label__labelText--from { diff --git a/src/components/lunch/calendar/LunchCalendarLunchBox.tsx b/src/components/lunch/calendar/LunchCalendarLunchBox.tsx index fdf51852..1db8c7e1 100644 --- a/src/components/lunch/calendar/LunchCalendarLunchBox.tsx +++ b/src/components/lunch/calendar/LunchCalendarLunchBox.tsx @@ -21,7 +21,7 @@ import Alert from '@/components/common/Alert'; function LunchCalendarLunchBox() { const [searchText, setSearchText] = useState(''); - const { setNextComponent } = usePagesStore(); + const { setNextComponent, reset } = usePagesStore(); const { bottomSheetState, openBottomSheet, closeBottomSheet } = useBottomSheetStore(); const { isSave } = useSaveStore(); @@ -51,8 +51,10 @@ function LunchCalendarLunchBox() { if (imageFiles.length === 0) { router.replace('/lunch/calendar'); + reset(); + } else { + setNextComponent(calendar.Inform); } - setNextComponent(calendar.Inform); } catch (err) { const error = err as ErrorProps; openAlert('📢', error.message || '리뷰 등록 오류'); diff --git a/src/components/lunch/calendar/LunchCalendarMain.tsx b/src/components/lunch/calendar/LunchCalendarMain.tsx index 1d963ad8..f8c0a0df 100644 --- a/src/components/lunch/calendar/LunchCalendarMain.tsx +++ b/src/components/lunch/calendar/LunchCalendarMain.tsx @@ -3,6 +3,7 @@ import { useRouter } from 'next/router'; import { css } from '@emotion/react'; import { CALENDAR_CONTENT } from '@/constants/lunch'; import { Rice } from '@/assets/icons'; +import { getReviewDetailsData } from '@/pages/api/lunch/calendarRequests'; import Header from '@/components/common/Header'; import Alert from '@/components/common/Alert'; import LunchCalendarWriteBtn from '@/components/lunch/calendar/LunchCalendarWriteBtn'; @@ -11,23 +12,34 @@ import LunchCalendarForm from '@/components/lunch/calendar/LunchCalendarForm'; import LunchCalendarDetailsSlide from '@/components/lunch/calendar/LunchCalendarDetailsSlide'; import useWriteStore from '@/stores/useWriteStore'; import useAlertStore from '@/stores/useAlertStore'; -import useCalendarStore from '@/stores/useCalendarStore'; +import { ErrorProps } from '@/types/common/response'; import checkTodayReview from '@/utils/checkTodayReview'; function LunchCalendarMain() { const [isCompleted, setIsCompleted] = useState(false); const isChecked = useWriteStore((state) => state.isChecked); - const reviewDetails = useCalendarStore((state) => state.reviewDetails); - const { alertState } = useAlertStore(); + const { alertState, openAlert } = useAlertStore(); const { title, subTitle } = CALENDAR_CONTENT; const router = useRouter(); useEffect(() => { - const res = checkTodayReview(reviewDetails); - setIsCompleted(res); - }, [reviewDetails]); + checkReviews(); + }, []); + + const checkReviews = async () => { + try { + const year = new Date().getFullYear(); + const month = new Date().getMonth() + 1; + const { data } = await getReviewDetailsData(year, month); + const res = checkTodayReview(data); + setIsCompleted(res); + } catch (err) { + const error = err as ErrorProps; + openAlert('📢', error.message || '리뷰 체크 오류'); + } + }; const onClickHeaderHandler = () => { router.back(); diff --git a/src/pages/api/lunch/calendarRequests.ts b/src/pages/api/lunch/calendarRequests.ts index 45e79b40..3a5ca3eb 100644 --- a/src/pages/api/lunch/calendarRequests.ts +++ b/src/pages/api/lunch/calendarRequests.ts @@ -1,12 +1,6 @@ import { apiInstance } from '@/pages/api/axios'; // 달력 -export const getReviewData = async (year: number, month: number) => { - const res = await apiInstance.get( - `/reviews/members?year=${year}&month=${month}`, - ); - return res.data; -}; export const getReviewDetailsData = async (year: number, month: number) => { const res = await apiInstance.get(