@bytebrand/fe-ui-core 4.1.21 → 4.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useEffect, useState, SyntheticEvent } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
|
|
4
4
|
import RangeControlled from '../common/RangeControlled/RangeControlled';
|
|
@@ -6,7 +6,7 @@ import Rate from './Rate';
|
|
|
6
6
|
import { RadioGroup } from '@mui/material';
|
|
7
7
|
import CheckboxMaterial from '../../_common/CheckboxMaterial/CheckboxMaterial';
|
|
8
8
|
|
|
9
|
-
import { COST_TYPE_OPTIONS
|
|
9
|
+
import { COST_TYPE_OPTIONS } from '../../../framework/constants/Search';
|
|
10
10
|
|
|
11
11
|
import styles from './Cost.styl';
|
|
12
12
|
|
|
@@ -18,48 +18,39 @@ interface ICostProps {
|
|
|
18
18
|
onChangeControls: (name: string, value: any) => void;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
interface ICostState {
|
|
22
|
-
costType: string;
|
|
23
|
-
isRateWidgetOpened: boolean;
|
|
24
|
-
}
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.state = {
|
|
30
|
-
costType: COST_TYPE_DEFAULT,
|
|
31
|
-
isRateWidgetOpened: false
|
|
32
|
-
};
|
|
33
|
-
}
|
|
22
|
+
const Cost = ({ t, onChange, onChangeControls, RATE, PRICE }: ICostProps) => {
|
|
23
|
+
const [costType, setCostType] = useState(null);
|
|
24
|
+
const [isRateWidgetOpened, setRateWidgetOpened] = useState(false);
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
// if rate is not assigned and price is set - choose initial 'price' radio
|
|
28
|
+
if (!costType && (PRICE.controls.to || PRICE.controls.from))
|
|
29
|
+
setCostType(
|
|
30
|
+
(!!PRICE.controls.from || !!PRICE.controls.to)
|
|
31
|
+
&& RATE.controls.monthlyInstallmentFrom === 'any'
|
|
32
|
+
&& RATE.controls.monthlyInstallmentTo === 'any'
|
|
33
|
+
? COST_TYPE_OPTIONS[1]
|
|
34
|
+
: COST_TYPE_OPTIONS[0]);
|
|
35
|
+
}, [PRICE.controls.to, PRICE.controls.from])
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
this.setState({ isRateWidgetOpened: true });
|
|
41
|
-
}
|
|
37
|
+
const onTypeChange = (_event: SyntheticEvent, value: string) => { setCostType(value) };
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
this.setState({ isRateWidgetOpened: false });
|
|
45
|
-
}
|
|
39
|
+
const onRateWidgetOpen = () => { setRateWidgetOpened(true) }
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
const { onChange } = this.props;
|
|
41
|
+
const onRateWidgetClose = () => { setRateWidgetOpened(false) }
|
|
49
42
|
|
|
43
|
+
const onRateChange = (value: any) => {
|
|
50
44
|
onChange('RATE', value);
|
|
51
|
-
|
|
45
|
+
onRateWidgetClose();
|
|
52
46
|
};
|
|
53
47
|
|
|
54
|
-
renderRadioGroup = () => {
|
|
55
|
-
const { t } = this.props;
|
|
56
|
-
const { costType } = this.state;
|
|
57
|
-
|
|
48
|
+
const renderRadioGroup = () => {
|
|
58
49
|
const radioGroupProps = {
|
|
59
50
|
value: costType,
|
|
60
51
|
name: 'COST_TYPE',
|
|
61
52
|
className: styles.radioGroup,
|
|
62
|
-
onChange:
|
|
53
|
+
onChange: onTypeChange
|
|
63
54
|
};
|
|
64
55
|
|
|
65
56
|
return (
|
|
@@ -71,23 +62,21 @@ class Cost extends React.Component<ICostProps, ICostState> {
|
|
|
71
62
|
);
|
|
72
63
|
};
|
|
73
64
|
|
|
74
|
-
renderRate = () => {
|
|
75
|
-
const { t, RATE } = this.props;
|
|
65
|
+
const renderRate = () => {
|
|
76
66
|
const rateProps = {
|
|
77
67
|
t,
|
|
78
68
|
values: RATE.values,
|
|
79
69
|
controls: RATE.controls,
|
|
80
|
-
isRateWidgetOpened
|
|
81
|
-
onRateWidgetOpen
|
|
82
|
-
onRateWidgetClose
|
|
83
|
-
onRateChange
|
|
70
|
+
isRateWidgetOpened,
|
|
71
|
+
onRateWidgetOpen,
|
|
72
|
+
onRateWidgetClose,
|
|
73
|
+
onRateChange
|
|
84
74
|
};
|
|
85
75
|
|
|
86
76
|
return <Rate {...rateProps} />;
|
|
87
77
|
};
|
|
88
78
|
|
|
89
|
-
renderPrice = () => {
|
|
90
|
-
const { t, PRICE, onChange, onChangeControls } = this.props;
|
|
79
|
+
const renderPrice = () => {
|
|
91
80
|
|
|
92
81
|
const priceProps = {
|
|
93
82
|
t,
|
|
@@ -100,26 +89,22 @@ class Cost extends React.Component<ICostProps, ICostState> {
|
|
|
100
89
|
controls: PRICE.controls,
|
|
101
90
|
isNumberWithDot: true
|
|
102
91
|
};
|
|
103
|
-
|
|
104
92
|
return <RangeControlled {...priceProps} />;
|
|
105
93
|
};
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
const { t } = this.props;
|
|
109
|
-
const { costType } = this.state;
|
|
110
|
-
const containerClassName = classnames(styles.cost, { [styles.overlay]: this.state.isRateWidgetOpened });
|
|
95
|
+
const containerClassName = classnames(styles.cost, { [styles.overlay]: isRateWidgetOpened });
|
|
111
96
|
const title = costType === 'price' ? t('filters.priceTitle', { currency: '€' }) : t('filters.rateTitle');
|
|
112
97
|
|
|
113
98
|
return (
|
|
114
99
|
<div className={containerClassName}>
|
|
115
100
|
<div className={styles.title}>
|
|
116
101
|
<h3 className={styles.titleText}>{title}</h3>
|
|
117
|
-
{
|
|
102
|
+
{renderRadioGroup()}
|
|
118
103
|
</div>
|
|
119
|
-
{costType === 'price' ?
|
|
104
|
+
{costType === 'price' ? renderPrice() : renderRate()}
|
|
120
105
|
</div>
|
|
121
106
|
);
|
|
122
|
-
|
|
107
|
+
|
|
123
108
|
}
|
|
124
109
|
|
|
125
110
|
export default Cost;
|
|
@@ -278,8 +278,10 @@ const getDecoratedLightProps = (
|
|
|
278
278
|
|
|
279
279
|
if (moment.utc(offerAvailabilityTimestamp, 'X').isBefore()) {
|
|
280
280
|
offerAvailability = t('cbd:selector_availabilityMode_always');
|
|
281
|
-
} else {
|
|
281
|
+
} else if (!!offerAvailabilityTimestamp) {
|
|
282
282
|
offerAvailability = t('vehicleProps:value.fromDate', { date: humanViewTime });
|
|
283
|
+
} else {
|
|
284
|
+
offerAvailability = t('vehicleProps:value.onRequest'); // case when "availabilityFrom" is undefined
|
|
283
285
|
}
|
|
284
286
|
break;
|
|
285
287
|
|