import ReportDialog from './ReportDialog';
import Icon from '../common/Icon';
-import { findResult } from '../../helpers/Participant';
+import { findResult } from '../../helpers/User';
import i18n from '../../i18n';
-const ReportButton = ({ participant, round }) => {
+const getButtonLabel = (user, round) => {
+ const result = findResult(user, round);
+ if (round.locked) {
+ if (result && result.comment) {
+ return i18n.t('results.editComment');
+ } else {
+ return i18n.t('results.addComment');
+ }
+ } else {
+ if (result && (result.time || result.forfeit)) {
+ return i18n.t('results.edit');
+ } else {
+ return i18n.t('results.report');
+ }
+ }
+};
+
+const ReportButton = ({ round, user }) => {
const [showDialog, setShowDialog] = useState(false);
+ if (round.locked && !findResult(user, round)) {
+ return null;
+ }
+
return <>
<Button
onClick={() => setShowDialog(true)}
variant="secondary"
>
- {i18n.t(findResult(participant, round) ? 'results.edit' : 'results.report')}
+ {getButtonLabel(user, round)}
{' '}
<Icon.EDIT title="" />
</Button>
<ReportDialog
onHide={() => setShowDialog(false)}
- participant={participant}
round={round}
show={showDialog}
+ user={user}
/>
</>;
};
ReportButton.propTypes = {
- participant: PropTypes.shape({
- }),
round: PropTypes.shape({
+ locked: PropTypes.bool,
}),
tournament: PropTypes.shape({
}),
+ user: PropTypes.shape({
+ }),
};
export default withTranslation()(ReportButton);