The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix sandbox payout flow, banners, and staging copy-to-live validation
Kiran Ka9ab5090704b
diff --git a/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.tsindex fc612aa0b0..f834049d17 100644--- a/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.ts+++ b/apps/web/app/(ee)/api/cron/payouts/process/process-payouts.ts@@ -27,7 +27,6 @@ import {nFormatter,pluralize,} from "@dub/utils";-import { addMinutes } from "date-fns";const nonUsdPaymentMethodTypes = {sepa_debit: "eur",@@ -312,16 +311,6 @@ export async function processPayouts({// Simulate that flow here with a 2-minute delay so// sandbox payouts behave like a settled ACH charge.if (!isProductionWorkspace) {- await prisma.invoice.update({- where: {- id: invoice.id,- },- data: {- status: "completed",- paidAt: addMinutes(new Date(), 2),- },- });-await qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/cron/payouts/charge-succeeded`,method: "POST",diff --git a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/apply/success/page.tsx b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/apply/success/page.tsxindex 981466cba5..8e66a2cce9 100644--- a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/apply/success/page.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/apply/success/page.tsx@@ -2,6 +2,7 @@ import { getProgram } from "@/lib/fetchers/get-program";import { ProgramEnvironmentBanner } from "@/lib/sandbox/components/program-environment-banner";import { DEFAULT_PARTNER_GROUP } from "@/lib/zod/schemas/groups";import { prisma } from "@dub/prisma";+import { WorkspaceEnvironment } from "@dub/prisma/client";import { Logo } from "@dub/ui";import { BoltFill, CursorRays, LinesY, MoneyBills2 } from "@dub/ui/icons";import { OG_AVATAR_URL } from "@dub/utils";@@ -81,6 +82,8 @@ export default async function SuccessPage(props: {: null;const hasPartnerProfile = !!enrollmentId;+ const isNonProduction =+ program.workspace.environment !== WorkspaceEnvironment.production;return (<div@@ -93,7 +96,12 @@ export default async function SuccessPage(props: {}><ProgramEnvironmentBanner environment={program.workspace.environment} />- <ApplyHeader group={program.group} showLogin={false} showApply={false} />+ <ApplyHeader+ group={program.group}+ showLogin={false}+ showApply={false}+ hasBanner={isNonProduction}+ /><div className="p-6"><div className="grid grid-cols-1 gap-5 sm:pt-20"><span className="w-fit rounded-md bg-neutral-100 px-2 py-1 text-xs font-medium text-neutral-700">diff --git a/apps/web/lib/hooks/use-dashboard-banner-visible.ts b/apps/web/lib/hooks/use-dashboard-banner-visible.tsindex 0a8986eca7..e6096e07af 100644--- a/apps/web/lib/hooks/use-dashboard-banner-visible.ts+++ b/apps/web/lib/hooks/use-dashboard-banner-visible.ts@@ -13,11 +13,14 @@ export function useDashboardBannerVisible() {loading,} = useWorkspace();+ const isProductionWorkspace = environment === WorkspaceEnvironment.production;++ // Only visible in production workspacesconst isUpgradeBannerVisible =- exceededEvents || exceededLinks || exceededPayouts || !!paymentFailedAt;+ (exceededEvents || exceededLinks || exceededPayouts || !!paymentFailedAt) &&+ isProductionWorkspace;- const isEnvironmentBannerVisible =- environment !== WorkspaceEnvironment.production && !isUpgradeBannerVisible;+ const isEnvironmentBannerVisible = !isProductionWorkspace;const hasBanner =(isUpgradeBannerVisible || isEnvironmentBannerVisible) && !loading;diff --git a/apps/web/lib/sandbox/components/copy-discount-to-live-modal.tsx b/apps/web/lib/sandbox/components/copy-discount-to-live-modal.tsxindex af774256f3..3a4da8a858 100644--- a/apps/web/lib/sandbox/components/copy-discount-to-live-modal.tsx+++ b/apps/web/lib/sandbox/components/copy-discount-to-live-modal.tsx@@ -77,7 +77,7 @@ function CopyDiscountToLiveModal({}}- toast.error(error.serverError);+ toast.error(error.serverError ?? "Failed to copy discount to live.");},});diff --git a/apps/web/lib/sandbox/components/copy-reward-to-live-modal.tsx b/apps/web/lib/sandbox/components/copy-reward-to-live-modal.tsxindex e7fa595280..8246f6fec4 100644--- a/apps/web/lib/sandbox/components/copy-reward-to-live-modal.tsx+++ b/apps/web/lib/sandbox/components/copy-reward-to-live-modal.tsx@@ -55,7 +55,7 @@ function CopyRewardToLiveModal({toast.success("Reward copied to live program!");},onError({ error }) {- toast.error(parseActionError(error, "Failed to copy reward to live"));+ toast.error(parseActionError(error, "Failed to copy reward to live."));},});diff --git a/apps/web/lib/sandbox/copy-discount-to-live.ts b/apps/web/lib/sandbox/copy-discount-to-live.tsindex 6178151d41..dc69ca54f7 100644--- a/apps/web/lib/sandbox/copy-discount-to-live.ts+++ b/apps/web/lib/sandbox/copy-discount-to-live.ts@@ -47,6 +47,7 @@ export const copyDiscountToLiveAction = authActionClientenvironment: true,stripeConnectId: true,shopifyStoreId: true,+ stagingWorkspaceId: true,users: {where: {userId: user.id,@@ -65,9 +66,17 @@ export const copyDiscountToLiveAction = authActionClientconst { workspace: targetWorkspace } = targetProgram;+ if (targetWorkspace.stagingWorkspaceId !== workspace.id) {+ throw new Error(+ "Target program is not linked to this staging workspace.",+ );+ }+// Check user has access in the target programif (targetWorkspace.users.length === 0) {- throw new Error("You are not allowed to copy a reward to this program.");+ throw new Error(+ "You are not allowed to copy a discount to this program.",+ );}throwIfNoPermission({@@ -76,7 +85,7 @@ export const copyDiscountToLiveAction = authActionClient});if (targetWorkspace.environment !== WorkspaceEnvironment.production) {- throw new Error("Reward can only be copied to a live program.");+ throw new Error("Discount can only be copied to a live program.");}const discount = await getDiscountOrThrow({diff --git a/apps/web/lib/sandbox/copy-reward-to-live.ts b/apps/web/lib/sandbox/copy-reward-to-live.tsindex 59b9fc9d00..b77dec1dab 100644--- a/apps/web/lib/sandbox/copy-reward-to-live.ts+++ b/apps/web/lib/sandbox/copy-reward-to-live.ts@@ -42,6 +42,7 @@ export const copyRewardToLiveAction = authActionClientselect: {id: true,environment: true,+ stagingWorkspaceId: true,users: {where: {userId: user.id,@@ -60,6 +61,12 @@ export const copyRewardToLiveAction = authActionClientconst { workspace: targetWorkspace } = targetProgram;+ if (targetWorkspace.stagingWorkspaceId !== workspace.id) {+ throw new Error(+ "Target program is not linked to this staging workspace.",+ );+ }+// Check user has access in the target programif (targetWorkspace.users.length === 0) {throw new Error("You are not allowed to copy a reward to this program.");diff --git a/apps/web/lib/sandbox/mock-payout-completion.ts b/apps/web/lib/sandbox/mock-payout-completion.tsindex eb65fd0e42..9647ae4c50 100644--- a/apps/web/lib/sandbox/mock-payout-completion.ts+++ b/apps/web/lib/sandbox/mock-payout-completion.ts@@ -73,6 +73,17 @@ export async function mockPayoutCompletion({});await prisma.$transaction([+ prisma.commission.updateMany({+ where: {+ payoutId: {+ in: payoutIds,+ },+ },+ data: {+ status: "paid",+ },+ }),+prisma.payout.updateMany({where: {id: {@@ -85,14 +96,13 @@ export async function mockPayoutCompletion({},}),- prisma.commission.updateMany({+ prisma.invoice.update({where: {- payoutId: {- in: payoutIds,- },+ id: invoice.id,},data: {- status: "paid",+ status: "completed",+ paidAt: new Date(),},}),]);