forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout-button.js
51 lines (44 loc) · 1.36 KB
/
checkout-button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import {EnableableOperationPropType} from '../prop-types';
import {checkoutStates} from '../controllers/pr-checkout-controller';
export default class CheckoutButton extends React.Component {
static propTypes = {
checkoutOp: EnableableOperationPropType.isRequired,
classNamePrefix: PropTypes.string.isRequired,
classNames: PropTypes.array,
}
render() {
const {checkoutOp} = this.props;
const extraClasses = this.props.classNames || [];
let buttonText = 'Checkout';
let buttonTitle = null;
if (!checkoutOp.isEnabled()) {
buttonTitle = checkoutOp.getMessage();
const reason = checkoutOp.why();
if (reason === checkoutStates.HIDDEN) {
return null;
}
buttonText = reason.when({
current: 'Checked out',
default: 'Checkout',
});
extraClasses.push(this.props.classNamePrefix + reason.when({
disabled: 'disabled',
busy: 'busy',
current: 'current',
}));
}
const classNames = cx('btn', 'btn-primary', 'checkoutButton', ...extraClasses);
return (
<button
className={classNames}
disabled={!checkoutOp.isEnabled()}
title={buttonTitle}
onClick={() => checkoutOp.run()}>
{buttonText}
</button>
);
}
}