diff --git a/apps/nextjs/src/app/(info)/docs/rails/page.tsx b/apps/nextjs/src/app/(info)/docs/rails/page.tsx index 86bcffa9..ed1a2c3f 100644 --- a/apps/nextjs/src/app/(info)/docs/rails/page.tsx +++ b/apps/nextjs/src/app/(info)/docs/rails/page.tsx @@ -12,7 +12,7 @@ export default async function OpenApiDocs() { return redirect("/"); } - const me = (await getAccountMe())?.data; + const me = await getAccountMe(); if (!me?.admin) { return redirect("/"); // Redirect to home page if account is not an admin) diff --git a/apps/nextjs/src/app/api/uploadthing/core.ts b/apps/nextjs/src/app/api/uploadthing/core.ts index 74ae7de1..d0fb201f 100644 --- a/apps/nextjs/src/app/api/uploadthing/core.ts +++ b/apps/nextjs/src/app/api/uploadthing/core.ts @@ -24,9 +24,12 @@ export const UploadThingRouter = { }) .onUploadComplete(({ metadata, file }) => { // This code RUNS ON YOUR SERVER after upload - console.log("Upload complete for userId:", metadata.userId); - - console.log("file url", file.url); + console.log( + "Upload complete for userId:", + metadata.userId, + "file url", + file.url, + ); // !!! Whatever is returned here is sent to the client `onClientUploadComplete` callback return { uploadedBy: metadata.userId }; diff --git a/apps/nextjs/src/app/dashboard/@profiles/page.tsx b/apps/nextjs/src/app/dashboard/@profiles/page.tsx index 3281951e..507cf22c 100644 --- a/apps/nextjs/src/app/dashboard/@profiles/page.tsx +++ b/apps/nextjs/src/app/dashboard/@profiles/page.tsx @@ -3,13 +3,13 @@ import { getProfilesByAccountId } from "~/app/server-actions/profiles/actions"; import NewProfile from "~/components/profiles/new-profile"; export default async function Profiles() { - const me = (await getAccountMe())?.data; + const me = await getAccountMe(); if (!me) { return null; } - const profiles = await getProfilesByAccountId(me.id); + const profiles = await getProfilesByAccountId(Number(me.id)); return (
diff --git a/apps/nextjs/src/app/dashboard/layout.tsx b/apps/nextjs/src/app/dashboard/layout.tsx index ee0226f6..28c1dae2 100644 --- a/apps/nextjs/src/app/dashboard/layout.tsx +++ b/apps/nextjs/src/app/dashboard/layout.tsx @@ -4,7 +4,7 @@ import { getAccountMe } from "~/app/server-actions/accounts/actions"; export default async function DashboardLayout({ children, }: Readonly) { - const me = (await getAccountMe())?.data; + const me = await getAccountMe(); return (
diff --git a/apps/nextjs/src/app/organizations/[org_slug]/page.tsx b/apps/nextjs/src/app/organizations/[org_slug]/page.tsx index 703efb42..a12606cc 100644 --- a/apps/nextjs/src/app/organizations/[org_slug]/page.tsx +++ b/apps/nextjs/src/app/organizations/[org_slug]/page.tsx @@ -17,15 +17,15 @@ export async function generateMetadata( props: Readonly, ) { const params = await props.params; - const { data: org } = await getOrganization(params.org_slug); + const org = await getOrganization(params.org_slug); return { title: org?.name ?? "Organization" }; } export async function generateStaticParams() { - const { partners, nonpartners } = await getOrganizations(); + const orgs = await getOrganizations(); - return [...partners, ...nonpartners].map(({ slug }) => ({ org_slug: slug })); + return orgs.map(({ slug }) => ({ org_slug: slug })); } // const columns = [ @@ -60,7 +60,7 @@ export default async function OrganizationDetailPage( props: Readonly, ) { const params = await props.params; - const { data: organization } = await getOrganization(params.org_slug); + const organization = await getOrganization(params.org_slug); if (!organization) { return
404 - Not Found
; diff --git a/apps/nextjs/src/app/organizations/[org_slug]/tournaments/[tournament_id]/(tournament_page)/page.tsx b/apps/nextjs/src/app/organizations/[org_slug]/tournaments/[tournament_id]/(tournament_page)/page.tsx index f9b6b515..dc886d67 100644 --- a/apps/nextjs/src/app/organizations/[org_slug]/tournaments/[tournament_id]/(tournament_page)/page.tsx +++ b/apps/nextjs/src/app/organizations/[org_slug]/tournaments/[tournament_id]/(tournament_page)/page.tsx @@ -3,6 +3,7 @@ import Link from "next/link"; import { Chip } from "@battle-stadium/ui"; import type { OrganizationTournamentProps } from "~/types"; +import { getOrganization } from "~/app/server-actions/organizations/actions"; import { getTournament, getTournaments, @@ -41,7 +42,11 @@ export default async function OrganizationTournament( return
404 - Not Found
; } - const { organization } = tournament; + const organization = await getOrganization(tournament.organization.slug); + + if (!organization) { + return
404 - Not Found
; + } return ( <> @@ -95,6 +100,7 @@ function TournamentDetailChips(props: Readonly) { Light Flat Register diff --git a/apps/nextjs/src/app/organizations/page.tsx b/apps/nextjs/src/app/organizations/page.tsx index e75c6f85..3b7de9a5 100644 --- a/apps/nextjs/src/app/organizations/page.tsx +++ b/apps/nextjs/src/app/organizations/page.tsx @@ -2,6 +2,7 @@ import type { Metadata } from "next"; import type { Tournament } from "~/lib/api"; import PartneredOrganizations from "~/components/organizations/partnered-organizations"; +import { getOrganizations } from "../server-actions/organizations/actions"; export const metadata: Metadata = { title: "Organizations", @@ -11,7 +12,8 @@ export interface OrganizationsPageProps { orgs: Tournament[]; } -export default function OrganizationsPage() { +export default async function OrganizationsPage() { + const orgs = await getOrganizations(); return ( <>
@@ -20,6 +22,12 @@ export default function OrganizationsPage() {

TODO: Organizations Table

+ {orgs.map((org) => ( +
+

{org.name}

+

{org.description}

+
+ ))}
); diff --git a/apps/nextjs/src/app/players/[username]/page.tsx b/apps/nextjs/src/app/players/[username]/page.tsx index 9c90b100..ce640c35 100644 --- a/apps/nextjs/src/app/players/[username]/page.tsx +++ b/apps/nextjs/src/app/players/[username]/page.tsx @@ -1,4 +1,4 @@ -import { getAccount } from "~/app/server-actions/accounts/actions"; +import { getProfile } from "~/app/server-actions/profiles/actions"; interface PlayerProfilePageProps { params: Promise<{ @@ -10,7 +10,7 @@ export async function generateMetadata( props: Readonly, ) { const params = await props.params; - const { data: player } = await getAccount(params.username); + const player = await getProfile(params.username); return { title: player?.username ?? "Player" }; } @@ -19,14 +19,12 @@ export default async function PlayerProfilePage( props: Readonly, ) { const params = await props.params; - const { data: player } = await getAccount(params.username); + const player = await getProfile(params.username); return (

{player?.username}

-

- {player?.first_name} {player?.last_name} -

+

{player?.slug}

); } diff --git a/apps/nextjs/src/app/players/page.tsx b/apps/nextjs/src/app/players/page.tsx index 5115580c..5eec151b 100644 --- a/apps/nextjs/src/app/players/page.tsx +++ b/apps/nextjs/src/app/players/page.tsx @@ -13,7 +13,7 @@ const columns = [ ]; export default async function PlayersPage() { - const { data: players } = await getProfiles(); + const players = await getProfiles(); - return ; + return ; } diff --git a/apps/nextjs/src/app/players/players-table.tsx b/apps/nextjs/src/app/players/players-table.tsx index 616292e5..054bb93a 100644 --- a/apps/nextjs/src/app/players/players-table.tsx +++ b/apps/nextjs/src/app/players/players-table.tsx @@ -1,12 +1,13 @@ "use client"; +import type { profiles } from "@battle-stadium/db/schema"; + // import { type Key } from "react"; // import Link from "next/link"; -import type { Profile } from "~/lib/api"; export interface PlayersTableProps { - players: Profile[]; + players: (typeof profiles.$inferSelect)[]; columns: { key: string; label: string }[]; } @@ -29,7 +30,8 @@ export default function PlayersTable({ // switch (columnKey) { // case "username": // return ( -// +// // {username} // // ); diff --git a/apps/nextjs/src/app/server-actions/accounts/actions.ts b/apps/nextjs/src/app/server-actions/accounts/actions.ts index 72e2cdaa..687ebb28 100644 --- a/apps/nextjs/src/app/server-actions/accounts/actions.ts +++ b/apps/nextjs/src/app/server-actions/accounts/actions.ts @@ -1,49 +1,46 @@ "use server"; -import type { FetchOptions } from "openapi-fetch"; import { auth } from "@clerk/nextjs/server"; -import type { paths } from "~/lib/api/openapi-v1"; -import { BattleStadiumApiClient, defaultConfig } from "~/lib/api"; +import { db, eq } from "@battle-stadium/db"; +import { accounts, clerkUsers, profiles } from "@battle-stadium/db/schema"; -export async function getAccounts( - options?: FetchOptions, -) { - const usersOptions = { - ...defaultConfig("listUsers"), - ...options, - }; - const skipClerkAuth = true; - - return BattleStadiumApiClient(skipClerkAuth).GET("/accounts", usersOptions); +export async function getAccounts() { + return await db.query.accounts.findMany(); } -export async function getAccount( - username: string, - options?: FetchOptions, -) { - const userOptions = { - ...defaultConfig(`getUser-${username}`), - ...options, - params: { path: { username } }, - }; - - return BattleStadiumApiClient().GET("/accounts/{username}", userOptions); +export async function getAccount(username: string) { + const profile = await db.query.profiles.findFirst({ + where: eq(profiles.username, username), + }); + + if (!profile?.accountId) { + return null; + } + + return await db.query.accounts.findFirst({ + where: eq(accounts.id, BigInt(profile.accountId)), + }); } -export async function getAccountMe( - options?: FetchOptions, -) { +export async function getAccountMe() { const { userId } = await auth(); if (!userId) { return null; } - const userMeOptions = { - ...defaultConfig(`getAccountMe(${userId})`), - ...options, - }; + const clerkUser = await db.query.clerkUsers.findFirst({ + where: eq(clerkUsers.clerkUserId, userId), + }); + + if (!clerkUser?.accountId) { + return null; + } + + const account = await db.query.accounts.findFirst({ + where: eq(accounts.id, BigInt(clerkUser.accountId)), + }); - return BattleStadiumApiClient().GET("/accounts/me", userMeOptions); + return account; } diff --git a/apps/nextjs/src/app/server-actions/organizations/actions.ts b/apps/nextjs/src/app/server-actions/organizations/actions.ts index 8e2067f8..1c97f66e 100644 --- a/apps/nextjs/src/app/server-actions/organizations/actions.ts +++ b/apps/nextjs/src/app/server-actions/organizations/actions.ts @@ -1,51 +1,24 @@ "use server"; -import type { FetchOptions } from "openapi-fetch"; +import { eq } from "@battle-stadium/db"; +import { db } from "@battle-stadium/db/client"; +import { organizations } from "@battle-stadium/db/schema"; -import type { paths } from "~/lib/api/openapi-v1"; -import { BattleStadiumApiClient, defaultConfig } from "~/lib/api"; - -export async function getOrganizations( - options?: FetchOptions, -) { - const organizationsOptions = { - ...defaultConfig("getOrganizations"), - ...options, - params: { - query: { - page: options?.params.query.page ?? 0, - per_page: options?.params.query.per_page ?? 20, - }, - }, - }; - const skipClerkAuth = true; - - const resp = await BattleStadiumApiClient(skipClerkAuth).GET( - "/organizations", - organizationsOptions, - ); - const allOrgs = resp.data?.data; - const partnerOrgs = (allOrgs ?? []).filter((org) => org.partner); - const nonPartnerOrgs = (allOrgs ?? []).filter((org) => !org.partner); - - return { - partners: partnerOrgs, - nonpartners: nonPartnerOrgs, - }; +export async function getOrganizations() { + const orgs = await db.query.organizations.findMany(); + return orgs; } -export async function getOrganization( - slug: string, - options?: FetchOptions, -) { - const organizationOptions = { - ...defaultConfig(`getOrganization(${slug})`), - ...options, - params: { path: { slug } }, - }; +export async function getPartneredOrganizations() { + const orgs = await db.query.organizations.findMany({ + where: eq(organizations.partner, true), + }); + return orgs; +} - return BattleStadiumApiClient().GET( - "/organizations/{slug}", - organizationOptions, - ); +export async function getOrganization(slug: string) { + const org = await db.query.organizations.findFirst({ + where: eq(organizations.slug, slug), + }); + return org; } diff --git a/apps/nextjs/src/app/server-actions/profiles/actions.ts b/apps/nextjs/src/app/server-actions/profiles/actions.ts index b49b2713..ffe16326 100644 --- a/apps/nextjs/src/app/server-actions/profiles/actions.ts +++ b/apps/nextjs/src/app/server-actions/profiles/actions.ts @@ -3,18 +3,20 @@ import type { FetchOptions } from "openapi-fetch"; import { revalidateTag } from "next/cache"; +import { db, eq } from "@battle-stadium/db"; +import { profiles } from "@battle-stadium/db/schema"; + import type { paths } from "~/lib/api/openapi-v1"; import { BattleStadiumApiClient, defaultConfig } from "~/lib/api"; -export async function getProfiles( - options?: FetchOptions, -) { - const profilesOptions = { - ...defaultConfig("getPlayerProfiles"), - ...options, - }; +export async function getProfiles() { + return await db.query.profiles.findMany(); +} - return BattleStadiumApiClient().GET("/profiles", profilesOptions); +export async function getProfile(username: string) { + return await db.query.profiles.findFirst({ + where: eq(profiles.username, username), + }); } export async function getProfilesByAccountId( diff --git a/apps/nextjs/src/components/battle-stadium.tsx b/apps/nextjs/src/components/battle-stadium.tsx index 4f3ba5d6..a9990bd3 100644 --- a/apps/nextjs/src/components/battle-stadium.tsx +++ b/apps/nextjs/src/components/battle-stadium.tsx @@ -32,7 +32,7 @@ export default function BattleStadium() { className="flex flex-row gap-2 md:gap-4" >
- + We use cookies to provide the best experience. By continuing to use our site, you agree to our  - + Cookie Policy.

diff --git a/apps/nextjs/src/components/footer.tsx b/apps/nextjs/src/components/footer.tsx index 1ed5df65..cbe6cd90 100644 --- a/apps/nextjs/src/components/footer.tsx +++ b/apps/nextjs/src/components/footer.tsx @@ -54,7 +54,12 @@ export default function Footer() {
{navLinks.map((item) => ( - + {item.name} ))} @@ -62,7 +67,12 @@ export default function Footer() { {/* */}
{socialItems.map((item) => ( - + {item.name}