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
src
|
@ -377,6 +377,37 @@ export default function PostPage() {
|
||||||
key="promote-mod"
|
key="promote-mod"
|
||||||
startContent={<Shield />}
|
startContent={<Shield />}
|
||||||
description="Promote user to Mod"
|
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
|
Appoint as mod
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
@ -385,11 +416,39 @@ export default function PostPage() {
|
||||||
)}
|
)}
|
||||||
{user?.admin &&
|
{user?.admin &&
|
||||||
post.author.mod &&
|
post.author.mod &&
|
||||||
post.author.id !== user.id ? (
|
!post.author.admin ? (
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
key="demote-mod"
|
key="demote-mod"
|
||||||
startContent={<ShieldX />}
|
startContent={<ShieldX />}
|
||||||
description="Demote user from Mod"
|
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
|
Remove as mod
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
@ -401,12 +460,87 @@ export default function PostPage() {
|
||||||
key="promote-admin"
|
key="promote-admin"
|
||||||
startContent={<ShieldAlert />}
|
startContent={<ShieldAlert />}
|
||||||
description="Promote user to Admin"
|
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
|
Appoint as admin
|
||||||
</DropdownItem>
|
</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>
|
</DropdownSection>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
|
|
|
@ -378,6 +378,37 @@ export default function PostCard({
|
||||||
key="promote-mod"
|
key="promote-mod"
|
||||||
startContent={<Shield />}
|
startContent={<Shield />}
|
||||||
description="Promote user to Mod"
|
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
|
Appoint as mod
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
@ -386,11 +417,39 @@ export default function PostCard({
|
||||||
)}
|
)}
|
||||||
{user?.admin &&
|
{user?.admin &&
|
||||||
post.author.mod &&
|
post.author.mod &&
|
||||||
post.author.id !== user.id ? (
|
!post.author.admin ? (
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
key="demote-mod"
|
key="demote-mod"
|
||||||
startContent={<ShieldX />}
|
startContent={<ShieldX />}
|
||||||
description="Demote user from Mod"
|
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
|
Remove as mod
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
@ -402,12 +461,85 @@ export default function PostCard({
|
||||||
key="promote-admin"
|
key="promote-admin"
|
||||||
startContent={<ShieldAlert />}
|
startContent={<ShieldAlert />}
|
||||||
description="Promote user to Admin"
|
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
|
Appoint as admin
|
||||||
</DropdownItem>
|
</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>
|
</DropdownSection>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
|
|
Loading…
Reference in a new issue