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-06 16:00:28 +02:00
|
|
|
import { Zap } from 'lucide-react';
|
2024-02-09 16:28:18 +02:00
|
|
|
import { ToggleLeft, ToggleRight } from 'lucide-react';
|
2024-02-16 13:44:28 +02:00
|
|
|
import { Loader } from 'lucide-react';
|
2024-02-06 16:00:28 +02:00
|
|
|
|
2024-02-09 16:28:18 +02:00
|
|
|
import { trpc } from '@documenso/trpc/react';
|
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() {
|
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-06 16:00:28 +02:00
|
|
|
<div key={webhook.id} className="border-border rounded-lg border p-4">
|
|
|
|
|
<div className="flex items-center justify-between gap-x-4">
|
|
|
|
|
<div>
|
|
|
|
|
<h4 className="text-lg font-semibold">Webhook URL</h4>
|
2024-02-26 12:52:30 +02:00
|
|
|
<p className="text-muted-foreground break-all">{webhook.webhookUrl}</p>
|
2024-02-06 16:00:28 +02:00
|
|
|
<h4 className="mt-4 text-lg font-semibold">Event triggers</h4>
|
|
|
|
|
{webhook.eventTriggers.map((trigger, index) => (
|
2024-02-14 14:38:58 +02:00
|
|
|
<span key={index} className="text-muted-foreground flex flex-row items-center">
|
|
|
|
|
<Zap className="mr-1 h-4 w-4" /> {trigger}
|
|
|
|
|
</span>
|
2024-02-06 16:00:28 +02:00
|
|
|
))}
|
2024-02-09 16:28:18 +02:00
|
|
|
{webhook.enabled ? (
|
|
|
|
|
<h4 className="mt-4 flex items-center gap-2 text-lg">
|
|
|
|
|
Active <ToggleRight className="h-6 w-6 fill-green-200 stroke-green-400" />
|
|
|
|
|
</h4>
|
|
|
|
|
) : (
|
|
|
|
|
<h4 className="mt-4 flex items-center gap-2 text-lg">
|
|
|
|
|
Inactive <ToggleLeft className="h-6 w-6 fill-slate-200 stroke-slate-400" />
|
|
|
|
|
</h4>
|
|
|
|
|
)}
|
2024-02-06 16:00:28 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-02-16 13:58:03 +02:00
|
|
|
<div className="mt-6 flex flex-col-reverse space-y-2 space-y-reverse sm:mt-0 sm:flex-row sm:justify-end sm:space-x-2 sm:space-y-0">
|
2024-02-14 14:38:58 +02:00
|
|
|
<Button asChild variant="outline">
|
|
|
|
|
<Link href={`/settings/webhooks/${webhook.id}`}>Edit</Link>
|
2024-02-06 16:00:28 +02:00
|
|
|
</Button>
|
|
|
|
|
<DeleteWebhookDialog webhook={webhook}>
|
|
|
|
|
<Button variant="destructive">Delete</Button>
|
|
|
|
|
</DeleteWebhookDialog>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|