@@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
33import type { CycleType } from '../constant/mock' ;
44
55import type { TodoItemTypes } from '@/page/todo/myTodo/component/TodoBox/TodoBox.types' ;
6- import { createDate , formatDateDot } from '@/common/util/format' ;
6+ import { formatDateDot } from '@/common/util/format' ;
77import { useGetRecommendation } from '@/api/domain/myTodo/hook/useGetRecommendation' ;
88import { usePostRecommendation } from '@/api/domain/myTodo/hook/usePostRecommendation' ;
99import { useDeleteRecommendation } from '@/api/domain/myTodo/hook/useDeleteRecommendation' ;
@@ -32,11 +32,12 @@ interface UseMyTodoProps {
3232 initialMyTodos ?: TodoItemTypes [ ] ;
3333}
3434
35- const MIN_DATE = createDate ( 2025 , 1 , 1 ) ;
36- const MAX_DATE = createDate ( 2025 , 1 , 31 ) ;
35+ export const useMyTodo = ( { initialDate } : UseMyTodoProps = { } ) => {
36+ const defaultDate = initialDate ?? new Date ( ) ;
37+ const startOfMonth = new Date ( defaultDate . getFullYear ( ) , defaultDate . getMonth ( ) , 1 ) ;
38+ const endOfMonth = new Date ( defaultDate . getFullYear ( ) , defaultDate . getMonth ( ) + 1 , 0 ) ;
3739
38- export const useMyTodo = ( { initialDate = createDate ( 2025 , 7 , 18 ) } : UseMyTodoProps = { } ) => {
39- const [ currentDate , setCurrentDate ] = useState ( initialDate ) ;
40+ const [ currentDate , setCurrentDate ] = useState ( defaultDate ) ;
4041 const [ selectedCycle , setSelectedCycle ] = useState < CycleType > ( ) ;
4142 const [ selectedParentId , setSelectedParentId ] = useState < number > ( ) ;
4243 const [ todos , setTodos ] = useState < TodoItemTypes [ ] > ( [ ] ) ;
@@ -65,10 +66,13 @@ export const useMyTodo = ({ initialDate = createDate(2025, 7, 18) }: UseMyTodoPr
6566 setTodos ( mockSubGoals ) ;
6667 } , [ ] ) ;
6768
68- const hasPreviousDate = currentDate > MIN_DATE ;
69- const hasNextDate = currentDate < MAX_DATE ;
69+ const hasPreviousDate = currentDate > startOfMonth ;
70+ const hasNextDate = currentDate < endOfMonth ;
7071
7172 const handleDateChange = ( newDate : Date ) => {
73+ if ( newDate < startOfMonth || newDate > endOfMonth ) {
74+ return ;
75+ }
7276 setCurrentDate ( newDate ) ;
7377 } ;
7478
0 commit comments