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

97 lines
3.5 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-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';
2024-02-26 22:24:23 +11:00
import { LocaleDate } from '~/components/formatter/locale-date';
2024-02-06 16:00:28 +02:00
export default function WebhookPage() {
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
title="Webhooks"
subtitle="On this page, you can create new Webhooks and manage the existing ones."
>
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">
You have no webhooks yet. Your webhooks will be shown here once you create them.
</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-06 16:00:28 +02:00
<div className="flex items-center justify-between gap-x-4">
<div>
2024-02-26 22:24:23 +11:00
<div className="truncate font-mono text-xs">{webhook.id}</div>
<div className="mt-1.5 flex items-center gap-2">
<h5 className="text-sm">{webhook.webhookUrl}</h5>
<Badge variant={webhook.enabled ? 'neutral' : 'warning'} size="small">
{webhook.enabled ? 'Enabled' : 'Disabled'}
</Badge>
</div>
<p className="text-muted-foreground mt-2 text-xs">
Listening to{' '}
{webhook.eventTriggers
.map((trigger) => toFriendlyWebhookEventName(trigger))
.join(', ')}
</p>
<p className="text-muted-foreground mt-2 text-xs">
Created on{' '}
<LocaleDate date={webhook.createdAt} format={DateTime.DATETIME_FULL} />
</p>
</div>
<div className="flex flex-shrink-0 gap-4">
<Button asChild variant="outline">
<Link href={`/settings/webhooks/${webhook.id}`}>Edit</Link>
</Button>
<DeleteWebhookDialog webhook={webhook}>
<Button variant="destructive">Delete</Button>
</DeleteWebhookDialog>
2024-02-06 16:00:28 +02:00
</div>
</div>
</div>
))}
</div>
)}
</div>
);
}