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.

wip request invite form

Kiran K71b205860651
diff --git a/apps/web/app/api/referrals/invite/route.ts b/apps/web/app/api/referrals/invite/route.ts
new file mode 100644
index 0000000000..bf7812ff37
--- /dev/null
+++ b/apps/web/app/api/referrals/invite/route.ts
@@ -0,0 +1,15 @@
+import { parseRequestBody } from "@/lib/api/utils";
+import { requestPartnerInviteSchema } from "@/lib/dots/schemas";
+import { withAuth } from "@/lib/referrals/auth";
+import { NextResponse } from "next/server";
+
+// POST /api/referrals/invite - invite a partner to dub partners
+export const POST = withAuth(async ({ req }) => {
+ const { email } = requestPartnerInviteSchema.parse(
+ await parseRequestBody(req),
+ );
+
+ // TODO: Invite the partner to program
+
+ return NextResponse.json({});
+});
diff --git a/apps/web/app/app.dub.co/embed/request-partner-invite-modal.tsx b/apps/web/app/app.dub.co/embed/request-partner-invite-modal.tsx
new file mode 100644
index 0000000000..0e6609a344
--- /dev/null
+++ b/apps/web/app/app.dub.co/embed/request-partner-invite-modal.tsx
@@ -0,0 +1,139 @@
+import { requestPartnerInviteSchema } from "@/lib/dots/schemas";
+import useWorkspace from "@/lib/swr/use-workspace";
+import z from "@/lib/zod";
+import { Button, Modal } from "@dub/ui";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useCallback, useMemo, useState } from "react";
+import { useForm } from "react-hook-form";
+
+type RequestPartnerInvite = z.infer<typeof requestPartnerInviteSchema>;
+
+interface RequestPartnerInviteProps {
+ showModal: boolean;
+ setShowModal: (showModal: boolean) => void;
+}
+
+interface RequestPartnerInviteFormProps {
+ closeModal: () => void;
+}
+
+const RequestPartnerInvite = ({
+ showModal,
+ setShowModal,
+}: RequestPartnerInviteProps) => {
+ return (
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ drawerRootProps={{ repositionInputs: false }}
+ >
+ <h3 className="border-b border-gray-200 px-4 py-4 text-lg font-medium sm:px-6">
+ Request invite to Dub Partners for receiving payouts
+ </h3>
+ <div className="scrollbar-hide mt-6 max-h-[calc(100dvh-200px)] overflow-auto overflow-y-scroll">
+ <RequestPartnerInviteForm closeModal={() => setShowModal(false)} />
+ </div>
+ </Modal>
+ );
+};
+
+const RequestPartnerInviteForm = ({
+ closeModal,
+}: RequestPartnerInviteFormProps) => {
+ const { id: workspaceId, mutate } = useWorkspace();
+
+ const {
+ register,
+ handleSubmit,
+ formState: { isValid, isSubmitting },
+ } = useForm<RequestPartnerInvite>({
+ resolver: zodResolver(requestPartnerInviteSchema),
+ });
+
+ // const { executeAsync, isExecuting } = useAction(requestPartnerInviteAction, {
+ // async onSuccess() {
+ // toast.success(
+ // "Bank account added successfully. Waiting for verification.",
+ // );
+ // mutate();
+ // closeModal();
+ // },
+ // onError({ error }) {
+ // toast.error(error.serverError?.serverError);
+ // },
+ // });
+
+ const onSubmit = async (data: RequestPartnerInvite) => {
+ // await executeAsync({ ...data, workspaceId: workspaceId! });
+ };
+
+ return (
+ <form onSubmit={handleSubmit(onSubmit)}>
+ <div className="flex flex-col gap-y-6 px-4 text-left sm:px-6">
+ <div className="flex flex-col gap-3">
+ <div>
+ <label
+ htmlFor="accountNumber"
+ className="flex items-center space-x-2"
+ >
+ <h2 className="text-sm font-medium text-gray-900">
+ Account number
+ </h2>
+ </label>
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <input
+ {...register("email")}
+ 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="000000000"
+ required
+ autoFocus
+ autoComplete="off"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div className="mt-8 flex justify-end gap-2 border-t border-gray-200 px-4 py-4 sm:px-6">
+ <Button
+ type="button"
+ variant="secondary"
+ text="Cancel"
+ className="h-9 w-fit"
+ disabled={isSubmitting}
+ onClick={closeModal}
+ />
+
+ <Button
+ type="submit"
+ text="Request invite"
+ className="h-9 w-fit"
+ disabled={!isValid}
+ loading={isSubmitting}
+ />
+ </div>
+ </form>
+ );
+};
+
+export function useRequestPartnerInviteModal() {
+ const [showRequestPartnerInviteModal, setShowRequestPartnerInviteModal] =
+ useState(false);
+
+ const RequestPartnerInviteModal = useCallback(() => {
+ return (
+ <RequestPartnerInvite
+ showModal={showRequestPartnerInviteModal}
+ setShowModal={setShowRequestPartnerInviteModal}
+ />
+ );
+ }, [showRequestPartnerInviteModal, setShowRequestPartnerInviteModal]);
+
+ return useMemo(
+ () => ({
+ setShowRequestPartnerInviteModal,
+ RequestPartnerInviteModal,
+ }),
+ [setShowRequestPartnerInviteModal, RequestPartnerInviteModal],
+ );
+}
diff --git a/apps/web/lib/dots/schemas.ts b/apps/web/lib/dots/schemas.ts
index d1af9c56dd..f56c16d74a 100644
--- a/apps/web/lib/dots/schemas.ts
+++ b/apps/web/lib/dots/schemas.ts
@@ -121,3 +121,7 @@ export const dotsUserSchema = z.object({
payout_methods: z.array(payoutMethodSchema),
compliance: z.any(),
});
+
+export const requestPartnerInviteSchema = z.object({
+ email: z.string().email(),
+});