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.

Allow updating partner email

Steven Tey52e51209d220
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
index 5a2f7281e4..16633cde9b 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
@@ -12,6 +12,7 @@ import {
Button,
buttonVariants,
DotsPattern,
+ DynamicTooltipWrapper,
FileUpload,
LoadingSpinner,
ToggleGroup,
@@ -89,6 +90,7 @@ function FormWrapper({
type ProfileFormData = {
name: string;
+ email: string;
image: string | null;
description: string | null;
country: string;
@@ -103,6 +105,7 @@ function FormProvider({
const form = useForm<ProfileFormData>({
defaultValues: {
name: partner.name,
+ email: partner.email ?? "",
image: partner.image,
description: partner.description ?? null,
country: partner.country ?? "",
@@ -115,6 +118,8 @@ function FormProvider({
}
function Controls({ formRef }: { formRef: RefObject<HTMLFormElement> }) {
+ const { partner } = usePartnerProfile();
+
const { MergePartnerAccountsModal, setShowMergePartnerAccountsModal } =
useMergePartnerAccountsModal();
@@ -135,7 +140,19 @@ function Controls({ formRef }: { formRef: RefObject<HTMLFormElement> }) {
text="Save changes"
className="h-8 w-fit px-2.5"
loading={isSubmitting}
- onClick={() => formRef.current?.requestSubmit()}
+ onClick={() => {
+ if (partner?.stripeConnectId) {
+ const confirmed = window.confirm(
+ "Updating your email, country, or profile type will reset your Stripe account, which will require you to restart the payouts connection process. Are you sure you want to continue?",
+ );
+
+ if (!confirmed) {
+ return;
+ }
+ }
+
+ formRef.current?.requestSubmit();
+ }}
/>
</>
);
@@ -186,6 +203,7 @@ function ProfileForm({
<form
ref={formRef}
onSubmit={handleSubmit(async (data) => {
+ console.log({ data });
const imageChanged = data.image !== partner.image;
await executeAsync({
@@ -252,29 +270,57 @@ function ProfileForm({
/>
</div>
</label>
+ <label className="flex flex-col gap-1.5">
+ <span className="text-sm font-medium text-neutral-800">Email</span>
+ <DynamicTooltipWrapper
+ tooltipProps={
+ completedPayoutsCount > 0
+ ? {
+ content:
+ "Since you've already received payouts on Dub, you cannot change your email. If you need to update your email, please contact support.",
+ }
+ : undefined
+ }
+ >
+ <input
+ type="email"
+ className={cn(
+ "block w-full rounded-md focus:outline-none sm:text-sm",
+ errors.name
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ completedPayoutsCount > 0 &&
+ "cursor-not-allowed bg-neutral-100 text-neutral-400",
+ )}
+ placeholder="[email protected]"
+ disabled={completedPayoutsCount > 0}
+ {...register("email", {
+ required: true,
+ })}
+ />
+ </DynamicTooltipWrapper>
+ </label>
<label className="flex flex-col">
<span className="text-sm font-medium text-neutral-800">
Country
</span>
- <div>
- <Controller
- control={control}
- name="country"
- rules={{ required: true }}
- render={({ field }) => (
- <CountryCombobox
- value={field.value || ""}
- onChange={field.onChange}
- error={errors.country ? true : false}
- disabledTooltip={
- 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
- }
- />
- )}
- />
- </div>
+ <Controller
+ control={control}
+ name="country"
+ rules={{ required: true }}
+ render={({ field }) => (
+ <CountryCombobox
+ value={field.value || ""}
+ onChange={field.onChange}
+ error={errors.country ? true : false}
+ disabledTooltip={
+ 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
+ }
+ />
+ )}
+ />
</label>
<label className="flex flex-col gap-1.5">
@@ -302,7 +348,16 @@ function ProfileForm({
<span className="text-sm font-medium text-neutral-800">
Profile type
</span>
- <div className="w-full">
+ <DynamicTooltipWrapper
+ tooltipProps={
+ 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
+ }
+ >
<LayoutGroup>
<div className="w-full">
<ToggleGroup
@@ -328,13 +383,14 @@ function ProfileForm({
)}
optionClassName={cn(
"h-9 flex items-center justify-center rounded-lg flex-1",
- completedPayoutsCount > 0 && "pointer-events-none",
+ completedPayoutsCount > 0 &&
+ "pointer-events-none text-neutral-400",
)}
indicatorClassName="bg-white"
/>
</div>
</LayoutGroup>
- </div>
+ </DynamicTooltipWrapper>
</label>
<AnimatePresence mode="popLayout">
@@ -378,14 +434,6 @@ function ProfileForm({
</AnimatePresence>
</div>
</div>
- {/* <div className="flex justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-100 px-5 py-3.5">
- <Button
- type="submit"
- text="Save changes"
- className="h-8 w-fit px-2.5"
- loading={isSubmitting || isPending}
- />
- </div> */}
</form>
);
}
diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.ts
index 9bffa2db3f..2d73649f13 100644
--- a/apps/web/lib/actions/partners/update-partner-profile.ts
+++ b/apps/web/lib/actions/partners/update-partner-profile.ts
@@ -19,6 +19,7 @@ import { authPartnerActionClient } from "../safe-action";
const updatePartnerProfileSchema = z
.object({
name: z.string(),
+ email: z.string().email(),
image: uploadedImageSchema.nullish(),
description: z.string().nullable(),
country: z.enum(Object.keys(COUNTRIES) as [string, ...string[]]).nullable(),
@@ -48,8 +49,17 @@ export const updatePartnerProfileAction = authPartnerActionClient
.schema(updatePartnerProfileSchema)
.action(async ({ ctx, parsedInput }) => {
const { partner } = ctx;
- const { name, image, description, country, profileType, companyName } =
- parsedInput;
+ const {
+ name,
+ email,
+ image,
+ description,
+ country,
+ profileType,
+ companyName,
+ } = parsedInput;
+
+ const emailChanged = partner.email !== email;
const countryChanged =
partner.country?.toLowerCase() !== country?.toLowerCase();
@@ -60,7 +70,13 @@ export const updatePartnerProfileAction = authPartnerActionClient
const companyNameChanged =
partner.companyName?.toLowerCase() !== companyName?.toLowerCase();
- if (countryChanged || profileTypeChanged || companyNameChanged) {
+ if (
+ (emailChanged ||
+ countryChanged ||
+ profileTypeChanged ||
+ companyNameChanged) &&
+ partner.stripeConnectId
+ ) {
// Partner is only able to update their country, profile type, or company name
// as long as they don't have any completed payouts
const completedPayoutsCount = await prisma.payout.count({
@@ -72,24 +88,22 @@ export const updatePartnerProfileAction = authPartnerActionClient
if (completedPayoutsCount > 0) {
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 received payouts on Dub, you cannot change your email, 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,
- },
- });
- }
+ const response = await stripe.accounts.del(partner.stripeConnectId);
+
+ if (response.deleted) {
+ await prisma.partner.update({
+ where: {
+ id: partner.id,
+ },
+ data: {
+ stripeConnectId: null,
+ payoutsEnabledAt: null,
+ },
+ });
}
}
@@ -108,6 +122,7 @@ export const updatePartnerProfileAction = authPartnerActionClient
},
data: {
name,
+ email,
description,
...(imageUrl && { image: imageUrl }),
country,