Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Webhook in setting for all users, but enable for pain plans
Ashish Viradiya0d27983a2263
diff --git a/components/settings/settings-header.tsx b/components/settings/settings-header.tsxindex 0c157f5d..87c1447e 100644--- a/components/settings/settings-header.tsx+++ b/components/settings/settings-header.tsx@@ -53,6 +53,12 @@ export function SettingsHeader() {href: `/settings/presets`,segment: "presets",},+ {+ label: "Webhooks",+ href: `/settings/webhooks`,+ segment: "webhooks",+ disabled: !features?.webhooks,+ },{label: "Billing",href: `/settings/billing`,@@ -64,12 +70,6 @@ export function SettingsHeader() {segment: "tokens",disabled: !features?.tokens,},- {- label: "Webhooks",- href: `/settings/webhooks`,- segment: "webhooks",- disabled: !features?.webhooks,- },{label: "Incoming Webhooks",href: `/settings/incoming-webhooks`,diff --git a/components/sidebar/app-sidebar.tsx b/components/sidebar/app-sidebar.tsxindex a4645382..af7ea62c 100644--- a/components/sidebar/app-sidebar.tsx+++ b/components/sidebar/app-sidebar.tsx@@ -125,6 +125,11 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {url: "/settings/domains",current: router.pathname.includes("settings/domains"),},+ {+ title: "Webhooks",+ url: "/settings/webhooks",+ current: router.pathname.includes("settings/webhooks"),+ },{title: "Billing",url: "/settings/billing",diff --git a/pages/settings/webhooks/new.tsx b/pages/settings/webhooks/new.tsxindex 0a5f7554..71a074ea 100644--- a/pages/settings/webhooks/new.tsx+++ b/pages/settings/webhooks/new.tsx@@ -8,7 +8,12 @@ import { useTeam } from "@/context/team-context";import { ArrowLeft, Check } from "lucide-react";import { toast } from "sonner";import useSWR from "swr";+import { z } from "zod";+import {+ PlanEnum,+ UpgradePlanModal,+} from "@/components/billing/upgrade-plan-modal";import AppLayout from "@/components/layouts/app";import { SettingsHeader } from "@/components/settings/settings-header";import Copy from "@/components/shared/icons/copy";@@ -19,6 +24,7 @@ import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";import { newId } from "@/lib/id-helper";+import { usePlan } from "@/lib/swr/use-billing";import { fetcher } from "@/lib/utils";interface WebhookEvent {@@ -60,9 +66,19 @@ export const linkEvents: WebhookEvent[] = [{ id: "link-downloaded", label: "Link Downloaded", value: "link.downloaded" },];+const formSchema = z.object({+ name: z+ .string()+ .min(3, "Please provide a webhook name with at least 3 characters."),+ url: z.string().url("Please enter a valid URL."),+ secret: z.string(),+ triggers: z.array(z.string()),+});+export default function NewWebhook() {const router = useRouter();const teamInfo = useTeam();+ const { plan } = usePlan();const teamId = teamInfo?.currentTeam?.id;const [isLoading, setIsLoading] = useState(false);@@ -96,6 +112,16 @@ export default function NewWebhook() {const createWebhook = async () => {try {setIsLoading(true);+ const result = formSchema.safeParse(formData);+ if (!result.success) {+ const errors = result.error.flatten().fieldErrors;+ Object.values(errors).forEach((errorMessages) => {+ if (errorMessages) {+ toast.error(errorMessages[0]);+ }+ });+ return;+ }const response = await fetch(`/api/teams/${teamId}/webhooks`, {method: "POST",headers: {@@ -136,7 +162,7 @@ export default function NewWebhook() {<formonSubmit={(e) => {e.preventDefault();- createWebhook();+ if (plan !== "free") createWebhook();}}className="space-y-8">@@ -152,7 +178,6 @@ export default function NewWebhook() {onChange={(e) =>setFormData((prev) => ({ ...prev, name: e.target.value }))}- requireddata-1p-ignoreautoComplete="off"autoFocus@@ -286,7 +311,6 @@ export default function NewWebhook() {onChange={(e) =>setFormData((prev) => ({ ...prev, url: e.target.value }))}- required/></div>@@ -326,9 +350,21 @@ export default function NewWebhook() {</div><div className="flex space-x-4">- <Button type="submit" disabled={isLoading}>- {isLoading ? "Creating..." : "Create Webhook"}- </Button>+ {plan === "free" ? (+ <UpgradePlanModal+ key="create-webhook"+ clickedPlan={PlanEnum.Business}+ trigger="create_webhook"+ >+ <Button type="submit" disabled={isLoading}>+ Create Webhook+ </Button>+ </UpgradePlanModal>+ ) : (+ <Button type="submit" disabled={isLoading}>+ {isLoading ? "Creating..." : "Create Webhook"}+ </Button>+ )}<Buttontype="button"variant="outline"