mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-12 05:36:38 +00:00
share links
This commit is contained in:
65
src/app/[orgId]/settings/share-links/page.tsx
Normal file
65
src/app/[orgId]/settings/share-links/page.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import { internal } from "@app/api";
|
||||
import { authCookieHeader } from "@app/api/cookies";
|
||||
import { AxiosResponse } from "axios";
|
||||
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
||||
import { redirect } from "next/navigation";
|
||||
import { cache } from "react";
|
||||
import { GetOrgResponse } from "@server/routers/org";
|
||||
import OrgProvider from "@app/providers/OrgProvider";
|
||||
import { ListAccessTokensResponse } from "@server/routers/accessToken";
|
||||
import ShareLinksTable, { ShareLinkRow } from "./components/ShareLinksTable";
|
||||
|
||||
type ShareLinksPageProps = {
|
||||
params: Promise<{ orgId: string }>;
|
||||
};
|
||||
|
||||
export default async function ShareLinksPage(props: ShareLinksPageProps) {
|
||||
const params = await props.params;
|
||||
|
||||
let tokens: ListAccessTokensResponse["accessTokens"] = [];
|
||||
|
||||
try {
|
||||
const res = await internal.get<AxiosResponse<ListAccessTokensResponse>>(
|
||||
`/org/${params.orgId}/access-tokens`,
|
||||
await authCookieHeader()
|
||||
);
|
||||
tokens = res.data.data.accessTokens;
|
||||
} catch (e) {
|
||||
console.error("Error fetching tokens", e);
|
||||
}
|
||||
|
||||
let org = null;
|
||||
try {
|
||||
const getOrg = cache(async () =>
|
||||
internal.get<AxiosResponse<GetOrgResponse>>(
|
||||
`/org/${params.orgId}`,
|
||||
await authCookieHeader()
|
||||
)
|
||||
);
|
||||
const res = await getOrg();
|
||||
org = res.data.data;
|
||||
} catch {
|
||||
redirect(`/${params.orgId}/settings/resources`);
|
||||
}
|
||||
|
||||
if (!org) {
|
||||
redirect(`/${params.orgId}/settings/resources`);
|
||||
}
|
||||
|
||||
const rows: ShareLinkRow[] = tokens.map((token) => {
|
||||
return token;
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsSectionTitle
|
||||
title="Manage Share Links"
|
||||
description="Create shareable links to grant temporary or permanent access to your resources"
|
||||
/>
|
||||
|
||||
<OrgProvider org={org}>
|
||||
<ShareLinksTable shareLinks={rows} orgId={params.orgId} />
|
||||
</OrgProvider>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user