2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import SendRowErrorMessage from './send-row-error-message';
|
2018-04-07 00:29:51 +02:00
|
|
|
|
|
|
|
export default class SendRowWrapper extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
errorType: PropTypes.string,
|
2018-04-27 02:38:14 +02:00
|
|
|
label: PropTypes.string,
|
|
|
|
showError: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAmountFormRow() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { children, errorType = '', label, showError = false } = this.props;
|
2020-11-03 00:41:28 +01:00
|
|
|
const formField = Array.isArray(children)
|
|
|
|
? children[1] || children[0]
|
2021-02-04 19:15:23 +01:00
|
|
|
: children;
|
|
|
|
const customLabelContent = children.length > 1 ? children[0] : null;
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2018-04-07 00:29:51 +02:00
|
|
|
return (
|
|
|
|
<div className="send-v2__form-row">
|
|
|
|
<div className="send-v2__form-label">
|
2018-12-14 03:19:36 +01:00
|
|
|
{label}
|
2019-05-20 18:38:08 +02:00
|
|
|
{customLabelContent}
|
|
|
|
</div>
|
|
|
|
<div className="send-v2__form-field-container">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="send-v2__form-field">{formField}</div>
|
2019-05-20 18:38:08 +02:00
|
|
|
<div>
|
2021-10-21 18:11:31 +02:00
|
|
|
{showError ? <SendRowErrorMessage errorType={errorType} /> : null}
|
2019-05-20 18:38:08 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-05-20 18:38:08 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderFormRow() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { children, errorType = '', label, showError = false } = this.props;
|
2019-05-20 18:38:08 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const formField = Array.isArray(children)
|
|
|
|
? children[1] || children[0]
|
2021-02-04 19:15:23 +01:00
|
|
|
: children;
|
2020-11-03 00:41:28 +01:00
|
|
|
const customLabelContent =
|
2021-02-04 19:15:23 +01:00
|
|
|
(Array.isArray(children) && children.length) > 1 ? children[0] : null;
|
2019-05-20 18:38:08 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="send-v2__form-row">
|
|
|
|
<div className="send-v2__form-label">
|
|
|
|
{label}
|
2021-10-21 18:11:31 +02:00
|
|
|
{showError ? <SendRowErrorMessage errorType={errorType} /> : null}
|
2018-12-14 03:19:36 +01:00
|
|
|
{customLabelContent}
|
2018-04-07 00:29:51 +02:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="send-v2__form-field">{formField}</div>
|
2018-04-07 00:29:51 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { errorType = '' } = this.props;
|
2019-05-20 18:38:08 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return errorType === 'amount'
|
|
|
|
? this.renderAmountFormRow()
|
2021-02-04 19:15:23 +01:00
|
|
|
: this.renderFormRow();
|
2019-05-20 18:38:08 +02:00
|
|
|
}
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|