From 8d22e6db3e6b6257cef4bd0c91b1ea1e8f5caa86 Mon Sep 17 00:00:00 2001 From: hyu-dev Date: Sat, 30 Dec 2023 22:09:42 +0900 Subject: [PATCH] =?UTF-8?q?fix.=20=ED=99=88=20=ED=94=8C=EB=9E=9C=20?= =?UTF-8?q?=EB=91=90=EB=B2=88=20=ED=98=B8=EC=B6=9C=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/connections/ProtectedLogin.tsx | 5 +++-- src/components/templates/HomeTemplate/HomeTemplate.tsx | 7 ++++--- .../templates/HomeTemplate/Month/MonthTemplate.tsx | 6 +++--- .../templates/HomeTemplate/Week/WeekTemplate.tsx | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/connections/ProtectedLogin.tsx b/src/components/connections/ProtectedLogin.tsx index 7e71af5..3c3c6d8 100644 --- a/src/components/connections/ProtectedLogin.tsx +++ b/src/components/connections/ProtectedLogin.tsx @@ -1,4 +1,4 @@ -import { setAccessToken, setCurrentDate } from '@/store/reducers'; +import { setAccessToken, setCurrentDate, setMonthCurrentDate } from '@/store/reducers'; import { TAppDispatch, TRootState } from '@/store/state'; import dayjs from 'dayjs'; import { Fragment, ReactNode, useEffect, useMemo } from 'react'; @@ -19,7 +19,8 @@ export const ProtectedLogin = ({ loginNode, appNode }: TProps) => { useEffect(() => { // 첫 접속시 당일 날짜 등록 - dispatch(setCurrentDate(dayjs().format())); + dispatch(setCurrentDate(dayjs().format('YYYY-MM-DD'))); + dispatch(setMonthCurrentDate(dayjs().format('YYYY-MM-DD'))); // 토큰 등록 dispatch(setAccessToken(localStorage.getItem('rb-access-token') ?? '')); }, []); diff --git a/src/components/templates/HomeTemplate/HomeTemplate.tsx b/src/components/templates/HomeTemplate/HomeTemplate.tsx index a153f25..a139c05 100644 --- a/src/components/templates/HomeTemplate/HomeTemplate.tsx +++ b/src/components/templates/HomeTemplate/HomeTemplate.tsx @@ -38,10 +38,11 @@ export const HomeTemplate = () => { dispatch(setMonthCurrentDate(dayjs(monthCurrentDate).add(1, 'month').format())); }; - // 홈화면 접속시 오늘 날짜로 초기화 useEffect(() => { - dispatch(setCurrentDate(dayjs().format('YYYY-MM-DD'))); - dispatch(setMonthCurrentDate(dayjs().format('YYYY-MM-DD'))); + return () => { + dispatch(setCurrentDate(dayjs().format('YYYY-MM-DD'))); + dispatch(setMonthCurrentDate(dayjs().format('YYYY-MM-DD'))); + }; }, []); return ( diff --git a/src/components/templates/HomeTemplate/Month/MonthTemplate.tsx b/src/components/templates/HomeTemplate/Month/MonthTemplate.tsx index 57345dc..1d2e276 100644 --- a/src/components/templates/HomeTemplate/Month/MonthTemplate.tsx +++ b/src/components/templates/HomeTemplate/Month/MonthTemplate.tsx @@ -9,7 +9,7 @@ import { Alert } from '@utils/Alert'; import { convertError } from '@utils/errors'; import { AxiosError } from 'axios'; import dayjs from 'dayjs'; -import { useCallback, useEffect, useMemo } from 'react'; +import { memo, useCallback, useEffect, useMemo } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useNavigate } from 'react-router-dom'; import { DefinitionList, FlexBox, GuideLabel, GuideText, Section, SubTitle, Wrap } from './Styled'; @@ -21,7 +21,7 @@ const data = { [EAchievementStatus.success]: '모든 플랜을 달성했어요!' }; -export const MonthTemplate = () => { +export const MonthTemplate = memo(() => { const { monthCurrentDate, monthRecord, recordTrophy, planTrophy } = useSelector( (state: TRootState) => state.planStore ); @@ -108,4 +108,4 @@ export const MonthTemplate = () => { ); -}; +}); diff --git a/src/components/templates/HomeTemplate/Week/WeekTemplate.tsx b/src/components/templates/HomeTemplate/Week/WeekTemplate.tsx index b1a2357..d4d76b6 100644 --- a/src/components/templates/HomeTemplate/Week/WeekTemplate.tsx +++ b/src/components/templates/HomeTemplate/Week/WeekTemplate.tsx @@ -12,7 +12,7 @@ import { Alert } from '@utils/Alert'; import { convertError } from '@utils/errors'; import { AxiosError } from 'axios'; import dayjs from 'dayjs'; -import { lazy, useEffect, useMemo, useState } from 'react'; +import { lazy, memo, useEffect, useMemo, useState } from 'react'; import { FormProvider, useForm } from 'react-hook-form'; import { useDispatch, useSelector } from 'react-redux'; import { AddPlanWrap, EmptyPlan, PageProgress, PlanListBox, PlanVisualBox, Wrap } from './Styled'; @@ -31,7 +31,7 @@ const IconEggTwoPlan = lazy(() => import('@assets/images/IconEggTwoPlan').then((data) => ({ default: data.IconEggTwoPlan })) ); -export const WeekTemplate = () => { +export const WeekTemplate = memo(() => { const MAX_CREATION_COUNT = 3; // 플랜 등록에 대한 정보 const methods = useForm({ @@ -147,4 +147,4 @@ export const WeekTemplate = () => { ); -}; +});