@@ -8,60 +8,40 @@ import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
8
8
import type { StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf' ;
9
9
import type { StdcmPathStep } from 'reducers/osrdconf/types' ;
10
10
import { useAppDispatch } from 'store' ;
11
- import { formatDateString , isArrivalDateInSearchTimeWindow } from 'utils/date' ;
11
+ import { dateToHHMMSS , formatDateString } from 'utils/date' ;
12
12
import { createStringSelectOptions } from 'utils/uiCoreHelpers' ;
13
13
14
14
import type { ArrivalTimeTypes , ScheduleConstraint } from '../../types' ;
15
15
16
16
type StdcmOpScheduleProps = {
17
17
disabled : boolean ;
18
18
pathStep : Extract < StdcmPathStep , { isVia : false } > ;
19
- opTimingData ?: {
20
- date : Date ;
21
- arrivalDate : string ;
22
- arrivalTime : string ;
23
- arrivalTimeHours : number ;
24
- arrivalTimeMinutes : number ;
25
- } ;
26
19
opId : string ;
27
20
isOrigin ?: boolean ;
28
21
} ;
29
22
30
- const defaultDate = ( date ?: Date ) => {
31
- const newDate = date ? new Date ( date ) : new Date ( ) ;
32
- newDate . setHours ( 0 , 0 , 0 ) ;
33
- return newDate ;
34
- } ;
35
-
36
- const StdcmOpSchedule = ( {
37
- disabled,
38
- pathStep,
39
- opTimingData,
40
- opId,
41
- isOrigin = false ,
42
- } : StdcmOpScheduleProps ) => {
23
+ const StdcmOpSchedule = ( { disabled, pathStep, opId, isOrigin = false } : StdcmOpScheduleProps ) => {
43
24
const { t } = useTranslation ( 'stdcm' ) ;
44
25
const dispatch = useAppDispatch ( ) ;
45
26
46
27
const { updateStdcmPathStep } = useOsrdConfActions ( ) as StdcmConfSliceActions ;
47
28
const { getSearchDatetimeWindow } = useOsrdConfSelectors ( ) ;
48
29
const searchDatetimeWindow = useSelector ( getSearchDatetimeWindow ) ;
49
30
50
- const { arrivalDate, arrivalTime, arrivalTimeHours, arrivalTimeMinutes } = useMemo ( ( ) => {
51
- const isArrivalDateValid =
52
- opTimingData ?. arrivalDate &&
53
- isArrivalDateInSearchTimeWindow ( opTimingData . date , searchDatetimeWindow ) ;
54
-
31
+ const { arrivalTime, arrivalTimeHours, arrivalTimeMinutes } = useMemo ( ( ) => {
32
+ if ( ! pathStep . arrival ) {
33
+ return {
34
+ arrivalTime : undefined ,
35
+ arrivalTimeHours : undefined ,
36
+ arrivalTimeMinutes : undefined ,
37
+ } ;
38
+ }
55
39
return {
56
- arrivalDate :
57
- opTimingData && isArrivalDateValid
58
- ? opTimingData . date
59
- : defaultDate ( searchDatetimeWindow ?. begin ) ,
60
- arrivalTime : opTimingData ?. arrivalTime ,
61
- arrivalTimeHours : opTimingData ?. arrivalTimeHours ,
62
- arrivalTimeMinutes : opTimingData ?. arrivalTimeMinutes ,
40
+ arrivalTime : dateToHHMMSS ( pathStep . arrival , { withoutSeconds : true } ) ,
41
+ arrivalTimeHours : pathStep . arrival . getHours ( ) ,
42
+ arrivalTimeMinutes : pathStep . arrival . getMinutes ( ) ,
63
43
} ;
64
- } , [ opTimingData , searchDatetimeWindow ] ) ;
44
+ } , [ pathStep . arrival ] ) ;
65
45
66
46
const tolerances = useMemo (
67
47
( ) => ( {
@@ -94,11 +74,12 @@ const StdcmOpSchedule = ({
94
74
) ;
95
75
96
76
const onArrivalChange = ( { date, hours, minutes } : ScheduleConstraint ) => {
97
- date . setHours ( hours , minutes ) ;
77
+ const newDate = new Date ( date ) ;
78
+ newDate . setHours ( hours , minutes ) ;
98
79
dispatch (
99
80
updateStdcmPathStep ( {
100
81
id : pathStep . id ,
101
- updates : { arrival : date } ,
82
+ updates : { arrival : newDate } ,
102
83
} )
103
84
) ;
104
85
} ;
@@ -137,7 +118,7 @@ const StdcmOpSchedule = ({
137
118
disabled,
138
119
} }
139
120
selectableSlot = { selectableSlot }
140
- value = { arrivalDate }
121
+ value = { pathStep . arrival }
141
122
onDateChange = { ( e ) => {
142
123
onArrivalChange ( {
143
124
date : e ,
@@ -153,7 +134,11 @@ const StdcmOpSchedule = ({
153
134
hours = { arrivalTimeHours }
154
135
minutes = { arrivalTimeMinutes }
155
136
onTimeChange = { ( { hours, minutes } ) => {
156
- onArrivalChange ( { date : arrivalDate , hours, minutes } ) ;
137
+ onArrivalChange ( {
138
+ date : pathStep . arrival || searchDatetimeWindow ! . begin ,
139
+ hours,
140
+ minutes,
141
+ } ) ;
157
142
} }
158
143
disabled = { disabled }
159
144
value = { arrivalTime }
0 commit comments