2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
|
|
|
import FormField from 'component/formField';
|
2017-08-07 00:24:55 +02:00
|
|
|
|
|
|
|
class FormFieldPrice extends React.PureComponent {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2017-12-21 22:08:54 +01:00
|
|
|
amount: props.defaultValue && props.defaultValue.amount ? props.defaultValue.amount : '',
|
2017-11-24 15:31:05 +01:00
|
|
|
currency:
|
2017-12-21 22:08:54 +01:00
|
|
|
props.defaultValue && props.defaultValue.currency ? props.defaultValue.currency : 'LBC',
|
2017-08-07 00:24:55 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-07 18:15:53 +02:00
|
|
|
handleChange(newValues) {
|
|
|
|
const newState = Object.assign({}, this.state, newValues);
|
|
|
|
this.setState(newState);
|
2017-08-07 00:24:55 +02:00
|
|
|
this.props.onChange({
|
2017-08-07 18:15:53 +02:00
|
|
|
amount: newState.amount,
|
|
|
|
currency: newState.currency,
|
2017-08-07 00:24:55 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFeeAmountChange(event) {
|
2017-08-07 18:15:53 +02:00
|
|
|
this.handleChange({
|
|
|
|
amount: event.target.value ? Number(event.target.value) : null,
|
|
|
|
});
|
2017-08-07 00:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleFeeCurrencyChange(event) {
|
2017-08-07 18:15:53 +02:00
|
|
|
this.handleChange({ currency: event.target.value });
|
2017-08-07 00:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-09-29 22:51:36 +02:00
|
|
|
const { defaultValue, placeholder, min } = this.props;
|
2017-08-07 00:24:55 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<span className="form-field">
|
|
|
|
<FormField
|
|
|
|
type="number"
|
|
|
|
name="amount"
|
|
|
|
min={min}
|
|
|
|
placeholder={placeholder || null}
|
2017-12-21 22:08:54 +01:00
|
|
|
step="any" // Unfortunately, you cannot set a step without triggering validation that enforces a multiple of the step
|
2017-08-07 00:24:55 +02:00
|
|
|
onChange={event => this.handleFeeAmountChange(event)}
|
2017-12-21 22:08:54 +01:00
|
|
|
defaultValue={defaultValue && defaultValue.amount ? defaultValue.amount : ''}
|
2017-08-07 00:24:55 +02:00
|
|
|
className="form-field__input--inline"
|
|
|
|
/>
|
|
|
|
<FormField
|
|
|
|
type="select"
|
|
|
|
name="currency"
|
|
|
|
onChange={event => this.handleFeeCurrencyChange(event)}
|
2017-12-21 22:08:54 +01:00
|
|
|
defaultValue={defaultValue && defaultValue.currency ? defaultValue.currency : ''}
|
2017-08-07 00:24:55 +02:00
|
|
|
className="form-field__input--inline"
|
|
|
|
>
|
2017-12-21 22:08:54 +01:00
|
|
|
<option value="LBC">{__('LBRY Credits (LBC)')}</option>
|
|
|
|
<option value="USD">{__('US Dollars')}</option>
|
2017-08-07 00:24:55 +02:00
|
|
|
</FormField>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FormFieldPrice;
|