added update functions

This commit is contained in:
Polaris
2024-08-01 21:42:14 -04:00
parent aabbef26bf
commit d3acd9377c
12 changed files with 391 additions and 132 deletions

View File

@ -30,7 +30,7 @@ import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "../../ui/use-toast";
import { getCurrentTrophies } from "./actions";
import { getCurrentTrophies, updatePlayerTrophy } from "./actions";
import { cozynet_chuni_static_trophies } from "@/prisma/schemas/artemis/generated/artemis";
const getAvatarTextureSrc = (id: number | undefined) => {
if (id === undefined) return "";
@ -76,6 +76,14 @@ export const TrophyCustomization: FC<AvatarSelectionProps> = ({
}, []);
function onSubmit(data: z.infer<typeof FormSchema>) {
const unchangedNamePlateId = trophyID;
const newNamePlateId = data.trophies ?? unchangedNamePlateId;
updatePlayerTrophy(newNamePlateId).then(() => {
setTrophyId(newNamePlateId);
});
resetFormValues();
toast({
title: "You submitted the following values:",
description: (
@ -84,6 +92,12 @@ export const TrophyCustomization: FC<AvatarSelectionProps> = ({
</pre>
),
});
function resetFormValues() {
form.reset({
trophies: undefined,
});
}
}
return (