]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/results/ReportButton.js
0a8c139469db478b09fde94cdd342249dba56d46
[alttp.git] / resources / js / components / results / ReportButton.js
1 import PropTypes from 'prop-types';
2 import React, { useState } from 'react';
3 import { Button } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
5
6 import ReportDialog from './ReportDialog';
7 import Icon from '../common/Icon';
8 import { findResult } from '../../helpers/Participant';
9 import i18n from '../../i18n';
10
11 const getButtonLabel = (participant, round) => {
12         const result = findResult(participant, round);
13         if (round.locked) {
14                 if (result && result.comment) {
15                         return i18n.t('results.editComment');
16                 } else {
17                         return i18n.t('results.addComment');
18                 }
19         } else {
20                 if (result && (result.time || result.forfeit)) {
21                         return i18n.t('results.edit');
22                 } else {
23                         return i18n.t('results.report');
24                 }
25         }
26 };
27
28 const ReportButton = ({ participant, round }) => {
29         const [showDialog, setShowDialog] = useState(false);
30
31         return <>
32                 <Button
33                         onClick={() => setShowDialog(true)}
34                         variant="secondary"
35                 >
36                         {getButtonLabel(participant, round)}
37                         {' '}
38                         <Icon.EDIT title="" />
39                 </Button>
40                 <ReportDialog
41                         onHide={() => setShowDialog(false)}
42                         participant={participant}
43                         round={round}
44                         show={showDialog}
45                 />
46         </>;
47 };
48
49 ReportButton.propTypes = {
50         participant: PropTypes.shape({
51         }),
52         round: PropTypes.shape({
53         }),
54         tournament: PropTypes.shape({
55         }),
56 };
57
58 export default withTranslation()(ReportButton);