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 server actions + UI

Kiran Kaf999f87fc29
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/payouts/payout-details-sheet.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/payouts/payout-details-sheet.tsx
index 2a0e9454b5..dd5fffe638 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/payouts/payout-details-sheet.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/payouts/payout-details-sheet.tsx
@@ -58,8 +58,8 @@ function PayoutDetailsSheetContent({
: "numeric",
})}-${formatDate(payout.periodEnd, { month: "short" })}`,
- ...(payout.type !== "custom" && {
- [capitalize(payout.type) as string]: payout.eventCount,
+ ...(payout.quantity && {
+ [capitalize(payout.type) as string]: payout.quantity,
}),
Amount: currencyFormatter(payout.amount / 100, {
diff --git a/apps/web/lib/actions/partners/create-manual-payout.ts b/apps/web/lib/actions/partners/create-manual-payout.ts
index 3e1dff413b..75876eba68 100644
--- a/apps/web/lib/actions/partners/create-manual-payout.ts
+++ b/apps/web/lib/actions/partners/create-manual-payout.ts
@@ -1,49 +1,30 @@
"use server";
+import { getAnalytics } from "@/lib/analytics/get-analytics";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { createId } from "@/lib/api/utils";
import { createSalesPayout } from "@/lib/partners/create-sales-payout";
-import { processPartnerPayout } from "@/lib/partners/process-payout";
import { prisma } from "@/lib/prisma";
-import { parseDateSchema } from "@/lib/zod/schemas/utils";
-import { Payout, PayoutType } from "@prisma/client";
-import { z } from "zod";
+import { createManualPayoutSchema } from "@/lib/zod/schemas/payouts";
+import { Payout } from "@prisma/client";
import { authActionClient } from "../safe-action";
-const schema = z.object({
- workspaceId: z.string(),
- programId: z.string(),
- partnerId: z.string(),
- start: parseDateSchema,
- end: parseDateSchema,
- type: z.nativeEnum(PayoutType),
- eventCount: z.number().default(0),
- amount: z.number().default(0),
- description: z.string().max(5000).nullish(),
-});
-
-// When leads:
-
export const createManualPayoutAction = authActionClient
- .schema(schema)
+ .schema(createManualPayoutSchema)
.action(async ({ parsedInput, ctx }) => {
const { workspace } = ctx;
- const {
- programId,
- partnerId,
- start,
- end,
- type,
- amount,
- description,
- eventCount,
- } = parsedInput;
-
- if (!workspace.dotsAppId) {
- throw new Error("Partner payouts are not enabled for this workspace.");
+ const { programId, partnerId, start, end, type, amount, description } =
+ parsedInput;
+
+ if (["clicks", "leads", "sales"].includes(type) && (!start || !end)) {
+ throw new Error("Please select a date range to create a payout.");
}
- const [program, programEnrollment] = await Promise.all([
+ // if (!workspace.dotsAppId) {
+ // throw new Error("Partner payouts are not enabled for this workspace.");
+ // }
+
+ const [_, programEnrollment] = await Promise.all([
getProgramOrThrow({
workspaceId: workspace.id,
programId,
@@ -58,18 +39,37 @@ export const createManualPayoutAction = authActionClient
},
select: {
dotsUserId: true,
+ linkId: true,
},
}),
]);
- if (!programEnrollment.dotsUserId) {
- throw new Error("Partner is not properly enrolled in this program.");
+ // if (!programEnrollment.dotsUserId) {
+ // throw new Error("Partner is not properly enrolled in this program.");
+ // }
+
+ if (!programEnrollment.linkId) {
+ throw new Error("No short link found for this partner in this program.");
}
let payout: Payout | undefined = undefined;
// Create a payout for clicks, leads, and custom events
if (["clicks", "leads", "custom"].includes(type)) {
+ let quantity: number | undefined = undefined;
+
+ if (type === "clicks" || type === "leads") {
+ const count = await getAnalytics({
+ linkId: programEnrollment.linkId,
+ event: type as any,
+ groupBy: "count",
+ start: start as Date,
+ end: end as Date,
+ });
+
+ quantity = count[type];
+ }
+
const amountInCents = amount * 100;
const fee = amountInCents * 0.02;
@@ -80,18 +80,18 @@ export const createManualPayoutAction = authActionClient
partnerId,
fee,
type,
- description,
- eventCount,
- periodStart: start as Date,
- periodEnd: end as Date,
+ quantity,
amount: amountInCents,
total: amountInCents + fee,
+ periodEnd: end as Date,
+ periodStart: start as Date,
+ description,
},
});
}
// Create a payout for sales
- if (type === "sales") {
+ else if (type === "sales") {
payout = await createSalesPayout({
programId,
partnerId,
@@ -100,19 +100,7 @@ export const createManualPayoutAction = authActionClient
});
}
- if (!payout) {
- throw new Error("Failed to create payout. Please try again.");
- }
+ console.info("Manual payout created", payout);
- const { transfer, orgTransfer } = await processPartnerPayout({
- workspace,
- programEnrollment,
- program,
- payout,
- });
-
- return {
- transfer,
- orgTransfer,
- };
+ return payout;
});
diff --git a/apps/web/lib/actions/partners/create-partner-payout.ts b/apps/web/lib/actions/partners/create-partner-payout.ts
deleted file mode 100644
index f4924df01e..0000000000
--- a/apps/web/lib/actions/partners/create-partner-payout.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-"use server";
-
-import { processPartnerPayout } from "@/lib/partners/process-payout";
-import { prisma } from "@/lib/prisma";
-import { z } from "zod";
-import { authActionClient } from "../safe-action";
-
-const schema = z.object({
- workspaceId: z.string(),
- payoutId: z.string(),
-});
-
-export const createPartnerPayoutAction = authActionClient
- .schema(schema)
- .action(async ({ parsedInput, ctx }) => {
- const { workspace } = ctx;
- const { payoutId } = parsedInput;
-
- if (!workspace.dotsAppId) {
- throw new Error("Partner payouts are not enabled for this workspace.");
- }
-
- const payout = await prisma.payout.findUniqueOrThrow({
- where: { id: payoutId },
- });
-
- const result = await prisma.programEnrollment.findUniqueOrThrow({
- where: {
- partnerId_programId: {
- partnerId: payout.partnerId,
- programId: payout.programId,
- },
- },
- select: {
- dotsUserId: true,
- program: true,
- },
- });
-
- const { program, ...programEnrollment } = result;
-
- if (!programEnrollment.dotsUserId) {
- throw new Error("Partner is not properly enrolled in this program");
- }
-
- const { transfer, orgTransfer } = await processPartnerPayout({
- workspace,
- programEnrollment,
- program,
- payout,
- });
-
- return {
- transfer,
- orgTransfer,
- };
- });
diff --git a/apps/web/lib/actions/partners/process-partner-payout.ts b/apps/web/lib/actions/partners/process-partner-payout.ts
new file mode 100644
index 0000000000..d6f1b1177d
--- /dev/null
+++ b/apps/web/lib/actions/partners/process-partner-payout.ts
@@ -0,0 +1,134 @@
+"use server";
+
+import { limiter } from "@/lib/cron/limiter";
+import { createOrgTransfer } from "@/lib/dots/create-org-transfer";
+import { createTransfer } from "@/lib/dots/create-transfer";
+import { prisma } from "@/lib/prisma";
+import { formatDate } from "@dub/utils";
+import { waitUntil } from "@vercel/functions";
+import { sendEmail } from "emails";
+import PartnerPayoutSent from "emails/partner-payout-sent";
+import { v5 as uuidv5 } from "uuid";
+import { z } from "zod";
+import { authActionClient } from "../safe-action";
+
+const schema = z.object({
+ workspaceId: z.string(),
+ payoutId: z.string(),
+});
+
+export const processPartnerPayoutAction = authActionClient
+ .schema(schema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace } = ctx;
+ const { payoutId } = parsedInput;
+
+ if (!workspace.dotsAppId) {
+ throw new Error("Partner payouts are not enabled for this workspace.");
+ }
+
+ const payout = await prisma.payout.findUniqueOrThrow({
+ where: { id: payoutId },
+ });
+
+ const result = await prisma.programEnrollment.findUniqueOrThrow({
+ where: {
+ partnerId_programId: {
+ partnerId: payout.partnerId,
+ programId: payout.programId,
+ },
+ },
+ select: {
+ dotsUserId: true,
+ program: true,
+ },
+ });
+
+ const { program, ...programEnrollment } = result;
+
+ if (!programEnrollment.dotsUserId) {
+ throw new Error("Partner is not properly enrolled in this program");
+ }
+
+ const transfer = await createTransfer({
+ amount: payout.amount,
+ dotsAppId: workspace.dotsAppId,
+ dotsUserId: programEnrollment.dotsUserId,
+ idempotencyKey: uuidv5(payout.id, uuidv5.URL),
+ });
+
+ // we're splitting this out of the Promise.all() to avoid a race condition
+ // e.g. if the transfer fails, we shouldn't proceed with creating the org transfer
+ const orgTransfer = await createOrgTransfer({
+ amount: payout.fee,
+ dotsAppId: workspace.dotsAppId,
+ });
+
+ await Promise.all([
+ prisma.payout.update({
+ where: { id: payout.id },
+ data: { dotsTransferId: transfer.id, status: "completed" },
+ }),
+
+ ...(payout.type === "sales"
+ ? [
+ prisma.sale.updateMany({
+ where: { payoutId: payout.id },
+ data: { status: "paid" },
+ }),
+ ]
+ : []),
+ ]);
+
+ waitUntil(
+ (async () => {
+ const partnerUsers = await prisma.partnerUser.findMany({
+ where: {
+ partnerId: payout.partnerId,
+ },
+ include: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ });
+
+ await Promise.all(
+ partnerUsers.map(({ user }) =>
+ limiter.schedule(() =>
+ sendEmail({
+ subject: "You've been paid!",
+ email: user.email!,
+ from: "Dub Partners <[email protected]>",
+ react: PartnerPayoutSent({
+ email: user.email!,
+ program,
+ payout: {
+ id: payout.id,
+ amount: payout.amount,
+ startDate: formatDate(payout.periodStart, {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ }),
+ endDate: formatDate(payout.periodEnd, {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ }),
+ },
+ }),
+ }),
+ ),
+ ),
+ );
+ })(),
+ );
+
+ return {
+ transfer,
+ orgTransfer,
+ };
+ });
diff --git a/apps/web/lib/partners/create-sales-payout.ts b/apps/web/lib/partners/create-sales-payout.ts
index 6225023dcb..8bc3aedf48 100644
--- a/apps/web/lib/partners/create-sales-payout.ts
+++ b/apps/web/lib/partners/create-sales-payout.ts
@@ -58,7 +58,7 @@ export const createSalesPayout = async ({
total: amount + fee,
periodStart,
periodEnd,
- eventCount: sales.length,
+ quantity: sales.length,
},
});
diff --git a/apps/web/lib/partners/process-payout.ts b/apps/web/lib/partners/process-payout.ts
deleted file mode 100644
index 89b6545f9a..0000000000
--- a/apps/web/lib/partners/process-payout.ts
+++ /dev/null
@@ -1,112 +0,0 @@
-import { prisma } from "@/lib/prisma";
-import { formatDate } from "@dub/utils";
-import { Payout, Program, ProgramEnrollment, Project } from "@prisma/client";
-import { waitUntil } from "@vercel/functions";
-import { sendEmail } from "emails";
-import PartnerPayoutSent from "emails/partner-payout-sent";
-import { v5 as uuidv5 } from "uuid";
-import { limiter } from "../cron/limiter";
-import { createOrgTransfer } from "../dots/create-org-transfer";
-import { createTransfer } from "../dots/create-transfer";
-
-export const processPartnerPayout = async ({
- workspace,
- program,
- programEnrollment,
- payout,
-}: {
- workspace: Pick<Project, "dotsAppId">;
- program: Pick<Program, "id" | "name" | "logo">;
- programEnrollment: Pick<ProgramEnrollment, "dotsUserId">;
- payout: Payout;
-}) => {
- if (!workspace.dotsAppId) {
- throw new Error("Partner payouts are not enabled for this workspace.");
- }
-
- if (!programEnrollment.dotsUserId) {
- throw new Error("Partner is not properly enrolled in this program.");
- }
-
- const transfer = await createTransfer({
- amount: payout.amount,
- dotsAppId: workspace.dotsAppId,
- dotsUserId: programEnrollment.dotsUserId,
- idempotencyKey: uuidv5(payout.id, uuidv5.URL),
- });
-
- // we're splitting this out of the Promise.all() to avoid a race condition
- // e.g. if the transfer fails, we shouldn't proceed with creating the org transfer
- const orgTransfer = await createOrgTransfer({
- amount: payout.fee,
- dotsAppId: workspace.dotsAppId,
- });
-
- await Promise.all([
- prisma.payout.update({
- where: { id: payout.id },
- data: { dotsTransferId: transfer.id, status: "completed" },
- }),
-
- ...(payout.type === "sales"
- ? [
- prisma.sale.updateMany({
- where: { payoutId: payout.id },
- data: { status: "paid" },
- }),
- ]
- : []),
- ]);
-
- waitUntil(
- (async () => {
- const partnerUsers = await prisma.partnerUser.findMany({
- where: {
- partnerId: payout.partnerId,
- },
- include: {
- user: {
- select: {
- email: true,
- },
- },
- },
- });
-
- await Promise.all(
- partnerUsers.map(({ user }) =>
- limiter.schedule(() =>
- sendEmail({
- subject: "You've been paid!",
- email: user.email!,
- from: "Dub Partners <[email protected]>",
- react: PartnerPayoutSent({
- email: user.email!,
- program,
- payout: {
- id: payout.id,
- amount: payout.amount,
- startDate: formatDate(payout.periodStart, {
- year: "numeric",
- month: "short",
- day: "numeric",
- }),
- endDate: formatDate(payout.periodEnd, {
- year: "numeric",
- month: "short",
- day: "numeric",
- }),
- },
- }),
- }),
- ),
- ),
- );
- })(),
- );
-
- return {
- transfer,
- orgTransfer,
- };
-};
diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.ts
index d31b175db5..800a8c5894 100644
--- a/apps/web/lib/zod/schemas/partners.ts
+++ b/apps/web/lib/zod/schemas/partners.ts
@@ -80,7 +80,7 @@ export const PayoutSchema = z.object({
periodStart: z.date(),
periodEnd: z.date(),
dotsTransferId: z.string().nullable(),
- eventCount: z.number(),
+ quantity: z.number().nullable(),
createdAt: z.date(),
updatedAt: z.date(),
});
diff --git a/apps/web/lib/zod/schemas/payouts.ts b/apps/web/lib/zod/schemas/payouts.ts
new file mode 100644
index 0000000000..4300a5379f
--- /dev/null
+++ b/apps/web/lib/zod/schemas/payouts.ts
@@ -0,0 +1,14 @@
+import { parseDateSchema } from "@/lib/zod/schemas/utils";
+import { PayoutType } from "@prisma/client";
+import { z } from "zod";
+
+export const createManualPayoutSchema = z.object({
+ workspaceId: z.string(),
+ programId: z.string(),
+ partnerId: z.string({ required_error: "Please select a partner" }),
+ start: parseDateSchema.nullable(),
+ end: parseDateSchema.nullable(),
+ type: z.nativeEnum(PayoutType),
+ amount: z.number().default(0),
+ description: z.string().max(5000).nullable(),
+});
diff --git a/apps/web/prisma/schema/payout.prisma b/apps/web/prisma/schema/payout.prisma
index 0557f386ad..e9768298aa 100644
--- a/apps/web/prisma/schema/payout.prisma
+++ b/apps/web/prisma/schema/payout.prisma
@@ -22,9 +22,9 @@ model Payout {
status PayoutStatus @default(pending)
type PayoutType @default(sales)
description String?
- periodStart DateTime
- periodEnd DateTime
- eventCount Int @default(0) // Number of clicks/leads/sales in this payout
+ periodStart DateTime?
+ periodEnd DateTime?
+ quantity Int? // Number of clicks/leads/sales in this payout
dotsTransferId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
diff --git a/apps/web/ui/partners/create-payout-sheet.tsx b/apps/web/ui/partners/create-payout-sheet.tsx
index 77157ae173..04b1c51d7b 100644
--- a/apps/web/ui/partners/create-payout-sheet.tsx
+++ b/apps/web/ui/partners/create-payout-sheet.tsx
@@ -4,6 +4,7 @@ import { createManualPayoutAction } from "@/lib/actions/partners/create-manual-p
import usePartners from "@/lib/swr/use-partners";
import useProgram from "@/lib/swr/use-program";
import useWorkspace from "@/lib/swr/use-workspace";
+import { createManualPayoutSchema } from "@/lib/zod/schemas/payouts";
import { X } from "@/ui/shared/icons";
import {
Button,
@@ -19,21 +20,22 @@ import { Dispatch, SetStateAction, useId, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { mutate } from "swr";
+import { z } from "zod";
interface CreatePayoutSheetProps {
setIsOpen: Dispatch<SetStateAction<boolean>>;
}
-interface FormData {
- dateRange: {
- start: Date;
- end: Date;
- };
- amount: number;
- partnerId: string;
- type: PayoutType;
- description?: string;
-}
+const schema = createManualPayoutSchema.pick({
+ partnerId: true,
+ type: true,
+ start: true,
+ end: true,
+ amount: true,
+ description: true,
+});
+
+type FormData = z.infer<typeof schema>;
function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
const dateRangePickerId = useId();
@@ -41,24 +43,23 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
const { data: partners } = usePartners();
const { id: workspaceId } = useWorkspace();
- const today = new Date();
-
- const { register, handleSubmit, watch, setValue } = useForm<FormData>({
+ const {
+ register,
+ handleSubmit,
+ watch,
+ setValue,
+ formState: { errors },
+ clearErrors,
+ } = useForm<FormData>({
defaultValues: {
- dateRange: {
- start: new Date(
- today.getFullYear(),
- today.getMonth(),
- today.getDate() - 31,
- ),
- end: new Date(today.getFullYear(), today.getMonth(), today.getDate()),
- },
+ type: "sales",
},
+ // resolver: zodResolver(schema),
});
const partnerId = watch("partnerId");
- const dateRange = watch("dateRange");
- const type = watch("type");
+ const payoutType = watch("type");
+
const partner = partners?.find((p) => p.id === partnerId);
const partnerOptions = useMemo(() => {
@@ -102,22 +103,27 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
);
},
onError({ error }) {
+ console.log("error", error);
toast.error(error.serverError);
},
});
const onSubmit = async (data: FormData) => {
+ console.log("data", data);
+
if (workspaceId && program) {
await executeAsync({
...data,
workspaceId,
programId: program.id,
- start: data.dateRange.start.toISOString(),
- end: data.dateRange.end.toISOString(),
+ start: data.start ? data.start.toISOString() : null,
+ end: data.end ? data.end.toISOString() : null,
});
}
};
+ const isValid = Object.keys(errors).length === 0;
+
return (
<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col">
<div>
@@ -133,7 +139,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
/>
</Sheet.Close>
</div>
- <div className="flex flex-col gap-3 p-6">
+ <div className="flex flex-col gap-4 p-6">
<div className="flex flex-col gap-2">
<label className="flex items-center space-x-2 text-sm font-medium text-gray-900">
Partner
@@ -145,6 +151,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
setSelected={(option) => {
if (option) {
setValue("partnerId", option.value);
+ clearErrors("partnerId");
}
}}
options={partnerOptions}
@@ -158,33 +165,13 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
"data-[state=open]:ring-1 data-[state=open]:ring-gray-500 data-[state=open]:border-gray-500",
"focus:ring-1 focus:ring-gray-500 focus:border-gray-500 transition-none",
!partnerId && "text-gray-400",
+ errors.partnerId && "border-red-500",
),
}}
/>
- </div>
-
- <div className="flex flex-col gap-2">
- <label
- htmlFor={dateRangePickerId}
- className="block text-sm font-medium text-gray-700"
- >
- Date Range
- </label>
- <DateRangePicker
- id={dateRangePickerId}
- onChange={(dateRange) => {
- if (dateRange) {
- setValue("dateRange", {
- start: dateRange.from!,
- end: dateRange.to!,
- });
- }
- }}
- value={{
- from: dateRange.start,
- to: dateRange.end,
- }}
- />
+ {errors.partnerId && (
+ <p className="text-xs text-red-600">{errors.partnerId.message}</p>
+ )}
</div>
<div className="flex flex-col gap-2">
@@ -192,7 +179,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
htmlFor="type"
className="flex items-center space-x-2 text-sm font-medium text-gray-900"
>
- Type
+ What type of payout is this?
</label>
<select
{...register("type", { required: true })}
@@ -206,7 +193,25 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
</select>
</div>
- {type !== "sales" && (
+ <div className="flex flex-col gap-2">
+ <label
+ htmlFor={dateRangePickerId}
+ className="block text-sm font-medium text-gray-700"
+ >
+ Range for payout {payoutType === "custom" ? "(optional)" : ""}
+ </label>
+ <DateRangePicker
+ id={dateRangePickerId}
+ onChange={(dateRange) => {
+ if (dateRange) {
+ setValue("start", dateRange.from!);
+ setValue("end", dateRange.to!);
+ }
+ }}
+ />
+ </div>
+
+ {payoutType !== "sales" && (
<div className="flex flex-col gap-2">
<label
htmlFor="amount"
@@ -218,7 +223,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
<input
{...register("amount", {
required: true,
- setValueAs: (value) => Number(value),
+ setValueAs: (value) => Number(value) || "",
})}
className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
placeholder="500"
@@ -234,7 +239,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
htmlFor="description"
className="flex items-center space-x-2 text-sm font-medium text-gray-900"
>
- Description
+ Description (optional)
</label>
<textarea
{...register("description")}
@@ -261,6 +266,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
text="Create payout"
className="w-fit"
loading={isExecuting}
+ // disabled={!isValid}
/>
</div>
</div>
diff --git a/apps/web/ui/partners/payout-details-sheet.tsx b/apps/web/ui/partners/payout-details-sheet.tsx
index a3c0954ab9..c93a4664e9 100644
--- a/apps/web/ui/partners/payout-details-sheet.tsx
+++ b/apps/web/ui/partners/payout-details-sheet.tsx
@@ -1,4 +1,4 @@
-import { createPartnerPayoutAction } from "@/lib/actions/partners/create-partner-payout";
+import { processPartnerPayoutAction } from "@/lib/actions/partners/process-partner-payout";
import useWorkspace from "@/lib/swr/use-workspace";
import { PayoutResponse, SaleResponse } from "@/lib/types";
import { X } from "@/ui/shared/icons";
@@ -81,8 +81,8 @@ function PayoutDetailsSheetContent({
: "numeric",
})}-${formatDate(payout.periodEnd, { month: "short" })}`,
- ...(payout.type !== "custom" && {
- [capitalize(payout.type) as string]: payout.eventCount,
+ ...(payout.quantity && {
+ [capitalize(payout.type) as string]: payout.quantity,
}),
Amount: currencyFormatter(payout.amount / 100, {
@@ -166,7 +166,7 @@ function PayoutDetailsSheetContent({
const { queryParams } = useRouterStuff();
- const { executeAsync, isExecuting } = useAction(createPartnerPayoutAction, {
+ const { executeAsync, isExecuting } = useAction(processPartnerPayoutAction, {
onSuccess: async () => {
await mutate(
(key) =>