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.

Improve OTP UI

Tim Wilsondfcc4f17141d
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 646bf93bcd..95e992ae78 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
@@ -1,7 +1,9 @@
"use client";
import { verifyEmailAction } from "@/lib/actions/verify-email";
-import { Button, Input } from "@dub/ui";
+import { Button } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { OTPInput } from "input-otp";
import { useAction } from "next-safe-action/hooks";
import { useRouter, useSearchParams } from "next/navigation";
import { useState } from "react";
@@ -16,7 +18,7 @@ export default function VerifyEmailForm() {
verifyEmailAction,
{
onSuccess() {
- toast.success("Success.");
+ toast.success("Email verified! Redirecting to login...");
router.push("/login");
},
},
@@ -51,21 +53,43 @@ export default function VerifyEmailForm() {
await executeAsync({ email, code });
}}
>
- <div className="flex flex-col space-y-4">
- <Input
- type="text"
- placeholder="Enter OTP"
- required
- value={code}
- onChange={(e) => setCode(e.target.value)}
+ <div className="flex flex-col gap-8">
+ <OTPInput
maxLength={6}
+ value={code}
+ onChange={setCode}
+ autoFocus
+ containerClassName="group flex items-center justify-center"
+ render={({ slots }) => (
+ <div className="flex items-center">
+ {slots.map(({ char, isActive, hasFakeCaret }, idx) => (
+ <div
+ key={idx}
+ className={cn(
+ "relative flex h-14 w-10 items-center justify-center text-xl",
+ "border-y border-r border-gray-200 bg-white first:rounded-l-lg first:border-l last:rounded-r-lg",
+ "ring ring-0 transition-all",
+ isActive &&
+ "z-10 border border-gray-500 ring-4 ring-gray-200",
+ )}
+ >
+ {char}
+ {hasFakeCaret && (
+ <div className="animate-caret-blink pointer-events-none absolute inset-0 flex items-center justify-center">
+ <div className="h-5 w-px bg-black" />
+ </div>
+ )}
+ </div>
+ ))}
+ </div>
+ )}
/>
<input type="hidden" value={email} />
<Button
text={status === "executing" ? "Verifying..." : "Continue"}
type="submit"
loading={isExecuting}
- disabled={!code}
+ disabled={!code || code.length < 6}
/>
</div>
</form>
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
index 1b3e3794af..beb6907967 100644
--- 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
@@ -1,5 +1,5 @@
-import { BlurImage, Button, Logo } from "@dub/ui";
-import { constructMetadata, HOME_DOMAIN } from "@dub/utils";
+import { BlurImage, Button, Wordmark } from "@dub/ui";
+import { constructMetadata, truncate } from "@dub/utils";
import { Suspense } from "react";
import VerifyEmailForm from "./form";
@@ -24,31 +24,42 @@ const logos = [
export const runtime = "nodejs";
-export default function VerifyEmailPage() {
+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="w-full max-w-md 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">
- <a href={HOME_DOMAIN}>
- <Logo className="h-10 w-10" />
- </a>
- <h3 className="text-xl font-semibold">Verify your email</h3>
- <p className="text-sm text-gray-500">
- Enter the 6 digits verification code sent to your email address.
- </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 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>
</div>
</div>
diff --git a/apps/web/package.json b/apps/web/package.json
index 111a8e8b0e..9ddaa50d4a 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -71,6 +71,7 @@
"github-slugger": "^2.0.0",
"he": "^1.2.0",
"html-escaper": "^3.0.3",
+ "input-otp": "^1.2.4",
"js-cookie": "^3.0.5",
"json-2-csv": "^5.5.0",
"jszip": "^3.10.1",
diff --git a/apps/web/tailwind.config.ts b/apps/web/tailwind.config.ts
index 2b570d3ad8..68333a4e0a 100644
--- a/apps/web/tailwind.config.ts
+++ b/apps/web/tailwind.config.ts
@@ -23,6 +23,8 @@ const config: Pick<Config, "presets"> = {
// Table pinned column shadow animation
"table-pinned-shadow":
"table-pinned-shadow cubic-bezier(0, 0, 1, 0)",
+ // OTP caret blink animation
+ "caret-blink": "caret-blink 1s ease-out infinite",
},
keyframes: {
...sharedConfig?.theme?.extend?.keyframes,
@@ -47,6 +49,11 @@ const config: Pick<Config, "presets"> = {
"0%": { filter: "drop-shadow(rgba(0, 0, 0, 0.1) -2px 10px 6px)" },
"100%": { filter: "drop-shadow(rgba(0, 0, 0, 0) -2px 10px 6px)" },
},
+ // OTP caret blink animation
+ "caret-blink": {
+ "0%,70%,100%": { opacity: "0" },
+ "20%,50%": { opacity: "1" },
+ },
},
},
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ab67dd9062..57324f4777 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -209,6 +209,9 @@ importers:
html-escaper:
specifier: ^3.0.3
version: 3.0.3
+ input-otp:
+ specifier: ^1.2.4
js-cookie:
specifier: ^3.0.5
version: 3.0.5
@@ -13155,6 +13158,16 @@ packages:
resolution: {integrity: sha512-qlD8YNDqyTKTyuITrDOffsl6Tdhv+UC4hcdAVuQsK4IMQ99nSgd1MIA/Q+jQYoh9r3hVUXhYh7urSRmXPkW04g==}
dev: false
+ resolution: {integrity: sha512-md6rhmD+zmMnUh5crQNSQxq3keBRYvE3odbr4Qb9g2NWzQv9azi+t1a3X4TBTbh98fsGHgEEJlzbe1q860uGCA==}
+ peerDependencies:
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ dependencies:
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-Y+R5hJrzs52QCG2laLn4udYVnxsfny9CpOhNhUvk/SSSVyF6T27FzRbF0sroPidSu3X8oEAkOn2K804mjpt6UQ==}
engines: {node: '>= 0.4'}