-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathTrainAddingSettings.tsx
108 lines (101 loc) · 3.4 KB
/
TrainAddingSettings.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { AiOutlineNumber } from 'react-icons/ai';
import { IoFootstepsSharp } from 'react-icons/io5';
import { RxSpaceEvenlyHorizontally } from 'react-icons/rx';
import { useSelector } from 'react-redux';
import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
import {
updateTrainStep,
updateTrainCount,
updateTrainDelta,
} from 'reducers/osrdconf/operationalStudiesConf';
import {
getTrainStep,
getTrainCount,
getTrainDelta,
} from 'reducers/osrdconf/operationalStudiesConf/selectors';
import { useAppDispatch } from 'store';
import { useDebounce } from 'utils/helpers';
export default function TrainAddingSettings() {
const [trainStep, setTrainStep] = useState(useSelector(getTrainStep));
const [trainCount, setTrainCount] = useState(useSelector(getTrainCount));
const [trainDelta, setTrainDelta] = useState(useSelector(getTrainDelta));
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);
const dispatch = useAppDispatch();
const debouncedTrainStep = useDebounce(trainStep, 500);
const debouncedTrainCount = useDebounce(trainCount, 500);
const debouncedTrainDelta = useDebounce(trainDelta, 500);
useEffect(() => {
dispatch(updateTrainStep(debouncedTrainStep));
}, [debouncedTrainStep]);
useEffect(() => {
dispatch(updateTrainCount(debouncedTrainCount));
}, [debouncedTrainCount]);
useEffect(() => {
dispatch(updateTrainDelta(debouncedTrainDelta));
}, [debouncedTrainDelta]);
return (
<div className="osrd-config-item-container d-flex align-items-start">
<span className="mr-2">
<InputSNCF
type="number"
label={
<>
<IoFootstepsSharp />
<small className="text-nowrap">{t('trainScheduleStep')}</small>
</>
}
id="osrdconf-trainstep"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTrainStep(+e.target.value)}
value={trainStep}
noMargin
isInvalid={trainStep < 1}
errorMsg={trainStep < 1 ? t('errorMessages.tooLowInput') : undefined}
min={1}
sm
/>
</span>
<span className="mr-2">
<InputSNCF
type="number"
label={
<>
<AiOutlineNumber />
<small className="text-nowrap">{t('trainScheduleCount')}</small>
</>
}
id="osrdconf-traincount"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTrainCount(+e.target.value)}
value={trainCount}
noMargin
isInvalid={trainCount < 1}
errorMsg={trainCount < 1 ? t('errorMessages.tooLowInput') : undefined}
min={1}
sm
/>
</span>
<span>
<InputSNCF
type="number"
label={
<>
<RxSpaceEvenlyHorizontally />
<small className="text-nowrap">{t('trainScheduleDelta')}</small>
</>
}
id="osrdconf-delta"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTrainDelta(+e.target.value)}
value={trainDelta}
unit="min"
noMargin
isInvalid={trainDelta < 1}
errorMsg={trainDelta < 1 ? t('errorMessages.tooLowInput') : undefined}
min={1}
sm
textRight
/>
</span>
</div>
);
}