import * as React from 'react'; import { Colors } from '../../models/colors'; import { Query } from '../../models/query'; import { SliderProps } from '../../containers/slider/Slider'; import SliderOne from '../../components/sliders/slider-one/SliderOne'; import InputWithCurrency from '../../components/common-inputs/input-with-currency/InputWithCurrency'; import { wrapperStyle, footerStyle } from './amountPeriodSliders.style'; import { connect } from 'react-redux'; interface AmountPeriodSlidersProps { name: string; palette?: Colors; automationName?: string; query?: Query; value?: { term?: number; amount?: number }; slider?: React.ReactElement; onChange?: (name: string, value: any) => void; getConfig?: (name: string | string[]) => { [key: string]: any }; translator?: Function; checkIfTranslateExist?: Function; } class AmountPeriodSlider extends React.Component { shouldComponentUpdate(nextProps: AmountPeriodSlidersProps) { return this.props.value !== nextProps.value || this.props.query !== nextProps.query; } onChange = (name: string, value: string) => { let sliderData = this.props.value; this.props.onChange(this.props.name, Object.assign({}, sliderData, { [name]: value })); }; render() { const { minPeriod, maxPeriod, periodStep, initialPeriod, minAmount, maxAmount, amountStep, initialAmount, currency } = this.props.getConfig([ 'minPeriod', 'maxPeriod', 'periodStep', 'initialPeriod', 'minAmount', 'maxAmount', 'amountStep', 'initialAmount', 'currency' ]); const { amount, term } = this.props.value || { amount: initialAmount, term: initialPeriod }; const AmountSlider = React.cloneElement(this.props.slider || , { label: this.props.translator(`${this.props.name}.amount.label`), errorMessage: { min: this.props.translator(`${this.props.name}.amount.errorMessage.min`, { value: minAmount.toLocaleString() }), max: this.props.translator(`${this.props.name}.amount.errorMessage.max`, { value: maxAmount.toLocaleString() }) }, onChange: this.onChange, name: 'amount', palette: this.props.palette, value: amount, sliderData: { min: minAmount, max: maxAmount, step: amountStep, initialValue: initialAmount }, footerFormatter: (value: number) => value.toLocaleString(), input: , query: this.props.query, translator: this.props.translator }); const PeriodSlider = React.cloneElement(this.props.slider || , { label: this.props.translator(`${this.props.name}.term.label`), errorMessage: { min: this.props.translator(`${this.props.name}.term.errorMessage.min`, { value: minPeriod.toLocaleString() }), max: this.props.translator(`${this.props.name}.term.errorMessage.max`, { value: maxPeriod.toLocaleString() }) }, onChange: this.onChange, name: 'term', palette: this.props.palette, value: term, sliderData: { min: minPeriod, max: maxPeriod, step: periodStep, initialValue: initialPeriod }, footerFormatter: (value: number) => value, query: this.props.query, translator: this.props.translator }); return (
{AmountSlider} {PeriodSlider}
); } } export default AmountPeriodSlider;