"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 ChunithmGameVersionSelection({ 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} ))} )} />
); }