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.

fix a few things

Steven Tey2c069479ffe6
diff --git a/apps/web/lib/actions/partners/create-manual-payout.ts b/apps/web/lib/actions/partners/create-manual-payout.ts
index 75876eba68..575efabac8 100644
--- a/apps/web/lib/actions/partners/create-manual-payout.ts
+++ b/apps/web/lib/actions/partners/create-manual-payout.ts
@@ -70,7 +70,7 @@ export const createManualPayoutAction = authActionClient
quantity = count[type];
}
- const amountInCents = amount * 100;
+ const amountInCents = (quantity || 1) * (amount || 0) * 100;
const fee = amountInCents * 0.02;
payout = await prisma.payout.create({
diff --git a/apps/web/ui/partners/create-payout-sheet.tsx b/apps/web/ui/partners/create-payout-sheet.tsx
index f681c7d4b4..b3e3b6c25f 100644
--- a/apps/web/ui/partners/create-payout-sheet.tsx
+++ b/apps/web/ui/partners/create-payout-sheet.tsx
@@ -13,7 +13,7 @@ import {
Sheet,
useRouterStuff,
} from "@dub/ui";
-import { cn } from "@dub/utils";
+import { cn, formatDate } from "@dub/utils";
import { PayoutType } from "@prisma/client";
import { useAction } from "next-safe-action/hooks";
import {
@@ -49,7 +49,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
const { program } = useProgram();
const { data: partners } = usePartners();
const { id: workspaceId } = useWorkspace();
-
+ const { queryParams } = useRouterStuff();
const {
register,
handleSubmit,
@@ -67,6 +67,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
const payoutType = watch("type");
const start = watch("start");
const end = watch("end");
+ const amount = watch("amount");
const partnerOptions = useMemo(() => {
return partners?.map((partner) => ({
@@ -114,12 +115,16 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
}, [partnerId, start, end, payoutType]);
const { executeAsync, isExecuting } = useAction(createManualPayoutAction, {
- onSuccess: async () => {
+ onSuccess: async (res) => {
toast.success("Successfully created payout!");
setIsOpen(false);
mutate(
`/api/programs/${program?.id}/payouts?workspaceId=${workspaceId}&sortBy=periodStart&order=desc`,
);
+ const payoutId = res.data?.id;
+ if (payoutId) {
+ queryParams({ set: { payoutId } });
+ }
},
onError({ error }) {
toast.error(error.serverError);
@@ -193,7 +198,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
htmlFor="type"
className="flex items-center space-x-2 text-sm font-medium text-gray-900"
>
- What type of payout is this?
+ Payout type
</label>
<select
{...register("type", { required: true })}
@@ -212,7 +217,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
htmlFor={dateRangePickerId}
className="block text-sm font-medium text-gray-700"
>
- Range for payout {payoutType === "custom" ? "(optional)" : ""}
+ Payout period {payoutType === "custom" ? "(optional)" : ""}
</label>
<DateRangePicker
id={dateRangePickerId}
@@ -231,7 +236,7 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
htmlFor="amount"
className="text-sm font-medium text-neutral-800"
>
- Amount
+ Reward amount
</label>
<div className="relative mt-2 rounded-md shadow-sm">
<span className="absolute inset-y-0 left-0 flex items-center pl-3 text-sm text-neutral-400">
@@ -240,7 +245,8 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
<input
className={cn(
"block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
- "pl-6 pr-12",
+ "pl-6 pr-[6.5rem]",
+ payoutType === "custom" && "pr-12",
)}
{...register("amount", {
required: true,
@@ -249,15 +255,27 @@ function CreatePayoutSheetContent({ setIsOpen }: CreatePayoutSheetProps) {
})}
type="number"
autoComplete="off"
- placeholder="100"
+ placeholder="5"
/>
<span className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm text-neutral-400">
USD
+ {payoutType !== "custom" &&
+ ` per ${payoutType.replace(/s$/, "")}`}
</span>
</div>
</div>
)}
+ {payoutType !== "custom" && start && end && amount && partnerId && (
+ <div className="rounded-md border border-neutral-200 p-4">
+ <p>
+ Given {amount} USD for {payoutType.replace(/s$/, "")} between{" "}
+ {formatDate(start)} and {formatDate(end)}, to{" "}
+ {partners?.find((p) => p.id === partnerId)?.name}
+ </p>
+ </div>
+ )}
+
<div className="flex flex-col gap-2">
<label
htmlFor="description"