mirror of
https://github.com/Ategon/Jamjar.git
synced 2025-02-12 06:16:21 +00:00
Add promotions and demotions
This commit is contained in:
parent
d8894cd0eb
commit
f6c1ce75a6
2 changed files with 268 additions and 2 deletions
|
@ -377,6 +377,37 @@ export default function PostPage() {
|
|||
key="promote-mod"
|
||||
startContent={<Shield />}
|
||||
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
|
||||
</DropdownItem>
|
||||
|
@ -385,11 +416,39 @@ export default function PostPage() {
|
|||
)}
|
||||
{user?.admin &&
|
||||
post.author.mod &&
|
||||
post.author.id !== user.id ? (
|
||||
!post.author.admin ? (
|
||||
<DropdownItem
|
||||
key="demote-mod"
|
||||
startContent={<ShieldX />}
|
||||
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
|
||||
</DropdownItem>
|
||||
|
@ -401,12 +460,87 @@ export default function PostPage() {
|
|||
key="promote-admin"
|
||||
startContent={<ShieldAlert />}
|
||||
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
|
||||
</DropdownItem>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
{user?.admin &&
|
||||
post.author.admin &&
|
||||
post.author.id !== user.id ? (
|
||||
<DropdownItem
|
||||
key="demote-admin"
|
||||
startContent={<ShieldX />}
|
||||
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
|
||||
</DropdownItem>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</DropdownSection>
|
||||
) : (
|
||||
<></>
|
||||
|
|
|
@ -378,6 +378,37 @@ export default function PostCard({
|
|||
key="promote-mod"
|
||||
startContent={<Shield />}
|
||||
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
|
||||
</DropdownItem>
|
||||
|
@ -386,11 +417,39 @@ export default function PostCard({
|
|||
)}
|
||||
{user?.admin &&
|
||||
post.author.mod &&
|
||||
post.author.id !== user.id ? (
|
||||
!post.author.admin ? (
|
||||
<DropdownItem
|
||||
key="demote-mod"
|
||||
startContent={<ShieldX />}
|
||||
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
|
||||
</DropdownItem>
|
||||
|
@ -402,12 +461,85 @@ export default function PostCard({
|
|||
key="promote-admin"
|
||||
startContent={<ShieldAlert />}
|
||||
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
|
||||
</DropdownItem>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
{user?.admin &&
|
||||
post.author.admin &&
|
||||
post.author.id !== user.id ? (
|
||||
<DropdownItem
|
||||
key="demote-admin"
|
||||
startContent={<ShieldX />}
|
||||
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
|
||||
</DropdownItem>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</DropdownSection>
|
||||
) : (
|
||||
<></>
|
||||
|
|
Loading…
Reference in a new issue