mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 17:26:38 +00:00
split clients table
This commit is contained in:
@@ -9,6 +9,7 @@ import { getTranslations } from "next-intl/server";
|
||||
|
||||
type ClientsPageProps = {
|
||||
params: Promise<{ orgId: string }>;
|
||||
searchParams: Promise<{ view?: string }>;
|
||||
};
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -17,13 +18,28 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
||||
const t = await getTranslations();
|
||||
|
||||
const params = await props.params;
|
||||
let clients: ListClientsResponse["clients"] = [];
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
// Default to 'user' view, or use the query param if provided
|
||||
let defaultView: "user" | "machine" = "user";
|
||||
defaultView = searchParams.view === "machine" ? "machine" : "user";
|
||||
|
||||
let userClients: ListClientsResponse["clients"] = [];
|
||||
let machineClients: ListClientsResponse["clients"] = [];
|
||||
|
||||
try {
|
||||
const res = await internal.get<AxiosResponse<ListClientsResponse>>(
|
||||
`/org/${params.orgId}/clients`,
|
||||
await authCookieHeader()
|
||||
);
|
||||
clients = res.data.data.clients;
|
||||
const [userRes, machineRes] = await Promise.all([
|
||||
internal.get<AxiosResponse<ListClientsResponse>>(
|
||||
`/org/${params.orgId}/clients?filter=user`,
|
||||
await authCookieHeader()
|
||||
),
|
||||
internal.get<AxiosResponse<ListClientsResponse>>(
|
||||
`/org/${params.orgId}/clients?filter=machine`,
|
||||
await authCookieHeader()
|
||||
)
|
||||
]);
|
||||
userClients = userRes.data.data.clients;
|
||||
machineClients = machineRes.data.data.clients;
|
||||
} catch (e) {}
|
||||
|
||||
function formatSize(mb: number): string {
|
||||
@@ -36,7 +52,7 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const clientRows: ClientRow[] = clients.map((client) => {
|
||||
const mapClientToRow = (client: ListClientsResponse["clients"][0]): ClientRow => {
|
||||
return {
|
||||
name: client.name,
|
||||
id: client.clientId,
|
||||
@@ -51,7 +67,10 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
||||
username: client.username,
|
||||
userEmail: client.userEmail
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const userClientRows: ClientRow[] = userClients.map(mapClientToRow);
|
||||
const machineClientRows: ClientRow[] = machineClients.map(mapClientToRow);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -60,7 +79,12 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
||||
description={t("manageClientsDescription")}
|
||||
/>
|
||||
|
||||
<ClientsTable clients={clientRows} orgId={params.orgId} />
|
||||
<ClientsTable
|
||||
userClients={userClientRows}
|
||||
machineClients={machineClientRows}
|
||||
orgId={params.orgId}
|
||||
defaultView={defaultView}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user