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.

Update create-payout-sheet.tsx

Kiran Kb62d58acc76b
diff --git a/apps/web/ui/partners/create-payout-sheet.tsx b/apps/web/ui/partners/create-payout-sheet.tsx
index 00368f20cf..fff3a2250a 100644
--- a/apps/web/ui/partners/create-payout-sheet.tsx
+++ b/apps/web/ui/partners/create-payout-sheet.tsx
@@ -215,25 +215,42 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
fetcher,
);
- const invoiceData = useMemo(() => {
+ const payoutAmount = useMemo(() => {
const quantity =
payoutType === "sales" ? salesCount?.pending : totalEvents?.[payoutType];
- let payoutAmount: number | undefined = undefined;
-
if (payoutType === "custom") {
- payoutAmount = amount;
- } else if (isPercentageBased && salesAmount?.amount) {
- payoutAmount =
+ return amount;
+ }
+
+ if (isPercentageBased && salesAmount?.amount) {
+ return (
calculateEarnings({
- program: program!,
- sales: quantity,
+ program: {
+ commissionAmount: amount,
+ commissionType: "percentage",
+ },
+ sales: 1,
saleAmount: salesAmount.amount,
- }) / 100;
- } else {
- payoutAmount = quantity && amount ? quantity * amount : undefined;
+ }) / 100
+ );
}
+ return quantity && amount ? quantity * amount : undefined;
+ }, [
+ payoutType,
+ salesCount,
+ totalEvents,
+ amount,
+ isPercentageBased,
+ salesAmount,
+ program,
+ ]);
+
+ const invoiceData = useMemo(() => {
+ const quantity =
+ payoutType === "sales" ? salesCount?.pending : totalEvents?.[payoutType];
+
const amountAsNumber = amount ? Number(amount) : undefined;
return {
@@ -337,8 +354,17 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
isValidating,
isValidatingSalesAmount,
isValidatingSalesCount,
+ payoutAmount,
]);
+ const buttonDisabled =
+ isExecuting ||
+ isValidating ||
+ isValidatingSalesAmount ||
+ isValidatingSalesCount ||
+ !partnerId ||
+ !payoutAmount;
+
return (
<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col">
<div>
@@ -586,7 +612,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
text="Create payout"
className="w-fit"
loading={isExecuting}
- disabled={isExecuting || isValidating}
+ disabled={buttonDisabled}
/>
</div>
</div>