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.

Add custom product ID to commission creation

Tim Wilson375f4431691d
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx
index bdc465ccd4..b2760e3a12 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx
@@ -42,6 +42,7 @@ function CreateCommissionSheetContent(props: CreateCommissionSheetProps) {
const { id: workspaceId, defaultProgramId } = useWorkspace();
const [hasInvoiceId, setHasInvoiceId] = useState(false);
+ const [hasProductId, setHasProductId] = useState(false);
const { rewards, loading: rewardsLoading } = useRewards();
const [hasCustomLeadEventDate, setHasCustomLeadEventDate] = useState(false);
const [hasCustomLeadEventName, setHasCustomLeadEventName] = useState(false);
@@ -651,6 +652,61 @@ function CreateCommissionSheetContent(props: CreateCommissionSheetProps) {
</div>
)}
</AnimatedSizeContainer>
+
+ <AnimatedSizeContainer
+ height
+ transition={{ ease: "easeInOut", duration: 0.2 }}
+ className={!hasProductId ? "hidden" : ""}
+ style={{ display: !hasProductId ? "none" : "block" }}
+ >
+ <div className="flex items-center gap-4">
+ <Switch
+ fn={setHasProductId}
+ checked={hasProductId}
+ trackDimensions="w-8 h-4"
+ thumbDimensions="w-3 h-3"
+ thumbTranslate="translate-x-4"
+ />
+ <div className="flex gap-1">
+ <h3 className="text-sm font-medium text-neutral-700">
+ Add{" "}
+ </h3>
+ <span className="rounded-md border border-neutral-200 bg-neutral-100 px-1 py-0.5 text-xs">
+ productID
+ </span>
+ </div>
+ </div>
+
+ {hasProductId && (
+ <div className="mt-4">
+ <label
+ htmlFor="productId"
+ className="flex items-center space-x-2"
+ >
+ <h2 className="text-sm font-medium text-neutral-900">
+ Product ID
+ </h2>
+ </label>
+ <div className="mt-2 p-px">
+ <input
+ type="text"
+ id="productId"
+ className={cn(
+ "block w-full rounded-md border-neutral-300 px-3 py-2 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ errors.productId &&
+ "border-red-600 focus:border-red-500 focus:ring-red-600",
+ )}
+ {...register("productId", {
+ required: hasProductId,
+ setValueAs: (value) =>
+ value === "" ? null : value,
+ })}
+ placeholder="Enter product ID"
+ />
+ </div>
+ </div>
+ )}
+ </AnimatedSizeContainer>
</div>
</ProgramSheetAccordionContent>
</ProgramSheetAccordionItem>
diff --git a/apps/web/lib/actions/partners/create-commission.ts b/apps/web/lib/actions/partners/create-commission.ts
index 018e3a1007..14bd4a2ef1 100644
--- a/apps/web/lib/actions/partners/create-commission.ts
+++ b/apps/web/lib/actions/partners/create-commission.ts
@@ -31,6 +31,7 @@ export const createCommissionAction = authActionClient
amount,
linkId,
invoiceId,
+ productId,
customerId,
saleAmount,
saleEventDate,
@@ -225,6 +226,7 @@ export const createCommissionAction = authActionClient
payment_processor: "custom",
currency: "usd",
timestamp: saleDate.toISOString(),
+ metadata: productId ? JSON.stringify({ productId }) : undefined,
}),
createPartnerCommission({
@@ -244,6 +246,9 @@ export const createCommissionAction = authActionClient
customer: {
country: customer.country,
},
+ sale: {
+ productId,
+ },
},
}),
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index ab7653d58f..2cd029d19e 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -147,6 +147,7 @@ export const createCommissionSchema = z.object({
saleEventDate: parseDateSchema.nullish(),
saleAmount: z.number().min(0).nullish(),
invoiceId: z.string().nullish(),
+ productId: z.string().nullish(),
});
export const updateCommissionSchema = z.object({