// src/app/register/page.tsx\ 'use client'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import Link from 'next/link'; import { Mail, Lock, User } from 'lucide-react'; import { useAuth } from '@/lib/hooks/useAuth'; import { OrganizationDetailsFields } from '@/components/ui/auth/OrganizationDetailsFields'; import { RegistrationProgressSteps } from '@/components/ui/auth/RegistrationProgressSteps'; import { Button } from '@/components/ui/common/Button'; import { Input } from '@/components/ui/common/Input'; const registerSchema = z.object({ name: z.string().min(2, 'Name must be at least 2 characters'), email: z.string().email('Please enter a valid email address'), password: z.string() .min(8, 'Password must be at least 8 characters') .regex(/[A-Z]/, 'Password must contain at least one uppercase letter') .regex(/[0-9]/, 'Password must contain at least one number'), confirmPassword: z.string(), organizationName: z.string().min(2, 'Organization name must be at least 2 characters'), organizationEmail: z.string().email('Please enter a valid organization email'), organizationType: z.enum(['CLINIC', 'LAB'], { message: 'Please select organization type', }), }).refine((data) => data.password === data.confirmPassword, { message: "Passwords don't match", path: ['confirmPassword'], }); type RegisterForm = z.infer; export default function RegisterPage() { const { registerTrial, isLoading } = useAuth(); const [step, setStep] = useState(1); const [error, setError] = useState(null); const { register, handleSubmit, watch, formState: { errors }, trigger, setValue, } = useForm({ resolver: zodResolver(registerSchema), mode: 'onChange', }); const organizationType = watch('organizationType'); const handleNext = async () => { const fieldsToValidate = step === 1 ? ['name', 'email', 'password', 'confirmPassword'] : ['organizationName', 'organizationEmail', 'organizationType']; const isValid = await trigger(fieldsToValidate as any); if (isValid) { setStep(step + 1); } }; const onSubmit = async (data: RegisterForm) => { try { setError(null); await registerTrial( data.email, data.password, data.name, data.organizationName, data.organizationEmail, data.organizationType ); // No need to redirect - auth context will handle it } catch (err: any) { setError(err.message || 'Registration failed. Please try again.'); } }; return (
DyoLink

Start your 30-day free trial

Already have an account?{' '} Sign in

{/* Trial Info Banner */}

Your trial includes:

  • Up to 5 team members
  • Full access to all features
  • 30 days free, no credit card required
{step === 1 && ( <> } /> } /> } /> } /> )} {step === 2 && ( <> {error && (

{error}

)}
)}

By signing up, you agree to our{' '} Terms of Service {' '} and{' '} Privacy Policy

); }