gab-social/app/javascript/gabsocial/components/modal/confirmation_modal.js

97 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-02-24 23:25:55 +00:00
import { injectIntl, FormattedMessage } from 'react-intl'
2020-03-11 23:56:18 +00:00
import Block from '../block'
2020-02-24 23:25:55 +00:00
import Button from '../button'
2020-03-11 23:56:18 +00:00
import Heading from '../heading'
import Text from '../text'
2019-07-02 08:10:25 +01:00
2020-02-24 23:25:55 +00:00
export default
@injectIntl
class ConfirmationModal extends PureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
2020-05-02 07:25:55 +01:00
title: PropTypes.any.isRequired,
message: PropTypes.any.isRequired,
confirm: PropTypes.any.isRequired,
2019-07-02 08:10:25 +01:00
onClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
onCancel: PropTypes.func,
2020-02-24 23:25:55 +00:00
}
2019-07-02 08:10:25 +01:00
componentDidMount() {
2020-02-24 23:25:55 +00:00
this.button.focus()
2019-07-02 08:10:25 +01:00
}
handleClick = () => {
2020-02-24 23:25:55 +00:00
this.props.onClose()
this.props.onConfirm()
2019-07-02 08:10:25 +01:00
}
handleCancel = () => {
2020-03-11 23:56:18 +00:00
const { onClose, onCancel } = this.props
2020-02-24 23:25:55 +00:00
onClose()
if (onCancel) onCancel()
2019-07-02 08:10:25 +01:00
}
setRef = (c) => {
2020-02-24 23:25:55 +00:00
this.button = c
2019-07-02 08:10:25 +01:00
}
2020-03-11 23:56:18 +00:00
render() {
const {
title,
message,
confirm,
} = this.props
2019-07-02 08:10:25 +01:00
return (
2020-03-11 23:56:18 +00:00
<div className={_s.width330PX}>
<Block>
<div className={[_s.default, _s.px15, _s.py15].join(' ')}>
<div className={[_s.default, _s.px15, _s.py15].join(' ')}>
2020-04-23 07:13:29 +01:00
<Heading size='h1' isCentered>
2020-03-11 23:56:18 +00:00
{title}
</Heading>
<div className={[_s.default, _s.mt10].join(' ')}>
<Text align='center' color='secondary'>
{message}
</Text>
<div className={[_s.default, _s.flexRow, _s.mt10, _s.pt10].join(' ')}>
<Button
backgroundColor='tertiary'
color='primary'
onClick={this.handleCancel}
className={[_s.mr10, _s.flexGrow1].join(' ')}
>
2020-05-03 06:22:49 +01:00
<Text size='medium' weight='bold' align='center' color='inherit'>
2020-03-11 23:56:18 +00:00
<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
</Text>
</Button>
2020-05-03 06:22:49 +01:00
2020-03-11 23:56:18 +00:00
<Button
backgroundColor='brand'
color='white'
onClick={this.handleClick}
ref={this.setRef}
className={_s.flexGrow1}
>
2020-05-03 06:22:49 +01:00
<Text size='medium' weight='bold' align='center' color='inherit'>
2020-03-11 23:56:18 +00:00
{confirm}
</Text>
</Button>
</div>
</div>
</div>
</div>
</Block>
2019-07-02 08:10:25 +01:00
</div>
2020-02-24 23:25:55 +00:00
)
2019-07-02 08:10:25 +01:00
}
}