1- import React , { Dispatch , SetStateAction , useState } from 'react'
1+ import React , { Dispatch , SetStateAction , useEffect , useState } from 'react'
22import { ReactComponent as CloseIcon } from '@assets/myRecordIcon/close.svg'
33import { ReactComponent as ArrowDown } from '@assets/myRecordIcon/arrow_down.svg'
44import { ReactComponent as ArrowUp } from '@assets/myRecordIcon/arrow_up.svg'
@@ -7,7 +7,8 @@ import Button from '@components/Button'
77import DateBox from './DateBox'
88import CalendarMonthYear from './CalendarMonthYear'
99import { useMyRecordByMonthYear } from '@react-query/hooks/useMyRecordByMonthYear'
10- import { useNavigate } from 'react-router-dom'
10+ import { useLocation , useNavigate } from 'react-router-dom'
11+ import { getMonthYearDetail } from './getCalendarDetail'
1112
1213interface CalendarProps {
1314 setIsOpenCalendar : Dispatch < SetStateAction < boolean > >
@@ -16,6 +17,7 @@ interface CalendarProps {
1617const WEEK_TO_KR = [ '์ผ' , '์' , 'ํ' , '์' , '๋ชฉ' , '๊ธ' , 'ํ ' ]
1718
1819export default function Calendar ( { setIsOpenCalendar } : CalendarProps ) {
20+ const { state } = useLocation ( )
1921 const navigate = useNavigate ( )
2022 const { today, monthYear, setMonthYear, recordsWithMonthYear } =
2123 useMyRecordByMonthYear ( )
@@ -25,7 +27,17 @@ export default function Calendar({ setIsOpenCalendar }: CalendarProps) {
2527 setIsOpenCalendar ( false )
2628 } )
2729 const isTodayMonthYear =
28- monthYear . month === today . month && monthYear . year && today . month
30+ monthYear . month === today . month && monthYear . year === today . year
31+ const isFutureMonthYear =
32+ monthYear . month > today . month && monthYear . year === today . year
33+
34+ useEffect ( ( ) => {
35+ if ( state ) {
36+ setIsClickMonthYear ( false )
37+ setMonthYear ( getMonthYearDetail ( new Date ( `${ state . year } -${ state . month } ` ) ) )
38+ setSelectedDate ( state . day )
39+ }
40+ } , [ ] )
2941
3042 return (
3143 < div className = "fixed top-0 z-30 block h-full w-full" >
@@ -70,6 +82,7 @@ export default function Calendar({ setIsOpenCalendar }: CalendarProps) {
7082 hasRecord = { recordsWithMonthYear ?. includes ( 1 ) }
7183 selectedDate = { selectedDate }
7284 setSelectedDate = { setSelectedDate }
85+ isFutureMonthYear = { isFutureMonthYear }
7386 />
7487 { [ ...Array ( monthYear . lastDayOfMonth ) ] . map ( ( _ , i ) =>
7588 i > 0 ? (
@@ -80,6 +93,7 @@ export default function Calendar({ setIsOpenCalendar }: CalendarProps) {
8093 selectedDate = { selectedDate }
8194 hasRecord = { recordsWithMonthYear ?. includes ( i + 1 ) }
8295 setSelectedDate = { setSelectedDate }
96+ isFutureMonthYear = { isFutureMonthYear }
8397 />
8498 ) : null
8599 ) }
@@ -89,7 +103,16 @@ export default function Calendar({ setIsOpenCalendar }: CalendarProps) {
89103 aria-label = "select-record-date-button"
90104 property = { 'solid' }
91105 active = { selectedDate !== 0 }
92- onClick = { ( ) => navigate ( '/myrecord/date' ) }
106+ onClick = { ( ) =>
107+ navigate ( '/myrecord/date' , {
108+ state : {
109+ year : monthYear . year ,
110+ month : monthYear . month ,
111+ day : selectedDate ,
112+ } ,
113+ replace : state ? true : false ,
114+ } )
115+ }
93116 >
94117 ์ ํ
95118 </ Button >
@@ -102,6 +125,7 @@ export default function Calendar({ setIsOpenCalendar }: CalendarProps) {
102125 year = { monthYear . year }
103126 setIsChangedMonthYear = { setIsClickMonthYear }
104127 setMonthYear = { setMonthYear }
128+ setSelectedDate = { setSelectedDate }
105129 />
106130 ) }
107131 </ div >
0 commit comments