@@ -2,16 +2,23 @@ import React, { ChangeEvent, useCallback, useContext } from "react";
2
2
3
3
import { RING_COLOR } from "../constants" ;
4
4
import 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" ;
8
6
9
7
import { PeriodDay } from "types" ;
10
8
11
9
const Time : React . FC = ( ) => {
12
10
// 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 ) ;
15
22
16
23
const ringFocusColor = RING_COLOR . focus [ primaryColor as keyof typeof RING_COLOR . focus ] ;
17
24
@@ -35,13 +42,39 @@ const Time: React.FC = () => {
35
42
const HOURS = Array . from ( { length : 12 } ) ;
36
43
const MINUTES = Array . from ( { length : 12 } ) ;
37
44
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
+ } ;
39
55
40
- const handleChangeMinute = ( e : ChangeEvent < HTMLSelectElement > ) => changeMinute ( e . target . value ) ;
56
+ const handleChangeMinute = ( e : ChangeEvent < HTMLSelectElement > ) => {
57
+ changeMinute ( e . target . value ) ;
41
58
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 > ) => {
43
68
changePeriodDay ( e . target . value as PeriodDay ) ;
44
69
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
+
45
78
return (
46
79
< div className = "w-full md:w-auto flex items-center justify-center space-x-3" >
47
80
< div className = "pb-6" >
0 commit comments