Skip to content

Commit

Permalink
update promote player
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Feb 26, 2024
1 parent c4f6047 commit 8e28d50
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions components/PromotePlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
"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",
},
body: JSON.stringify({ playerId }),
});

if (!res.ok) {
throw new Error(await res.json());
setError(await res.json());
return;
}

mutate("/api/user");
Expand All @@ -24,7 +28,7 @@ export default function PromotePlayer({ playerId }: { playerId: string }) {
return (
<button
className="btn btn-square btn-xs btn-warning"
onClick={() => promotePlayer}
onClick={() => onClick()}
>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down

0 comments on commit 8e28d50

Please sign in to comment.