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.

improve error messaging

Steven Teyf925ff6e8fc1
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/invite-partner-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/invite-partner-button.tsx
index fb0c5e0516..40e3e9c13d 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/invite-partner-button.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/invite-partner-button.tsx
@@ -2,14 +2,24 @@
import { clientAccessCheck } from "@/lib/client-access-check";
import useWorkspace from "@/lib/swr/use-workspace";
-import { Button, useKeyboardShortcut, useMediaQuery } from "@dub/ui";
+import { useTrialLimitActivateModal } from "@/ui/modals/trial-limit-activate-modal";
+import {
+ Button,
+ TooltipContent,
+ useKeyboardShortcut,
+ useMediaQuery,
+} from "@dub/ui";
+import { isWorkspaceBillingTrialActive } from "@dub/utils";
import { useInvitePartnerSheet } from "./invite-partner-sheet";
export function InvitePartnerButton() {
const { isMobile } = useMediaQuery();
- const { role } = useWorkspace();
+ const { slug, role, exceededPartners, trialEndsAt } = useWorkspace();
const { invitePartnerSheet, setIsOpen: setShowInvitePartnerSheet } =
useInvitePartnerSheet();
+ const { openTrialLimitModal, TrialLimitActivateModal } =
+ useTrialLimitActivateModal();
+ const trialActive = isWorkspaceBillingTrialActive(trialEndsAt);
const permissionsError = clientAccessCheck({
action: "partners.write",
@@ -18,11 +28,12 @@ export function InvitePartnerButton() {
}).error;
useKeyboardShortcut("p", () => setShowInvitePartnerSheet(true), {
- enabled: !permissionsError,
+ enabled: !exceededPartners && !permissionsError,
});
return (
<>
+ <TrialLimitActivateModal />
{invitePartnerSheet}
<Button
type="button"
@@ -30,7 +41,19 @@ export function InvitePartnerButton() {
text={`Invite${isMobile ? "" : " partner"}`}
shortcut="P"
className="h-8 px-3 sm:h-9"
- disabledTooltip={permissionsError || undefined}
+ disabledTooltip={
+ exceededPartners ? (
+ <TooltipContent
+ title="Your have exceeded your partners limit. You need to upgrade to invite more partners."
+ cta={trialActive ? "Start paid plan" : "Upgrade plan"}
+ {...(trialActive
+ ? { onClick: () => openTrialLimitModal("partnerEnrollments") }
+ : { href: `/${slug}/upgrade` })}
+ />
+ ) : (
+ permissionsError || undefined
+ )
+ }
/>
</>
);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/payout-stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/payout-stats.tsx
index 5e48059f7d..959727c2d1 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/payout-stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/payout-stats.tsx
@@ -3,20 +3,29 @@
import { clientAccessCheck } from "@/lib/client-access-check";
import { usePayoutsCount } from "@/lib/swr/use-payouts-count";
import useWorkspace from "@/lib/swr/use-workspace";
+import { useTrialLimitActivateModal } from "@/ui/modals/trial-limit-activate-modal";
import { ConfirmPayoutsSheet } from "@/ui/partners/confirm-payouts-sheet";
import {
Button,
buttonVariants,
Tooltip,
+ TooltipContent,
useKeyboardShortcut,
useRouterStuff,
} from "@dub/ui";
-import { cn, currencyFormatter } from "@dub/utils";
+import {
+ cn,
+ currencyFormatter,
+ isWorkspaceBillingTrialActive,
+} from "@dub/utils";
import { PayoutStatus } from "@prisma/client";
import Link from "next/link";
export function PayoutStats() {
- const { slug, role } = useWorkspace();
+ const { slug, role, exceededPayouts, trialEndsAt } = useWorkspace();
+ const { openTrialLimitModal, TrialLimitActivateModal } =
+ useTrialLimitActivateModal();
+ const trialActive = isWorkspaceBillingTrialActive(trialEndsAt);
const permissionsError = clientAccessCheck({
action: "payouts.write",
@@ -63,7 +72,7 @@ export function PayoutStats() {
const totalPaid = completedPayoutsAmount + processingPayoutsAmount;
useKeyboardShortcut("c", () => {
- if (!permissionsError) {
+ if (!permissionsError && !exceededPayouts) {
queryParams({
set: {
confirmPayouts: "true",
@@ -74,6 +83,7 @@ export function PayoutStats() {
return (
<>
+ <TrialLimitActivateModal />
<ConfirmPayoutsSheet />
<div className="grid grid-cols-1 divide-neutral-200 rounded-lg border border-neutral-200 bg-neutral-50 max-sm:divide-y sm:grid-cols-2 sm:divide-x">
<div className="flex flex-col p-4">
@@ -95,9 +105,19 @@ export function PayoutStats() {
}}
disabled={eligiblePayoutsLoading || confirmButtonDisabled}
disabledTooltip={
- confirmButtonDisabled
- ? "You have no pending payouts that match the minimum payout requirement for partners that have payouts enabled."
- : permissionsError || undefined
+ exceededPayouts ? (
+ <TooltipContent
+ title="You have exceeded your payouts limit. You need to upgrade to send more payouts."
+ cta={trialActive ? "Start paid plan" : "Upgrade plan"}
+ {...(trialActive
+ ? { onClick: () => openTrialLimitModal("payouts") }
+ : { href: `/${slug}/upgrade` })}
+ />
+ ) : confirmButtonDisabled ? (
+ "You have no pending payouts that match the minimum payout requirement for partners that have payouts enabled."
+ ) : (
+ permissionsError || undefined
+ )
}
/>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx
index 264c68a883..5d38b9a29c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx
@@ -428,13 +428,13 @@ function ImportOption({
content={
trialActive ? (
<TooltipContent
- title="Your workspace has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
+ title="Your workspace have exceeded your monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
cta="Start paid plan"
onClick={() => openTrialLimitModal("links")}
/>
) : (
<TooltipContent
- title="Your workspace has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
+ title="Your workspace have exceeded your monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
cta={nextPlan ? `Upgrade to ${nextPlan.name}` : "Contact support"}
href={`/${slug}/upgrade`}
/>
diff --git a/apps/web/lib/swr/use-workspace.ts b/apps/web/lib/swr/use-workspace.ts
index c404e59e88..cb45240cfa 100644
--- a/apps/web/lib/swr/use-workspace.ts
+++ b/apps/web/lib/swr/use-workspace.ts
@@ -48,6 +48,11 @@ export default function useWorkspace({
workspace.payoutsUsage >= workspace.payoutsLimit
? true
: false,
+ exceededPartners:
+ workspace?.partnersLimit &&
+ workspace.partnersUsage >= workspace.partnersLimit
+ ? true
+ : false,
exceededAI: workspace && workspace.aiUsage >= workspace.aiLimit,
exceededDomains:
workspace?.domains && workspace.domains.length >= workspace.domainsLimit,
diff --git a/apps/web/ui/layout/upgrade-banner.tsx b/apps/web/ui/layout/upgrade-banner.tsx
index a5cb31fcec..ffa813fec0 100644
--- a/apps/web/ui/layout/upgrade-banner.tsx
+++ b/apps/web/ui/layout/upgrade-banner.tsx
@@ -83,7 +83,7 @@ export function UpgradeBanner() {
initial={{ transform: "translateY(-100%)" }}
animate={{ transform: "translateY(0)" }}
className={cn(
- "fixed left-0 right-0 top-0 z-50 flex items-center justify-center overflow-hidden px-6 py-2 text-white sm:h-12 sm:py-0",
+ "fixed left-0 right-0 top-0 z-30 flex items-center justify-center overflow-hidden px-6 py-2 text-white sm:h-12 sm:py-0",
needsUpgrade ? "bg-amber-600" : "bg-red-600",
)}
>
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index d0429c5a36..70fea28267 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -307,19 +307,13 @@ export function CreateLinkButton({
shortcut="C"
disabledTooltip={
exceededLinks ? (
- trialActive ? (
- <TooltipContent
- title="Your workspace has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
- cta="Start paid plan"
- onClick={() => openTrialLimitModal("links")}
- />
- ) : (
- <TooltipContent
- title="Your workspace has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
- cta="Upgrade plan"
- href={`/${slug}/upgrade`}
- />
- )
+ <TooltipContent
+ title="Your workspace have exceeded your monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
+ cta={trialActive ? "Start paid plan" : "Upgrade plan"}
+ {...(trialActive
+ ? { onClick: () => openTrialLimitModal("links") }
+ : { href: `/${slug}/upgrade` })}
+ />
) : (
permissionsError || undefined
)
diff --git a/apps/web/ui/partners/confirm-payouts-sheet.tsx b/apps/web/ui/partners/confirm-payouts-sheet.tsx
index 385b9e8e84..05599f3a18 100644
--- a/apps/web/ui/partners/confirm-payouts-sheet.tsx
+++ b/apps/web/ui/partners/confirm-payouts-sheet.tsx
@@ -24,6 +24,7 @@ import usePaymentMethods from "@/lib/swr/use-payment-methods";
import useProgram from "@/lib/swr/use-program";
import useWorkspace from "@/lib/swr/use-workspace";
import { PayoutResponse } from "@/lib/types";
+import { useTrialLimitActivateModal } from "@/ui/modals/trial-limit-activate-modal";
import { X } from "@/ui/shared/icons";
import {
Button,
@@ -49,6 +50,7 @@ import {
currencyFormatter,
fetcher,
formatDate,
+ isWorkspaceBillingTrialActive,
nFormatter,
pluralize,
truncate,
@@ -89,6 +91,7 @@ function ConfirmPayoutsSheetContent() {
defaultProgramId,
payoutsUsage,
payoutsLimit,
+ trialEndsAt,
payoutFee,
payoutFeeWaiverLimit,
payoutFeeWaiverUsage,
@@ -808,6 +811,9 @@ function ConfirmPayoutsSheetContent() {
action: "payouts.write",
customPermissionDescription: "confirm payouts",
});
+ const { openTrialLimitModal, TrialLimitActivateModal } =
+ useTrialLimitActivateModal();
+ const trialActive = isWorkspaceBillingTrialActive(trialEndsAt);
const [isTouchDevice, setIsTouchDevice] = useState(false);
@@ -816,159 +822,164 @@ function ConfirmPayoutsSheetContent() {
}, []);
return (
- <div className="flex h-full flex-col">
- <div className="flex h-16 items-center justify-between border-b border-neutral-200 px-6 py-4">
- <Sheet.Title className="text-lg font-semibold">
- Confirm payouts
- </Sheet.Title>
- <Sheet.Close asChild>
- <Button
- variant="outline"
- icon={<X className="size-5" />}
- className="h-auto w-fit p-1"
- />
- </Sheet.Close>
- </div>
+ <>
+ <TrialLimitActivateModal />
+ <div className="flex h-full flex-col">
+ <div className="flex h-16 items-center justify-between border-b border-neutral-200 px-6 py-4">
+ <Sheet.Title className="text-lg font-semibold">
+ Confirm payouts
+ </Sheet.Title>
+ <Sheet.Close asChild>
+ <Button
+ variant="outline"
+ icon={<X className="size-5" />}
+ className="h-auto w-fit p-1"
+ />
+ </Sheet.Close>
+ </div>
- <div className="flex-1 overflow-y-auto">
- <div className="flex flex-col gap-4 p-6">
- <div className="text-base font-medium text-neutral-900">
- Invoice details
- </div>
- <div className="grid grid-cols-3 gap-2 text-sm">
- {invoiceData.map(({ key, value, tooltipContent }) => (
- <Fragment key={key}>
- <div
- className={cn(
- "flex items-center py-0.5 font-medium text-neutral-500",
- tooltipContent &&
- "cursor-help underline decoration-dotted underline-offset-2",
- )}
- >
- <DynamicTooltipWrapper
- tooltipProps={
- tooltipContent
- ? {
- content: tooltipContent,
- }
- : undefined
- }
+ <div className="flex-1 overflow-y-auto">
+ <div className="flex flex-col gap-4 p-6">
+ <div className="text-base font-medium text-neutral-900">
+ Invoice details
+ </div>
+ <div className="grid grid-cols-3 gap-2 text-sm">
+ {invoiceData.map(({ key, value, tooltipContent }) => (
+ <Fragment key={key}>
+ <div
+ className={cn(
+ "flex items-center py-0.5 font-medium text-neutral-500",
+ tooltipContent &&
+ "cursor-help underline decoration-dotted underline-offset-2",
+ )}
>
- {key}
- </DynamicTooltipWrapper>
- </div>
- <div className="col-span-2 flex items-center text-neutral-800">
- {value}
- </div>
- </Fragment>
- ))}
+ <DynamicTooltipWrapper
+ tooltipProps={
+ tooltipContent
+ ? {
+ content: tooltipContent,
+ }
+ : undefined
+ }
+ >
+ {key}
+ </DynamicTooltipWrapper>
+ </div>
+ <div className="col-span-2 flex items-center text-neutral-800">
+ {value}
+ </div>
+ </Fragment>
+ ))}
+ </div>
</div>
- </div>
- <div className="px-6 py-3">
- <Table {...table} />
+ <div className="px-6 py-3">
+ <Table {...table} />
+ </div>
</div>
- </div>
- <div className="flex flex-col gap-3 border-t border-neutral-200 px-5 py-4">
- <ConfirmPayoutsButton
- onClick={async () => {
- if (!workspaceId || !selectedPaymentMethod) {
- return false;
+ <div className="flex flex-col gap-3 border-t border-neutral-200 px-5 py-4">
+ <ConfirmPayoutsButton
+ onClick={async () => {
+ if (!workspaceId || !selectedPaymentMethod) {
+ return false;
+ }
+
+ const result = await confirmPayouts({
+ workspaceId,
+ paymentMethodId: selectedPaymentMethod.id.replace("-fast", ""),
+ fastSettlement: selectedPaymentMethod.fastSettlement,
+ cutoffPeriod,
+ ...(isExplicitSelectionMode
+ ? { selectedPayoutIds: resolvedSelectedPayoutIds }
+ : excludedPayoutIds.length > 0
+ ? { excludedPayoutIds }
+ : {}),
+ amount: amount ?? 0,
+ fee: fee ?? 0,
+ total: total ?? 0,
+ });
+
+ if (!result?.data?.invoiceId) return false;
+
+ setTimeout(
+ () =>
+ result?.data?.invoiceId &&
+ router.push(
+ `/${slug}/program/payouts/success?invoiceId=${result.data.invoiceId}`,
+ ),
+ 1000,
+ );
+
+ return true;
+ }}
+ text={
+ amount && amount > 0
+ ? `${isTouchDevice ? "Press" : "Click"} and hold to confirm ${currencyFormatter(amount)} payout`
+ : `${isTouchDevice ? "Press" : "Click"} and hold to confirm payout`
}
-
- const result = await confirmPayouts({
- workspaceId,
- paymentMethodId: selectedPaymentMethod.id.replace("-fast", ""),
- fastSettlement: selectedPaymentMethod.fastSettlement,
- cutoffPeriod,
- ...(isExplicitSelectionMode
- ? { selectedPayoutIds: resolvedSelectedPayoutIds }
- : excludedPayoutIds.length > 0
- ? { excludedPayoutIds }
- : {}),
- amount: amount ?? 0,
- fee: fee ?? 0,
- total: total ?? 0,
- });
-
- if (!result?.data?.invoiceId) return false;
-
- setTimeout(
- () =>
- result?.data?.invoiceId &&
- router.push(
- `/${slug}/program/payouts/success?invoiceId=${result.data.invoiceId}`,
- ),
- 1000,
- );
-
- return true;
- }}
- text={
- amount && amount > 0
- ? `${isTouchDevice ? "Press" : "Click"} and hold to confirm ${currencyFormatter(amount)} payout`
- : `${isTouchDevice ? "Press" : "Click"} and hold to confirm payout`
- }
- disabled={
- eligiblePayoutsLoading ||
- eligiblePayoutsSummaryLoading ||
- !selectedPaymentMethod ||
- amount === 0
- }
- disabledTooltip={
- plan &&
- typeof payoutsUsage === "number" &&
- typeof payoutsLimit === "number" &&
- typeof amount === "number" &&
- payoutsUsage + amount > payoutsLimit ? (
- <TooltipContent
- title={exceededLimitError({
- plan,
- planPeriod,
- limit: payoutsLimit,
- type: "payouts",
- })}
- cta="Upgrade"
- href={`/${slug}/settings/billing/upgrade?planPeriod=yearly`}
- />
- ) : amount && amount < INVOICE_MIN_PAYOUT_AMOUNT_CENTS ? (
- "Your payout total is less than the minimum invoice amount of $10."
- ) : (
- permissionsError || undefined
- )
- }
- />
- {commissionsCount && commissionsCount.hold.count > 0 && (
- <div className="flex items-center justify-center gap-2 text-sm text-neutral-600">
- <span>
- Excluding{" "}
- <span className="font-medium text-neutral-800">
- {nFormatter(commissionsCount.hold.count, { full: true })}
- </span>
- {` on hold ${pluralize("commission", commissionsCount.hold.count)} `}
- <span className="font-medium text-neutral-800">
- (
- {currencyFormatter(commissionsCount.hold.earnings, {
- trailingZeroDisplay: "stripIfInteger",
- })}
- )
+ disabled={
+ eligiblePayoutsLoading ||
+ eligiblePayoutsSummaryLoading ||
+ !selectedPaymentMethod ||
+ amount === 0
+ }
+ disabledTooltip={
+ plan &&
+ typeof payoutsUsage === "number" &&
+ typeof payoutsLimit === "number" &&
+ typeof amount === "number" &&
+ payoutsUsage + amount > payoutsLimit ? (
+ <TooltipContent
+ title={exceededLimitError({
+ plan,
+ planPeriod,
+ limit: payoutsLimit,
+ type: "payouts",
+ })}
+ cta={trialActive ? "Start paid plan" : "Upgrade plan"}
+ {...(trialActive
+ ? { onClick: () => openTrialLimitModal("payouts") }
+ : { href: `/${slug}/upgrade` })}
+ />
+ ) : amount && amount < INVOICE_MIN_PAYOUT_AMOUNT_CENTS ? (
+ "Your payout total is less than the minimum invoice amount of $10."
+ ) : (
+ permissionsError || undefined
+ )
+ }
+ />
+ {commissionsCount && commissionsCount.hold.count > 0 && (
+ <div className="flex items-center justify-center gap-2 text-sm text-neutral-600">
+ <span>
+ Excluding{" "}
+ <span className="font-medium text-neutral-800">
+ {nFormatter(commissionsCount.hold.count, { full: true })}
+ </span>
+ {` on hold ${pluralize("commission", commissionsCount.hold.count)} `}
+ <span className="font-medium text-neutral-800">
+ (
+ {currencyFormatter(commissionsCount.hold.earnings, {
+ trailingZeroDisplay: "stripIfInteger",
+ })}
+ )
+ </span>
</span>
- </span>
- <a
- href={`/${slug}/program/commissions?status=hold`}
- target="_blank"
- >
- <Button
- variant="secondary"
- text="Review"
- className="h-7 w-fit cursor-alias rounded-md border border-neutral-200 px-2 text-sm"
- />
- </a>
- </div>
- )}
+ <a
+ href={`/${slug}/program/commissions?status=hold`}
+ target="_blank"
+ >
+ <Button
+ variant="secondary"
+ text="Review"
+ className="h-7 w-fit cursor-alias rounded-md border border-neutral-200 px-2 text-sm"
+ />
+ </a>
+ </div>
+ )}
+ </div>
</div>
- </div>
+ </>
);
}