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.

confirm payout sheet UI

Kiran K31de742cfb51
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx
index ae1ce1be8c..dace9c185a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-stats.tsx
@@ -3,6 +3,7 @@
import usePayoutsCount from "@/lib/swr/use-payouts-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { PayoutsCount } from "@/lib/types";
+import { usePayoutInvoiceSheet } from "@/ui/partners/payout-invoice-sheet";
import { PayoutStatus } from "@dub/prisma/client";
import { Button, buttonVariants } from "@dub/ui";
import { cn, currencyFormatter } from "@dub/utils";
@@ -10,6 +11,7 @@ import Link from "next/link";
export function PayoutStats() {
const { slug } = useWorkspace();
+ const { payoutInvoiceSheet, setIsOpen } = usePayoutInvoiceSheet();
const { payoutsCount, loading } = usePayoutsCount<PayoutsCount[]>({
groupBy: "status",
@@ -24,55 +26,65 @@ export function PayoutStats() {
);
return (
- <div className="grid grid-cols-1 divide-neutral-200 rounded-lg border border-neutral-200 bg-neutral-50 max-sm:divide-y sm:grid-cols-2 sm:divide-x">
- <div className="flex flex-col p-4">
- <div className="flex justify-between gap-5">
- <div className="p-1">
- <div className="text-sm text-neutral-500">Pending payouts</div>
+ <>
+ {payoutInvoiceSheet}
+ <div className="grid grid-cols-1 divide-neutral-200 rounded-lg border border-neutral-200 bg-neutral-50 max-sm:divide-y sm:grid-cols-2 sm:divide-x">
+ <div className="flex flex-col p-4">
+ <div className="flex justify-between gap-5">
+ <div className="p-1">
+ <div className="text-sm text-neutral-500">Pending payouts</div>
+ </div>
+ <Button
+ text="Confirm payouts"
+ className="h-7 w-fit px-2"
+ onClick={() => setIsOpen(true)}
+ />
+ </div>
+ <div className="mt-2 text-2xl text-neutral-800">
+ {loading ? (
+ <div className="h-8 w-32 animate-pulse rounded bg-neutral-200" />
+ ) : (
+ currencyFormatter(
+ pendingPayouts?.amount ? pendingPayouts.amount / 100 : 0,
+ {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ },
+ ) + " USD"
+ )}
</div>
- <Button text="Confirm payouts" className="h-7 w-fit px-2" />
- </div>
- <div className="mt-2 text-2xl text-neutral-800">
- {loading ? (
- <div className="h-8 w-32 animate-pulse rounded bg-neutral-200" />
- ) : (
- currencyFormatter(
- pendingPayouts?.amount ? pendingPayouts.amount / 100 : 0,
- {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- },
- ) + " USD"
- )}
</div>
- </div>
- <div className="flex flex-col p-4">
- <div className="flex justify-between gap-5">
- <div className="p-1">
- <div className="text-sm text-neutral-500">Total paid</div>
+ <div className="flex flex-col p-4">
+ <div className="flex justify-between gap-5">
+ <div className="p-1">
+ <div className="text-sm text-neutral-500">Total paid</div>
+ </div>
+ <Link
+ href={`/${slug}/settings/billing/invoices`}
+ className={cn(
+ buttonVariants({ variant: "secondary" }),
+ "flex h-7 items-center rounded-md border px-2 text-sm",
+ )}
+ >
+ View invoices
+ </Link>
</div>
- <Link
- href={`/${slug}/settings/billing/invoices`}
- className={cn(
- buttonVariants({ variant: "secondary" }),
- "flex h-7 items-center rounded-md border px-2 text-sm",
+ <div className="mt-2 text-2xl text-neutral-800">
+ {loading ? (
+ <div className="h-8 w-32 animate-pulse rounded bg-neutral-200" />
+ ) : (
+ currencyFormatter(
+ totalPaid?.amount ? totalPaid.amount / 100 : 0,
+ {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ },
+ ) + " USD"
)}
- >
- View invoices
- </Link>
- </div>
- <div className="mt-2 text-2xl text-neutral-800">
- {loading ? (
- <div className="h-8 w-32 animate-pulse rounded bg-neutral-200" />
- ) : (
- currencyFormatter(totalPaid?.amount ? totalPaid.amount / 100 : 0, {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- }) + " USD"
- )}
+ </div>
</div>
</div>
- </div>
+ </>
);
}
diff --git a/apps/web/lib/actions/partners/confirm-payouts.ts b/apps/web/lib/actions/partners/confirm-payouts.ts
new file mode 100644
index 0000000000..ad908f242f
--- /dev/null
+++ b/apps/web/lib/actions/partners/confirm-payouts.ts
@@ -0,0 +1,32 @@
+"use server";
+
+import { getProgramOrThrow } from "@/lib/api/programs/get-program";
+import z from "../../zod";
+import { authActionClient } from "../safe-action";
+import { P } from "@upstash/redis/zmscore-b6b93f14";
+
+const confirmPayoutsSchema = z.object({
+ workspaceId: z.string(),
+ programId: z.string(),
+ // payoutIds: z.array(z.string()),
+});
+
+// Confirm payouts
+export const confirmPayoutsAction = authActionClient
+ .schema(confirmPayoutsSchema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace } = ctx;
+ const { programId } = parsedInput;
+
+ const program = await getProgramOrThrow({
+ workspaceId: workspace.id,
+ programId,
+ });
+
+ // TODO:
+ // Find the pending payouts for the program
+ // Create a new invoice
+ // Update the payouts with the invoice id
+ // Start a Qstash workflow
+ // Return the invoice id
+ });
diff --git a/apps/web/lib/actions/partners/onboard-partner.ts b/apps/web/lib/actions/partners/onboard-partner.ts
index 5018cd4411..c03f5338c0 100644
--- a/apps/web/lib/actions/partners/onboard-partner.ts
+++ b/apps/web/lib/actions/partners/onboard-partner.ts
@@ -16,6 +16,7 @@ export const onboardPartnerAction = authUserActionClient
.schema(onboardPartnerSchema)
.action(async ({ ctx, parsedInput }) => {
const { user } = ctx;
+ const { name, email, image, country, description } = parsedInput;
const partnersPortalEnabled = await userIsInBeta(
user.email,
@@ -26,11 +27,8 @@ export const onboardPartnerAction = authUserActionClient
throw new Error("Partners portal feature flag disabled.");
}
- const { name, email, image, country, phoneNumber, description } =
- parsedInput;
-
if (!COUNTRY_PHONE_CODES[country]) {
- throw new Error("Invalid country code or country not supported.");
+ throw new Error("Invalid country code.");
}
// Create the Stripe connected account for the partner
@@ -38,7 +36,6 @@ export const onboardPartnerAction = authUserActionClient
name,
email,
country,
- phoneNumber,
});
// TODO:
diff --git a/apps/web/lib/stripe/create-connected-account.ts b/apps/web/lib/stripe/create-connected-account.ts
index ad2a1f10f7..79de08e864 100644
--- a/apps/web/lib/stripe/create-connected-account.ts
+++ b/apps/web/lib/stripe/create-connected-account.ts
@@ -6,10 +6,9 @@ export const createConnectedAccount = async ({
name,
email,
country,
- phoneNumber,
}: Pick<
z.infer<typeof onboardPartnerSchema>,
- "name" | "email" | "country" | "phoneNumber"
+ "name" | "email" | "country"
>) => {
const [firstName, lastName] = name.split(" ");
@@ -23,7 +22,6 @@ export const createConnectedAccount = async ({
first_name: firstName,
last_name: lastName,
email,
- phone: phoneNumber,
},
capabilities: {
transfers: {
diff --git a/apps/web/lib/swr/use-payouts.ts b/apps/web/lib/swr/use-payouts.ts
index 9147230b0c..3e31d661b6 100644
--- a/apps/web/lib/swr/use-payouts.ts
+++ b/apps/web/lib/swr/use-payouts.ts
@@ -27,5 +27,6 @@ export default function usePayouts({
return {
payouts,
error,
+ loading: !payouts && !error,
};
}
diff --git a/apps/web/scripts/stripe-connect.ts b/apps/web/scripts/stripe-connect.ts
index b2b7cc1efc..a82b9e51a2 100644
--- a/apps/web/scripts/stripe-connect.ts
+++ b/apps/web/scripts/stripe-connect.ts
@@ -1,7 +1,6 @@
// Stripe Connect MVP
import "dotenv-flow/config";
-import { createConnectedAccount } from "@/lib/stripe/create-connected-account";
import Stripe from "stripe";
@@ -37,13 +36,24 @@ async function main() {
// await createCustomer();
try {
- const account = await createConnectedAccount({
- name: "Kiran 1",
- email: "[email protected]",
- country: "US",
- phoneNumber: "1234567890",
+ const account = await stripe.accounts.update("acct_1QVUkdPJLmUm0iMu", {
+ email: "[email protected]",
});
+ console.log("Updated account", account);
+
+ // const account = await createConnectedAccount({
+ // name: "Kiran US",
+ // email: "[email protected]",
+ // country: "US",
+ // });
+
+ // const account = await createConnectedAccount({
+ // name: "Kiran IN",
+ // email: "[email protected]",
+ // country: "IN",
+ // });
+
console.log("Created connected account", account);
} catch (error) {
console.error(error);
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsx
new file mode 100644
index 0000000000..59c1ed5681
--- /dev/null
+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx
@@ -0,0 +1,222 @@
+import usePayouts from "@/lib/swr/use-payouts";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { X } from "@/ui/shared/icons";
+import {
+ Button,
+ buttonVariants,
+ Sheet,
+ Table,
+ useRouterStuff,
+ useTable,
+} from "@dub/ui";
+import { cn, currencyFormatter, DICEBEAR_AVATAR_URL } from "@dub/utils";
+import Link from "next/link";
+import { useParams } from "next/navigation";
+import { Dispatch, Fragment, SetStateAction, useMemo, useState } from "react";
+import { SaleRowMenu } from "./sale-row-menu";
+
+interface PayoutInvoiceSheetProps {
+ setIsOpen: Dispatch<SetStateAction<boolean>>;
+}
+
+// TODO:
+// Handle case when there are 2 payouts for the same partner
+
+function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {
+ const { id: workspaceId, slug } = useWorkspace();
+ const { programId } = useParams<{ programId: string }>();
+
+ const {
+ payouts,
+ error: payoutsError,
+ loading: payoutsLoading,
+ } = usePayouts({
+ query: {
+ status: "pending",
+ },
+ });
+
+ const invoiceData = useMemo(() => {
+ const amount =
+ payouts?.reduce((acc, payout) => acc + payout.amount, 0) || 0;
+ const fee = amount * 0.02; // TODO: Fix it
+ const total = amount + fee;
+
+ return {
+ Method: "-",
+
+ Amount: currencyFormatter(amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ }),
+
+ Fee: currencyFormatter(fee / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ }),
+
+ Total: currencyFormatter(total / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ }),
+ };
+ }, [payouts]);
+
+ const table = useTable({
+ data: payouts || [],
+ columns: [
+ {
+ header: "Partner",
+ cell: ({ row }) => (
+ <div className="flex items-center gap-2">
+ <img
+ src={
+ row.original.partner.image ||
+ `${DICEBEAR_AVATAR_URL}${row.original.partner.name}`
+ }
+ alt={row.original.partner.name}
+ className="size-6 rounded-full"
+ />
+ <span className="text-sm text-neutral-700">
+ {row.original.partner.name}
+ </span>
+ </div>
+ ),
+ },
+ {
+ id: "total",
+ header: "Total",
+ cell: ({ row }) =>
+ currencyFormatter(row.original.amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ }),
+ },
+ // Menu
+ {
+ id: "menu",
+ enableHiding: false,
+ minSize: 43,
+ size: 43,
+ maxSize: 43,
+ cell: ({ row }) => <SaleRowMenu row={row} />,
+ },
+ ],
+ columnPinning: { right: ["menu"] },
+ thClassName: (id) =>
+ cn(id === "total" && "[&>div]:justify-end", "border-l-0"),
+ tdClassName: (id) => cn(id === "total" && "text-right", "border-l-0"),
+ className: "[&_tr:last-child>td]:border-b-transparent",
+ scrollWrapperClassName: "min-h-[40px]",
+ resourceName: (p) => `partner${p ? "s" : ""}`,
+ loading: payoutsLoading,
+ error: payoutsError
+ ? "Failed to load payouts for this invoice."
+ : undefined,
+ } as any);
+
+ return (
+ <>
+ <div>
+ <div className="flex items-start justify-between border-b border-neutral-200 p-6">
+ <Sheet.Title className="text-xl font-semibold">
+ Payout invoice
+ </Sheet.Title>
+ <Sheet.Close asChild>
+ <Button
+ variant="outline"
+ icon={<X className="size-5" />}
+ className="h-auto w-fit p-1"
+ />
+ </Sheet.Close>
+ </div>
+ <div className="flex flex-col gap-4 p-6">
+ <div className="text-base font-medium text-neutral-900">
+ Invoice details
+ </div>
+ <div className="grid grid-cols-2 gap-3 text-sm">
+ {Object.entries(invoiceData).map(([key, value]) => (
+ <Fragment key={key}>
+ <div className="flex items-center font-medium text-neutral-500">
+ {key}
+ </div>
+ <div className="text-neutral-800">{value}</div>
+ </Fragment>
+ ))}
+ </div>
+ </div>
+
+ <div className="p-6 pt-2">
+ <Table {...table} />
+ <div className="mt-2 flex justify-end">
+ <Link
+ href="/"
+ className={cn(
+ buttonVariants({ variant: "secondary" }),
+ "flex h-7 items-center rounded-lg border px-2 text-sm",
+ )}
+ >
+ View all
+ </Link>
+ </div>
+ </div>
+ </div>
+ <div className="flex grow flex-col justify-end">
+ <div className="flex items-center justify-end gap-2 border-t border-neutral-200 p-5">
+ <Button
+ type="button"
+ variant="secondary"
+ onClick={() => setIsOpen(false)}
+ text="Close"
+ className="w-fit"
+ />
+ <Button
+ type="button"
+ variant="primary"
+ // loading={isExecuting}
+ onClick={async () => {
+ // await executeAsync({
+ // workspaceId: workspaceId!,
+ // payoutId: payout.id,
+ // });
+ }}
+ text="Confirm payout"
+ className="w-fit"
+ />
+ </div>
+ </div>
+ </>
+ );
+}
+
+export function PayoutInvoiceSheet({
+ isOpen,
+ setIsOpen,
+}: PayoutInvoiceSheetProps & {
+ isOpen: boolean;
+}) {
+ const { queryParams } = useRouterStuff();
+
+ return (
+ <Sheet
+ open={isOpen}
+ onOpenChange={setIsOpen}
+ onClose={() => {
+ queryParams({ del: "payoutId", scroll: false });
+ }}
+ >
+ <PayoutInvoiceSheetContent setIsOpen={setIsOpen} />
+ </Sheet>
+ );
+}
+
+export function usePayoutInvoiceSheet() {
+ const [isOpen, setIsOpen] = useState(false);
+
+ return {
+ payoutInvoiceSheet: (
+ <PayoutInvoiceSheet isOpen={isOpen} setIsOpen={setIsOpen} />
+ ),
+ setIsOpen,
+ };
+}