mirror of
https://github.com/Tony0410/nextstep.git
synced 2026-05-25 13:51:40 +08:00
Features added: - Emergency Info Card: Full-screen emergency view with patient info - Refill Tracker: Track pill counts with auto-decrement on dose - Activity Feed: View caregiver activity with filtering - Symptom Tracker: Log symptoms with severity and offline sync - Print Views: Daily meds, appointments, doctor visit summaries - iCal Export: Calendar subscription for appointments - PDF Export: Medical summary for doctor visits - Calendar View: Monthly calendar for appointments - Appointment Preparation: Checklist for upcoming appointments - Medication Reminders: PWA push notifications with quiet hours Bug fixes: - Fix invite workflow: Register/login now properly redirect back - Add undo for doctor questions (can unmark "asked" questions) - Fix API route type annotations for Next.js 14 compatibility - Add Suspense boundary for useSearchParams in login/register Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
115 lines
3.4 KiB
TypeScript
115 lines
3.4 KiB
TypeScript
'use client'
|
|
|
|
import { Suspense, useState } from 'react'
|
|
import { useRouter, useSearchParams } from 'next/navigation'
|
|
import Link from 'next/link'
|
|
import { Heart } from 'lucide-react'
|
|
import { Button, Input, Card, showToast } from '@/components/ui'
|
|
|
|
function LoginForm() {
|
|
const router = useRouter()
|
|
const searchParams = useSearchParams()
|
|
const redirectTo = searchParams.get('redirect')
|
|
const [email, setEmail] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
const [loading, setLoading] = useState(false)
|
|
const [error, setError] = useState('')
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault()
|
|
setError('')
|
|
setLoading(true)
|
|
|
|
try {
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ email, password }),
|
|
})
|
|
|
|
const data = await response.json()
|
|
|
|
if (!response.ok) {
|
|
setError(data.error || 'Login failed')
|
|
return
|
|
}
|
|
|
|
showToast('Welcome back!', 'success')
|
|
// If there's a redirect param (e.g., from invite link), go there
|
|
router.push(redirectTo || '/today')
|
|
router.refresh()
|
|
} catch {
|
|
setError('Something went wrong. Please try again.')
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background flex flex-col items-center justify-center p-4">
|
|
<div className="w-full max-w-sm">
|
|
{/* Logo */}
|
|
<div className="text-center mb-8">
|
|
<div className="w-16 h-16 bg-primary-500 rounded-2xl flex items-center justify-center mx-auto mb-4">
|
|
<Heart className="w-8 h-8 text-white" />
|
|
</div>
|
|
<h1 className="text-2xl font-bold text-secondary-900">Next Step</h1>
|
|
<p className="text-secondary-500 mt-1">Health management made simple</p>
|
|
</div>
|
|
|
|
<Card className="mb-6">
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<Input
|
|
label="Email"
|
|
type="email"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder="you@example.com"
|
|
required
|
|
autoComplete="email"
|
|
/>
|
|
<Input
|
|
label="Password"
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder="••••••••"
|
|
required
|
|
autoComplete="current-password"
|
|
/>
|
|
|
|
{error && (
|
|
<p className="text-sm text-red-600 bg-red-50 px-3 py-2 rounded-button">
|
|
{error}
|
|
</p>
|
|
)}
|
|
|
|
<Button type="submit" fullWidth loading={loading}>
|
|
Sign In
|
|
</Button>
|
|
</form>
|
|
</Card>
|
|
|
|
<p className="text-center text-secondary-500">
|
|
Don't have an account?{' '}
|
|
<Link href="/register" className="text-primary-600 font-medium hover:text-primary-700">
|
|
Create one
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default function LoginPage() {
|
|
return (
|
|
<Suspense fallback={
|
|
<div className="min-h-screen bg-background flex items-center justify-center">
|
|
<div className="w-8 h-8 border-2 border-primary-500 border-t-transparent rounded-full animate-spin" />
|
|
</div>
|
|
}>
|
|
<LoginForm />
|
|
</Suspense>
|
|
)
|
|
}
|