Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dashboard Team Info #68

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/app/(main)/(routes)/(protected)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/app/_components/ui/card";
import { serverTRPC } from "@/app/_trpc/server";
import { composeServerComponentClient } from "@/server/lib/supabase/server";
import { getUser } from "@/shared/supabase/auth";
import { type Metadata } from "next";

export const metadata: Metadata = {
title: "Dashboard | HackPSH",
description: "Overview your progress within the competition.",
};

export default function DashboardPage() {
export default async function DashboardPage() {
const supabase = composeServerComponentClient();

const user = await getUser(supabase);
const { team_name, team_join_code, team_points, team_members } =
await serverTRPC.team.get_team_info.query({
user_uuid: user.id,
});

return (
<div>
<div className="mt-14 flex w-full flex-col items-center justify-center">
<p className="mb-10 text-center text-3xl font-bold tracking-tight">
Dashboard
</p>
</div>
<div className="container my-8">
<Card>
<CardHeader>
<CardTitle className="text-4xl">Team</CardTitle>
</CardHeader>
<CardContent className="flex flex-col space-y-4 text-muted-foreground">
<div>
<p className="text-xl text-foreground">General Information</p>
<p>Team Name: {team_name}</p>
<p>Team Code: {team_join_code}</p>
<p>Points: {team_points}</p>
</div>

<div>
<p className="text-xl text-foreground">Members</p>
{team_members.map((member, index) => (
<p key={`member-${index}`} className="text-muted-foreground">
{member.user_display_name}
</p>
))}
</div>
</CardContent>
</Card>
</div>
);
}
7 changes: 3 additions & 4 deletions src/app/_components/onboarding/support-us-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
FormLabel,
} from "../ui/form";
import { cn } from "@/app/_lib/client-utils";
import NumberStepper from "./number-stepper";
import { Switch } from "../ui/switch";
import { Button } from "../ui/button";
import { Icons } from "../ui/icons";
Expand Down Expand Up @@ -85,7 +84,7 @@ export default function SupportUsForm({
control={form.control}
name="user_support_administrative"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
<FormItem className="flex flex-row items-center justify-between p-4 border rounded-lg">
<div className="space-y-0.5">
<FormLabel className="text-base">Administrative</FormLabel>
<FormDescription>
Expand All @@ -107,7 +106,7 @@ export default function SupportUsForm({
control={form.control}
name="user_support_technical"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
<FormItem className="flex flex-row items-center justify-between p-4 border rounded-lg">
<div className="space-y-0.5">
<FormLabel className="text-base">Technical</FormLabel>
<FormDescription>
Expand All @@ -131,7 +130,7 @@ export default function SupportUsForm({
disabled={form.formState.isSubmitting}
>
{form.formState.isSubmitting && (
<Icons.spinner className="mr-2 h-4 w-4 animate-spin" />
<Icons.spinner className="w-4 h-4 mr-2 animate-spin" />
)}
Next
</Button>
Expand Down
34 changes: 34 additions & 0 deletions src/server/dao/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,37 @@ export async function joinTeam(
});
}
}

export async function getTeamInfo(db: Database, user_uuid: string) {
try {
const teamUUID = await db.query.app_user_profile.findFirst({
columns: { user_team_uuid: true },
where: (user_data, { eq }) => eq(user_data.user_uuid, user_uuid),
});

const teamGeneralInfo = await db.query.app_team.findFirst({
columns: {
team_name: true,
team_join_code: true,
team_points: true,
},
where: (team_data, { eq }) =>
eq(team_data.team_uuid, teamUUID!.user_team_uuid!),
});

const teamMembers = await db.query.app_user_profile.findMany({
columns: {
user_display_name: true,
},
where: (user_data, { eq }) =>
eq(user_data.user_team_uuid, teamUUID!.user_team_uuid!),
});

return { teamGeneralInfo, teamMembers };
} catch (error) {
throw new TRPCError({
message: "The database has encountered some issues.",
code: "INTERNAL_SERVER_ERROR",
});
}
}
16 changes: 16 additions & 0 deletions src/server/procedures/protected/team/getTeamInfoProcedure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getTeamInfo } from "@/server/dao/team";
import { protectedProcedure } from "@/server/trpc";
import { LookupUserSchema } from "@/server/zod-schemas/user";

export default protectedProcedure
.input(LookupUserSchema)
.query(async ({ ctx, input }) => {
const result = await getTeamInfo(ctx.db, input.user_uuid);

return {
team_name: result.teamGeneralInfo?.team_name,
team_join_code: result.teamGeneralInfo?.team_join_code,
team_points: result.teamGeneralInfo?.team_points,
team_members: result.teamMembers,
};
});
2 changes: 2 additions & 0 deletions src/server/routers/team.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import createTeamProcedure from "../procedures/protected/team/createTeamProcedure";
import getTeamInfoProcedure from "../procedures/protected/team/getTeamInfoProcedure";
import joinTeamProcedure from "../procedures/protected/team/joinTeamProcedure";
import { createTRPCRouter } from "../trpc";

export const teamRouter = createTRPCRouter({
join_team: joinTeamProcedure,
create_team: createTeamProcedure,
get_team_info: getTeamInfoProcedure,
});