2022-02-23 20:03:46 +01:00
import PropTypes from 'prop-types' ;
2023-05-28 16:38:10 +02:00
import { PureComponent } from 'react' ;
2022-02-23 20:03:46 +01:00
import { injectIntl , defineMessages , FormattedMessage } from 'react-intl' ;
2023-05-28 16:38:10 +02:00
2022-02-23 20:03:46 +01:00
import Toggle from 'react-toggle' ;
2023-05-28 16:38:10 +02:00
import Button from 'flavours/glitch/components/button' ;
2022-02-23 20:03:46 +01:00
const messages = defineMessages ( {
placeholder : { id : 'report.placeholder' , defaultMessage : 'Type or paste additional comments' } ,
} ) ;
2023-05-28 14:18:23 +02:00
class Comment extends PureComponent {
2022-02-23 20:03:46 +01:00
static propTypes = {
onSubmit : PropTypes . func . isRequired ,
comment : PropTypes . string . isRequired ,
onChangeComment : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
isSubmitting : PropTypes . bool ,
forward : PropTypes . bool ,
isRemote : PropTypes . bool ,
domain : PropTypes . string ,
onChangeForward : PropTypes . func . isRequired ,
} ;
handleClick = ( ) => {
const { onSubmit } = this . props ;
onSubmit ( ) ;
} ;
handleChange = e => {
const { onChangeComment } = this . props ;
onChangeComment ( e . target . value ) ;
} ;
handleKeyDown = e => {
if ( e . keyCode === 13 && ( e . ctrlKey || e . metaKey ) ) {
this . handleClick ( ) ;
}
} ;
handleForwardChange = e => {
const { onChangeForward } = this . props ;
onChangeForward ( e . target . checked ) ;
} ;
render ( ) {
const { comment , isRemote , forward , domain , isSubmitting , intl } = this . props ;
return (
2023-05-28 14:56:24 +02:00
< >
2022-02-23 20:03:46 +01:00
< h3 className = 'report-dialog-modal__title' > < FormattedMessage id = 'report.comment.title' defaultMessage = 'Is there anything else you think we should know?' / > < / h3 >
< textarea
className = 'report-dialog-modal__textarea'
placeholder = { intl . formatMessage ( messages . placeholder ) }
value = { comment }
onChange = { this . handleChange }
onKeyDown = { this . handleKeyDown }
disabled = { isSubmitting }
/ >
{ isRemote && (
2023-05-28 14:56:24 +02:00
< >
2022-02-23 20:03:46 +01:00
< p className = 'report-dialog-modal__lead' > < FormattedMessage id = 'report.forward_hint' defaultMessage = 'The account is from another server. Send an anonymized copy of the report there as well?' / > < / p >
< label className = 'report-dialog-modal__toggle' >
< Toggle checked = { forward } disabled = { isSubmitting } onChange = { this . handleForwardChange } / >
< FormattedMessage id = 'report.forward' defaultMessage = 'Forward to {target}' values = { { target : domain } } / >
< / label >
2023-05-28 14:56:24 +02:00
< / >
2022-02-23 20:03:46 +01:00
) }
< div className = 'flex-spacer' / >
< div className = 'report-dialog-modal__actions' >
2022-02-27 07:37:00 +01:00
< Button onClick = { this . handleClick } disabled = { isSubmitting } > < FormattedMessage id = 'report.submit' defaultMessage = 'Submit report' / > < / Button >
2022-02-23 20:03:46 +01:00
< / div >
2023-05-28 14:56:24 +02:00
< / >
2022-02-23 20:03:46 +01:00
) ;
}
}
2023-03-24 23:15:25 +01:00
export default injectIntl ( Comment ) ;