@@ -2,16 +2,23 @@ import React, { ChangeEvent, useCallback, useContext } from "react";
22
33import { RING_COLOR } from "../constants" ;
44import DatepickerContext from "../contexts/DatepickerContext" ;
5- import { classNames as cn } from "../helpers" ;
6-
7- import { DoubleVerticalChevronRightIcon } from "./utils" ;
5+ import { classNames as cn , formatDateTimeToISO } from "../helpers" ;
86
97import { PeriodDay } from "types" ;
108
119const Time : React . FC = ( ) => {
1210 // Contexts
13- const { primaryColor, changeHour, changeMinute, changePeriodDay } =
14- useContext ( DatepickerContext ) ;
11+ const {
12+ hour,
13+ minute,
14+ periodDay,
15+ period,
16+ primaryColor,
17+ changeDatepickerValue,
18+ changeHour,
19+ changeMinute,
20+ changePeriodDay
21+ } = useContext ( DatepickerContext ) ;
1522
1623 const ringFocusColor = RING_COLOR . focus [ primaryColor as keyof typeof RING_COLOR . focus ] ;
1724
@@ -35,13 +42,39 @@ const Time: React.FC = () => {
3542 const HOURS = Array . from ( { length : 12 } ) ;
3643 const MINUTES = Array . from ( { length : 12 } ) ;
3744
38- const handleChangeHour = ( e : ChangeEvent < HTMLSelectElement > ) => changeHour ( e . target . value ) ;
45+ const handleChangeHour = ( e : ChangeEvent < HTMLSelectElement > ) => {
46+ changeHour ( e . target . value ) ;
47+
48+ if ( period . start && period . end ) {
49+ changeDatepickerValue ( {
50+ startDate : formatDateTimeToISO ( period . start , e . target . value , minute , periodDay ) ,
51+ endDate : formatDateTimeToISO ( period . end , e . target . value , minute , periodDay )
52+ } ) ;
53+ }
54+ } ;
3955
40- const handleChangeMinute = ( e : ChangeEvent < HTMLSelectElement > ) => changeMinute ( e . target . value ) ;
56+ const handleChangeMinute = ( e : ChangeEvent < HTMLSelectElement > ) => {
57+ changeMinute ( e . target . value ) ;
4158
42- const handleChangePeriodDay = ( e : ChangeEvent < HTMLSelectElement > ) =>
59+ if ( period . start && period . end ) {
60+ changeDatepickerValue ( {
61+ startDate : formatDateTimeToISO ( period . start , hour , e . target . value , periodDay ) ,
62+ endDate : formatDateTimeToISO ( period . end , hour , e . target . value , periodDay )
63+ } ) ;
64+ }
65+ } ;
66+
67+ const handleChangePeriodDay = ( e : ChangeEvent < HTMLSelectElement > ) => {
4368 changePeriodDay ( e . target . value as PeriodDay ) ;
4469
70+ if ( period . start && period . end ) {
71+ changeDatepickerValue ( {
72+ startDate : formatDateTimeToISO ( period . start , hour , minute , e . target . value ) ,
73+ endDate : formatDateTimeToISO ( period . end , hour , minute , e . target . value )
74+ } ) ;
75+ }
76+ } ;
77+
4578 return (
4679 < div className = "w-full md:w-auto flex items-center justify-center space-x-3" >
4780 < div className = "pb-6" >
0 commit comments