2018-04-07 00:29:51 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-03-22 00:03:30 +01:00
|
|
|
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,
|
2020-01-07 21:10:44 +01:00
|
|
|
}
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2020-01-07 21:10:44 +01:00
|
|
|
}
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAmountFormRow() {
|
|
|
|
const { children, errorType = '', label, showError = false } = this.props
|
|
|
|
const formField = Array.isArray(children)
|
|
|
|
? children[1] || children[0]
|
|
|
|
: children
|
2018-04-30 18:03:49 +02:00
|
|
|
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>
|
|
|
|
{showError && <SendRowErrorMessage errorType={errorType} />}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderFormRow() {
|
|
|
|
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]
|
|
|
|
: children
|
|
|
|
const customLabelContent =
|
|
|
|
(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}
|
|
|
|
{showError && <SendRowErrorMessage errorType={errorType} />}
|
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>
|
2018-04-27 02:38:14 +02:00
|
|
|
)
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
|
|
|
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()
|
|
|
|
: this.renderFormRow()
|
2019-05-20 18:38:08 +02:00
|
|
|
}
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|