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.

Improve webhooks page

Steven Tey7b73eb62d48f
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/new/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/new/page-client.tsx
deleted file mode 100644
index cfa60ea92d..0000000000
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/new/page-client.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-"use client";
-
-import useWorkspace from "@/lib/swr/use-workspace";
-import { BackLink } from "@/ui/shared/back-link";
-import AddEditWebhookForm from "@/ui/webhooks/add-edit-webhook-form";
-import { MaxWidthWrapper } from "@dub/ui";
-import { redirect } from "next/navigation";
-
-export default function NewWebhookPageClient({
- newSecret,
-}: {
- newSecret: string;
-}) {
- const { slug, plan } = useWorkspace();
-
- const needsHigherPlan = plan === "free" || plan === "pro";
-
- if (needsHigherPlan) {
- redirect(`/${slug}/settings/webhooks`);
- }
-
- return (
- <>
- <MaxWidthWrapper className="grid max-w-screen-lg gap-8">
- <BackLink href={`/${slug}/settings/webhooks`}>
- Back to webhooks
- </BackLink>
- </MaxWidthWrapper>
-
- <MaxWidthWrapper className="max-w-screen-lg space-y-6">
- <AddEditWebhookForm webhook={null} newSecret={newSecret} />
- </MaxWidthWrapper>
- </>
- );
-}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/edit/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/edit/page-client.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/edit/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/edit/page.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page.tsx
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/layout.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/layout.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/layout.tsx
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page-client.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/page-client.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page-client.tsx
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/[webhookId]/page.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/page.tsx
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/create-webhook-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/create-webhook-button.tsx
new file mode 100644
index 0000000000..bd1b11e6a6
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/create-webhook-button.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
+import { getPlanCapabilities } from "@/lib/plan-capabilities";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { Button } from "@dub/ui";
+import Link from "next/link";
+import { usePathname } from "next/navigation";
+
+export default function CreateWebhookButton() {
+ const pathname = usePathname();
+
+ const { slug, plan, role } = useWorkspace();
+
+ const { canCreateWebhooks } = getPlanCapabilities(plan);
+
+ const { error: permissionsError } = clientAccessCheck({
+ action: "webhooks.write",
+ role: role,
+ });
+
+ // don't show button if not on main webhooks page or if workspace cannot create webhooks
+ if (!canCreateWebhooks || !pathname.endsWith("/settings/webhooks")) {
+ return null;
+ }
+
+ return (
+ <Link href={`/${slug}/settings/webhooks/new`}>
+ <Button
+ className="flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm"
+ text="Create Webhook"
+ disabledTooltip={permissionsError}
+ />
+ </Link>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/layout.tsx
new file mode 100644
index 0000000000..55ba3773e4
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/layout.tsx
@@ -0,0 +1,20 @@
+import { PageContent } from "@/ui/layout/page-content";
+import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
+import { ReactNode } from "react";
+import CreateWebhookButton from "./create-webhook-button";
+
+export default function WebhooksLayout({ children }: { children: ReactNode }) {
+ return (
+ <PageContent
+ title="Webhooks"
+ titleInfo={{
+ title:
+ "Webhooks allow you to receive HTTP requests whenever a specific event (eg: someone clicked your link) occurs in Dub.",
+ href: "https://d.to/webhooks",
+ }}
+ controls={<CreateWebhookButton />}
+ >
+ <PageWidthWrapper>{children}</PageWidthWrapper>
+ </PageContent>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page-client.tsx
new file mode 100644
index 0000000000..0beedb8dc1
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page-client.tsx
@@ -0,0 +1,21 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import AddEditWebhookForm from "@/ui/webhooks/add-edit-webhook-form";
+import { redirect } from "next/navigation";
+
+export default function NewWebhookPageClient({
+ newSecret,
+}: {
+ newSecret: string;
+}) {
+ const { slug, plan } = useWorkspace();
+
+ const needsHigherPlan = plan === "free" || plan === "pro";
+
+ if (needsHigherPlan) {
+ redirect(`/${slug}/settings/webhooks`);
+ }
+
+ return <AddEditWebhookForm webhook={null} newSecret={newSecret} />;
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/new/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/new/page.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page.tsx
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/page-client.tsx
similarity index 60%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/page-client.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/page-client.tsx
index 20198676e7..8a2d514051 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/page-client.tsx
@@ -1,26 +1,17 @@
"use client";
-import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWebhooks from "@/lib/swr/use-webhooks";
import useWorkspace from "@/lib/swr/use-workspace";
import EmptyState from "@/ui/shared/empty-state";
import WebhookCard from "@/ui/webhooks/webhook-card";
import WebhookPlaceholder from "@/ui/webhooks/webhook-placeholder";
-import { Button, InfoTooltip, TooltipContent } from "@dub/ui";
import { Webhook } from "lucide-react";
-import { useRouter } from "next/navigation";
export default function WebhooksPageClient() {
- const router = useRouter();
- const { slug, plan, role } = useWorkspace();
+ const { slug, plan } = useWorkspace();
const { webhooks, isLoading } = useWebhooks();
- const { error: permissionsError } = clientAccessCheck({
- action: "webhooks.write",
- role: role,
- });
-
const needsHigherPlan = plan === "free" || plan === "pro";
if (needsHigherPlan) {
@@ -40,32 +31,6 @@ export default function WebhooksPageClient() {
return (
<div className="grid gap-5">
- <div className="flex flex-wrap justify-between gap-6">
- <div className="flex items-center gap-x-2">
- <h1 className="text-2xl font-semibold tracking-tight text-black">
- Webhooks
- </h1>
- <InfoTooltip
- content={
- <TooltipContent
- title="Webhooks allow you to receive HTTP requests whenever a specific event (eg: someone clicked your link) occurs in Dub."
- href="https://d.to/webhooks"
- target="_blank"
- cta="Learn more"
- />
- }
- />
- </div>
- <div className="flex w-full items-center gap-3 sm:w-auto">
- <Button
- className="flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm"
- text="Create Webhook"
- onClick={() => router.push(`/${slug}/settings/webhooks/new`)}
- disabledTooltip={permissionsError}
- />
- </div>
- </div>
-
<div className="animate-fade-in">
{!isLoading ? (
webhooks && webhooks.length > 0 ? (
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/page.tsx
similarity index 64%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/page.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/page.tsx
index af274b35ff..d527d535c7 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/webhooks/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/page.tsx
@@ -1,5 +1,5 @@
import WebhooksPageClient from "./page-client";
-export default async function WebhooksPage() {
+export default function WebhooksPage() {
return <WebhooksPageClient />;
}
diff --git a/apps/web/lib/plan-capabilities.ts b/apps/web/lib/plan-capabilities.ts
index 375c837f1c..8e495ac820 100644
--- a/apps/web/lib/plan-capabilities.ts
+++ b/apps/web/lib/plan-capabilities.ts
@@ -8,6 +8,7 @@ export const getPlanCapabilities = (
canAddFolder: !!plan && !["free"].includes(plan),
canManageFolderPermissions: !!plan && !["free", "pro"].includes(plan), // default access level is write
canManageCustomers: !!plan && !["free", "pro"].includes(plan),
+ canCreateWebhooks: !!plan && !["free", "pro"].includes(plan),
canManageProgram: !!plan && !["free", "pro"].includes(plan),
canTrackConversions: !!plan && !["free", "pro"].includes(plan),
canExportAuditLogs: !!plan && ["enterprise"].includes(plan),