]> git.localhorst.tv Git - alttp.git/commitdiff
show tournament participation in profile
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 20 Mar 2022 15:25:20 +0000 (16:25 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 20 Mar 2022 15:25:20 +0000 (16:25 +0100)
app/Http/Controllers/UserController.php
app/Models/User.php
resources/js/components/users/Participation.js [new file with mode: 0644]
resources/js/components/users/Profile.js
resources/js/i18n/de.js
resources/js/i18n/en.js

index c0ab73d9b442a30ff340375e97d4747b0e5e9a5f..8c451fc1328c3260ff6a9ed0c984b353536d917a 100644 (file)
@@ -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();
        }
 
index 7f03b4acdf6a24ea4dc2bcec5145cb66a2b31ea9..535af2e07e828232ba2e9e2843ad507d1222d481 100644 (file)
@@ -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 (file)
index 0000000..e45fcf6
--- /dev/null
@@ -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 <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);
index f38ba2f3d8830b8447a3ecbf5b9bfe8802f9446e..10c70dbf92bb4037a8ae2dbc96ab2fae22829c6d 100644 (file)
@@ -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 }) => <Container>
                                <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,
        }),
index 6feeb64d35dd951c65bb6ce7f595751d7e6d3d0e..ee1f9c3e77d4cc881edb63037cd8844eef1ba5ba 100644 (file)
@@ -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: {
index 3f01805f73cb986e7843bd5e263dee9d8459af1f..bd7fb372535c825d296d5554e3f49e64692b65d2 100644 (file)
@@ -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: {