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.

Prefill/lock name + email

Tim Wilsoneb23ea998ae5
diff --git a/apps/web/app/partners.dub.co/(auth)/(default)/register/page-client.tsx b/apps/web/app/partners.dub.co/(auth)/(default)/register/page-client.tsx
index a6704cab1c..2a670f133b 100644
--- a/apps/web/app/partners.dub.co/(auth)/(default)/register/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(auth)/(default)/register/page-client.tsx
@@ -15,11 +15,15 @@ type PartialProgram = Pick<Program, "name" | "logo">;
export default function RegisterPageClient({
program,
+ email,
+ lockEmail,
}: {
program?: PartialProgram;
+ email?: string;
+ lockEmail?: boolean;
}) {
return (
- <RegisterProvider>
+ <RegisterProvider email={email} lockEmail={lockEmail}>
<div className="mx-auto my-10 w-full max-w-[480px] md:mt-20 lg:mt-20">
<RegisterFlow program={program} />
</div>
diff --git a/apps/web/app/partners.dub.co/(auth)/(default)/register/page.tsx b/apps/web/app/partners.dub.co/(auth)/(default)/register/page.tsx
index 9ff78ef554..dbb865379c 100644
--- a/apps/web/app/partners.dub.co/(auth)/(default)/register/page.tsx
+++ b/apps/web/app/partners.dub.co/(auth)/(default)/register/page.tsx
@@ -1,4 +1,6 @@
import { getProgram } from "@/lib/fetchers/get-program";
+import { prisma } from "@dub/prisma";
+import { cookies } from "next/headers";
import { notFound } from "next/navigation";
import RegisterPageClient from "./page-client";
@@ -14,5 +16,40 @@ export default async function RegisterPage({
if (programSlug && !program) notFound();
- return <RegisterPageClient program={program} />;
+ let email: string | undefined = undefined;
+ let lockEmail = false;
+
+ if (program) {
+ const cookieStore = cookies();
+ const programApplicationIds = cookieStore
+ .get("programApplicationIds")
+ ?.value?.split(",");
+
+ const applications = programApplicationIds?.length
+ ? await prisma.programApplication.findMany({
+ where: {
+ id: {
+ in: programApplicationIds.filter(Boolean),
+ },
+ enrollment: null,
+ partnerId: null,
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ take: 10,
+ })
+ : [];
+
+ if (applications.length) {
+ email = applications[0].email;
+ lockEmail =
+ applications.length === 1 ||
+ applications.every((app) => app.email === email);
+ }
+ }
+
+ return (
+ <RegisterPageClient program={program} email={email} lockEmail={lockEmail} />
+ );
}
diff --git a/apps/web/app/partners.dub.co/(onboarding)/onboarding/page.tsx b/apps/web/app/partners.dub.co/(onboarding)/onboarding/page.tsx
index 0045e59869..fae03fe83e 100644
--- a/apps/web/app/partners.dub.co/(onboarding)/onboarding/page.tsx
+++ b/apps/web/app/partners.dub.co/(onboarding)/onboarding/page.tsx
@@ -54,7 +54,7 @@ async function OnboardingFormRSC() {
orderBy: {
createdAt: "desc",
},
- take: 2,
+ take: 10,
})
: [];
@@ -64,7 +64,11 @@ async function OnboardingFormRSC() {
...partner,
...(applications.length && { name: applications[0].name }),
}}
- lockName={applications.length === 1}
+ lockName={
+ applications.length === 1 ||
+ (applications.length > 0 &&
+ applications.every((app) => app.name === applications[0].name))
+ }
/>
);
}
diff --git a/apps/web/ui/auth/register/context.tsx b/apps/web/ui/auth/register/context.tsx
index 0347a99653..b92ef8eb4e 100644
--- a/apps/web/ui/auth/register/context.tsx
+++ b/apps/web/ui/auth/register/context.tsx
@@ -1,6 +1,11 @@
"use client";
-import React, { createContext, useContext, useState } from "react";
+import React, {
+ createContext,
+ PropsWithChildren,
+ useContext,
+ useState,
+} from "react";
interface RegisterContextType {
email: string;
@@ -9,22 +14,31 @@ interface RegisterContextType {
setEmail: (email: string) => void;
setPassword: (password: string) => void;
setStep: (step: "signup" | "verify") => void;
+ lockEmail?: boolean;
}
const RegisterContext = createContext<RegisterContextType | undefined>(
undefined,
);
-export const RegisterProvider: React.FC<{ children: React.ReactNode }> = ({
- children,
-}) => {
- const [email, setEmail] = useState("");
+export const RegisterProvider: React.FC<
+ PropsWithChildren<{ email?: string; lockEmail?: boolean }>
+> = ({ email: emailProp, lockEmail, children }) => {
+ const [email, setEmail] = useState(emailProp ?? "");
const [password, setPassword] = useState("");
const [step, setStep] = useState<"signup" | "verify">("signup");
return (
<RegisterContext.Provider
- value={{ email, password, step, setEmail, setPassword, setStep }}
+ value={{
+ email,
+ password,
+ step,
+ setEmail,
+ setPassword,
+ setStep,
+ lockEmail,
+ }}
>
{children}
</RegisterContext.Provider>
diff --git a/apps/web/ui/auth/register/signup-email.tsx b/apps/web/ui/auth/register/signup-email.tsx
index c680046132..43716c0ac6 100644
--- a/apps/web/ui/auth/register/signup-email.tsx
+++ b/apps/web/ui/auth/register/signup-email.tsx
@@ -12,14 +12,19 @@ import { useRegisterContext } from "./context";
type SignUpProps = z.infer<typeof signUpSchema>;
export const SignUpEmail = () => {
- const { setStep, setEmail, setPassword } = useRegisterContext();
+ const { setStep, setEmail, setPassword, email, lockEmail } =
+ useRegisterContext();
const {
register,
handleSubmit,
formState: { errors },
getValues,
- } = useForm<SignUpProps>();
+ } = useForm<SignUpProps>({
+ defaultValues: {
+ email,
+ },
+ });
const { executeAsync, isPending } = useAction(sendOtpAction, {
onSuccess: () => {
@@ -44,6 +49,7 @@ export const SignUpEmail = () => {
placeholder="Work Email"
autoComplete="email"
required
+ readOnly={!errors.email && lockEmail}
{...register("email")}
error={errors.email?.message}
/>
diff --git a/packages/ui/src/input.tsx b/packages/ui/src/input.tsx
index c9e3a71e7c..64282acb6c 100644
--- a/packages/ui/src/input.tsx
+++ b/packages/ui/src/input.tsx
@@ -23,7 +23,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<input
type={isPasswordVisible ? "text" : type}
className={cn(
- "w-full max-w-md rounded-md border border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ "w-full max-w-md rounded-md border border-neutral-300 text-neutral-900 placeholder-neutral-400 read-only:bg-neutral-100 read-only:text-neutral-500 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
props.error &&
"border-red-500 focus:border-red-500 focus:ring-red-500",
className,