2024-02-06 16:00:28 +02:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { Zap } from 'lucide-react';
|
2024-02-09 16:28:18 +02:00
|
|
|
import { ToggleLeft, ToggleRight } 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-09 16:28:18 +02:00
|
|
|
const { data: webhooks } = 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-09 16:28:18 +02:00
|
|
|
{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-09 16:28:18 +02:00
|
|
|
{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>
|
|
|
|
|
<p className="text-muted-foreground">{webhook.webhookUrl}</p>
|
|
|
|
|
<h4 className="mt-4 text-lg font-semibold">Event triggers</h4>
|
|
|
|
|
{webhook.eventTriggers.map((trigger, index) => (
|
|
|
|
|
<p key={index} className="text-muted-foreground flex flex-row items-center">
|
|
|
|
|
<Zap className="mr-1 h-4 w-4 fill-yellow-400 stroke-yellow-600" /> {trigger}
|
|
|
|
|
</p>
|
|
|
|
|
))}
|
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>
|
|
|
|
|
<div className="flex flex-col-reverse space-y-2 space-y-reverse sm:flex-row sm:justify-end sm:space-x-2 sm:space-y-0">
|
|
|
|
|
<Button variant="secondary" className="">
|
|
|
|
|
Edit
|
|
|
|
|
</Button>
|
|
|
|
|
<DeleteWebhookDialog webhook={webhook}>
|
|
|
|
|
<Button variant="destructive">Delete</Button>
|
|
|
|
|
</DeleteWebhookDialog>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|