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.

add UpgradeRequiredToast

Kiran Kdb03a5b74113
diff --git a/apps/web/app/(ee)/api/discount-codes/route.ts b/apps/web/app/(ee)/api/discount-codes/route.ts
index cecdb3971b..a6b6a786ed 100644
--- a/apps/web/app/(ee)/api/discount-codes/route.ts
+++ b/apps/web/app/(ee)/api/discount-codes/route.ts
@@ -58,7 +58,7 @@ export const POST = withWorkspace(
throw new DubApiError({
code: "bad_request",
message:
- "Stripe connect ID not found for your workspace. Please install Dub Stripe app.",
+ "Your workspace isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create discount codes.",
});
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/links/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/links/page-client.tsx
index a6ba3d8a44..b75f94e7e8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/links/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/links/page-client.tsx
@@ -13,6 +13,7 @@ import {
LoadingSpinner,
Table,
Tag,
+ TooltipContent,
useTable,
} from "@dub/ui";
import { Trash } from "@dub/ui/icons";
@@ -165,7 +166,7 @@ const PartnerDiscountCodes = ({
}: {
partner: EnrolledPartnerProps;
}) => {
- const { slug } = useWorkspace();
+ const { slug, stripeConnectId } = useWorkspace();
const [selectedDiscountCode, setSelectedDiscountCode] =
useState<DiscountCodeProps | null>(null);
@@ -252,6 +253,17 @@ const PartnerDiscountCodes = ({
} as any);
const disabledReason = useMemo(() => {
+ if (!stripeConnectId) {
+ return (
+ <TooltipContent
+ title="Your workspace isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create discount codes."
+ cta="Install Stripe app"
+ href="/settings/integrations/stripe"
+ target="_blank"
+ />
+ );
+ }
+
if (!partner.discountId) {
return "No discount assigned to this partner group. Please add a discount before you can create a discount code.";
}
@@ -265,7 +277,7 @@ const PartnerDiscountCodes = ({
}
return undefined;
- }, [partner.discountId, partner.links, discountCodes]);
+ }, [partner.discountId, partner.links, discountCodes, stripeConnectId]);
return (
<>
diff --git a/apps/web/lib/swr/use-api-mutation.ts b/apps/web/lib/swr/use-api-mutation.ts
index dd19eb41df..eec91bccca 100644
--- a/apps/web/lib/swr/use-api-mutation.ts
+++ b/apps/web/lib/swr/use-api-mutation.ts
@@ -6,7 +6,6 @@ interface ApiRequestOptions<TBody, TResponse> {
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
body?: TBody;
headers?: Record<string, string>;
- showToast?: boolean;
onSuccess?: (data: TResponse) => void;
onError?: (error: string) => void;
}
@@ -36,8 +35,6 @@ export function useApiMutation<
TBody = any,
>(): ApiResponse<TResponse> {
const { id: workspaceId } = useWorkspace();
- const [data, setData] = useState<TResponse | null>(null);
- const [error, setError] = useState<string | null>(null);
const [isSubmitting, setIsSubmitting] = useState(false);
const makeRequest = useCallback(
@@ -45,18 +42,9 @@ export function useApiMutation<
endpoint: string,
options: ApiRequestOptions<TBody, TResponse> = {},
) => {
- const {
- method = "GET",
- body,
- headers,
- showToast = true,
- onSuccess,
- onError,
- } = options;
+ const { method = "GET", body, headers, onSuccess, onError } = options;
setIsSubmitting(true);
- setError(null);
- setData(null);
try {
debug("Starting request", {
@@ -89,7 +77,6 @@ export function useApiMutation<
// Handle success
const data = (await response.json()) as TResponse;
- setData(data);
onSuccess?.(data);
debug("Response received", data);
@@ -99,10 +86,9 @@ export function useApiMutation<
? error.message
: "Something went wrong. Please try again.";
- setError(errorMessage);
- onError?.(errorMessage);
-
- if (showToast) {
+ if (onError) {
+ onError?.(errorMessage);
+ } else {
toast.error(errorMessage);
}
diff --git a/apps/web/ui/partners/add-discount-code-modal.tsx b/apps/web/ui/partners/add-discount-code-modal.tsx
index caaa6ee735..9e083a0923 100644
--- a/apps/web/ui/partners/add-discount-code-modal.tsx
+++ b/apps/web/ui/partners/add-discount-code-modal.tsx
@@ -19,6 +19,7 @@ import { toast } from "sonner";
import { useDebounce } from "use-debounce";
import { z } from "zod";
import { X } from "../shared/icons";
+import { UpgradeRequiredToast } from "../shared/upgrade-required-toast";
type FormData = z.infer<typeof createDiscountCodeSchema>;
@@ -87,6 +88,23 @@ const AddDiscountCodeModal = ({
copyToClipboard(data.code);
toast.success("Discount code created and copied to clipboard!");
},
+ onError: (error) => {
+ // Check if the error is related to Stripe permissions
+ if (
+ error.includes(
+ "Having the 'read_write' scope would allow this request to continue",
+ )
+ ) {
+ toast.custom(() => (
+ <UpgradeRequiredToast
+ title="Stripe permissions required"
+ message="Your connected Stripe account doesn't have the permissions needed to create discount codes. Please update your Stripe app permissions in the dashboard or reach out to our support team for help."
+ />
+ ));
+ } else {
+ toast.error(error);
+ }
+ },
});
};