|
1 | 1 | import React from 'react';
|
2 |
| -import StdcmSingleAllowance from 'applications/stdcm/components/OldAllowances/withOSRDStdcmParams'; |
| 2 | +import { useDispatch, useSelector } from 'react-redux'; |
| 3 | + |
3 | 4 | import { useTranslation } from 'react-i18next';
|
4 | 5 |
|
| 6 | +import StdcmSingleAllowance from 'applications/stdcm/components/OldAllowances/withOSRDStdcmParams'; |
| 7 | +import InputSNCF from 'common/BootstrapSNCF/InputSNCF'; |
| 8 | +import InputGroupSNCF, { InputGroupSNCFValue } from 'common/BootstrapSNCF/InputGroupSNCF'; |
| 9 | + |
| 10 | +import { |
| 11 | + getGridMarginBefore, |
| 12 | + getGridMarginAfter, |
| 13 | + getStandardStdcmAllowance, |
| 14 | +} from 'reducers/osrdconf/selectors'; |
| 15 | +import { |
| 16 | + updateGridMarginAfter, |
| 17 | + updateGridMarginBefore, |
| 18 | + updateStdcmStandardAllowance, |
| 19 | +} from 'reducers/osrdconf'; |
| 20 | +import { StandardAllowance } from 'applications/operationalStudies/consts'; |
| 21 | +import { AllowanceValue } from 'common/api/osrdEditoastApi'; |
| 22 | +import { ALLOWANCE_UNITS_KEYS } from './OldAllowances/allowancesConsts'; |
| 23 | + |
| 24 | +// const STDCMAllowances = () => { |
| 25 | +// const { t } = useTranslation('allowances'); |
| 26 | + |
| 27 | +// return ( |
| 28 | +// <div className="osrd-config-item mb-2 osrd-config-item-container"> |
| 29 | +// <div className="row"> |
| 30 | +// <div className="col-6"> |
| 31 | +// <div>{t('allowances:gridMarginBeforeAfter')}</div> |
| 32 | +// <div className="row"> |
| 33 | +// <div className="col-6"> |
| 34 | +// <StdcmSingleAllowance typeKey="gridMarginBefore" isCondensed /> |
| 35 | +// </div> |
| 36 | +// <div className="col-6"> |
| 37 | +// <StdcmSingleAllowance typeKey="gridMarginAfter" isCondensed /> |
| 38 | +// </div> |
| 39 | +// </div> |
| 40 | +// </div> |
| 41 | +// <div className="col-6"> |
| 42 | +// <div>{t('allowances:standardAllowance')}</div> |
| 43 | +// <StdcmSingleAllowance typeKey="standardStdcmAllowance" isCondensed /> |
| 44 | +// </div> |
| 45 | +// </div> |
| 46 | +// </div> |
| 47 | +// ); |
| 48 | +// }; |
| 49 | + |
5 | 50 | const STDCMAllowances = () => {
|
6 | 51 | const { t } = useTranslation('allowances');
|
| 52 | + const dispatch = useDispatch(); |
| 53 | + const gridMarginBefore = useSelector(getGridMarginBefore); |
| 54 | + const gridMarginAfter = useSelector(getGridMarginAfter); |
| 55 | + const stdcmStandardAllowance = useSelector(getStandardStdcmAllowance); |
| 56 | + const standardAllowanceTypes = [ |
| 57 | + { |
| 58 | + id: 'percentage', |
| 59 | + label: t ? t('allowanceTypes.percentage') : '', |
| 60 | + unit: ALLOWANCE_UNITS_KEYS.percentage, |
| 61 | + }, |
| 62 | + { |
| 63 | + id: 'time_per_distance', |
| 64 | + label: t ? t('allowanceTypes.time_per_distance') : '', |
| 65 | + unit: ALLOWANCE_UNITS_KEYS.time_per_distance, |
| 66 | + }, |
| 67 | + ]; |
| 68 | + |
| 69 | + const onchangeType = (newTypeValue: InputGroupSNCFValue) => { |
| 70 | + if (newTypeValue.type == null) return; |
| 71 | + const processedType: StandardAllowance = { |
| 72 | + type: newTypeValue.type as AllowanceValue['value_type'], |
| 73 | + value: |
| 74 | + newTypeValue.value === '' || newTypeValue.value === undefined ? 0 : +newTypeValue.value, |
| 75 | + }; |
| 76 | + |
| 77 | + dispatch(updateStdcmStandardAllowance(processedType)); |
| 78 | + }; |
7 | 79 |
|
8 | 80 | return (
|
9 |
| - <div className="osrd-config-item mb-2 osrd-config-item-container"> |
10 |
| - <div className="row"> |
11 |
| - <div className="col-6"> |
12 |
| - <div>{t('allowances:gridMarginBeforeAfter')}</div> |
13 |
| - <div className="row"> |
14 |
| - <div className="col-6"> |
15 |
| - <StdcmSingleAllowance typeKey="gridMarginBefore" isCondensed /> |
16 |
| - </div> |
17 |
| - <div className="col-6"> |
18 |
| - <StdcmSingleAllowance typeKey="gridMarginAfter" isCondensed /> |
19 |
| - </div> |
| 81 | + <div className="row osrd-config-item mb-2 osrd-config-item-container"> |
| 82 | + <div className="col-6"> |
| 83 | + <label htmlFor="gridMarginBeforeAfter">{t('allowances:gridMarginBeforeAfter')}</label> |
| 84 | + <div id="gridMarginBeforeAfter" className="row"> |
| 85 | + <div className="col-6"> |
| 86 | + <InputSNCF |
| 87 | + id="standardAllowanceTypeGridMarginBefore" |
| 88 | + type="text" |
| 89 | + value={gridMarginBefore} |
| 90 | + unit={ALLOWANCE_UNITS_KEYS.time} |
| 91 | + condensed |
| 92 | + onChange={(e) => dispatch(updateGridMarginBefore(+e.target.value || 0))} |
| 93 | + sm |
| 94 | + noMargin |
| 95 | + /> |
| 96 | + </div> |
| 97 | + <div className="col-6"> |
| 98 | + <InputSNCF |
| 99 | + id="standardAllowanceTypeGridMarginAfter" |
| 100 | + type="text" |
| 101 | + value={gridMarginAfter} |
| 102 | + unit={ALLOWANCE_UNITS_KEYS.time} |
| 103 | + condensed |
| 104 | + onChange={(e) => dispatch(updateGridMarginAfter(+e.target.value || 0))} |
| 105 | + sm |
| 106 | + noMargin |
| 107 | + /> |
20 | 108 | </div>
|
21 | 109 | </div>
|
22 |
| - <div className="col-6"> |
23 |
| - <div>{t('allowances:standardAllowance')}</div> |
24 |
| - <StdcmSingleAllowance typeKey="standardStdcmAllowance" isCondensed /> |
25 |
| - </div> |
| 110 | + </div> |
| 111 | + <div className="col-6"> |
| 112 | + <label htmlFor="standardAllowanceTypeSelect">{t('allowances:standardAllowance')}</label> |
| 113 | + <InputGroupSNCF |
| 114 | + id="standardAllowanceTypeSelect" |
| 115 | + options={standardAllowanceTypes} |
| 116 | + handleType={onchangeType} |
| 117 | + value={stdcmStandardAllowance?.value || 0} |
| 118 | + type={stdcmStandardAllowance?.type || ''} |
| 119 | + condensed |
| 120 | + sm |
| 121 | + /> |
26 | 122 | </div>
|
27 | 123 | </div>
|
28 | 124 | );
|
|
0 commit comments