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.

create compliance info URL

Kiran Kef7c43ae0eca
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/bank-account.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/bank-account.tsx
new file mode 100644
index 0000000000..793447f6c9
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/bank-account.tsx
@@ -0,0 +1,51 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import { useAddBankAccountModal } from "@/ui/modals/add-bank-account-modal";
+import { Badge, Button } from "@dub/ui";
+import { CreditCard } from "lucide-react";
+
+export const BankAccount = () => {
+ const { bankAccountName, maskedAccountNumber, bankAccountVerified } =
+ useWorkspace();
+
+ const { AddBankAccountModal, setShowAddBankAccountModal } =
+ useAddBankAccountModal();
+
+ return (
+ <>
+ <AddBankAccountModal />
+ <div className="flex items-center gap-5 rounded-lg border bg-white p-5">
+ <div className="hidden h-12 w-12 items-center justify-center rounded-full border border-neutral-300 sm:inline-flex">
+ <CreditCard className="h-5 w-5 text-gray-600" />
+ </div>
+
+ <div className="flex grow flex-col gap-1">
+ <div className="text-base font-semibold text-gray-700">
+ {bankAccountName ?? "Add your bank account"}
+ </div>
+ <div className="text-sm text-neutral-500">
+ {maskedAccountNumber
+ ? `*******${maskedAccountNumber}`
+ : "Add your bank account"}
+ </div>
+ </div>
+
+ <div>
+ {bankAccountName ? (
+ bankAccountVerified ? (
+ <Badge variant="blue">VERIFIED</Badge>
+ ) : (
+ <Badge variant="gray">PENDING VERIFICATION</Badge>
+ )
+ ) : (
+ <Button
+ text="Add bank account"
+ onClick={() => setShowAddBankAccountModal(true)}
+ />
+ )}
+ </div>
+ </div>
+ </>
+ );
+};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/compliance-flow.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/compliance-flow.tsx
new file mode 100644
index 0000000000..fd55620743
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/compliance-flow.tsx
@@ -0,0 +1,56 @@
+"use client";
+
+import { refreshComplianceFlowAction } from "@/lib/actions/refresh-compliance-flow";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { Button } from "@dub/ui";
+import { CreditCard } from "lucide-react";
+import { useAction } from "next-safe-action/hooks";
+import { toast } from "sonner";
+
+export const ComplianceFlow = () => {
+ const { id: workspaceId } = useWorkspace();
+
+ const { executeAsync, isExecuting } = useAction(refreshComplianceFlowAction, {
+ async onSuccess({ data }) {
+ if (!data?.link) {
+ return;
+ }
+
+ window.open(data.link, "_blank");
+ },
+ onError({ error }) {
+ toast.error(error.serverError?.serverError);
+ },
+ });
+
+ const onSubmit = async () => {
+ await executeAsync({ workspaceId: workspaceId! });
+ };
+
+ return (
+ <>
+ <div className="flex items-center gap-5 rounded-lg border bg-white p-5">
+ <div className="hidden h-12 w-12 items-center justify-center rounded-full border border-neutral-300 sm:inline-flex">
+ <CreditCard className="h-5 w-5 text-gray-600" />
+ </div>
+
+ <div className="flex grow flex-col gap-1">
+ <div className="text-base font-semibold text-gray-700">
+ Submit compliance information
+ </div>
+ <div className="text-sm text-neutral-500">
+ A URL will be generated for you to submit your KYB compliance.
+ </div>
+ </div>
+
+ <div>
+ <Button
+ text="Submit KYB compliance"
+ onClick={onSubmit}
+ loading={isExecuting}
+ />
+ </div>
+ </div>
+ </>
+ );
+};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/page-client.tsx
deleted file mode 100644
index 6ae7c96c38..0000000000
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/page-client.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-"use client";
-
-import useWorkspace from "@/lib/swr/use-workspace";
-import { useAddBankAccountModal } from "@/ui/modals/add-bank-account-modal";
-import { Badge, Button, MaxWidthWrapper } from "@dub/ui";
-import { CreditCard } from "lucide-react";
-
-export const BankAccountsClient = () => {
- const { bankAccountName, maskedAccountNumber, bankAccountVerified } =
- useWorkspace();
-
- const { AddBankAccountModal, setShowAddBankAccountModal } =
- useAddBankAccountModal();
-
- return (
- <>
- <AddBankAccountModal />
- <div className="relative min-h-[calc(100vh-16px)]">
- <MaxWidthWrapper className="grid gap-5 pb-10 pt-3">
- <div className="flex items-center gap-5 rounded-lg border bg-white p-5">
- <div className="hidden h-12 w-12 items-center justify-center rounded-full border border-neutral-300 sm:inline-flex">
- <CreditCard className="h-5 w-5 text-gray-600" />
- </div>
-
- <div className="flex grow flex-col gap-1">
- <div className="text-base font-semibold text-gray-700">
- {bankAccountName ?? "Add your bank account"}
- </div>
- <div className="text-sm text-neutral-500">
- {maskedAccountNumber
- ? `*******${maskedAccountNumber}`
- : "Add your bank account"}
- </div>
- </div>
-
- <div>
- {bankAccountName ? (
- bankAccountVerified ? (
- <Badge variant="blue">VERIFIED</Badge>
- ) : (
- <Badge variant="gray">PENDING VERIFICATION</Badge>
- )
- ) : (
- <Button
- text="Add bank account"
- onClick={() => setShowAddBankAccountModal(true)}
- />
- )}
- </div>
- </div>
- </MaxWidthWrapper>
- </div>
- </>
- );
-};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/page.tsx
index 3613ac4353..5c02d88634 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/bank-accounts/page.tsx
@@ -1,13 +1,20 @@
import LayoutLoader from "@/ui/layout/layout-loader";
import { PageContent } from "@/ui/layout/page-content";
+import { MaxWidthWrapper } from "@dub/ui";
import { Suspense } from "react";
-import { BankAccountsClient } from "./page-client";
+import { BankAccount } from "./bank-account";
+import { ComplianceFlow } from "./compliance-flow";
export default function BankAccounts() {
return (
<Suspense fallback={<LayoutLoader />}>
<PageContent title="Bank Accounts">
- <BankAccountsClient />
+ <div className="relative min-h-[calc(100vh-16px)]">
+ <MaxWidthWrapper className="grid gap-5 pb-10 pt-3">
+ <BankAccount />
+ <ComplianceFlow />
+ </MaxWidthWrapper>
+ </div>
</PageContent>
</Suspense>
);
diff --git a/apps/web/lib/actions/add-bank-account.ts b/apps/web/lib/actions/add-bank-account.ts
index 1013d17d50..da77d50364 100644
--- a/apps/web/lib/actions/add-bank-account.ts
+++ b/apps/web/lib/actions/add-bank-account.ts
@@ -9,7 +9,7 @@ import { authActionClient } from "./safe-action";
const schema = addBankAccountSchema.extend({ workspaceId: z.string() });
-export const addBankAccount = authActionClient
+export const addBankAccountAction = authActionClient
.schema(schema)
.action(async ({ parsedInput, ctx }) => {
const { workspace } = ctx;
diff --git a/apps/web/lib/actions/refresh-compliance-flow.ts b/apps/web/lib/actions/refresh-compliance-flow.ts
new file mode 100644
index 0000000000..cca9243c2c
--- /dev/null
+++ b/apps/web/lib/actions/refresh-compliance-flow.ts
@@ -0,0 +1,27 @@
+"use server";
+
+import { z } from "zod";
+import { refreshComplianceFlow } from "../dots/refresh-compliance-flow";
+import { authActionClient } from "./safe-action";
+
+const schema = z.object({
+ workspaceId: z.string(),
+});
+
+export const refreshComplianceFlowAction = authActionClient
+ .schema(schema)
+ .action(async ({ ctx }) => {
+ const { workspace } = ctx;
+
+ if (!workspace.dotsAppId) {
+ throw new Error(`Dots app not found for workspace ${workspace.id}`);
+ }
+
+ const { link } = await refreshComplianceFlow({
+ dotsAppId: workspace.dotsAppId,
+ });
+
+ return {
+ link,
+ };
+ });
diff --git a/apps/web/lib/dots/add-app-ach-account.ts b/apps/web/lib/dots/add-app-ach-account.ts
index e3185da9de..6b87f6edae 100644
--- a/apps/web/lib/dots/add-app-ach-account.ts
+++ b/apps/web/lib/dots/add-app-ach-account.ts
@@ -1,6 +1,11 @@
+import z from "../zod";
import { DOTS_API_URL } from "./env";
-import { achAccountSchema } from "./schemas";
-import { getBasicAuthToken } from "./utils";
+import { dotsHeaders } from "./utils";
+
+const schema = z.object({
+ name: z.string(),
+ mask: z.string(),
+});
export const addAppAchAccount = async ({
dotsAppId,
@@ -17,10 +22,7 @@ export const addAppAchAccount = async ({
`${DOTS_API_URL}/apps/${dotsAppId}/ach-account`,
{
method: "PUT",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Basic ${getBasicAuthToken()}`,
- },
+ headers: dotsHeaders(),
body: JSON.stringify({
account_number: accountNumber,
routing_number: routingNumber,
@@ -31,9 +33,8 @@ export const addAppAchAccount = async ({
if (!response.ok) {
console.error(await response.text());
-
throw new Error(`Failed to add ACH account to Dots app ${dotsAppId}.`);
}
- return achAccountSchema.parse(await response.json());
+ return schema.parse(await response.json());
};
diff --git a/apps/web/lib/dots/create-dots-app.ts b/apps/web/lib/dots/create-dots-app.ts
index 102184a480..2c5866d24f 100644
--- a/apps/web/lib/dots/create-dots-app.ts
+++ b/apps/web/lib/dots/create-dots-app.ts
@@ -1,7 +1,13 @@
import { Project } from "@prisma/client";
+import z from "../zod";
import { DOTS_API_URL } from "./env";
-import { dotsAppSchema } from "./schemas";
-import { getBasicAuthToken } from "./utils";
+import { dotsHeaders } from "./utils";
+
+const schema = z.object({
+ id: z.string(),
+ name: z.string(),
+ status: z.string(),
+});
export const createDotsApp = async ({
workspace,
@@ -10,10 +16,7 @@ export const createDotsApp = async ({
}) => {
const response = await fetch(`${DOTS_API_URL}/apps`, {
method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Basic ${getBasicAuthToken()}`,
- },
+ headers: dotsHeaders(),
body: JSON.stringify({
name: workspace.name,
metadata: {
@@ -30,5 +33,5 @@ export const createDotsApp = async ({
);
}
- return dotsAppSchema.parse(await response.json());
+ return schema.parse(await response.json());
};
diff --git a/apps/web/lib/dots/refresh-compliance-flow.ts b/apps/web/lib/dots/refresh-compliance-flow.ts
new file mode 100644
index 0000000000..abb9282116
--- /dev/null
+++ b/apps/web/lib/dots/refresh-compliance-flow.ts
@@ -0,0 +1,29 @@
+import z from "../zod";
+import { DOTS_API_URL } from "./env";
+import { dotsHeaders } from "./utils";
+
+const schema = z.object({
+ link: z.string(),
+});
+
+export const refreshComplianceFlow = async ({
+ dotsAppId,
+}: {
+ dotsAppId: string;
+}) => {
+ const response = await fetch(
+ `${DOTS_API_URL}/apps/${dotsAppId}/compliance-flow`,
+ {
+ method: "POST",
+ headers: dotsHeaders(),
+ body: JSON.stringify({}),
+ },
+ );
+
+ if (!response.ok) {
+ console.error(await response.text());
+ throw new Error(`Failed to refresh compliance flow for ${dotsAppId}.`);
+ }
+
+ return schema.parse(await response.json());
+};
diff --git a/apps/web/lib/dots/schemas.ts b/apps/web/lib/dots/schemas.ts
index 4b5043446b..a916038a05 100644
--- a/apps/web/lib/dots/schemas.ts
+++ b/apps/web/lib/dots/schemas.ts
@@ -1,18 +1,7 @@
import z from "../zod";
-export const dotsAppSchema = z.object({
- id: z.string(),
- name: z.string(),
- status: z.string(),
-});
-
export const addBankAccountSchema = z.object({
accountNumber: z.string().min(1),
routingNumber: z.string().min(1),
accountType: z.enum(["checking", "savings"]).default("checking"),
});
-
-export const achAccountSchema = z.object({
- name: z.string(),
- mask: z.string(),
-});
diff --git a/apps/web/lib/dots/utils.ts b/apps/web/lib/dots/utils.ts
index f687ad7e4f..63d8962fe1 100644
--- a/apps/web/lib/dots/utils.ts
+++ b/apps/web/lib/dots/utils.ts
@@ -3,3 +3,10 @@ import { DOTS_API_KEY, DOTS_CLIENT_ID } from "./env";
export const getBasicAuthToken = () => {
return Buffer.from(`${DOTS_CLIENT_ID}:${DOTS_API_KEY}`).toString("base64");
};
+
+export const dotsHeaders = () => {
+ return {
+ Authorization: `Basic ${getBasicAuthToken()}`,
+ "Content-Type": "application/json",
+ };
+};
diff --git a/apps/web/ui/modals/add-bank-account-modal.tsx b/apps/web/ui/modals/add-bank-account-modal.tsx
index 6929f455f9..f962a6b92a 100644
--- a/apps/web/ui/modals/add-bank-account-modal.tsx
+++ b/apps/web/ui/modals/add-bank-account-modal.tsx
@@ -1,4 +1,4 @@
-import { addBankAccount } from "@/lib/actions/add-bank-account";
+import { addBankAccountAction } from "@/lib/actions/add-bank-account";
import { addBankAccountSchema } from "@/lib/dots/schemas";
import useWorkspace from "@/lib/swr/use-workspace";
import z from "@/lib/zod";
@@ -48,7 +48,7 @@ const AddBankAccountForm = ({ closeModal }: AddBankAccountFormProps) => {
resolver: zodResolver(addBankAccountSchema),
});
- const { executeAsync, isExecuting } = useAction(addBankAccount, {
+ const { executeAsync, isExecuting } = useAction(addBankAccountAction, {
async onSuccess() {
toast.success(
"Bank account added successfully. Waiting for verification.",