1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Button, Col, Form, Modal, Row } from 'react-bootstrap';
4 import { useTranslation } from 'react-i18next';
6 import Box from '../users/Box';
7 import { getTime } from '../../helpers/Result';
8 import { maySeeResults } from '../../helpers/permissions';
9 import { findResult } from '../../helpers/User';
10 import { useUser } from '../../hooks/user';
12 const getPlacement = (result, t) =>
13 `${result.placement}. (${t('results.points', { count: result.score })})`;
15 const DetailDialog = ({
22 const { t } = useTranslation();
23 const { user: authUser } = useUser();
25 const result = React.useMemo(
26 () => findResult(user, round),
29 const maySee = React.useMemo(
30 () => maySeeResults(authUser, tournament, round),
31 [authUser, round, tournament],
34 return <Modal className="result-dialog" onHide={onHide} show={show}>
35 <Modal.Header closeButton>
37 {t('results.details')}
42 <Form.Group as={Col} sm={6}>
43 <Form.Label>{t('results.round')}</Form.Label>
45 #{round.number || '?'}
47 {t('rounds.date', { date: new Date(round.created_at) })}
50 <Form.Group as={Col} sm={6}>
51 <Form.Label>{t('results.runner')}</Form.Label>
52 <div><Box user={user} /></div>
54 <Form.Group as={Col} sm={6}>
55 <Form.Label>{t('results.result')}</Form.Label>
57 {maySee && result && result.has_finished
58 ? getTime(result, maySee)
59 : t('results.pending')}
62 <Form.Group as={Col} sm={6}>
63 <Form.Label>{t('results.placement')}</Form.Label>
65 {maySee && result && result.placement
66 ? getPlacement(result, t)
67 : t('results.pending')}
70 {maySee && result && result.comment ?
71 <Form.Group as={Col} sm={12}>
72 <Form.Label>{t('results.comment')}</Form.Label>
73 <div>{result.comment}</div>
79 <Button onClick={onHide} variant="secondary">
86 DetailDialog.propTypes = {
87 onHide: PropTypes.func,
88 round: PropTypes.shape({
89 created_at: PropTypes.string,
90 number: PropTypes.number,
93 tournament: PropTypes.shape({
95 user: PropTypes.shape({
99 export default DetailDialog;