Skip to content

Commit

Permalink
Add deleted bans to filters
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Jun 10, 2024
1 parent ad2616f commit d80eb38
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
9 changes: 7 additions & 2 deletions frontend/src/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type httpMethods = 'POST' | 'GET' | 'DELETE' | 'PUT';
export const apiCall = async <TResponse = EmptyBody | null, TRequestBody = Record<string, unknown> | object>(
url: string,
method: httpMethods = 'GET',
body?: TRequestBody | undefined | FormData,
body?: TRequestBody | undefined | FormData | Record<string, string>,
abortController?: AbortController,
isFormData: boolean = false
): Promise<TResponse> => {
Expand Down Expand Up @@ -119,7 +119,12 @@ export const apiCall = async <TResponse = EmptyBody | null, TRequestBody = Recor
requestOptions.signal = abortController.signal;
}

const response = await fetch(new URL(url, apiRootURL()), requestOptions);
const fullURL = new URL(url, apiRootURL());
if (method == 'GET' && body) {
fullURL.search = new URLSearchParams(body as Record<string, string>).toString();
}

const response = await fetch(fullURL, requestOptions);

switch (response.status) {
case 415:
Expand Down
12 changes: 0 additions & 12 deletions frontend/src/api/queries.ts

This file was deleted.

74 changes: 51 additions & 23 deletions frontend/src/routes/_mod.admin.ban.steam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { createFileRoute, useNavigate } from '@tanstack/react-router';
import { ColumnFiltersState, createColumnHelper, PaginationState, SortingState } from '@tanstack/react-table';
import { zodValidator } from '@tanstack/zod-form-adapter';
import { z } from 'zod';
import { BanReason, BanReasons, banReasonsCollection, SteamBanRecord } from '../api';
import { steamBansQuery } from '../api/queries.ts';
import { apiGetBansSteam, BanReason, BanReasons, banReasonsCollection, SteamBanRecord } from '../api';
import { ContainerWithHeader } from '../component/ContainerWithHeader.tsx';
import { ContainerWithHeaderAndButtons } from '../component/ContainerWithHeaderAndButtons.tsx';
import { FullTable } from '../component/FullTable.tsx';
Expand All @@ -30,6 +29,7 @@ import { TableCellRelativeDateField } from '../component/TableCellRelativeDateFi
import { TableHeadingCell } from '../component/TableHeadingCell.tsx';
import { Title } from '../component/Title';
import { Buttons } from '../component/field/Buttons.tsx';
import { CheckboxSimple } from '../component/field/CheckboxSimple.tsx';
import { SelectFieldSimple } from '../component/field/SelectFieldSimple.tsx';
import { TextFieldSimple } from '../component/field/TextFieldSimple.tsx';
import { ModalBanSteam, ModalUnbanSteam } from '../component/modal';
Expand All @@ -49,14 +49,17 @@ const banSteamSearchSchema = z.object({
]),
source_id: z.string().optional(),
target_id: z.string().optional(),
reason: z.nativeEnum(BanReason).optional()
reason: z.nativeEnum(BanReason).optional(),
deleted: z.boolean().optional()
});

export const Route = createFileRoute('/_mod/admin/ban/steam')({
component: AdminBanSteam,
validateSearch: (search) => banSteamSearchSchema.parse(search)
});

const queryKey = ['steamBans'];

function AdminBanSteam() {
const queryClient = useQueryClient();
const navigate = useNavigate({ from: Route.fullPath });
Expand All @@ -66,12 +69,19 @@ function AdminBanSteam() {
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>(initColumnFilter(search));
const { sendFlash } = useUserFlashCtx();

const { data: bans, isLoading } = useQuery(steamBansQuery());
const { data: bans, isLoading } = useQuery({
queryKey: queryKey,
queryFn: async () => {
return await apiGetBansSteam({
deleted: true
});
}
});

const onNewBanSteam = async () => {
try {
const ban = await NiceModal.show<SteamBanRecord>(ModalBanSteam, {});
queryClient.setQueryData(steamBansQuery().queryKey, [...(bans ?? []), ban]);
queryClient.setQueryData(queryKey, [...(bans ?? []), ban]);
} catch (e) {
sendFlash('error', `Error trying to setup ban: ${e}`);
}
Expand All @@ -89,7 +99,8 @@ function AdminBanSteam() {
defaultValues: {
source_id: search.source_id ?? '',
target_id: search.target_id ?? '',
reason: search.reason ?? BanReason.Any
reason: search.reason ?? BanReason.Any,
deleted: search.deleted ?? false
}
});

Expand All @@ -116,7 +127,7 @@ function AdminBanSteam() {
personaName: ban.target_personaname
});
queryClient.setQueryData(
steamBansQuery().queryKey,
queryKey,
(bans ?? []).filter((b) => b.ban_id != ban.ban_id)
);
sendFlash('success', 'Unbanned player successfully');
Expand All @@ -133,7 +144,7 @@ function AdminBanSteam() {
existing: ban
});
queryClient.setQueryData(
steamBansQuery().queryKey,
queryKey,
(bans ?? []).map((b) => (b.ban_id == updated.ban_id ? updated : b))
);
} catch (e) {
Expand All @@ -157,16 +168,15 @@ function AdminBanSteam() {
}}
>
<Grid container spacing={2}>
<Grid xs={4}>
<Grid xs={6} md={3}>
<Field
name={'source_id'}
children={(props) => {
return <TextFieldSimple {...props} label={'Author Steam ID'} />;
}}
/>
</Grid>
<Grid xs={6} md={3}>
<Field
name={'source_id'}
children={(props) => {
return <TextFieldSimple {...props} label={'Author Steam ID'} />;
}}
/>
</Grid>

<Grid xs={6} md={3}>
<Field
name={'target_id'}
Expand Down Expand Up @@ -200,7 +210,14 @@ function AdminBanSteam() {
}}
/>
</Grid>

<Grid xs={6} md={3}>
<Field
name={'deleted'}
children={(props) => {
return <CheckboxSimple {...props} label={'Show deleted/expired'} />;
}}
/>
</Grid>
<Grid xs={12} mdOffset="auto">
<Subscribe
selector={(state) => [state.canSubmit, state.isSubmitting]}
Expand Down Expand Up @@ -327,14 +344,25 @@ const makeColumns = (
}
}),
columnHelper.accessor('include_friends', {
header: () => <TableHeadingCell name={'F'} />,
cell: (info) => <TableCellBool enabled={info.getValue() as boolean} />
header: () => <TableHeadingCell name={'F'} tooltip={'Friends list also banned'} />,
cell: (info) => <TableCellBool enabled={info.getValue()} />
}),
columnHelper.accessor('evade_ok', {
header: () => <TableHeadingCell name={'E'} />,
cell: (info) => <TableCellBool enabled={info.getValue() as boolean} />
header: () => (
<TableHeadingCell
name={'E'}
tooltip={'Evasion OK. Players connecting from the same ip will not be banned.'}
/>
),
cell: (info) => <TableCellBool enabled={info.getValue()} />
}),
columnHelper.accessor('deleted', {
filterFn: (row, _, filterValue) => {
return filterValue ? true : !row.original.deleted;
},
header: () => <TableHeadingCell name={'D'} tooltip={'Deleted / Expired Bans'} />,
cell: (info) => <TableCellBool enabled={info.getValue()} />
}),

columnHelper.accessor('report_id', {
header: () => <TableHeadingCell name={'Rep.'} />,
cell: (info) =>
Expand Down

0 comments on commit d80eb38

Please sign in to comment.