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.

prisma:format

Steven Teyf756063d9aa9
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
index 4140a53dc4..9cccb546f7 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
@@ -1,8 +1,7 @@
import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile";
import { hasPermission } from "@/lib/auth/partner-user-permissions";
import { mutatePrefix } from "@/lib/swr/mutate";
-import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
-import { PartnerProps, PayoutsCount } from "@/lib/types";
+import { PartnerProps } from "@/lib/types";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
import { CountryCombobox } from "@/ui/partners/country-combobox";
import {
@@ -17,6 +16,7 @@ import {
DynamicTooltipWrapper,
FileUpload,
ToggleGroup,
+ TooltipContent,
buttonVariants,
} from "@dub/ui";
import { OG_AVATAR_URL, cn } from "@dub/utils";
@@ -171,15 +171,6 @@ function BasicInfoForm({
const { profileType } = watch();
- const { payoutsCount } = usePartnerPayoutsCount<PayoutsCount[]>({
- groupBy: "status",
- });
-
- const completedPayoutsCount =
- payoutsCount
- ?.filter((payout) => ["sent", "completed"].includes(payout.status))
- .reduce((acc, payout) => acc + payout.count, 0) ?? 0;
-
const { executeAsync } = useAction(updatePartnerProfileAction, {
onSuccess: async ({ data }) => {
if (data?.needsEmailVerification) {
@@ -311,11 +302,16 @@ function BasicInfoForm({
onChange={field.onChange}
error={errors.country ? true : false}
disabledTooltip={
- disabled
- ? "You don't have permission to update this field"
- : completedPayoutsCount > 0
- ? "Since you've already received payouts on Dub, you cannot change your country. If you need to update your country, please contact support."
- : undefined
+ disabled ? (
+ "You don't have permission to update this field"
+ ) : partner?.payoutsEnabledAt ? (
+ <TooltipContent
+ title="Since you've already connected your bank account for payouts, you cannot change your profile country."
+ cta="Contact support"
+ href="https://dub.co/support"
+ target="_blank"
+ />
+ ) : undefined
}
/>
)}
@@ -327,18 +323,18 @@ function BasicInfoForm({
Profile type
</span>
<DynamicTooltipWrapper
- tooltipProps={
- disabled
- ? {
- content: "You don't have permission to update this field",
- }
- : completedPayoutsCount > 0
- ? {
- content:
- "Since you've already received payouts on Dub, you cannot change your profile type. If you need to update your profile type, please contact support.",
- }
- : undefined
- }
+ tooltipProps={{
+ content: disabled ? (
+ "You don't have permission to update this field"
+ ) : partner?.payoutsEnabledAt ? (
+ <TooltipContent
+ title="Since you've already connected your bank account for payouts, you cannot change your profile type."
+ cta="Contact support"
+ href="https://dub.co/support"
+ target="_blank"
+ />
+ ) : undefined,
+ }}
>
<LayoutGroup>
<div className="w-full">
@@ -355,18 +351,18 @@ function BasicInfoForm({
]}
selected={profileType}
selectAction={(option: "individual" | "company") => {
- if (!disabled && completedPayoutsCount === 0) {
+ if (!disabled && !partner?.payoutsEnabledAt) {
setValue("profileType", option);
}
}}
className={cn(
"flex w-full items-center gap-0.5 rounded-lg border-neutral-300 bg-neutral-100 p-0.5",
- (disabled || completedPayoutsCount > 0) &&
+ (disabled || partner?.payoutsEnabledAt) &&
"cursor-not-allowed",
)}
optionClassName={cn(
"h-9 flex items-center justify-center rounded-lg flex-1",
- (disabled || completedPayoutsCount > 0) &&
+ (disabled || partner?.payoutsEnabledAt) &&
"pointer-events-none text-neutral-400",
)}
indicatorClassName="bg-white"
@@ -399,10 +395,10 @@ function BasicInfoForm({
<div>
<input
type="text"
- disabled={disabled || completedPayoutsCount > 0}
+ disabled={disabled}
className={cn(
"block w-full rounded-md focus:outline-none sm:text-sm",
- (disabled || completedPayoutsCount > 0) &&
+ disabled &&
"cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.companyName
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
diff --git a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
index ff5149379b..9e426f1274 100644
--- a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
@@ -10,6 +10,7 @@ import {
buttonVariants,
FileUpload,
ToggleGroup,
+ TooltipContent,
useEnterSubmit,
useLocalStorage,
useMediaQuery,
@@ -180,9 +181,14 @@ export function OnboardingForm({
{...field}
error={errors.country ? true : false}
disabledTooltip={
- partner?.payoutsEnabledAt
- ? "Since you've already received payouts, you cannot change your country. Contact support if you need to update your country."
- : undefined
+ partner?.payoutsEnabledAt ? (
+ <TooltipContent
+ title="Since you've already connected your bank account for payouts, you cannot change your profile country."
+ cta="Contact support"
+ href="https://dub.co/support"
+ target="_blank"
+ />
+ ) : undefined
}
/>
)}
diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.ts
index e16c87f560..ba694fcf3b 100644
--- a/apps/web/lib/actions/partners/update-partner-profile.ts
+++ b/apps/web/lib/actions/partners/update-partner-profile.ts
@@ -20,7 +20,6 @@ import {
} from "@dub/utils";
import { Partner, PartnerProfileType } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
-import { stripe } from "../../stripe";
import z from "../../zod";
import { uploadedImageSchema } from "../../zod/schemas/misc";
import { authPartnerActionClient } from "../safe-action";
@@ -74,8 +73,7 @@ export const updatePartnerProfileAction = authPartnerActionClient
)
throw new Error("Legal company name is required.");
- // Delete the Stripe Express account if needed
- await deleteStripeAccountIfRequired({
+ await updatedComplianceFieldsChecks({
partner,
input: parsedInput,
});
@@ -250,7 +248,7 @@ export const updatePartnerProfileAction = authPartnerActionClient
}
});
-const deleteStripeAccountIfRequired = async ({
+const updatedComplianceFieldsChecks = async ({
partner,
input,
}: {
@@ -265,49 +263,12 @@ const deleteStripeAccountIfRequired = async ({
input.profileType !== undefined &&
partner.profileType.toLowerCase() !== input.profileType.toLowerCase();
- const companyNameChanged =
- input.profileType === "company" &&
- partner.companyName?.toLowerCase() !== input.companyName?.toLowerCase();
-
- const deleteExpressAccount =
- (countryChanged || profileTypeChanged || companyNameChanged) &&
- partner.stripeConnectId;
-
- if (!deleteExpressAccount) {
- return;
- }
-
- // Partner is not able to update their country, profile type, or company name
- // if they have already have a Stripe Express account + any sent / completed payouts
- const completedPayoutsCount = await prisma.payout.count({
- where: {
- partnerId: partner.id,
- status: {
- in: ["processing", "processed", "sent", "completed"],
- },
- },
- });
-
- if (completedPayoutsCount > 0) {
+ if (partner.payoutsEnabledAt && (countryChanged || profileTypeChanged)) {
throw new Error(
- "Since you've already received payouts on Dub, you cannot change your country or profile type. Please contact support to update those fields.",
+ "Since you've already connected your bank account for payouts, you cannot change your country or profile type. Please contact support to update those fields.",
);
}
- if (partner.stripeConnectId) {
- const response = await stripe.accounts.del(partner.stripeConnectId);
-
- if (response.deleted) {
- await prisma.partner.update({
- where: {
- id: partner.id,
- },
- data: {
- stripeConnectId: null,
- payoutsEnabledAt: null,
- payoutMethodHash: null,
- },
- });
- }
- }
+ // TODO: log country and profile type changes
+ return;
};
diff --git a/apps/web/ui/partners/country-combobox.tsx b/apps/web/ui/partners/country-combobox.tsx
index 9e983642b1..dfb3ae77f4 100644
--- a/apps/web/ui/partners/country-combobox.tsx
+++ b/apps/web/ui/partners/country-combobox.tsx
@@ -1,6 +1,6 @@
import { Combobox } from "@dub/ui";
import { cn, COUNTRIES } from "@dub/utils";
-import { useMemo } from "react";
+import { ReactNode, useMemo } from "react";
export function CountryCombobox({
value,
@@ -11,7 +11,7 @@ export function CountryCombobox({
}: {
value: string;
onChange: (value: string) => void;
- disabledTooltip?: string;
+ disabledTooltip?: string | ReactNode;
error?: boolean;
className?: string;
}) {
@@ -63,7 +63,7 @@ export function CountryCombobox({
!value && "text-neutral-400",
disabledTooltip && "cursor-not-allowed",
error && "border-red-500 ring-red-500 ring-1",
- className
+ className,
),
disabledTooltip,
}}
diff --git a/packages/prisma/schema/message.prisma b/packages/prisma/schema/message.prisma
index ac1917bf25..baa5a26588 100644
--- a/packages/prisma/schema/message.prisma
+++ b/packages/prisma/schema/message.prisma
@@ -18,7 +18,7 @@ model Message {
readInApp DateTime?
readInEmail DateTime?
createdAt DateTime @default(now())
-updatedAt DateTime @updatedAt
+ updatedAt DateTime @updatedAt
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
partner Partner @relation(fields: [partnerId], references: [id], onDelete: Cascade)
diff --git a/packages/prisma/schema/partner.prisma b/packages/prisma/schema/partner.prisma
index d82937237b..9ee89192e3 100644
--- a/packages/prisma/schema/partner.prisma
+++ b/packages/prisma/schema/partner.prisma
@@ -58,7 +58,6 @@ model Partner {
tiktok String?
tiktokVerifiedAt DateTime?
invoiceSettings Json?
- monthlyTraffic MonthlyTraffic?
programs ProgramEnrollment[]
users PartnerUser[]
@@ -72,14 +71,15 @@ model Partner {
discountCodes DiscountCode[]
notificationEmails NotificationEmail[]
+ monthlyTraffic MonthlyTraffic?
industryInterests PartnerIndustryInterest[]
preferredEarningStructures PartnerPreferredEarningStructure[]
salesChannels PartnerSalesChannel[]
discoveredByPrograms DiscoveredPartner[]
- @@fulltext([email, name]) // For full-text search
@@index(discoverableAt)
+ @@fulltext([email, name]) // For full-text search
}
model PartnerInvite {
diff --git a/packages/prisma/schema/program.prisma b/packages/prisma/schema/program.prisma
index 2b4fee237f..9acffe67c8 100644
--- a/packages/prisma/schema/program.prisma
+++ b/packages/prisma/schema/program.prisma
@@ -117,14 +117,12 @@ model ProgramEnrollment {
// unique constraints
@@unique([partnerId, programId])
@@unique([tenantId, programId])
-
// indexes for sorting partners
@@index([programId, status, totalClicks])
@@index([programId, status, totalLeads])
@@index([programId, status, totalConversions])
@@index([programId, status, totalSaleAmount])
@@index([programId, status, totalCommissions])
-
// other indexes
@@index([groupId, status])
@@index(clickRewardId)