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 'allow-country-change' of https://github.com/dubinc/dub into allow-country-change

Kiran Kd58ab9bf0d7c
diff --cc apps/web/app/partners.dub.co/(dashboard)/settings/page-client.tsx
index ea6d92cdf5,7194dec171..d88547f049
--- a/apps/web/app/partners.dub.co/(dashboard)/settings/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/settings/page-client.tsx
@@@ -120,8 -109,9 +120,11 @@@ function ProfileForm({ partner }: { par
groupBy: "status",
});
- const processingPayoutsCount =
- payoutsCount?.find((payout) => payout.status === "processing")?.count ?? 0;
- const sentPayoutsCount = payoutsCount?.find(
- (payout) => payout.status === "processing" || payout.status === "completed",
- )?.count;
++ const sentPayoutsCount =
++ payoutsCount?.find(
++ (payout) =>
++ payout.status === "processing" || payout.status === "completed",
++ )?.count ?? 0;
const formRef = useRef<HTMLFormElement>(null);
const { handleKeyDown } = useEnterSubmit(formRef);
@@@ -230,7 -220,11 +233,11 @@@
value={field.value || ""}
onChange={field.onChange}
error={errors.country ? true : false}
- disabled={processingPayoutsCount > 0}
+ disabledTooltip={
- sentPayoutsCount && sentPayoutsCount > 0
++ sentPayoutsCount > 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
+ }
/>
)}
/>
@@@ -261,88 -255,23 +268,88 @@@
</label>
</FormRow>
- {partner.profileType === "company" && (
- <FormRow>
- <label className="contents">
- <span className="text-sm font-medium text-neutral-800">
- Legal company name
- </span>
- <div>
- <input
- type="text"
- className="mt-2 block w-full rounded-md border-neutral-300 text-neutral-900 read-only:bg-neutral-100 read-only:text-neutral-500 sm:text-sm"
- readOnly
- defaultValue={partner.companyName ?? ""}
- />
- </div>
- </label>
- </FormRow>
- )}
+ <FormRow>
+ <label className="contents">
+ <span className="text-sm font-medium text-neutral-800">
+ Profile Type
+ </span>
+ <div className="w-full">
+ <LayoutGroup>
+ <div className="w-full">
+ <ToggleGroup
+ options={[
+ {
+ value: "individual",
+ label: "Individual",
+ },
+ {
+ value: "company",
+ label: "Company",
+ },
+ ]}
+ selected={profileType}
+ selectAction={(option: "individual" | "company") => {
- if (processingPayoutsCount === 0) {
++ if (sentPayoutsCount === 0) {
+ setValue("profileType", option);
+ }
+ }}
+ className={cn(
+ "flex w-full items-center gap-0.5 rounded-lg border-neutral-300 bg-neutral-100 p-0.5",
- processingPayoutsCount > 0 && "cursor-not-allowed",
++ sentPayoutsCount > 0 && "cursor-not-allowed",
+ )}
+ optionClassName={cn(
+ "h-9 flex items-center justify-center rounded-lg flex-1",
- processingPayoutsCount > 0 && "pointer-events-none",
++ sentPayoutsCount > 0 && "pointer-events-none",
+ )}
+ indicatorClassName="bg-white"
+ />
+ </div>
+ </LayoutGroup>
+ </div>
+ </label>
+ </FormRow>
+
+ <AnimatePresence mode="popLayout">
+ {profileType === "company" && (
+ <motion.div
+ layout
+ initial={{ opacity: 0, height: 0 }}
+ animate={{ opacity: 1, height: "auto" }}
+ exit={{ opacity: 0, height: 0 }}
+ transition={{
+ type: "spring",
+ stiffness: 300,
+ damping: 30,
+ opacity: { duration: 0.2 },
+ layout: { duration: 0.3, type: "spring" },
+ }}
+ className="contents"
+ >
+ <FormRow>
+ <label className="contents">
+ <span className="text-sm font-medium text-neutral-800">
+ Legal company name
+ </span>
+ <div>
+ <input
+ type="text"
+ className={cn(
+ "mt-2 block w-full rounded-md focus:outline-none sm:text-sm",
+ errors.companyName
+ ? "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",
+ )}
- disabled={processingPayoutsCount > 0}
++ disabled={sentPayoutsCount > 0}
+ {...register("companyName", {
+ required: profileType === "company",
+ })}
+ />
+ </div>
+ </label>
+ </FormRow>
+ </motion.div>
+ )}
+ </AnimatePresence>
</div>
</div>
<div className="flex justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-100 px-5 py-3.5">
diff --cc apps/web/lib/actions/partners/update-partner-profile.ts
index a74570a74c,eabbaa21be..527a47a03e
--- a/apps/web/lib/actions/partners/update-partner-profile.ts
+++ b/apps/web/lib/actions/partners/update-partner-profile.ts
@@@ -40,27 -19,19 +40,27 @@@ export const updatePartnerProfileActio
.schema(updatePartnerProfileSchema)
.action(async ({ ctx, parsedInput }) => {
const { partner } = ctx;
- const { name, image, description, country } = parsedInput;
+ const { name, image, description, country, profileType, companyName } =
+ parsedInput;
+
+ const countryChanged =
+ partner.country?.toLowerCase() !== country?.toLowerCase();
+
+ const profileTypeChanged =
+ partner.profileType.toLowerCase() !== profileType.toLowerCase();
+
+ const companyNameChanged =
+ partner.companyName?.toLowerCase() !== companyName?.toLowerCase();
- console.log({ countryChanged, profileTypeChanged, companyNameChanged });
-
- if (
- partner.country &&
- partner.country.toLowerCase() !== country?.toLowerCase()
- ) {
- // Partner should be able to update their country if they don't have any sent payouts
+ if (countryChanged || profileTypeChanged || companyNameChanged) {
+ // Partner should be able to update their country, profile type, or company name
- // if they don't have any payouts with status `processing`
- const pendingPayoutsCount = await prisma.payout.count({
++ // if they don't have any sent payouts
+ const sentPayoutsCount = await prisma.payout.count({
where: {
partnerId: partner.id,
- status: "processing",
+ status: {
+ in: ["processing", "completed"],
+ },
},
});