diff --git a/src/app/p/[slug]/page.tsx b/src/app/p/[slug]/page.tsx index 9d76271..cb8f110 100644 --- a/src/app/p/[slug]/page.tsx +++ b/src/app/p/[slug]/page.tsx @@ -377,6 +377,37 @@ export default function PostPage() { key="promote-mod" startContent={} description="Promote user to Mod" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + mod: true, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Promoted User to Mod"); + window.location.reload(); + } else { + toast.error( + "Error while promoting user to Mod" + ); + } + }} > Appoint as mod @@ -385,11 +416,39 @@ export default function PostPage() { )} {user?.admin && post.author.mod && - post.author.id !== user.id ? ( + !post.author.admin ? ( } description="Demote user from Mod" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Demoted User"); + window.location.reload(); + } else { + toast.error("Error while demoting user"); + } + }} > Remove as mod @@ -401,12 +460,87 @@ export default function PostPage() { key="promote-admin" startContent={} description="Promote user to Admin" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + admin: true, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Promoted User to Admin"); + window.location.reload(); + } else { + toast.error( + "Error while promoting user to Admin" + ); + } + }} > Appoint as admin ) : ( <> )} + {user?.admin && + post.author.admin && + post.author.id !== user.id ? ( + } + description="Demote user to mod" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + mod: true, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Demoted User to Mod"); + window.location.reload(); + } else { + toast.error( + "Error while demoting user to mod" + ); + } + }} + > + Remove as admin + + ) : ( + <> + )} ) : ( <> diff --git a/src/components/posts/PostCard.tsx b/src/components/posts/PostCard.tsx index 92e38c4..ef7ba1f 100644 --- a/src/components/posts/PostCard.tsx +++ b/src/components/posts/PostCard.tsx @@ -378,6 +378,37 @@ export default function PostCard({ key="promote-mod" startContent={} description="Promote user to Mod" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + mod: true, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Promoted User to Mod"); + window.location.reload(); + } else { + toast.error( + "Error while promoting user to Mod" + ); + } + }} > Appoint as mod @@ -386,11 +417,39 @@ export default function PostCard({ )} {user?.admin && post.author.mod && - post.author.id !== user.id ? ( + !post.author.admin ? ( } description="Demote user from Mod" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Demoted User"); + window.location.reload(); + } else { + toast.error("Error while demoting user"); + } + }} > Remove as mod @@ -402,12 +461,85 @@ export default function PostCard({ key="promote-admin" startContent={} description="Promote user to Admin" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + admin: true, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Promoted User to Admin"); + window.location.reload(); + } else { + toast.error( + "Error while promoting user to Admin" + ); + } + }} > Appoint as admin ) : ( <> )} + {user?.admin && + post.author.admin && + post.author.id !== user.id ? ( + } + description="Demote user to mod" + onPress={async () => { + const response = await fetch( + process.env.NEXT_PUBLIC_MODE === "PROD" + ? "https://d2jam.com/api/v1/mod" + : "http://localhost:3005/api/v1/mod", + { + body: JSON.stringify({ + targetname: post.author.slug, + mod: true, + username: getCookie("user"), + }), + method: "POST", + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${getCookie( + "token" + )}`, + }, + credentials: "include", + } + ); + + if (response.ok) { + toast.success("Demoted User to Mod"); + window.location.reload(); + } else { + toast.error("Error while demoting user to mod"); + } + }} + > + Remove as admin + + ) : ( + <> + )} ) : ( <>