Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
💄 Replace OTP inputs with shadcn input-otp component (#2480)
Luke Vella095d4430a65b
diff --git a/apps/web/src/app/[locale]/(auth)/components/auth-page.tsx b/apps/web/src/app/[locale]/(auth)/components/auth-page.tsxindex a27bb3f33..62416499e 100644--- a/apps/web/src/app/[locale]/(auth)/components/auth-page.tsx+++ b/apps/web/src/app/[locale]/(auth)/components/auth-page.tsx@@ -2,7 +2,7 @@ import { Logo } from "@/components/logo";export function AuthPageContainer({ children }: { children: React.ReactNode }) {return (- <div className="space-y-8 lg:space-y-10">+ <div className="space-y-8"><div className="mb-12 flex justify-center"><Logo /></div>diff --git a/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsx b/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsxindex 42f254ab9..5b5bf7bcd 100644--- a/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsx+++ b/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsx@@ -15,10 +15,10 @@ import { useSearchParams } from "next/navigation";import { useForm } from "react-hook-form";import * as z from "zod";+import { InputOTP } from "@/components/input-otp";import { Trans, useTranslation } from "@/i18n/client";import { authClient } from "@/lib/auth-client";import { validateRedirectUrl } from "@/utils/redirect";-import { InputOTP } from "../../../../../../components/input-otp";const otpFormSchema = z.object({otp: z.string().length(6),@@ -83,7 +83,10 @@ export function OTPForm({ email }: { email: string }) {return (<Form {...form}>- <form className="space-y-6" onSubmit={handleSubmit}>+ <form+ className="flex flex-col items-center space-y-6 text-center"+ onSubmit={handleSubmit}+ ><FormFieldcontrol={form.control}name="otp"@@ -92,8 +95,6 @@ export function OTPForm({ email }: { email: string }) {<FormItem><FormControl><InputOTP- large- placeholder={t("verificationCodePlaceholder")}disabled={form.formState.isSubmitting ||form.formState.isSubmitSuccessful@@ -105,7 +106,7 @@ export function OTPForm({ email }: { email: string }) {{...field}/></FormControl>- <FormDescription>+ <FormDescription className="mt-4"><Trans i18nKey="verificationCodeHelp" /></FormDescription><FormMessage />diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsxindex ac4196c8d..70fb7ca78 100644--- a/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsx@@ -120,7 +120,6 @@ function VerifyEmailChangeForm({<FormItem><FormControl><InputOTP- placeholder={t("verificationCodePlaceholder")}disabled={form.formState.isSubmitting}autoFocus={true}onValidCode={() => {diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsxindex 92c38704b..1c246b9bf 100644--- a/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx@@ -144,7 +144,6 @@ export function RsvpVerifyEmail({<FormControl><InputOTPautoFocus- placeholder={t("verificationCodePlaceholder")}disabled={form.formState.isSubmitting}onValidCode={() => handleSubmit()}{...field}diff --git a/apps/web/src/app/[locale]/setup/page.tsx b/apps/web/src/app/[locale]/setup/page.tsxindex 16a567830..fb2796cc3 100644--- a/apps/web/src/app/[locale]/setup/page.tsx+++ b/apps/web/src/app/[locale]/setup/page.tsx@@ -18,7 +18,7 @@ export default async function SetupPage() {return (<div className="flex min-h-dvh justify-center bg-background p-4 sm:items-center"><div className="w-full max-w-sm">- <article className="space-y-8 lg:space-y-10">+ <article className="space-y-8"><div className="flex justify-center py-8"><Logo /></div>diff --git a/apps/web/src/components/input-otp.tsx b/apps/web/src/components/input-otp.tsxindex e701c26c0..10d8e6ec0 100644--- a/apps/web/src/components/input-otp.tsx+++ b/apps/web/src/components/input-otp.tsx@@ -1,30 +1,42 @@-import { Input } from "@rallly/ui/input";-import React from "react";+"use client";-const InputOTP = React.forwardRef<- HTMLInputElement,- React.ComponentProps<typeof Input> & { onValidCode?: (code: string) => void }->(({ onValidCode, onChange, ...rest }, ref) => {- return (- <Input- ref={ref}- {...rest}- onChange={(e) => {- onChange?.(e);+import {+ InputOTP as InputOTPBase,+ InputOTPGroup,+ InputOTPSlot,+ REGEXP_ONLY_DIGITS,+} from "@rallly/ui/input-otp";+import type * as React from "react";+import { useTranslation } from "@/i18n/client";++type InputOTPProps = Omit<+ React.ComponentProps<typeof InputOTPBase>,+ "maxLength" | "pattern" | "children" | "render" | "onComplete"+> & {+ onValidCode?: (code: string) => void;+};- if (e.target.value.length === 6) {- onValidCode?.(e.target.value);- }- }}+function InputOTP({ onValidCode, ...props }: InputOTPProps) {+ const { t } = useTranslation();+ return (+ <InputOTPBasemaxLength={6}- data-1p-ignoreinputMode="numeric"- autoComplete="one-time-code"- pattern="\d{6}"- />+ pattern={REGEXP_ONLY_DIGITS}+ aria-label={t("verificationCodePlaceholder")}+ onComplete={onValidCode}+ {...props}+ >+ <InputOTPGroup>+ <InputOTPSlot index={0} />+ <InputOTPSlot index={1} />+ <InputOTPSlot index={2} />+ <InputOTPSlot index={3} />+ <InputOTPSlot index={4} />+ <InputOTPSlot index={5} />+ </InputOTPGroup>+ </InputOTPBase>);-});--InputOTP.displayName = "InputOTP";+}export { InputOTP };diff --git a/apps/web/tests/authentication.spec.ts b/apps/web/tests/authentication.spec.tsindex cf0996d47..701bd4430 100644--- a/apps/web/tests/authentication.spec.ts+++ b/apps/web/tests/authentication.spec.ts@@ -60,7 +60,7 @@ test.describe.serial(() => {// The existing user should have received a sign-in OTPconst code = await getCode(testUserEmail);- await page.getByPlaceholder("Enter your 6-digit code").fill(code);+ await page.getByLabel("Enter your 6-digit code").fill(code);// Existing user should be signed inawait expect(page.getByText("Test User")).toBeVisible();@@ -97,7 +97,7 @@ test.describe.serial(() => {await page.getByRole("button", { name: "Login with email" }).click();- await page.getByPlaceholder("Enter your 6-digit code").fill("000000");+ await page.getByLabel("Enter your 6-digit code").fill("000000");await expect(page.getByText("Your verification code is incorrect"),@@ -119,7 +119,7 @@ test.describe.serial(() => {const code = await getCode(testUserEmail);- await page.getByPlaceholder("Enter your 6-digit code").fill(code);+ await page.getByLabel("Enter your 6-digit code").fill(code);await expect(page.getByText("Test User")).toBeVisible();});diff --git a/apps/web/tests/login-page.ts b/apps/web/tests/login-page.tsindex f485ec93a..3f668c13e 100644--- a/apps/web/tests/login-page.ts+++ b/apps/web/tests/login-page.ts@@ -31,7 +31,7 @@ export class LoginPage {await this.page.getByRole("heading", { name: "Finish Logging In" }).waitFor();- await this.page.getByPlaceholder("Enter your 6-digit code").fill(code);+ await this.page.getByLabel("Enter your 6-digit code").fill(code);}// Wait for page to loaddiff --git a/apps/web/tests/register-page.ts b/apps/web/tests/register-page.tsindex 67a7d770f..09a4c4838 100644--- a/apps/web/tests/register-page.ts+++ b/apps/web/tests/register-page.ts@@ -36,7 +36,7 @@ export class RegisterPage {await this.page.getByRole("heading", { name: "Finish Logging In" }).waitFor();- await this.page.getByPlaceholder("Enter your 6-digit code").fill(code);+ await this.page.getByLabel("Enter your 6-digit code").fill(code);// Verify successful registrationawait expect(this.page.getByText(name)).toBeVisible();diff --git a/packages/tailwind-config/shared-styles.css b/packages/tailwind-config/shared-styles.cssindex 1c4e63aa9..9c395a804 100644--- a/packages/tailwind-config/shared-styles.css+++ b/packages/tailwind-config/shared-styles.css@@ -172,6 +172,20 @@--ease-in-expo: cubic-bezier(0.68, -0.6, 0.32, 1.6);--ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);+ --animate-caret-blink: caret-blink 1.25s ease-out infinite;++ @keyframes caret-blink {+ 0%,+ 70%,+ 100% {+ opacity: 1;+ }+ 20%,+ 50% {+ opacity: 0;+ }+ }+--font-sans:var(--font-inter), ui-sans-serif, system-ui, sans-serif,"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";diff --git a/packages/test-helpers/src/login.ts b/packages/test-helpers/src/login.tsindex 4255d6426..a8b3f5331 100644--- a/packages/test-helpers/src/login.ts+++ b/packages/test-helpers/src/login.ts@@ -18,7 +18,7 @@ export async function loginWithEmail(} else {const code = await getCode(email);await page.getByRole("heading", { name: "Finish Logging In" }).waitFor();- await page.getByPlaceholder("Enter your 6-digit code").fill(code);+ await page.getByLabel("Enter your 6-digit code").fill(code);}await page.waitForLoadState("networkidle");diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex 123aeee36..8a7e13cc0 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -43,6 +43,7 @@"class-variance-authority": "^0.7.1","clsx": "^1.2.1","cmdk": "^1.1.1",+ "input-otp": "^1.4.2","lucide-react": "^0.479.0","next-themes": "^0.4.6","react": "19.2.6",diff --git a/packages/ui/src/input-otp.tsx b/packages/ui/src/input-otp.tsxnew file mode 100644index 000000000..8d15382a3--- /dev/null+++ b/packages/ui/src/input-otp.tsx@@ -0,0 +1,84 @@+"use client";++import { OTPInput, OTPInputContext, REGEXP_ONLY_DIGITS } from "input-otp";+import { MinusIcon } from "lucide-react";+import * as React from "react";+import { cn } from "./lib/utils";++function InputOTP({+ className,+ containerClassName,+ ...props+}: React.ComponentProps<typeof OTPInput> & {+ containerClassName?: string;+}) {+ return (+ <OTPInput+ data-slot="input-otp"+ containerClassName={cn(+ "flex items-center gap-2 has-disabled:opacity-50",+ containerClassName,+ )}+ className={cn("disabled:cursor-not-allowed", className)}+ {...props}+ />+ );+}++function InputOTPGroup({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="input-otp-group"+ className={cn("flex items-center gap-2", className)}+ {...props}+ />+ );+}++function InputOTPSlot({+ index,+ className,+ ...props+}: React.ComponentProps<"div"> & {+ index: number;+}) {+ const inputOTPContext = React.useContext(OTPInputContext);+ const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {};++ return (+ <div+ data-slot="input-otp-slot"+ data-active={isActive}+ className={cn(+ "relative flex h-12 w-10 items-center justify-center rounded-lg border border-input bg-background/80 text-base shadow-xs outline-none transition-[color,box-shadow] dark:bg-foreground/5",+ "data-[active=true]:z-10 data-[active=true]:border-ring data-[active=true]:ring-[3px] data-[active=true]:ring-ring/50",+ "aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[active=true]:aria-invalid:border-destructive dark:aria-invalid:ring-destructive/40",+ className,+ )}+ {...props}+ >+ {char}+ {hasFakeCaret && (+ <div className="pointer-events-none absolute inset-0 flex items-center justify-center">+ <div className="h-5 w-px animate-caret-blink bg-foreground duration-1000" />+ </div>+ )}+ </div>+ );+}++function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {+ return (+ <div data-slot="input-otp-separator" aria-hidden="true" {...props}>+ <MinusIcon />+ </div>+ );+}++export {+ InputOTP,+ InputOTPGroup,+ InputOTPSeparator,+ InputOTPSlot,+ REGEXP_ONLY_DIGITS,+};diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 446f2964f..0bbf5b226 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -843,6 +843,9 @@ importers:cmdk:specifier: ^1.1.1version: 1.1.1(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])+ input-otp:+ specifier: ^1.4.2lucide-react:specifier: ^0.479.0version: 0.479.0([email protected])@@ -8297,6 +8300,12 @@ packages:resolution: {integrity: sha512-lhYo5qNTQp3EvSSp3sRvXMbVQTLrvGV6DycRMJ5dm2BLMiJ30wpXKdDdgX+GmJZ5uQMucwRKHamXSst3Sj/Giw==}+ resolution: {integrity: sha512-l3jWwYNvrEa6NTCt7BECfCm48GvwuZzkoeG3gBL2w4CHeOXW3eKFmf9UNYkNfYc3mxMrthMnxjIE07MT0zLBQA==}+ peerDependencies:+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc+resolution: {integrity: sha512-3NixUXq+hM8ezj2wc7wC37b32/rHq1MwNZDYdvx+d6jokOD+r+i8Q4Pkylh9tISYP114A128LCX8RKhopC5RfQ==}engines: {node: '>=18'}@@ -20669,6 +20678,11 @@ snapshots:dependencies:css-in-js-utils: 3.1.0+ dependencies:+ react: 19.2.6+ react-dom: 19.2.6([email protected])+[email protected](@types/[email protected]):dependencies:'@inquirer/core': 10.3.2(@types/[email protected])