Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update webhook fix

Kiran Kc2dc9d4cb27c
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
index 76e135ff26..539f85ce05 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
@@ -37,7 +37,7 @@ export default function UpdateWebhookPageClient({
return (
<>
- <WebhookHeader webhookId={webhookId} />
+ <WebhookHeader webhookId={webhookId} page="edit" />
<MaxWidthWrapper className="max-w-screen-lg space-y-6">
{webhook && <AddEditWebhookForm webhook={webhook} />}
</MaxWidthWrapper>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page-client.tsx
index f37cb78af0..0fd508dc4b 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page-client.tsx
@@ -34,7 +34,7 @@ export default function WebhookLogsPageClient({
return (
<>
- <WebhookHeader webhookId={webhookId} />
+ <WebhookHeader webhookId={webhookId} page="events" />
<MaxWidthWrapper className="max-w-screen-lg space-y-6">
<></>
</MaxWidthWrapper>
diff --git a/apps/web/lib/edge-config/get-feature-flags.ts b/apps/web/lib/edge-config/get-feature-flags.ts
index 201283c0af..581ebff93c 100644
--- a/apps/web/lib/edge-config/get-feature-flags.ts
+++ b/apps/web/lib/edge-config/get-feature-flags.ts
@@ -20,8 +20,8 @@ export const getFeatureFlags = async ({
conversions: false,
integrations: false,
dublink: false,
- webhooks: false,
referrals: false,
+ webhooks: true,
};
if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {
diff --git a/apps/web/lib/zod/schemas/webhooks.ts b/apps/web/lib/zod/schemas/webhooks.ts
index 86a033a42c..dd40057706 100644
--- a/apps/web/lib/zod/schemas/webhooks.ts
+++ b/apps/web/lib/zod/schemas/webhooks.ts
@@ -20,7 +20,7 @@ export const createWebhookSchema = z.object({
url: z.string().url().max(190),
secret: z.string().startsWith(WEBHOOK_SECRET_PREFIX),
triggers: z.array(z.enum(WEBHOOK_TRIGGERS)),
- linkId: z.string().optional(),
+ linkId: z.string().nullable().optional(),
});
export const updateWebhookSchema = createWebhookSchema.partial();
diff --git a/apps/web/ui/webhooks/add-edit-webhook-form.tsx b/apps/web/ui/webhooks/add-edit-webhook-form.tsx
index 5c1df8c989..acdabbc305 100644
--- a/apps/web/ui/webhooks/add-edit-webhook-form.tsx
+++ b/apps/web/ui/webhooks/add-edit-webhook-form.tsx
@@ -4,7 +4,7 @@ import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { NewWebhook, WebhookProps } from "@/lib/types";
import { WEBHOOK_TRIGGERS } from "@/lib/webhook/constants";
-import { Button, Checkbox, InfoTooltip } from "@dub/ui";
+import { Button, Checkbox, CopyButton, InfoTooltip } from "@dub/ui";
import { cn } from "@dub/utils";
import { redirect, useRouter } from "next/navigation";
import { FormEvent, useMemo, useState } from "react";
@@ -149,23 +149,20 @@ export default function AddEditWebhookForm({
</div>
</div>
- <div>
- <label htmlFor="secret" className="flex items-center space-x-2">
+ <div className="space-y-2">
+ <label className="flex items-center space-x-2">
<h2 className="text-sm font-medium text-gray-900">
Signing secret
</h2>
<InfoTooltip content="A secret token used to sign the webhook payload." />
</label>
- <div className="relative mt-2 rounded-md shadow-sm">
- <input
- className="block w-full cursor-not-allowed rounded-md border-gray-300 bg-gray-50 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
- required
- value={secret}
- onChange={(e) => setData({ ...data, url: e.target.value })}
- autoComplete="off"
- readOnly
- disabled
- />
+ <div className="flex items-center justify-between rounded-md border border-gray-300 bg-white py-1 px-3">
+ <p className="text-nowrap font-mono text-sm text-gray-500">
+ {secret}
+ </p>
+ <div className="flex flex-col gap-2">
+ <CopyButton value={secret} className="rounded-md" />
+ </div>
</div>
</div>
diff --git a/apps/web/ui/webhooks/webhook-header.tsx b/apps/web/ui/webhooks/webhook-header.tsx
index 4878d42911..fd4d236158 100644
--- a/apps/web/ui/webhooks/webhook-header.tsx
+++ b/apps/web/ui/webhooks/webhook-header.tsx
@@ -7,13 +7,19 @@ import { useRemoveOAuthAppModal } from "@/ui/modals/remove-oauth-app-modal";
import { ThreeDots } from "@/ui/shared/icons";
import { Button, MaxWidthWrapper, Popover, TokenAvatar } from "@dub/ui";
import { fetcher } from "@dub/utils";
-import { ChevronLeft, Edit3, Trash } from "lucide-react";
+import { ChevronLeft, Edit3, FileStack, Trash } from "lucide-react";
import Link from "next/link";
import { notFound, useRouter } from "next/navigation";
import { useState } from "react";
import useSWR from "swr";
-export default function WebhookHeader({ webhookId }: { webhookId: string }) {
+export default function WebhookHeader({
+ webhookId,
+ page,
+}: {
+ webhookId: string;
+ page: "edit" | "events";
+}) {
const router = useRouter();
const { slug, id: workspaceId, role } = useWorkspace();
const [openPopover, setOpenPopover] = useState(false);
@@ -76,16 +82,36 @@ export default function WebhookHeader({ webhookId }: { webhookId: string }) {
<Popover
content={
<div className="grid w-screen gap-px p-2 sm:w-48">
- <Button
- text="Update webhook"
- variant="outline"
- icon={<Edit3 className="h-4 w-4" />}
- className="h-9 justify-start px-2 font-medium"
- onClick={async () => {
- setOpenPopover(false);
- router.push(`/${slug}/settings/webhooks/${webhookId}/edit`);
- }}
- />
+ {page === "events" && (
+ <Button
+ text="Update webhook"
+ variant="outline"
+ icon={<Edit3 className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ onClick={async () => {
+ setOpenPopover(false);
+ router.push(
+ `/${slug}/settings/webhooks/${webhookId}/edit`,
+ );
+ }}
+ />
+ )}
+
+ {page === "edit" && (
+ <Button
+ text="Webhook logs"
+ variant="outline"
+ icon={<FileStack className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ onClick={async () => {
+ setOpenPopover(false);
+ router.push(
+ `/${slug}/settings/webhooks/${webhookId}/events`,
+ );
+ }}
+ />
+ )}
+
<Button
text="Remove webhook"
variant="danger-outline"
diff --git a/packages/ui/src/copy-button.tsx b/packages/ui/src/copy-button.tsx
index 6668356a9d..6da7c8b2dd 100644
--- a/packages/ui/src/copy-button.tsx
+++ b/packages/ui/src/copy-button.tsx
@@ -46,6 +46,7 @@ export function CopyButton({
setTimeout(() => setCopied(false), 3000);
}}
className={cn(copyButtonVariants({ variant }), className)}
+ type="button"
>
<span className="sr-only">Copy</span>
{copied ? (