Skip to content

Commit

Permalink
fix. 홈 플랜 두번 호출 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyu-dev committed Dec 30, 2023
1 parent e4c5aa7 commit 8d22e6d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/components/connections/ProtectedLogin.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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') ?? ''));
}, []);
Expand Down
7 changes: 4 additions & 3 deletions src/components/templates/HomeTemplate/HomeTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions src/components/templates/HomeTemplate/Month/MonthTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
);
Expand Down Expand Up @@ -108,4 +108,4 @@ export const MonthTemplate = () => {
</Section>
</Wrap>
);
};
});
6 changes: 3 additions & 3 deletions src/components/templates/HomeTemplate/Week/WeekTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<TRegisterFormValue>({
Expand Down Expand Up @@ -147,4 +147,4 @@ export const WeekTemplate = () => {
</FormProvider>
</Wrap>
);
};
});

0 comments on commit 8d22e6d

Please sign in to comment.