Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

chore: remove feature flag

Marc Seitz5d2b3941fbbc
diff --git a/components/billing/plan-badge.tsx b/components/billing/plan-badge.tsx
index 0c8c455c..0520d2d7 100644
--- a/components/billing/plan-badge.tsx
+++ b/components/billing/plan-badge.tsx
@@ -12,7 +12,7 @@ export default function PlanBadge({
return (
<span
className={cn(
- "ml-1 inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-xs uppercase text-gray-700 ring-1 ring-gray-400 hover:bg-gray-200 dark:text-foreground dark:ring-gray-500 hover:dark:bg-gray-700",
+ "ml-1 inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-xs font-normal uppercase tracking-normal text-gray-700 ring-1 ring-gray-400 hover:bg-gray-200 dark:text-foreground dark:ring-gray-500 hover:dark:bg-gray-700",
className,
)}
>
diff --git a/components/settings/settings-header.tsx b/components/settings/settings-header.tsx
index 6776a6e9..71847220 100644
--- a/components/settings/settings-header.tsx
+++ b/components/settings/settings-header.tsx
@@ -10,7 +10,6 @@ export function SettingsHeader() {
const { data: features } = useSWR<{
tokens: boolean;
incomingWebhooks: boolean;
- webhooks: boolean;
}>(
teamInfo?.currentTeam?.id
? `/api/feature-flags?teamId=${teamInfo.currentTeam.id}`
@@ -62,7 +61,6 @@ export function SettingsHeader() {
label: "Webhooks",
href: `/settings/webhooks`,
segment: "webhooks",
- disabled: !features?.webhooks,
},
{
label: "Tokens",
diff --git a/pages/settings/webhooks/[id]/index.tsx b/pages/settings/webhooks/[id]/index.tsx
index f1a34c1b..2f8061ec 100644
--- a/pages/settings/webhooks/[id]/index.tsx
+++ b/pages/settings/webhooks/[id]/index.tsx
@@ -4,11 +4,11 @@ import { useEffect, useState } from "react";
import { useTeam } from "@/context/team-context";
import { Webhook } from "@prisma/client";
-import { format } from "date-fns";
import { ArrowLeft, Check, Copy, WebhookIcon } from "lucide-react";
import { toast } from "sonner";
import useSWR from "swr";
+import { usePlan } from "@/lib/swr/use-billing";
import { cn, fetcher } from "@/lib/utils";
import AppLayout from "@/components/layouts/app";
@@ -32,23 +32,14 @@ export default function WebhookDetail() {
const router = useRouter();
const { id } = router.query;
const teamInfo = useTeam();
+ const { isFree, isPro } = usePlan();
const teamId = teamInfo?.currentTeam?.id;
const [isEditing, setIsEditing] = useState(false);
const [isCopied, setIsCopied] = useState(false);
-
- // Feature flag check
- const { data: features } = useSWR<{ webhooks: boolean }>(
- teamId ? `/api/feature-flags?teamId=${teamId}` : null,
- fetcher,
- );
-
- // Redirect if feature is not enabled
- useEffect(() => {
- if (features && !features.webhooks) {
- router.push("/settings/general");
- toast.error("This feature is not available for your team");
- }
- }, [features, router]);
+ const [formData, setFormData] = useState<WebhookFormData>({
+ name: "",
+ triggers: [],
+ });
const { data: webhook, mutate } = useSWR<Webhook>(
teamId && id ? `/api/teams/${teamId}/webhooks/${id}` : null,
@@ -63,11 +54,6 @@ export default function WebhookDetail() {
},
);
- const [formData, setFormData] = useState<WebhookFormData>({
- name: "",
- triggers: [],
- });
-
useEffect(() => {
if (webhook) {
setFormData({
@@ -78,6 +64,11 @@ export default function WebhookDetail() {
}, [webhook]);
const handleUpdate = async () => {
+ if (isFree || isPro) {
+ toast.error("This feature is not available on your plan");
+ return;
+ }
+
try {
const response = await fetch(`/api/teams/${teamId}/webhooks/${id}`, {
method: "PATCH",
@@ -346,7 +337,15 @@ export default function WebhookDetail() {
<div className="pt-4">
{isEditing ? (
<div className="flex gap-2">
- <Button onClick={handleUpdate}>Save Changes</Button>
+ <Button
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleUpdate();
+ }}
+ >
+ Save Changes
+ </Button>
<Button
variant="outline"
className="dark:bg-transparent dark:hover:bg-muted"
@@ -356,7 +355,19 @@ export default function WebhookDetail() {
</Button>
</div>
) : (
- <Button onClick={() => setIsEditing(true)}>
+ <Button
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ if (isFree || isPro) {
+ toast.error(
+ "This feature is not available on your plan",
+ );
+ return;
+ }
+ setIsEditing(true);
+ }}
+ >
Click to edit webhook
</Button>
)}
diff --git a/pages/settings/webhooks/index.tsx b/pages/settings/webhooks/index.tsx
index e1ddcae8..259ff2cc 100644
--- a/pages/settings/webhooks/index.tsx
+++ b/pages/settings/webhooks/index.tsx
@@ -1,22 +1,19 @@
import Link from "next/link";
import { useRouter } from "next/router";
-import { useEffect } from "react";
-
import { useTeam } from "@/context/team-context";
-import { format } from "date-fns";
-import { CircleHelpIcon, CopyIcon, WebhookIcon } from "lucide-react";
-import { toast } from "sonner";
+import { CircleHelpIcon, CrownIcon, WebhookIcon } from "lucide-react";
import useSWR from "swr";
+import { usePlan } from "@/lib/swr/use-billing";
+import { fetcher } from "@/lib/utils";
+
+import PlanBadge from "@/components/billing/plan-badge";
import AppLayout from "@/components/layouts/app";
import { SettingsHeader } from "@/components/settings/settings-header";
-import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import { BadgeTooltip } from "@/components/ui/tooltip";
-import { fetcher } from "@/lib/utils";
-
interface Webhook {
id: string;
name: string;
@@ -27,22 +24,9 @@ interface Webhook {
export default function WebhookSettings() {
const router = useRouter();
const teamInfo = useTeam();
+ const { isFree, isPro } = usePlan();
const teamId = teamInfo?.currentTeam?.id;
- // Feature flag check
- const { data: features } = useSWR<{ webhooks: boolean }>(
- teamId ? `/api/feature-flags?teamId=${teamId}` : null,
- fetcher,
- );
-
- // Redirect if feature is not enabled
- useEffect(() => {
- if (features && !features.webhooks) {
- router.push("/settings/general");
- toast.error("This feature is not available for your team");
- }
- }, [features, router]);
-
const { data: webhooks } = useSWR<Webhook[]>(
teamId ? `/api/teams/${teamId}/webhooks` : null,
fetcher,
@@ -55,8 +39,9 @@ export default function WebhookSettings() {
<div>
<div className="mb-4 flex items-center justify-between md:mb-8 lg:mb-12">
<div className="space-y-1">
- <h3 className="text-2xl font-semibold tracking-tight text-foreground">
- Webhooks
+ <h3 className="flex items-center gap-2 text-2xl font-semibold tracking-tight text-foreground">
+ Webhooks{" "}
+ {isFree || isPro ? <PlanBadge plan="Business" /> : null}
</h3>
<p className="flex flex-row items-center gap-2 text-sm text-muted-foreground">
Send data to external services when events happen in Papermark
@@ -65,9 +50,9 @@ export default function WebhookSettings() {
</BadgeTooltip>
</p>
</div>
- <Button onClick={() => router.push("/settings/webhooks/new")}>
- Create Webhook
- </Button>
+ <Link href="/settings/webhooks/new">
+ <Button>Create Webhook</Button>
+ </Link>
</div>
{/* Webhooks List */}
diff --git a/pages/settings/webhooks/new.tsx b/pages/settings/webhooks/new.tsx
index c5fd4bae..00d23e38 100644
--- a/pages/settings/webhooks/new.tsx
+++ b/pages/settings/webhooks/new.tsx
@@ -8,12 +8,10 @@ import { useTeam } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
import { ArrowLeft, Check } from "lucide-react";
import { toast } from "sonner";
-import useSWR from "swr";
import { z } from "zod";
import { newId } from "@/lib/id-helper";
import { usePlan } from "@/lib/swr/use-billing";
-import { fetcher } from "@/lib/utils";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import AppLayout from "@/components/layouts/app";
@@ -93,20 +91,6 @@ export default function NewWebhook() {
setFormData((prev) => ({ ...prev, secret: generatedSecret }));
}, []);
- // Feature flag check
- // const { data: features } = useSWR<{ webhooks: boolean }>(
- // teamId ? `/api/feature-flags?teamId=${teamId}` : null,
- // fetcher,
- // );
-
- // Redirect if feature is not enabled
- // useEffect(() => {
- // if (features && !features.webhooks) {
- // router.push("/settings/general");
- // toast.error("This feature is not available on your plan");
- // }
- // }, [features, router]);
-
const createWebhook = async () => {
if (isFree || isPro) {
toast.error("This feature is not available on your plan");
@@ -162,7 +146,14 @@ export default function NewWebhook() {
</Button>
<div className="w-full max-w-3xl">
- <form onSubmit={createWebhook} className="space-y-8">
+ <form
+ onSubmit={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ createWebhook();
+ }}
+ className="space-y-8"
+ >
<div className="space-y-2">
<Label htmlFor="name">Name</Label>
<p className="text-sm text-muted-foreground">