'use client' import type * as React from 'react' import { cn } from '../../../utils/cn' import { useDeferredError } from '../../../hooks/ui/use-deferred-error' import { Button } from '../../ui/button' import { Input } from '../../ui/input' import { PasswordInput } from '../../ui/password-input' import type { AuthSsoProvider } from './sso-providers' import { SsoProviderButtons } from './sso-providers' export interface CompleteAccountFormProps { /** Controlled field values */ firstName: string lastName: string password: string confirmPassword: string onFirstNameChange: (value: string) => void onLastNameChange: (value: string) => void onPasswordChange: (value: string) => void onConfirmPasswordChange: (value: string) => void /** Primary submit ("Start Free Trial") */ onSubmit: () => void /** Secondary action rendered left of the submit (e.g. "Back to Organization"). */ onBack?: () => void /** SSO alternatives offered above the fields ("Continue with …"). */ ssoProviders?: AuthSsoProvider[] onSsoClick?: (provider: AuthSsoProvider) => void title?: string subtitle?: string dividerLabel?: string submitLabel?: string backLabel?: string ssoActionLabel?: string submitDisabled?: boolean loading?: boolean disabled?: boolean errors?: { firstName?: string lastName?: string password?: string confirmPassword?: string } className?: string /** Extra consumer-provided fields rendered below the built-in fields, above the actions. */ children?: React.ReactNode } /** * Account details form shared by the Sign Up ("Complete your Account") and * Accept Invitation screens. Presentational + controlled — SSO shortcuts on * top, then name + password fields ("or create account"). */ export function CompleteAccountForm({ firstName, lastName, password, confirmPassword, onFirstNameChange, onLastNameChange, onPasswordChange, onConfirmPasswordChange, onSubmit, onBack, ssoProviders, onSsoClick, title = 'Complete your Account', subtitle = 'Fill in the details below to get started', dividerLabel = 'or create account', submitLabel = 'Start Free Trial', backLabel = 'Back to Organization', ssoActionLabel = 'Continue with', submitDisabled = false, loading = false, disabled = false, errors, className, children, }: CompleteAccountFormProps) { const fieldsDisabled = disabled || loading // Validation messages are deferred while the user is typing (shown on blur or after a pause). const firstNameErr = useDeferredError(errors?.firstName, firstName) const lastNameErr = useDeferredError(errors?.lastName, lastName) const passwordErr = useDeferredError(errors?.password, password) const confirmErr = useDeferredError(errors?.confirmPassword, confirmPassword) const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter' && !fieldsDisabled && !submitDisabled) { onSubmit() } } return (
{/* Header */}

{title}

{subtitle}

{/* SSO shortcuts + divider */} {ssoProviders && ssoProviders.length > 0 && ( <>
{dividerLabel}
)} {/* Name + password fields — single column on every breakpoint */} onFirstNameChange(event.target.value)} onKeyDown={handleKeyDown} /> onLastNameChange(event.target.value)} onKeyDown={handleKeyDown} /> onPasswordChange(event.target.value)} onKeyDown={handleKeyDown} /> onConfirmPasswordChange(event.target.value)} onKeyDown={handleKeyDown} /> {children} {/* Actions — optional back + submit */}
{onBack ? ( ) : ( // Spacer keeps the button on the right half, matching the design
)}
) }