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.

improvements to resend code

Kiran Kb4f271cf4118
diff --git a/apps/web/app/app.dub.co/(auth)/register/verify-email/resend-code.tsx b/apps/web/app/app.dub.co/(auth)/register/resend-otp.tsx
similarity index 78%
rename from apps/web/app/app.dub.co/(auth)/register/verify-email/resend-code.tsx
rename to apps/web/app/app.dub.co/(auth)/register/resend-otp.tsx
index 4c2c9b2405..ccb8136a71 100644
--- a/apps/web/app/app.dub.co/(auth)/register/verify-email/resend-code.tsx
+++ b/apps/web/app/app.dub.co/(auth)/register/resend-otp.tsx
@@ -1,30 +1,28 @@
"use client";
-import { resendOtpAction } from "@/lib/actions/resend-otp";
+import { sendOtpAction } from "@/lib/actions/send-otp";
import { LoadingSpinner } from "@dub/ui";
import { cn } from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
import { useEffect, useState } from "react";
-export function ResendCode({ email }: { email: string }) {
+export const ResendOtp = ({ email }: { email: string }) => {
const [delaySeconds, setDelaySeconds] = useState(0);
const [state, setState] = useState<"default" | "success" | "error">(
"default",
);
- const { executeAsync, result, status, isExecuting } = useAction(
- resendOtpAction,
- {
- onSuccess: () => {
- setState("success");
- },
- onError: () => setState("error"),
- },
- );
+ const { executeAsync, isExecuting } = useAction(sendOtpAction, {
+ onSuccess: () => setState("success"),
+ onError: () => setState("error"),
+ });
useEffect(() => {
- if (state === "success") setDelaySeconds(60);
- else if (state === "error") setDelaySeconds(5);
+ if (state === "success") {
+ setDelaySeconds(60);
+ } else if (state === "error") {
+ setDelaySeconds(5);
+ }
}, [state]);
useEffect(() => {
@@ -33,8 +31,11 @@ export function ResendCode({ email }: { email: string }) {
() => setDelaySeconds(delaySeconds - 1),
1000,
);
+
return () => clearInterval(interval);
- } else setState("default");
+ } else {
+ setState("default");
+ }
}, [delaySeconds]);
return (
@@ -46,6 +47,7 @@ export function ResendCode({ email }: { email: string }) {
<LoadingSpinner className="h-3 w-3" />
</div>
)}
+
<p className={cn(isExecuting && "opacity-80")}>
Didn't receive a code?{" "}
<button
@@ -60,11 +62,13 @@ export function ResendCode({ email }: { email: string }) {
</p>
</>
)}
+
{state === "success" && (
<p className="text-sm text-gray-500">
Code sent successfully. <Delay seconds={delaySeconds} />
</p>
)}
+
{state === "error" && (
<p className="text-sm text-gray-500">
Failed to send code. <Delay seconds={delaySeconds} />
@@ -72,10 +76,10 @@ export function ResendCode({ email }: { email: string }) {
)}
</div>
);
-}
+};
-function Delay({ seconds }: { seconds: number }) {
+const Delay = ({ seconds }: { seconds: number }) => {
return (
<span className="ml-1 text-sm tabular-nums text-gray-400">{seconds}s</span>
);
-}
+};
diff --git a/apps/web/app/app.dub.co/(auth)/register/signup-oauth.tsx b/apps/web/app/app.dub.co/(auth)/register/signup-oauth.tsx
index a980356753..1d4f0785fe 100644
--- a/apps/web/app/app.dub.co/(auth)/register/signup-oauth.tsx
+++ b/apps/web/app/app.dub.co/(auth)/register/signup-oauth.tsx
@@ -47,4 +47,4 @@ export const SignUpOAuth = () => {
/>
</>
);
-}
+};
diff --git a/apps/web/app/app.dub.co/(auth)/register/verify-email-form.tsx b/apps/web/app/app.dub.co/(auth)/register/verify-email-form.tsx
index 72d39d97cb..06626acde3 100644
--- a/apps/web/app/app.dub.co/(auth)/register/verify-email-form.tsx
+++ b/apps/web/app/app.dub.co/(auth)/register/verify-email-form.tsx
@@ -10,12 +10,14 @@ import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { useRegisterContext } from "./context";
+import { ResendOtp } from "./resend-otp";
export const VerifyEmailForm = () => {
const router = useRouter();
const { isMobile } = useMediaQuery();
const [code, setCode] = useState("");
const { email, password } = useRegisterContext();
+ const [isInvalidCode, setIsInvalidCode] = useState(false);
const { executeAsync, isExecuting } = useAction(createUserAccountAction, {
onSuccess() {
@@ -24,6 +26,8 @@ export const VerifyEmailForm = () => {
},
onError({ error }) {
toast.error(error.serverError?.serverError);
+ setCode("");
+ setIsInvalidCode(true);
},
});
@@ -70,7 +74,8 @@ export const VerifyEmailForm = () => {
"border-y border-r border-gray-200 bg-white first:rounded-l-lg first:border-l last:rounded-r-lg",
"ring-0 transition-all",
isActive &&
- "z-10 border border-gray-500 ring-4 ring-gray-200",
+ "z-10 border border-gray-500 ring-2 ring-gray-200",
+ isInvalidCode && "border-red-500 ring-red-200",
)}
>
{char}
@@ -83,6 +88,9 @@ export const VerifyEmailForm = () => {
))}
</div>
)}
+ onComplete={() => {
+ executeAsync({ email, password, code });
+ }}
/>
<Button
@@ -93,6 +101,8 @@ export const VerifyEmailForm = () => {
/>
</div>
</form>
+
+ <ResendOtp email={email} />
</AnimatedSizeContainer>
</div>
</div>
diff --git a/apps/web/app/app.dub.co/(auth)/register/verify-email/page.tsx b/apps/web/app/app.dub.co/(auth)/register/verify-email/page.tsx
deleted file mode 100644
index 546da9d8b5..0000000000
--- a/apps/web/app/app.dub.co/(auth)/register/verify-email/page.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-import { BlurImage, Button, Wordmark } from "@dub/ui";
-import { constructMetadata, truncate } from "@dub/utils";
-import { Suspense } from "react";
-// import VerifyEmailForm from "./form";
-import { ResendCode } from "./resend-code";
-
-export const metadata = constructMetadata({
- title: `Create your ${process.env.NEXT_PUBLIC_APP_NAME} account`,
-});
-
-const logos = [
- "vercel",
- "perplexity",
- "prisma",
- "tinybird",
- "hashnode",
- "cal",
- "vercel",
- "perplexity",
- "prisma",
- "tinybird",
- "hashnode",
- "cal",
-];
-
-export const runtime = "nodejs";
-
-export default function VerifyEmailPage({
- searchParams,
-}: {
- searchParams: { email: string };
-}) {
- const email = searchParams.email;
-
- return (
- <div className="grid w-full grid-cols-1 md:grid-cols-5">
- <div className="col-span-1 flex items-center justify-center md:col-span-3">
- <div className="flex w-full max-w-md flex-col items-center">
- <Wordmark className="mb-8 h-12" />
- <div className="overflow-hidden border-y border-gray-200 sm:rounded-2xl sm:border sm:shadow-xl">
- <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 py-6 pt-8 text-center sm:px-16">
- <h3 className="text-xl font-semibold">
- Verify your email address
- </h3>
- <p className="text-sm text-gray-500">
- Enter the six digit verification code sent to{" "}
- <strong className="font-medium text-gray-600" title={email}>
- {truncate(email, 30)}
- </strong>
- </p>
- </div>
- <div className="flex flex-col space-y-3 bg-gray-50 px-4 py-8 sm:px-16">
- <Suspense
- fallback={
- <>
- <Button disabled={true} text="" variant="secondary" />
- <div className="mx-auto h-5 w-3/4 rounded-lg bg-gray-100" />
- </>
- }
- >
- {/* <VerifyEmailForm /> */}
- </Suspense>
- </div>
- </div>
- <ResendCode email={email} />
- </div>
- </div>
- <div className="hidden h-full flex-col justify-center space-y-12 overflow-hidden border-l border-gray-200 bg-white/10 shadow-[inset_10px_-50px_94px_0_rgb(199,199,199,0.2)] backdrop-blur md:col-span-2 md:flex">
- <a
- href="https://dub.co/features/analytics"
- target="_blank"
- className="ml-12 h-1/2 w-[112%] rounded-xl border border-gray-200 p-2 shadow-xl"
- >
- <BlurImage
- alt="Dub.co Analytics"
- src="https://assets.dub.co/features/analytics.png"
- width={1735}
- height={990}
- className="h-full rounded-lg border border-gray-200 object-cover"
- />
- </a>
- <a
- href="https://dub.co/customers"
- target="_blank"
- className="animate-infinite-scroll flex items-center space-x-4"
- >
- {logos.map((logo, idx) => (
- <BlurImage
- alt={`${logo} logo`}
- key={idx}
- src={`https://dub.co/_static/clients/${logo}.svg`}
- width={520}
- height={182}
- className="h-12 grayscale transition-all hover:grayscale-0"
- />
- ))}
- </a>
- </div>
- </div>
- );
-}
diff --git a/apps/web/ui/layout/auth-layout.tsx b/apps/web/ui/layout/auth-layout.tsx
index 1e8bc28f2a..ab8b717db2 100644
--- a/apps/web/ui/layout/auth-layout.tsx
+++ b/apps/web/ui/layout/auth-layout.tsx
@@ -25,7 +25,7 @@ export const AuthLayout = ({ children }: AuthLayoutProps) => {
<div className="grid w-full grid-cols-1 md:grid-cols-5">
<div className="col-span-1 flex min-h-screen flex-col items-center justify-between border-r border-gray-200 bg-white/10 shadow-[inset_10px_-50px_94px_0_rgb(199,199,199,0.2)] backdrop-blur sm:col-span-3">
<div className="flex h-full w-full flex-col items-center justify-center">
- <ClientOnly className="relative flex w-full flex-col items-center justify-center">
+ <ClientOnly className="relative flex w-full flex-col items-center justify-center">
<Wordmark className="mb-8 h-12" />
<Suspense>{children}</Suspense>
</ClientOnly>