mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 10:37:47 +01:00
admin stuff
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import "./ProfileCard.scss";
|
||||
import { Form, Link, useNavigation } from "react-router-dom";
|
||||
import { useHomeContext } from "./HomeContext";
|
||||
|
||||
export function ProfileCard({
|
||||
username,
|
||||
@@ -7,13 +8,17 @@ export function ProfileCard({
|
||||
uuid,
|
||||
actions,
|
||||
alreadyFollowing,
|
||||
isAdmin,
|
||||
}: {
|
||||
username: string;
|
||||
fullName: string;
|
||||
uuid: string;
|
||||
actions: boolean;
|
||||
alreadyFollowing: boolean;
|
||||
isAdmin: boolean;
|
||||
}) {
|
||||
const homeContext = useHomeContext();
|
||||
|
||||
const navigation = useNavigation();
|
||||
const busy = navigation.state === "submitting";
|
||||
|
||||
@@ -54,6 +59,32 @@ export function ProfileCard({
|
||||
</button>
|
||||
</Form>
|
||||
))}
|
||||
{homeContext.user.isAdmin &&
|
||||
(isAdmin ? (
|
||||
<Form method={"put"}>
|
||||
<input hidden={true} value={uuid} name={"uuid"} />
|
||||
<button
|
||||
type={"submit"}
|
||||
name={"intent"}
|
||||
value={"unadmin"}
|
||||
disabled={busy}
|
||||
>
|
||||
unadmin
|
||||
</button>
|
||||
</Form>
|
||||
) : (
|
||||
<Form method={"put"}>
|
||||
<input hidden={true} value={uuid} name={"uuid"} />
|
||||
<button
|
||||
type={"submit"}
|
||||
name={"intent"}
|
||||
value={"admin"}
|
||||
disabled={busy}
|
||||
>
|
||||
make admin
|
||||
</button>
|
||||
</Form>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -28,6 +28,7 @@ export function UserList() {
|
||||
uuid={u.uuid}
|
||||
key={u.uuid}
|
||||
actions={homeContext.user.uuid != u.uuid}
|
||||
isAdmin={u.isAdmin}
|
||||
alreadyFollowing={following.some(
|
||||
(f) => f.uuid == u.uuid,
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import {
|
||||
addAdmin,
|
||||
addFollower,
|
||||
deleteSelf,
|
||||
removeAdmin,
|
||||
removeFollower,
|
||||
signup,
|
||||
updateSelf,
|
||||
@@ -101,6 +103,10 @@ export async function userListAction({ request }: ActionFunctionArgs) {
|
||||
return await addFollower(formData.get("uuid")!.toString());
|
||||
} else if (intent == "unfollow") {
|
||||
return await removeFollower(formData.get("uuid")!.toString());
|
||||
} else if (intent == "unadmin") {
|
||||
return await removeAdmin(formData.get("uuid")!.toString());
|
||||
} else if (intent == "admin") {
|
||||
return await addAdmin(formData.get("uuid")!.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,3 +73,11 @@ export async function removeFollower(uuid: string): Promise<TNoContentToResp> {
|
||||
NoContentToResp,
|
||||
);
|
||||
}
|
||||
|
||||
export async function addAdmin(uuid: string): Promise<TNoContentToResp> {
|
||||
return fetchJSONAuth("/person/admins/" + uuid, "PUT", NoContentToResp);
|
||||
}
|
||||
|
||||
export async function removeAdmin(uuid: string): Promise<TNoContentToResp> {
|
||||
return fetchJSONAuth("/person/admins/" + uuid, "DELETE", NoContentToResp);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ export const PersonTo = z.object({
|
||||
uuid: z.string(),
|
||||
username: z.string(),
|
||||
fullName: z.string(),
|
||||
isAdmin: z.boolean(),
|
||||
});
|
||||
export type TPersonTo = z.infer<typeof PersonTo>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user