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.

1.0 KB
Raw Blame
"use client";

import { clientAccessCheck } from "@/lib/client-access-check";
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="h-9"
        text="Create webhook"
        disabledTooltip={permissionsError}
        aria-label="Create webhook"
      />
    </Link>
  );
}