From: Daniel Karbach Date: Sun, 20 Mar 2022 15:25:20 +0000 (+0100) Subject: show tournament participation in profile X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=beccf752aafd468c3753c6d48ae30bccd946c3b9;p=alttp.git show tournament participation in profile --- diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index c0ab73d..8c451fc 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -41,6 +41,8 @@ class UserController extends Controller public function single(Request $request, $id) { $user = User::findOrFail($id); $this->authorize('view', $user); + $user->load('participation'); + $user->load('participation.tournament'); return $user->toJson(); } diff --git a/app/Models/User.php b/app/Models/User.php index 7f03b4a..535af2e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -21,6 +21,10 @@ class User extends Authenticatable return false; } + public function participation() { + return $this->hasMany(Participant::class); + } + /** * The attributes that are mass assignable. * diff --git a/resources/js/components/users/Participation.js b/resources/js/components/users/Participation.js new file mode 100644 index 0000000..e45fcf6 --- /dev/null +++ b/resources/js/components/users/Participation.js @@ -0,0 +1,37 @@ +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 + {i18n.t('users.participationEmpty')} + ; + } + return
+ {user.participation.map(p =>
+ +
)} +
; +}; + +Participation.propTypes = { + user: PropTypes.shape({ + participation: PropTypes.arrayOf(PropTypes.shape({ + id: PropTypes.number, + })), + }), +}; + +export default withTranslation()(Participation); diff --git a/resources/js/components/users/Profile.js b/resources/js/components/users/Profile.js index f38ba2f..10c70db 100644 --- a/resources/js/components/users/Profile.js +++ b/resources/js/components/users/Profile.js @@ -5,6 +5,7 @@ import { withTranslation } from 'react-i18next'; import Box from './Box'; import EditStreamLinkButton from './EditStreamLinkButton'; +import Participation from './Participation'; import Icon from '../common/Icon'; import i18n from '../../i18n'; @@ -35,11 +36,17 @@ const Profile = ({ user }) =>

+ +

{i18n.t('users.tournaments')}

+ +
; Profile.propTypes = { user: PropTypes.shape({ + participation: PropTypes.arrayOf(PropTypes.shape({ + })), stream_link: PropTypes.string, username: PropTypes.string, }), diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 6feeb64..ee1f9c3 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -146,10 +146,12 @@ export default { 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: { diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 3f01805..bd7fb37 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -146,10 +146,12 @@ export default { 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: {