import { useState } from 'react'; import { Button } from './ui/button'; import { Card, CardContent } from './ui/card'; import { Input } from './ui/input'; import { Label } from './ui/label'; import { useSession } from '../lib/auth-client'; import { validatePhoneOrEmail } from '../lib/validators'; const logo = '/logo.png'; interface Props { onComplete: () => void; } export function Onboarding({ onComplete }: Props) { const { data: session } = useSession(); const [piFirstName, setPiFirstName] = useState(''); const [bldgCode, setBldgCode] = useState(''); const [lab, setLab] = useState(''); const [contact, setContact] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(''); const trimmedContact = contact.trim(); if (trimmedContact && !validatePhoneOrEmail(trimmedContact)) { setError('Contact must be a valid phone number or email address.'); return; } setLoading(true); const res = await fetch('/api/profile', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ pi_first_name: piFirstName.trim(), bldg_code: bldgCode.trim(), lab: lab.trim(), contact: trimmedContact || undefined, }), }); setLoading(false); if (res.ok) { onComplete(); } else { const data = await res.json(); setError(data.error || 'Failed to save profile'); } } return (
LabWise

Welcome{session?.user.name ? `, ${session.user.name.split(' ')[0]}` : ''}!

Set up your lab details. These will be used as defaults when adding inventory.

setPiFirstName(e.target.value)} placeholder="e.g. Smith" />
setBldgCode(e.target.value)} placeholder="e.g. EER" />
setLab(e.target.value)} placeholder="e.g. 3.822" />
setContact(e.target.value)} placeholder="Phone (e.g. 555-123-4567) or email" />
{error &&

{error}

}
); }