1 import PropTypes from 'prop-types';
2 import React, { useState } from 'react';
3 import { Button } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
6 import ReportDialog from './ReportDialog';
7 import Icon from '../common/Icon';
8 import { findResult } from '../../helpers/User';
9 import i18n from '../../i18n';
11 const getButtonLabel = (user, round) => {
12 const result = findResult(user, round);
14 if (result && result.comment) {
15 return i18n.t('results.editComment');
17 return i18n.t('results.addComment');
20 if (result && (result.time || result.forfeit)) {
21 return i18n.t('results.edit');
23 return i18n.t('results.report');
28 const ReportButton = ({ round, user }) => {
29 const [showDialog, setShowDialog] = useState(false);
31 if (round.locked && !findResult(user, round)) {
37 onClick={() => setShowDialog(true)}
40 {getButtonLabel(user, round)}
42 <Icon.EDIT title="" />
45 onHide={() => setShowDialog(false)}
53 ReportButton.propTypes = {
54 round: PropTypes.shape({
55 locked: PropTypes.bool,
57 tournament: PropTypes.shape({
59 user: PropTypes.shape({
63 export default withTranslation()(ReportButton);