work on team enrollment
This commit is contained in:
@@ -13,7 +13,6 @@ interface HeaderProps {
|
||||
}
|
||||
|
||||
const Header = ({ player }: HeaderProps) => {
|
||||
|
||||
const sheet = useSheet();
|
||||
const { user: authUser } = useAuth();
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Box } from "@mantine/core";
|
||||
import Header from "./header";
|
||||
import { Player, PlayerStats } from "@/features/players/types";
|
||||
import SwipeableTabs from "@/components/swipeable-tabs";
|
||||
import { usePlayer, usePlayerMatches, usePlayerStats } from "../../queries";
|
||||
import TeamList from "@/features/teams/components/team-list";
|
||||
import StatsOverview from "@/shared/components/stats-overview";
|
||||
import MatchList from "@/features/matches/components/match-list";
|
||||
import { BaseStats } from "@/shared/types/stats";
|
||||
|
||||
interface ProfileProps {
|
||||
id: string;
|
||||
@@ -17,26 +15,14 @@ const Profile = ({ id }: ProfileProps) => {
|
||||
const { data: matches } = usePlayerMatches(id);
|
||||
const { data: stats, isLoading: statsLoading } = usePlayerStats(id);
|
||||
|
||||
// Aggregate player stats from multiple tournaments into a single BaseStats object
|
||||
const aggregatedStats: BaseStats | null = stats && stats.length > 0 ? {
|
||||
id: `player_${id}_aggregate`,
|
||||
matches: stats.reduce((acc, stat) => acc + stat.matches, 0),
|
||||
wins: stats.reduce((acc, stat) => acc + stat.wins, 0),
|
||||
losses: stats.reduce((acc, stat) => acc + stat.losses, 0),
|
||||
total_cups_made: stats.reduce((acc, stat) => acc + stat.total_cups_made, 0),
|
||||
total_cups_against: stats.reduce((acc, stat) => acc + stat.total_cups_against, 0),
|
||||
margin_of_victory: stats.filter(s => s.margin_of_victory > 0).reduce((acc, stat, _, arr) => acc + stat.margin_of_victory / arr.length, 0),
|
||||
margin_of_loss: stats.filter(s => s.margin_of_loss > 0).reduce((acc, stat, _, arr) => acc + stat.margin_of_loss / arr.length, 0),
|
||||
} : null;
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
label: "Overview",
|
||||
content: <StatsOverview statsData={aggregatedStats} isLoading={statsLoading} />,
|
||||
content: <StatsOverview statsData={stats} isLoading={statsLoading} />,
|
||||
},
|
||||
{
|
||||
label: "Matches",
|
||||
content: <Box p="md"><MatchList matches={matches || []} /></Box>,
|
||||
content: <MatchList matches={matches || []} />,
|
||||
},
|
||||
{
|
||||
label: "Teams",
|
||||
@@ -47,7 +33,7 @@ const Profile = ({ id }: ProfileProps) => {
|
||||
return (
|
||||
<>
|
||||
<Header player={player} />
|
||||
<Box m='md' mt="lg">
|
||||
<Box m='xs' mt="lg">
|
||||
<SwipeableTabs tabs={tabs} />
|
||||
</Box>
|
||||
</>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { useServerSuspenseQuery } from "@/lib/tanstack-query/hooks";
|
||||
import { listPlayers, getPlayer, getUnassociatedPlayers, fetchMe, getPlayerStats, getAllPlayerStats, getPlayerMatches } from "./server";
|
||||
import { listPlayers, getPlayer, getUnassociatedPlayers, fetchMe, getPlayerStats, getAllPlayerStats, getPlayerMatches, getUnenrolledPlayers } from "./server";
|
||||
|
||||
export const playerKeys = {
|
||||
auth: ['auth'],
|
||||
list: ['players', 'list'],
|
||||
details: (id: string) => ['players', 'details', id],
|
||||
unassociated: ['players','unassociated'],
|
||||
unenrolled: (tournamentId: string) => ['players', 'unenrolled', tournamentId],
|
||||
stats: (id: string) => ['players', 'stats', id],
|
||||
allStats: ['players', 'stats', 'all'],
|
||||
matches: (id: string) => ['players', 'matches', id],
|
||||
@@ -28,6 +29,10 @@ export const playerQueries = {
|
||||
queryKey: playerKeys.unassociated,
|
||||
queryFn: async () => await getUnassociatedPlayers()
|
||||
}),
|
||||
unenrolled: (tournamentId: string) => ({
|
||||
queryKey: playerKeys.unenrolled(tournamentId),
|
||||
queryFn: async () => await getUnenrolledPlayers({ data: tournamentId })
|
||||
}),
|
||||
stats: (id: string) => ({
|
||||
queryKey: playerKeys.stats(id),
|
||||
queryFn: async () => await getPlayerStats({ data: id })
|
||||
@@ -81,4 +86,7 @@ export const useAllPlayerStats = () =>
|
||||
useServerSuspenseQuery(playerQueries.allStats());
|
||||
|
||||
export const usePlayerMatches = (id: string) =>
|
||||
useServerSuspenseQuery(playerQueries.matches(id));
|
||||
useServerSuspenseQuery(playerQueries.matches(id));
|
||||
|
||||
export const useUnenrolledPlayers = (tournamentId: string) =>
|
||||
useServerSuspenseQuery(playerQueries.unenrolled(tournamentId));
|
||||
@@ -125,7 +125,7 @@ export const getPlayerStats = createServerFn()
|
||||
.validator(z.string())
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult<PlayerStats[]>(async () => await pbAdmin.getPlayerStats(data))
|
||||
toServerResult<PlayerStats>(async () => await pbAdmin.getPlayerStats(data))
|
||||
);
|
||||
|
||||
export const getAllPlayerStats = createServerFn()
|
||||
@@ -139,4 +139,11 @@ export const getPlayerMatches = createServerFn()
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult<Match[]>(async () => await pbAdmin.getPlayerMatches(data))
|
||||
);
|
||||
|
||||
export const getUnenrolledPlayers = createServerFn()
|
||||
.validator(z.string())
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ data: tournamentId }) =>
|
||||
toServerResult(async () => await pbAdmin.getUnenrolledPlayers(tournamentId))
|
||||
);
|
||||
Reference in New Issue
Block a user