Skip to content

Commit

Permalink
Mod Pane: add audit log to more places
Browse files Browse the repository at this point in the history
  • Loading branch information
SupertigerDev committed Jan 21, 2025
1 parent 9d06b2e commit 8baf167
Show file tree
Hide file tree
Showing 4 changed files with 324 additions and 123 deletions.
11 changes: 8 additions & 3 deletions src/chat-api/services/ModerationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,20 @@ export interface AuditLog {
reason?: string;
expireAt?: number;
}

export const getAuditLog = async (limit: number, afterId?: string) => {
interface getAuditLogOpts {
search?: string;
limit: number;
afterId?: string;
}
export const getAuditLog = async ({ limit, afterId, search }: getAuditLogOpts) => {
const data = await request<AuditLog[]>({
method: "GET",
params: {
...(afterId ? { after: afterId } : undefined),
...(search ? { q: search } : undefined),
limit,
},
url: env.SERVER_URL + "/api/moderation/audit-logs",
url: env.SERVER_URL + "/api/moderation/audit-logs" + (search ? "/search" : ""),
useToken: true,
});
return data;
Expand Down
21 changes: 16 additions & 5 deletions src/components/moderation-pane/ModerationPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createResource,
createSignal,
For,
JSX,
lazy,
on,
onMount,
Expand Down Expand Up @@ -797,7 +798,10 @@ function StatsArea() {
);
}

function AuditLogPane() {
export function AuditLogPane(props: {
search: string;
style?: JSX.CSSProperties;
}) {
const LIMIT = 30;
const [items, setItems] = createSignal<AuditLog[]>([]);
const [afterId, setAfterId] = createSignal<string | undefined>(undefined);
Expand All @@ -807,7 +811,7 @@ function AuditLogPane() {

createEffect(
on(afterId, async () => {
fetchServers();
fetchLogs();
})
);

Expand All @@ -817,9 +821,13 @@ function AuditLogPane() {
};
const firstFive = () => items().slice(0, 5);

const fetchServers = () => {
const fetchLogs = () => {
setLoadMoreClicked(true);
getAuditLog(LIMIT, afterId())
getAuditLog({
limit: LIMIT,
afterId: afterId(),
search: props.search,
})
.then((newItems) => {
setItems([...items(), ...newItems]);
if (newItems.length >= LIMIT) setLoadMoreClicked(false);
Expand All @@ -831,7 +839,10 @@ function AuditLogPane() {
<PaneContainer
class="pane servers"
expanded={showAll()}
style={!showAll() ? { height: "initial" } : undefined}
style={{
...(!showAll() ? { height: "initial" } : undefined),
...props.style,
}}
>
<FlexRow
gap={5}
Expand Down
6 changes: 4 additions & 2 deletions src/components/moderation-pane/ServerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createUpdatedSignal } from "@/common/createUpdatedSignal";
import { useWindowProperties } from "@/common/useWindowProperties";
import { useNavigate, useParams } from "solid-navigator";
import { Show, createEffect, createSignal, onMount } from "solid-js";
import { User } from "./ModerationPane";
import { AuditLogPane, User } from "./ModerationPane";
import Text from "../ui/Text";
import SettingsBlock from "../ui/settings-block/SettingsBlock";
import Input from "../ui/input/Input";
Expand Down Expand Up @@ -175,13 +175,15 @@ export default function ServerPage() {
</div>
<div style={{ "margin-bottom": "10px" }}>
<UsersAuditLogsPane
title="Audit Logs"
title="Server Audit Logs"
search={params.serverId}
hideSearchBar
noMargin
/>
</div>

<AuditLogPane search={params.serverId} style={{ margin: 0 }} />

<Show when={Object.keys(updatedInputValues()).length}>
<SettingsBlock
label="Confirm Admin Password"
Expand Down
Loading

0 comments on commit 8baf167

Please sign in to comment.