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

98 lines
2.5 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
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
class ConfirmationModal extends React.PureComponent {
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 (
<div className={_s.w330PX}>
2020-03-11 23:56:18 +00:00
<Block>
<div className={[_s.d, _s.px15, _s.py15].join(' ')}>
<div className={[_s.d, _s.px15, _s.py15].join(' ')}>
2020-03-11 23:56:18 +00:00
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.d, _s.mt10].join(' ')}>
2020-03-11 23:56:18 +00:00
<Text align='center' color='secondary'>
{message}
</Text>
<div className={[_s.d, _s.flexRow, _s.mt10, _s.pt10].join(' ')}>
2020-03-11 23:56:18 +00:00
<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
}
}
ConfirmationModal.propTypes = {
title: PropTypes.any.isRequired,
message: PropTypes.any.isRequired,
confirm: PropTypes.any.isRequired,
onClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
onCancel: PropTypes.func,
}
export default injectIntl(ConfirmationModal)