diff --git a/app/(authenticated)/(admin)/admin/(admin components)/gameversions/actions.ts b/app/(authenticated)/(admin)/admin/(admin components)/gameversions/actions.ts index bede1ee..088a3a2 100644 --- a/app/(authenticated)/(admin)/admin/(admin components)/gameversions/actions.ts +++ b/app/(authenticated)/(admin)/admin/(admin components)/gameversions/actions.ts @@ -4,7 +4,7 @@ import { getAuth } from "@/auth/queries/getauth"; import { daphnis } from "@/lib/prisma"; import { GameVersion } from "@/prisma/schemas/daphnis/generated/daphnis"; -export async function getCurrentGame() { +export async function getGameList() { const { user } = await getAuth(); if (!user || !user.accessCode) { @@ -51,18 +51,3 @@ export async function updatePlayerGameVersionChuni(gameVersion?: GameVersion) { throw error; } } - -export async function getAllGameVersionsChuni() { - const { user } = await getAuth(); - - if (!user || !user.accessCode) { - throw new Error("User is not authenticated or accessCode is missing"); - } - - const AllGameVersions = await daphnis.user.findMany({ - select: { - gameVersion: true, - }, - }); - return AllGameVersions; -} diff --git a/app/(authenticated)/(admin)/admin/(admin components)/gameversions/page.tsx b/app/(authenticated)/(admin)/admin/(admin components)/gameversions/page.tsx index 4f323ce..4f015c4 100644 --- a/app/(authenticated)/(admin)/admin/(admin components)/gameversions/page.tsx +++ b/app/(authenticated)/(admin)/admin/(admin components)/gameversions/page.tsx @@ -3,10 +3,10 @@ import React from "react"; import { Card, CardHeader, CardTitle } from "@/components/ui/card"; import { ChunithmGameVersionSelection } from "./gameSelection"; -import { getAllGameVersionsChuni } from "./actions"; +import { getGameList } from "./actions"; const getAllGamesChunithm = async () => { - const gameVersions = await getAllGameVersionsChuni(); + const gameVersions = await getGameList(); return { gameVersions }; }; @@ -14,7 +14,7 @@ const Page = async () => { const AllChunithmVersions = await getAllGamesChunithm(); return ( - + Update Game Versions diff --git a/app/(authenticated)/(settings)/settings/(settings components)/home/page.tsx b/app/(authenticated)/(settings)/settings/(settings components)/home/page.tsx index ed50b77..28d917a 100644 --- a/app/(authenticated)/(settings)/settings/(settings components)/home/page.tsx +++ b/app/(authenticated)/(settings)/settings/(settings components)/home/page.tsx @@ -1,9 +1,6 @@ -import { getAuth } from "@/auth/queries/getauth"; import { GeneralSettings } from "./home"; const ProtectedDashboardPage = async () => { - const { user } = await getAuth(); - return (
diff --git a/app/(authenticated)/(settings)/settings/(settings components)/versions/actions.ts b/app/(authenticated)/(settings)/settings/(settings components)/versions/actions.ts new file mode 100644 index 0000000..fa029fe --- /dev/null +++ b/app/(authenticated)/(settings)/settings/(settings components)/versions/actions.ts @@ -0,0 +1,54 @@ +"use server"; + +import { getAuth } from "@/auth/queries/getauth"; +import { daphnis } from "@/lib/prisma"; +import { GameVersion } from "@/prisma/schemas/daphnis/generated/daphnis"; + +export async function getGameList() { + const { user } = await getAuth(); + + if (!user || !user.accessCode) { + throw new Error("User is not authenticated or accessCode is missing"); + } + + const currentGameVersion = await daphnis.user.findMany({ + where: { + UserId: user.UserId, + }, + select: { + gameVersion: true, + }, + }); + return currentGameVersion; +} + +export async function updatePlayerGameVersionChuni(gameVersion?: GameVersion) { + const { user } = await getAuth(); + + if (!user || !user.accessCode) { + throw new Error("User is not authenticated or accessCode is missing"); + } + + if (gameVersion === undefined) { + throw new Error("gameVersion is required"); + } + + try { + const updatedUser = await daphnis.user.update({ + where: { + UserId: user.UserId, + }, + data: { + gameVersion, + }, + select: { + gameVersion: true, + }, + }); + + return { gameVersion: updatedUser.gameVersion }; + } catch (error) { + console.error("Error updating game version:", error); + throw error; + } +} diff --git a/app/(authenticated)/(settings)/settings/(settings components)/versions/gameSelection.tsx b/app/(authenticated)/(settings)/settings/(settings components)/versions/gameSelection.tsx new file mode 100644 index 0000000..fe097d2 --- /dev/null +++ b/app/(authenticated)/(settings)/settings/(settings components)/versions/gameSelection.tsx @@ -0,0 +1,162 @@ +"use client"; + +import React, { FC, useState } from "react"; +import { Check, ChevronsUpDown } from "lucide-react"; +import { cn } from "@/lib/utils"; +import { Button } from "@/components/ui/button"; +import { + Command, + CommandEmpty, + CommandGroup, + CommandItem, + CommandList, +} from "@/components/ui/command"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { toast } from "@/components/ui/use-toast"; +import { z } from "zod"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { GameVersion, User } from "@/prisma/schemas/daphnis/generated/daphnis"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; +import { updatePlayerGameVersionChuni } from "./actions"; + +type ChunithmGameVersionSelectionProps = { + chunithmGameVersionNumber: { + gameVersions: { gameVersion: GameVersion }[]; + }; +}; +export function PlayerChangableChunithmGameVersionSelection({ + chunithmGameVersionNumber, +}: ChunithmGameVersionSelectionProps) { + const FormSchema = z.object({ + mapIconId: z.string({ + required_error: "Please select a Game Version.", + }), + }); + const form = useForm>({ + resolver: zodResolver(FormSchema), + }); + + const [selectedGameVersion, setSelectedGameVersion] = useState< + string | undefined + >(Object.values(GameVersion)[0]); + function onSubmit(data: z.infer) { + const newGameVersion = data.mapIconId ?? selectedGameVersion; + + // console.log("Submitted Game Version:", newGameVersion); + + updatePlayerGameVersionChuni(newGameVersion as GameVersion) + .then((result) => { + toast({ + title: "Game version updated successfully!", + description: ( +
+              
+                {JSON.stringify(result, null, 2)}
+              
+            
+ ), + }); + + setSelectedGameVersion(newGameVersion); + + form.reset({ + mapIconId: undefined, + }); + }) + .catch((error) => { + toast({ + title: "Error updating game version", + description: ( +
+              {error.message}
+            
+ ), + variant: "destructive", + }); + }); + } + + return ( +
+
+ + ( + + Chunithm + + + + + + + + + + No game version found. + + {Object.values(GameVersion).map((version) => ( + { + form.setValue("mapIconId", version); + setSelectedGameVersion(version); + }} + > + + {version} + + ))} + + + + + + + + + )} + /> + +
+ +
+ + +
+ ); +} diff --git a/app/(authenticated)/(settings)/settings/(settings components)/versions/page.tsx b/app/(authenticated)/(settings)/settings/(settings components)/versions/page.tsx new file mode 100644 index 0000000..14e1238 --- /dev/null +++ b/app/(authenticated)/(settings)/settings/(settings components)/versions/page.tsx @@ -0,0 +1,25 @@ +import { PlayerChangableChunithmGameVersionSelection } from "./gameSelection"; +import { getGameList } from "./actions"; +import { Card, CardHeader, CardTitle } from "@/components/ui/card"; + +const getAllGamesChunithm = async () => { + const gameVersions = await getGameList(); + return { gameVersions }; +}; + +const Versions = async () => { + const AllChunithmVersions = await getAllGamesChunithm(); + + return ( + + + Update Game Versions + + + + ); +}; + +export default Versions; diff --git a/app/(authenticated)/chunithm/page.tsx b/app/(authenticated)/chunithm/page.tsx index b873eae..83aa8c4 100644 --- a/app/(authenticated)/chunithm/page.tsx +++ b/app/(authenticated)/chunithm/page.tsx @@ -96,7 +96,7 @@ const Page = async () => { Customize Top Plays Hot Plays - Settings + {/* Settings */} Patcher @@ -143,9 +143,9 @@ const Page = async () => { - + {/* - + */}
); diff --git a/components/navigationbar/settingsnavigation.tsx b/components/navigationbar/settingsnavigation.tsx index 3bbc979..d93a87f 100644 --- a/components/navigationbar/settingsnavigation.tsx +++ b/components/navigationbar/settingsnavigation.tsx @@ -6,6 +6,7 @@ import { usePathname } from "next/navigation"; const NAV_ITEMS = [ { href: "/settings/home", label: "General" }, { href: "/settings/security", label: "Security" }, + { href: "/settings/versions", label: "Edit Game Version" }, ]; const SettingsSubMenuNavigation = () => {