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.

Merge branch 'main' into staging-sandbox

Kiran K01eb0b2e959e
diff --cc apps/web/app/(ee)/api/cron/payouts/charge-succeeded/queue-tremendous-payouts.ts
index 58bbbec7c9,3fe9d43faa..cc3a07e5d6
--- a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/queue-tremendous-payouts.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/queue-tremendous-payouts.ts
@@@ -1,8 -1,7 +1,8 @@@
+ import { logger } from "@/lib/axiom/server";
import { qstash } from "@/lib/cron";
import { prisma } from "@/lib/prisma";
+import { assertProductionWorkspace } from "@/lib/sandbox/workspace-guards";
import { TREMENDOUS_MAX_PAYOUT_AMOUNT_CENTS } from "@/lib/tremendous/constants";
- import { createTremendousCampaign } from "@/lib/tremendous/create-tremendous-campaign";
import { APP_DOMAIN_WITH_NGROK, chunk } from "@dub/utils";
import {
Invoice,
diff --cc apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
index 26cf74ccf6,24af10e8e7..110a3ea8bf
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/route.ts
@@@ -1,6 -1,7 +1,6 @@@
import { captureWebhookLog } from "@/lib/api-logs/capture-webhook-log";
import { withAxiom } from "@/lib/axiom/server";
- import { stripe } from "@/lib/stripe";
-import { prisma } from "@/lib/prisma";
+ import { isStripeRateLimitError, stripe } from "@/lib/stripe";
import { StripeMode } from "@/lib/types";
import { waitUntil } from "@vercel/functions";
import { logAndRespond } from "app/(ee)/api/cron/utils";
diff --cc apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
index 6b697db6ed,168b086ed5..9dc9c27920
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
@@@ -1,7 -1,7 +1,8 @@@
import { DubApiError } from "@/lib/api/errors";
import { getDubAdminRole, withWorkspace } from "@/lib/auth";
import { getDubCustomer } from "@/lib/dub";
+ import { getFeatureFlags } from "@/lib/edge-config";
+import { assertNotStagingWorkspace } from "@/lib/sandbox/workspace-guards";
import { stripe } from "@/lib/stripe";
import { isEligibleForTrial } from "@/lib/stripe/is-eligible-for-trial";
import { booleanQuerySchema } from "@/lib/zod/schemas/misc";
diff --cc apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
index f12d6d8e37,0ab9334632..973a360c0d
--- a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
@@@ -13,8 -8,8 +13,9 @@@ import
getWorkspaceUsersQuerySchema,
workspaceUserSchema,
} from "@/lib/zod/schemas/workspaces";
+ import { pluralize } from "@dub/utils";
import { WorkspaceRole } from "@prisma/client";
+import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
import * as z from "zod/v4";
@@@ -175,7 -152,25 +176,25 @@@ export const DELETE = withWorkspace
});
}
+ const activeRestrictedTokens = await prisma.restrictedToken.count({
+ where: {
+ projectId: workspace.id,
+ userId,
+ lastUsed: {
+ not: null,
+ },
+ },
+ });
+
+ if (activeRestrictedTokens) {
+ const tokenTense = pluralize("token", activeRestrictedTokens);
+ throw new DubApiError({
+ code: "bad_request",
+ message: `This user has ${activeRestrictedTokens} active restricted ${tokenTense}. Please remove the ${tokenTense} first before removing the user from the workspace.`,
+ });
+ }
+
- const [response] = await Promise.allSettled([
+ await Promise.allSettled([
// Remove the user from the workspace
prisma.projectUsers.delete({
where: {
diff --cc apps/web/lib/actions/partners/confirm-payouts.ts
index ca91bb8ac6,6149d471f4..c1f46289ee
--- a/apps/web/lib/actions/partners/confirm-payouts.ts
+++ b/apps/web/lib/actions/partners/confirm-payouts.ts
@@@ -15,10 -15,9 +15,11 @@@ import
} from "@/lib/constants/payouts";
import { qstash } from "@/lib/cron";
import { exceededLimitError } from "@/lib/exceeded-limit-error";
+ import { createTremendousCampaignJob } from "@/lib/jobs/handlers/create-tremendous-campaign-job";
import { CUTOFF_PERIOD_ENUM } from "@/lib/partners/cutoff-period";
import { prisma } from "@/lib/prisma";
+import { mockPaymentProvider } from "@/lib/sandbox/mock-payment-provider";
+import { isProductionEnvironment } from "@/lib/sandbox/workspace-guards";
import { stripe } from "@/lib/stripe";
import { checkPaymentMethodMandate } from "@/lib/stripe/check-payment-method-mandate";
import { getWebhooks } from "@/lib/webhook/get-webhooks";
diff --cc apps/web/lib/actions/partners/create-program.ts
index b55fd18c1d,fafe78f4b7..845e539c91
--- a/apps/web/lib/actions/partners/create-program.ts
+++ b/apps/web/lib/actions/partners/create-program.ts
@@@ -104,140 -103,134 +105,140 @@@ export const createProgram = async (
}
// create a new program
- const program = await prisma.$transaction(async (tx) => {
- const folderId = createId({ prefix: "fold_" });
- const defaultGroupId = createId({ prefix: "grp_" });
+ const { updatedWorkspace, program } = await prisma.$transaction(
+ async (tx) => {
+ const folderId = createId({ prefix: "fold_" });
+ const defaultGroupId = createId({ prefix: "grp_" });
- const programFolder = await tx.folder.upsert({
- where: {
- name_projectId: {
+ const programFolder = await tx.folder.upsert({
+ where: {
+ name_projectId: {
+ name: "Partner Links",
+ projectId: workspace.id,
+ },
+ },
+ update: {},
+ create: {
+ id: folderId,
name: "Partner Links",
projectId: workspace.id,
- },
- },
- update: {},
- create: {
- id: folderId,
- name: "Partner Links",
- projectId: workspace.id,
- accessLevel: "write",
- users: {
- create: {
- userId: user.id,
- role: "owner",
+ accessLevel: "write",
+ users: {
+ create: {
+ userId: user.id,
+ role: "owner",
+ },
},
},
- },
- });
+ });
- const programData = await tx.program.create({
- data: {
- id: programId,
- workspaceId: workspace.id,
- name,
- slug: workspace.slug,
- domain,
- url,
- logo: logoUrl, // TODO: remove after we refactor all program.logo fields to use group.logo instead
- defaultFolderId: programFolder.id,
- defaultGroupId,
- supportEmail,
- helpUrl,
- termsUrl,
- messagingEnabledAt: canMessagePartners ? new Date() : null,
- ...(type &&
- (amountInCents != null || amountInPercentage != null) && {
- rewards: {
- create: {
- id: createId({ prefix: "rw_" }),
- type,
- amountInCents: type === "flat" ? amountInCents : null,
- amountInPercentage:
- type === "percentage" && amountInPercentage != null
- ? amountInPercentage
- : null,
- maxDuration,
- event: defaultRewardType,
+ const programData = await tx.program.create({
+ data: {
+ id: programId,
+ workspaceId: workspace.id,
+ name,
+ slug: workspace.slug,
+ domain,
+ url,
+ logo: logoUrl, // TODO: remove after we refactor all program.logo fields to use group.logo instead
+ defaultFolderId: programFolder.id,
+ defaultGroupId,
+ supportEmail,
+ helpUrl,
+ termsUrl,
+ messagingEnabledAt: canMessagePartners ? new Date() : null,
+ ...(type &&
+ (amountInCents != null || amountInPercentage != null) && {
+ rewards: {
+ create: {
+ id: createId({ prefix: "rw_" }),
+ type,
+ amountInCents: type === "flat" ? amountInCents : null,
+ amountInPercentage:
+ type === "percentage" && amountInPercentage != null
+ ? amountInPercentage
+ : null,
+ maxDuration,
+ event: defaultRewardType,
+ },
},
- },
- }),
- },
- include: {
- rewards: true,
- },
- });
+ }),
+ },
+ include: {
+ rewards: true,
+ },
+ });
- const createdReward = programData.rewards?.[0];
+ const createdReward = programData.rewards?.[0];
- await tx.partnerGroup.upsert({
- where: {
- programId_slug: {
+ await tx.partnerGroup.upsert({
+ where: {
+ programId_slug: {
+ programId,
+ slug: DEFAULT_PARTNER_GROUP.slug,
+ },
+ },
+ create: {
+ id: defaultGroupId,
programId,
slug: DEFAULT_PARTNER_GROUP.slug,
- },
- },
- create: {
- id: defaultGroupId,
- programId,
- slug: DEFAULT_PARTNER_GROUP.slug,
- name: DEFAULT_PARTNER_GROUP.name,
- color: DEFAULT_PARTNER_GROUP.color,
- ...(logoUrl && { logo: logoUrl }),
- ...(createdReward && {
- [REWARD_EVENT_COLUMN_MAPPING[createdReward.event]]: createdReward.id,
- }),
- additionalLinks: sanitizeAdditionalLinks([
- {
- domain: getDomainWithoutWWW(programData.url!),
- validationMode: "domain",
- },
- ]),
- maxPartnerLinks: DEFAULT_ADDITIONAL_PARTNER_LINKS,
- partnerGroupDefaultLinks: {
- create: {
- id: createId({ prefix: "pgdl_" }),
- programId,
- domain: programData.domain!,
- url: programData.url!,
+ name: DEFAULT_PARTNER_GROUP.name,
+ color: DEFAULT_PARTNER_GROUP.color,
+ ...(logoUrl && { logo: logoUrl }),
+ ...(createdReward && {
+ [REWARD_EVENT_COLUMN_MAPPING[createdReward.event]]:
+ createdReward.id,
+ }),
- additionalLinks: [
++ additionalLinks: sanitizeAdditionalLinks([
+ {
- domain: getDomainWithoutWWW(programData.url!)!,
++ domain: getDomainWithoutWWW(programData.url!),
+ validationMode: "domain",
+ },
- ],
++ ]),
+ maxPartnerLinks: DEFAULT_ADDITIONAL_PARTNER_LINKS,
+ partnerGroupDefaultLinks: {
+ create: {
+ id: createId({ prefix: "pgdl_" }),
+ programId,
+ domain: programData.domain!,
+ url: programData.url!,
+ },
},
},
- },
- update: {}, // noop
- });
+ update: {}, // noop
+ });
- // folder might be upserted, so we need to check if it was created
- const didCreateFolder = programFolder.id === folderId;
+ // folder might be upserted, so we need to check if it was created
+ const didCreateFolder = programFolder.id === folderId;
- await tx.project.update({
- where: {
- id: workspace.id,
- },
- data: {
- defaultProgramId: programData.id,
- ...(didCreateFolder && {
- foldersUsage: {
- increment: 1,
+ const updatedWorkspace = await tx.project.update({
+ where: {
+ id: workspace.id,
+ },
+ data: {
+ defaultProgramId: programData.id,
+ ...(didCreateFolder && {
+ foldersUsage: {
+ increment: 1,
+ },
+ }),
+ store: {
+ ...store,
+ programOnboarding: undefined,
},
- }),
- store: {
- ...store,
- programOnboarding: undefined,
+ // if the workspace doesn't have an invoice prefix, generate one
+ ...(!workspace.invoicePrefix && {
+ invoicePrefix: generateRandomString(8),
+ }),
},
- // if the workspace doesn't have an invoice prefix, generate one
- ...(!workspace.invoicePrefix && {
- invoicePrefix: generateRandomString(8),
- }),
- },
- });
+ });
- return programData;
- });
+ return {
+ updatedWorkspace,
+ program: programData,
+ };
+ },
+ );
waitUntil(
Promise.allSettled([
diff --cc apps/web/lib/discounts/discount-provider-shopify.ts
index 7dc335c573,4f86f5be43..b665d7681b
--- a/apps/web/lib/discounts/discount-provider-shopify.ts
+++ b/apps/web/lib/discounts/discount-provider-shopify.ts
@@@ -32,15 -32,17 +32,17 @@@ interface ShopifyDiscountCodeDelete
}[];
}
+type Workspace = Pick<Project, "id" | "environment" | "shopifyStoreId">;
+
const MAX_ATTEMPTS = 3;
-async function requireInstalledIntegration(
- workspace: Pick<Project, "id" | "shopifyStoreId">,
-) {
+async function requireInstalledIntegration(workspace: Workspace) {
if (!workspace.shopifyStoreId) {
- throw new DiscountIntegrationNotAvailableError({
- message: `SHOPIFY_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Shopify yet. Please install the Dub Shopify app in settings to create a discount.`,
- });
+ throw new DiscountProviderError(
+ "shopify",
+ "INTEGRATION_NOT_AVAILABLE",
- "SHOPIFY_CONNECTION_REQUIRED: Your workspace isn't connected to Shopify yet. Please install the Dub Shopify app in settings to create a discount.",
++ `SHOPIFY_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Shopify yet. Please install the Dub Shopify app in settings to create a discount.`,
+ );
}
const installation = await prisma.installedIntegration.findFirst({
@@@ -51,9 -53,11 +53,11 @@@
});
if (!installation) {
- throw new DiscountIntegrationNotAvailableError({
- message: `SHOPIFY_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Shopify yet. Please install the Dub Shopify app in settings to create a discount.`,
- });
+ throw new DiscountProviderError(
+ "shopify",
+ "INTEGRATION_NOT_AVAILABLE",
- "SHOPIFY_CONNECTION_REQUIRED: Your workspace isn't connected to Shopify yet. Please install the Dub Shopify app in settings to create a discount.",
++ `SHOPIFY_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Shopify yet. Please install the Dub Shopify app in settings to create a discount.`,
+ );
}
let credentials = integrationCredentialsSchema.parse(
@@@ -61,9 -65,11 +65,11 @@@
);
if (!credentials?.scope?.includes("write_discounts")) {
- throw new DiscountIntegrationNotAvailableError({
- message: `SHOPIFY_APP_UPGRADE_REQUIRED: Your connected Shopify store in the workspace (${workspace.environment}) doesn't have permission to create discount codes. Please reinstall or upgrade the Dub Shopify app.`,
- });
+ throw new DiscountProviderError(
+ "shopify",
+ "PERMISSIONS_REQUIRED",
- "SHOPIFY_APP_UPGRADE_REQUIRED: Your connected Shopify store doesn't have permission to create discount codes. Please reinstall or upgrade the Dub Shopify app.",
++ `SHOPIFY_APP_UPGRADE_REQUIRED: Your connected Shopify store in the workspace (${workspace.environment}) doesn't have permission to create discount codes. Please reinstall or upgrade the Dub Shopify app.`,
+ );
}
return {
@@@ -228,71 -280,79 +280,79 @@@ function createShopifyDiscountProvider(
}) => {
const { credentials } = await requireInstalledIntegration(workspace);
- const lookup = await shopifyAdminGraphql<{
- codeDiscountNodeByCode: { id: string } | null;
- }>({
- shopifyStoreId: workspace.shopifyStoreId!,
- accessToken: credentials.accessToken!,
- query: /* GraphQL */ `
- query CodeDiscountNodeByCode($code: String!) {
- codeDiscountNodeByCode(code: $code) {
- id
+ try {
+ const lookup = await shopifyAdminGraphql<{
+ codeDiscountNodeByCode: { id: string } | null;
+ }>({
+ shopifyStoreId: workspace.shopifyStoreId!,
+ accessToken: credentials.accessToken!,
+ query: /* GraphQL */ `
+ query CodeDiscountNodeByCode($code: String!) {
+ codeDiscountNodeByCode(code: $code) {
+ id
+ }
}
- }
- `,
- variables: { code },
- });
+ `,
+ variables: { code },
+ });
- const id = lookup.codeDiscountNodeByCode?.id;
+ const id = lookup.codeDiscountNodeByCode?.id;
- if (!id) {
- console.error(
- `Shopify discount code ${code} not found (shopifyStoreId=${workspace.shopifyStoreId!}).`,
- );
- return;
- }
+ if (!id) {
+ console.error(
+ `Shopify discount code ${code} not found (shopifyStoreId=${workspace.shopifyStoreId!}).`,
+ );
+ return;
+ }
- const data = await shopifyAdminGraphql<{
- discountCodeDelete: ShopifyDiscountCodeDelete;
- }>({
- shopifyStoreId: workspace.shopifyStoreId!,
- accessToken: credentials.accessToken!,
- query: /* GraphQL */ `
- mutation DiscountCodeDelete($id: ID!) {
- discountCodeDelete(id: $id) {
- deletedCodeDiscountId
- userErrors {
- field
- message
- code
+ const data = await shopifyAdminGraphql<{
+ discountCodeDelete: ShopifyDiscountCodeDelete;
+ }>({
+ shopifyStoreId: workspace.shopifyStoreId!,
+ accessToken: credentials.accessToken!,
+ query: /* GraphQL */ `
+ mutation DiscountCodeDelete($id: ID!) {
+ discountCodeDelete(id: $id) {
+ deletedCodeDiscountId
+ userErrors {
+ field
+ message
+ code
+ }
}
}
- }
- `,
- variables: { id },
- });
+ `,
+ variables: { id },
+ });
- const { userErrors } = data.discountCodeDelete;
+ const { userErrors } = data.discountCodeDelete;
- if (userErrors.length > 0) {
- throw new ShopifyAdminGraphqlError(
- userErrors[0].code,
- userErrors[0].message,
- userErrors,
- );
- }
+ if (userErrors.length > 0) {
+ throw new ShopifyAdminGraphqlError(
+ userErrors[0].code,
+ userErrors[0].message,
+ userErrors,
+ );
+ }
- console.info(
- `Deleted Shopify discount code ${code} (id=${id}, shopifyStoreId=${workspace.shopifyStoreId}).`,
- );
+ console.info(
+ `Deleted Shopify discount code ${code} (id=${id}, shopifyStoreId=${workspace.shopifyStoreId}).`,
+ );
- return { id, code };
+ return {
+ id,
+ code,
+ };
+ } catch (error) {
+ throwIfShopifyUnauthorized(error);
+ throw error;
+ }
};
- const assertDiscountIntegrationAvailable = async ({
+ const assertDiscountIntegration = async ({
workspace,
}: {
- workspace: Pick<Project, "id" | "stripeConnectId" | "shopifyStoreId">;
+ workspace: Workspace;
}) => {
await requireInstalledIntegration(workspace);
};
diff --cc apps/web/lib/discounts/discount-provider-stripe.ts
index 54618af64f,7910499fa3..6503a5242b
--- a/apps/web/lib/discounts/discount-provider-stripe.ts
+++ b/apps/web/lib/discounts/discount-provider-stripe.ts
@@@ -16,13 -16,15 +16,15 @@@ import { DiscountProviderError } from "
const MAX_ATTEMPTS = 3;
-async function requireInstalledIntegration(
- workspace: Pick<Project, "id" | "stripeConnectId">,
-) {
+type Workspace = Pick<Project, "id" | "environment" | "stripeConnectId">;
+
+async function requireInstalledIntegration(workspace: Workspace) {
if (!workspace.stripeConnectId) {
- throw new DiscountIntegrationNotAvailableError({
- message: `STRIPE_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create a discount.`,
- });
+ throw new DiscountProviderError(
+ "stripe",
+ "INTEGRATION_NOT_AVAILABLE",
- "STRIPE_CONNECTION_REQUIRED: Your workspace isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create a discount.",
++ `STRIPE_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create a discount.`,
+ );
}
const installation = await prisma.installedIntegration.findFirst({
@@@ -33,9 -35,11 +35,11 @@@
});
if (!installation) {
- throw new DiscountIntegrationNotAvailableError({
- message: `STRIPE_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create a discount.`,
- });
+ throw new DiscountProviderError(
+ "stripe",
+ "INTEGRATION_NOT_AVAILABLE",
- "STRIPE_CONNECTION_REQUIRED: Your workspace isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create a discount.",
++ `STRIPE_CONNECTION_REQUIRED: Your workspace (${workspace.environment}) isn't connected to Stripe yet. Please install the Dub Stripe app in settings to create a discount.`,
+ );
}
const settings = stripeIntegrationSettingsSchema.parse(
@@@ -214,46 -271,58 +274,58 @@@ function createStripeDiscountProvider(
mode: settings.stripeMode,
});
- const promotionCodes = await stripeApp.promotionCodes.list(
- {
- code,
- limit: 1,
- },
- {
- stripeAccount: workspace.stripeConnectId!,
- },
- );
-
- if (promotionCodes.data.length === 0) {
- console.error(
- `Stripe promotion code ${code} not found (stripeConnectId=${workspace.stripeConnectId}).`,
+ try {
+ const promotionCodes = await stripeApp.promotionCodes.list(
+ {
+ code,
+ limit: 1,
+ },
+ {
+ stripeAccount: workspace.stripeConnectId!,
+ },
);
- return;
- }
- const promotionCode = promotionCodes.data[0];
+ if (promotionCodes.data.length === 0) {
+ console.error(
+ `Stripe promotion code ${code} not found (stripeConnectId=${workspace.stripeConnectId}).`,
+ );
+ return;
+ }
- await stripeApp.promotionCodes.update(
- promotionCode.id,
- {
- active: false,
- },
- {
- stripeAccount: workspace.stripeConnectId!,
- },
- );
+ const promotionCode = promotionCodes.data[0];
- console.info(
- `Disabled Stripe promotion code ${promotionCode.code} (id=${promotionCode.id}, stripeConnectId=${workspace.stripeConnectId}).`,
- );
+ await stripeApp.promotionCodes.update(
+ promotionCode.id,
+ {
+ active: false,
+ },
+ {
+ stripeAccount: workspace.stripeConnectId!,
+ },
+ );
+
+ console.info(
+ `Disabled Stripe promotion code ${promotionCode.code} (id=${promotionCode.id}, stripeConnectId=${workspace.stripeConnectId}).`,
+ );
- return promotionCode;
+ return promotionCode;
+ } catch (error: any) {
+ if (isStripePermissionsError(error)) {
+ throw new DiscountProviderError(
+ "stripe",
+ "PERMISSIONS_REQUIRED",
+ error.raw?.message || error.message,
+ );
+ }
+
+ throw error;
+ }
};
- const assertDiscountIntegrationAvailable = async ({
+ const assertDiscountIntegration = async ({
workspace,
}: {
- workspace: Pick<Project, "id" | "stripeConnectId" | "shopifyStoreId">;
+ workspace: Workspace;
}) => {
await requireInstalledIntegration(workspace);
};
diff --cc apps/web/ui/layout/upgrade-banner.tsx
index f8119277e2,a5cb31fcec..7d8cca2a58
--- a/apps/web/ui/layout/upgrade-banner.tsx
+++ b/apps/web/ui/layout/upgrade-banner.tsx
@@@ -1,9 -1,16 +1,17 @@@
"use client";
+ import { clientAccessCheck } from "@/lib/client-access-check";
+import { useDashboardBannerVisible } from "@/lib/hooks/use-dashboard-banner-visible";
import useWorkspace from "@/lib/swr/use-workspace";
+ import { useRetryPaymentModal } from "@/ui/modals/retry-payment-modal";
import { useTrialLimitActivateModal } from "@/ui/modals/trial-limit-activate-modal";
- import { Button, Crown, TriangleWarning, useMediaQuery } from "@dub/ui";
+ import {
+ Button,
+ Crown,
+ DynamicTooltipWrapper,
+ TriangleWarning,
+ useMediaQuery,
+ } from "@dub/ui";
import {
cn,
getTrialLimitResourceForOverageBanner,
@@@ -35,15 -41,28 +42,28 @@@ export function useUpgradeBannerVisibil
}
export function UpgradeBanner() {
- const { slug, exceededEvents, exceededLinks, exceededPayouts, trialEndsAt } =
- useWorkspace();
+ const {
+ slug,
+ exceededEvents,
+ exceededLinks,
+ exceededPayouts,
+ trialEndsAt,
+ role,
+ } = useWorkspace();
const { openTrialLimitModal, TrialLimitActivateModal } =
useTrialLimitActivateModal();
+ const { setShowRetryPaymentModal, RetryPaymentModal } =
+ useRetryPaymentModal();
const trialActive = isWorkspaceBillingTrialActive(trialEndsAt);
- const { isVisible, needsUpgrade, subscriptionCanceled } =
- useUpgradeBannerVisibility();
+ const { needsUpgrade, subscriptionCanceled } = useUpgradeBannerVisibility();
+ const { isUpgradeBannerVisible } = useDashboardBannerVisible();
+ const permissionsError = clientAccessCheck({
+ action: "billing.write",
+ role,
+ }).error;
+
const overageLimitResource = getTrialLimitResourceForOverageBanner({
exceededEvents: Boolean(exceededEvents),
exceededLinks: Boolean(exceededLinks),