2024-08-27 20:34:39 +09:00
|
|
|
import { Trans } from '@lingui/macro';
|
2023-12-31 13:58:15 +11:00
|
|
|
import { DateTime } from 'luxon';
|
|
|
|
|
|
2024-08-27 20:34:39 +09:00
|
|
|
import { setupI18nSSR } from '@documenso/lib/client-only/providers/i18n.server';
|
2023-12-31 13:58:15 +11:00
|
|
|
import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
|
|
|
|
import { getUserTokens } from '@documenso/lib/server-only/public-api/get-all-user-tokens';
|
|
|
|
|
import { Button } from '@documenso/ui/primitives/button';
|
|
|
|
|
|
|
|
|
|
import DeleteTokenDialog from '~/components/(dashboard)/settings/token/delete-token-dialog';
|
2023-11-24 13:59:33 +02:00
|
|
|
import { ApiTokenForm } from '~/components/forms/token';
|
|
|
|
|
|
2023-12-31 13:58:15 +11:00
|
|
|
export default async function ApiTokensPage() {
|
2024-09-10 12:38:08 +10:00
|
|
|
const { i18n } = setupI18nSSR();
|
2024-08-27 20:34:39 +09:00
|
|
|
|
2023-12-31 13:58:15 +11:00
|
|
|
const { user } = await getRequiredServerComponentSession();
|
|
|
|
|
|
|
|
|
|
const tokens = await getUserTokens({ userId: user.id });
|
|
|
|
|
|
2023-11-24 13:59:33 +02:00
|
|
|
return (
|
|
|
|
|
<div>
|
2024-08-27 20:34:39 +09:00
|
|
|
<h3 className="text-2xl font-semibold">
|
|
|
|
|
<Trans>API Tokens</Trans>
|
|
|
|
|
</h3>
|
2023-11-24 13:59:33 +02:00
|
|
|
|
|
|
|
|
<p className="text-muted-foreground mt-2 text-sm">
|
2024-08-27 20:34:39 +09:00
|
|
|
<Trans>
|
|
|
|
|
On this page, you can create new API tokens and manage the existing ones. <br />
|
|
|
|
|
Also see our{' '}
|
|
|
|
|
<a
|
|
|
|
|
className="text-primary underline"
|
|
|
|
|
href={'https://docs.documenso.com/developers/public-api'}
|
|
|
|
|
target="_blank"
|
|
|
|
|
>
|
|
|
|
|
Documentation
|
|
|
|
|
</a>
|
|
|
|
|
.
|
|
|
|
|
</Trans>
|
2023-11-24 13:59:33 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<hr className="my-4" />
|
|
|
|
|
|
2024-07-24 09:01:56 +05:30
|
|
|
<ApiTokenForm className="max-w-xl" tokens={tokens} />
|
2023-12-31 13:58:15 +11:00
|
|
|
|
|
|
|
|
<hr className="mb-4 mt-8" />
|
|
|
|
|
|
2024-08-27 20:34:39 +09:00
|
|
|
<h4 className="text-xl font-medium">
|
|
|
|
|
<Trans>Your existing tokens</Trans>
|
|
|
|
|
</h4>
|
2023-12-31 13:58:15 +11:00
|
|
|
|
|
|
|
|
{tokens.length === 0 && (
|
|
|
|
|
<div className="mb-4">
|
|
|
|
|
<p className="text-muted-foreground mt-2 text-sm italic">
|
2024-08-27 20:34:39 +09:00
|
|
|
<Trans>Your tokens will be shown here once you create them.</Trans>
|
2023-12-31 13:58:15 +11:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{tokens.length > 0 && (
|
|
|
|
|
<div className="mt-4 flex max-w-xl flex-col gap-y-4">
|
|
|
|
|
{tokens.map((token) => (
|
|
|
|
|
<div key={token.id} className="border-border rounded-lg border p-4">
|
|
|
|
|
<div className="flex items-center justify-between gap-x-4">
|
|
|
|
|
<div>
|
|
|
|
|
<h5 className="text-base">{token.name}</h5>
|
|
|
|
|
|
|
|
|
|
<p className="text-muted-foreground mt-2 text-xs">
|
2024-09-10 12:38:08 +10:00
|
|
|
<Trans>Created on {i18n.date(token.createdAt, DateTime.DATETIME_FULL)}</Trans>
|
2023-12-31 13:58:15 +11:00
|
|
|
</p>
|
2024-02-09 11:32:54 +02:00
|
|
|
{token.expires ? (
|
|
|
|
|
<p className="text-muted-foreground mt-1 text-xs">
|
2024-09-10 12:38:08 +10:00
|
|
|
<Trans>Expires on {i18n.date(token.expires, DateTime.DATETIME_FULL)}</Trans>
|
2024-02-09 11:32:54 +02:00
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
<p className="text-muted-foreground mt-1 text-xs">
|
2024-08-27 20:34:39 +09:00
|
|
|
<Trans>Token doesn't have an expiration date</Trans>
|
2024-02-09 11:32:54 +02:00
|
|
|
</p>
|
|
|
|
|
)}
|
2023-12-31 13:58:15 +11:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<DeleteTokenDialog token={token}>
|
2024-08-27 20:34:39 +09:00
|
|
|
<Button variant="destructive">
|
|
|
|
|
<Trans>Delete</Trans>
|
|
|
|
|
</Button>
|
2023-12-31 13:58:15 +11:00
|
|
|
</DeleteTokenDialog>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2023-11-24 13:59:33 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|