1+ import dayjs from "dayjs" ;
12import React , { ChangeEvent , useContext } from "react" ;
23
3- import { RING_COLOR } from "../constants" ;
4+ import { DATE_FORMAT , RING_COLOR } from "../constants" ;
45import DatepickerContext from "../contexts/DatepickerContext" ;
56import { classNames as cn , formatDateTimeToISO } from "../helpers" ;
67import { PeriodDay } from "../types" ;
@@ -55,34 +56,36 @@ const Time: React.FC = () => {
5556 const handleChangeHour = ( e : ChangeEvent < HTMLSelectElement > ) => {
5657 changeHour ( e . target . value ) ;
5758
58- if ( period . start && period . end ) {
59+ if ( period . start && period . end )
5960 changeDatepickerValue ( {
6061 startDate : formatDateTimeToISO ( period . start , e . target . value , minute , periodDay ) ,
6162 endDate : formatDateTimeToISO ( period . end , e . target . value , minute , periodDay )
6263 } ) ;
63- }
6464 } ;
6565
6666 const handleChangeMinute = ( e : ChangeEvent < HTMLSelectElement > ) => {
6767 changeMinute ( e . target . value ) ;
6868
69- if ( period . start && period . end ) {
69+ if ( period . start && period . end )
7070 changeDatepickerValue ( {
7171 startDate : formatDateTimeToISO ( period . start , hour , e . target . value , periodDay ) ,
7272 endDate : formatDateTimeToISO ( period . end , hour , e . target . value , periodDay )
7373 } ) ;
74- }
7574 } ;
7675
7776 const handleChangePeriodDay = ( e : ChangeEvent < HTMLSelectElement > ) => {
7877 changePeriodDay ( e . target . value as PeriodDay ) ;
7978
80- if ( period . start && period . end ) {
79+ if ( period . start && period . end )
8180 changeDatepickerValue ( {
82- startDate : formatDateTimeToISO ( period . start , hour , minute , e . target . value ) ,
83- endDate : formatDateTimeToISO ( period . end , hour , minute , e . target . value )
81+ startDate : formatDateTimeToISO (
82+ period . start ,
83+ hour ,
84+ minute ,
85+ e . target . value as PeriodDay
86+ ) ,
87+ endDate : formatDateTimeToISO ( period . end , hour , minute , e . target . value as PeriodDay )
8488 } ) ;
85- }
8689 } ;
8790
8891 return (
@@ -97,10 +100,10 @@ const Time: React.FC = () => {
97100 } }
98101 >
99102 { HOURS . map ( ( _ , index ) => {
100- const hour = index + 1 ;
103+ const hr = index + 1 ;
101104 return (
102- < option key = { hour } value = { hour } >
103- { hour }
105+ < option key = { hr } value = { hr } >
106+ { hr }
104107 </ option >
105108 ) ;
106109 } ) }
@@ -110,17 +113,18 @@ const Time: React.FC = () => {
110113 name = "minute"
111114 className = { cn ( selectClassname , "mr-4" ) }
112115 onChange = { handleChangeMinute }
116+ value = { minute }
113117 style = { {
114118 backgroundImage : "url(" + dataUri + ")"
115119 } }
116120 >
117121 { MINUTES . map ( ( _ , index ) => {
118- const minute = index * 5 ;
122+ const min = index * 5 ;
119123 return (
120- < option key = { minute } value = { minute } >
124+ < option key = { min } value = { min } >
121125 { new Intl . NumberFormat ( "en-US" , {
122126 minimumIntegerDigits : 2
123- } ) . format ( minute ) }
127+ } ) . format ( min ) }
124128 </ option >
125129 ) ;
126130 } ) }
@@ -129,6 +133,7 @@ const Time: React.FC = () => {
129133 name = "ampm"
130134 className = { selectClassname }
131135 onChange = { handleChangePeriodDay }
136+ value = { periodDay }
132137 style = { {
133138 backgroundImage : "url(" + dataUri + ")"
134139 } }
0 commit comments