Files
sign/apps/web/src/app/(dashboard)/settings/webhooks/page.tsx

112 lines
4.0 KiB
TypeScript
Raw Normal View History

2024-02-06 16:00:28 +02:00
'use client';
2024-02-14 14:38:58 +02:00
import Link from 'next/link';
2024-08-27 20:34:39 +09:00
import { Trans, msg } from '@lingui/macro';
import { useLingui } from '@lingui/react';
2024-02-16 13:44:28 +02:00
import { Loader } from 'lucide-react';
2024-02-26 22:24:23 +11:00
import { DateTime } from 'luxon';
2024-02-06 16:00:28 +02:00
2024-02-26 22:24:23 +11:00
import { toFriendlyWebhookEventName } from '@documenso/lib/universal/webhook/to-friendly-webhook-event-name';
2024-02-09 16:28:18 +02:00
import { trpc } from '@documenso/trpc/react';
2024-02-26 22:24:23 +11:00
import { cn } from '@documenso/ui/lib/utils';
import { Badge } from '@documenso/ui/primitives/badge';
2024-02-06 16:00:28 +02:00
import { Button } from '@documenso/ui/primitives/button';
import { SettingsHeader } from '~/components/(dashboard)/settings/layout/header';
2024-02-07 16:04:12 +02:00
import { CreateWebhookDialog } from '~/components/(dashboard)/settings/webhooks/create-webhook-dialog';
2024-02-06 16:00:28 +02:00
import { DeleteWebhookDialog } from '~/components/(dashboard)/settings/webhooks/delete-webhook-dialog';
export default function WebhookPage() {
const { _, i18n } = useLingui();
2024-08-27 20:34:39 +09:00
2024-02-16 13:44:28 +02:00
const { data: webhooks, isLoading } = trpc.webhook.getWebhooks.useQuery();
2024-02-06 16:00:28 +02:00
return (
<div>
<SettingsHeader
2024-08-27 20:34:39 +09:00
title={_(msg`Webhooks`)}
subtitle={_(msg`On this page, you can create new Webhooks and manage the existing ones.`)}
2024-02-06 16:00:28 +02:00
>
2024-02-07 16:04:12 +02:00
<CreateWebhookDialog />
2024-02-06 16:00:28 +02:00
</SettingsHeader>
2024-02-16 13:44:28 +02:00
{isLoading && (
<div className="absolute inset-0 flex items-center justify-center bg-white/50">
<Loader className="h-8 w-8 animate-spin text-gray-500" />
</div>
)}
2024-02-14 14:38:58 +02:00
{webhooks && webhooks.length === 0 && (
2024-02-06 16:00:28 +02:00
// TODO: Perhaps add some illustrations here to make the page more engaging
<div className="mb-4">
<p className="text-muted-foreground mt-2 text-sm italic">
2024-08-27 20:34:39 +09:00
<Trans>
You have no webhooks yet. Your webhooks will be shown here once you create them.
</Trans>
2024-02-06 16:00:28 +02:00
</p>
</div>
)}
2024-02-14 14:38:58 +02:00
{webhooks && webhooks.length > 0 && (
2024-02-06 16:00:28 +02:00
<div className="mt-4 flex max-w-xl flex-col gap-y-4">
2024-02-09 16:28:18 +02:00
{webhooks?.map((webhook) => (
2024-02-26 22:24:23 +11:00
<div
key={webhook.id}
className={cn(
'border-border rounded-lg border p-4',
!webhook.enabled && 'bg-muted/40',
)}
>
2024-02-28 09:14:10 +02:00
<div className="flex flex-col gap-x-4 sm:flex-row sm:items-center sm:justify-between">
2024-02-06 16:00:28 +02:00
<div>
2024-02-26 22:24:23 +11:00
<div className="truncate font-mono text-xs">{webhook.id}</div>
2024-02-28 09:14:10 +02:00
<div className="mt-1.5 flex items-center gap-4">
2024-02-28 09:18:05 +02:00
<h5
className="max-w-[30rem] truncate text-sm sm:max-w-[18rem]"
title={webhook.webhookUrl}
>
2024-02-28 09:14:10 +02:00
{webhook.webhookUrl}
</h5>
2024-02-26 22:24:23 +11:00
<Badge variant={webhook.enabled ? 'neutral' : 'warning'} size="small">
2024-08-27 20:34:39 +09:00
{webhook.enabled ? <Trans>Enabled</Trans> : <Trans>Disabled</Trans>}
2024-02-26 22:24:23 +11:00
</Badge>
</div>
<p className="text-muted-foreground mt-2 text-xs">
2024-08-27 20:34:39 +09:00
<Trans>
Listening to{' '}
{webhook.eventTriggers
.map((trigger) => toFriendlyWebhookEventName(trigger))
.join(', ')}
</Trans>
2024-02-26 22:24:23 +11:00
</p>
<p className="text-muted-foreground mt-2 text-xs">
<Trans>Created on {i18n.date(webhook.createdAt, DateTime.DATETIME_FULL)}</Trans>
2024-02-26 22:24:23 +11:00
</p>
</div>
2024-02-28 09:14:10 +02:00
<div className="mt-4 flex flex-shrink-0 gap-4 sm:mt-0">
2024-02-26 22:24:23 +11:00
<Button asChild variant="outline">
2024-08-27 20:34:39 +09:00
<Link href={`/settings/webhooks/${webhook.id}`}>
<Trans>Edit</Trans>
</Link>
2024-02-26 22:24:23 +11:00
</Button>
<DeleteWebhookDialog webhook={webhook}>
2024-08-27 20:34:39 +09:00
<Button variant="destructive">
<Trans>Delete</Trans>
</Button>
2024-02-26 22:24:23 +11:00
</DeleteWebhookDialog>
2024-02-06 16:00:28 +02:00
</div>
</div>
</div>
))}
</div>
)}
</div>
);
}