public function single(Request $request, $id) {
$user = User::findOrFail($id);
$this->authorize('view', $user);
+ $user->load('participation');
+ $user->load('participation.tournament');
return $user->toJson();
}
return false;
}
+ public function participation() {
+ return $this->hasMany(Participant::class);
+ }
+
/**
* The attributes that are mass assignable.
*
--- /dev/null
+import PropTypes from 'prop-types';
+import React from 'react';
+import { Alert, Button } from 'react-bootstrap';
+import { withTranslation } from 'react-i18next';
+import { useNavigate } from 'react-router-dom';
+
+import i18n from '../../i18n';
+
+const Participation = ({ user }) => {
+ const navigate = useNavigate();
+
+ if (!user || !user.participation || !user.participation.length) {
+ return <Alert variant="info">
+ {i18n.t('users.participationEmpty')}
+ </Alert>;
+ }
+ return <div className="participation">
+ {user.participation.map(p => <div key={p.id}>
+ <Button
+ onClick={() => navigate(`/tournaments/${p.tournament_id}`)}
+ variant="link"
+ >
+ {p.tournament.title}
+ </Button>
+ </div>)}
+ </div>;
+};
+
+Participation.propTypes = {
+ user: PropTypes.shape({
+ participation: PropTypes.arrayOf(PropTypes.shape({
+ id: PropTypes.number,
+ })),
+ }),
+};
+
+export default withTranslation()(Participation);
import Box from './Box';
import EditStreamLinkButton from './EditStreamLinkButton';
+import Participation from './Participation';
import Icon from '../common/Icon';
import i18n from '../../i18n';
<EditStreamLinkButton user={user} />
</p>
</Col>
+ <Col md={12}>
+ <h2>{i18n.t('users.tournaments')}</h2>
+ <Participation user={user} />
+ </Col>
</Row>
</Container>;
Profile.propTypes = {
user: PropTypes.shape({
+ participation: PropTypes.arrayOf(PropTypes.shape({
+ })),
stream_link: PropTypes.string,
username: PropTypes.string,
}),
discordTag: 'Discord Tag',
editStreamLink: 'Stream Link bearbeiten',
noStream: 'Kein Stream gesetzt',
+ participationEmpty: 'Hat noch an keinen Turnieren teilgenommen.',
setStreamLinkError: 'Konnte Stream Link nicht speichern',
setStreamLinkSuccess: 'Stream Link gespeichert',
stream: 'Stream',
streamLink: 'Stream Link',
+ tournaments: 'Turniere',
},
validation: {
error: {
discordTag: 'Discord tag',
editStreamLink: 'Edit stream link',
noStream: 'No stream set',
+ participationEmpty: 'Has not participated in any tourneys yet.',
setStreamLinkError: 'Could not save stream link',
setStreamLinkSuccess: 'Stream link saved',
stream: 'Stream',
streamLink: 'Stream link',
+ tournaments: 'Tournaments',
},
validation: {
error: {