From 8e28d50fd51498892678a848bd5e9427fe1cd8d4 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Sun, 25 Feb 2024 21:02:49 -0500 Subject: [PATCH] update promote player --- components/PromotePlayer.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/PromotePlayer.tsx b/components/PromotePlayer.tsx index 44a340e..c2cf608 100644 --- a/components/PromotePlayer.tsx +++ b/components/PromotePlayer.tsx @@ -1,13 +1,16 @@ "use client"; +import { useContext } from "react"; import { useSWRConfig } from "swr"; +import { ErrorContext } from "./App"; export default function PromotePlayer({ playerId }: { playerId: string }) { const { mutate } = useSWRConfig(); + const { setError } = useContext(ErrorContext); - async function promotePlayer() { - const res = await fetch("/api/user", { - // method: "POST", + async function onClick() { + const res = await fetch("/api/party/promote", { + method: "POST", headers: { "Content-Type": "application/json", }, @@ -15,7 +18,8 @@ export default function PromotePlayer({ playerId }: { playerId: string }) { }); if (!res.ok) { - throw new Error(await res.json()); + setError(await res.json()); + return; } mutate("/api/user"); @@ -24,7 +28,7 @@ export default function PromotePlayer({ playerId }: { playerId: string }) { return (