@bytebrand/fe-ui-core 4.1.22 → 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/fe-ui-core",
3
- "version": "4.1.22",
3
+ "version": "4.1.23",
4
4
  "description": "UI components for the auto.de project",
5
5
  "main": "index.ts",
6
6
  "module": "dist/common.js",
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
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, COST_TYPE_DEFAULT } from '../../../framework/constants/Search';
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
- class Cost extends React.Component<ICostProps, ICostState> {
27
- constructor(props: ICostProps) {
28
- super(props);
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
- onTypeChange = (_event: React.SyntheticEvent, value: string) => {
36
- this.setState({ costType: value });
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
- onRateWidgetOpen = () => {
40
- this.setState({ isRateWidgetOpened: true });
41
- }
37
+ const onTypeChange = (_event: SyntheticEvent, value: string) => { setCostType(value) };
42
38
 
43
- onRateWidgetClose = () => {
44
- this.setState({ isRateWidgetOpened: false });
45
- }
39
+ const onRateWidgetOpen = () => { setRateWidgetOpened(true) }
46
40
 
47
- onRateChange = (value: any) => {
48
- const { onChange } = this.props;
41
+ const onRateWidgetClose = () => { setRateWidgetOpened(false) }
49
42
 
43
+ const onRateChange = (value: any) => {
50
44
  onChange('RATE', value);
51
- this.onRateWidgetClose();
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: this.onTypeChange
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: this.state.isRateWidgetOpened,
81
- onRateWidgetOpen: this.onRateWidgetOpen,
82
- onRateWidgetClose: this.onRateWidgetClose,
83
- onRateChange: this.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
- render(): JSX.Element {
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
- {this.renderRadioGroup()}
102
+ {renderRadioGroup()}
118
103
  </div>
119
- {costType === 'price' ? this.renderPrice() : this.renderRate()}
104
+ {costType === 'price' ? renderPrice() : renderRate()}
120
105
  </div>
121
106
  );
122
- }
107
+
123
108
  }
124
109
 
125
110
  export default Cost;
@@ -263,9 +263,7 @@ const getDecoratedLightProps = (
263
263
  get value() {
264
264
  const offerAvailabilityMode = offer.availabilityMode;
265
265
  const offerAvailabilityTimestamp = offer.availabilityFrom;
266
- console.log(`%cqqq offerAvailabilityTimestamp = `, 'font-weight: bold;color: #90ee90', offerAvailabilityTimestamp);
267
266
  const humanViewTime = moment.unix(offerAvailabilityTimestamp).format('DD.MM.YYYY');
268
- console.log(`%cqqq humanViewTime = `, 'font-weight: bold;color: #90ee90', humanViewTime);
269
267
  let offerAvailability: string;
270
268
  switch (offerAvailabilityMode) {
271
269
  case 'selector_availabilityMode_always':