mirror of
https://github.com/Tony0410/nextstep.git
synced 2026-05-24 21:31:43 +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>
116 lines
3.3 KiB
TypeScript
116 lines
3.3 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import { List, Plus } from 'lucide-react'
|
|
import { useLiveQuery } from 'dexie-react-hooks'
|
|
|
|
import { db } from '@/lib/sync'
|
|
import { Card, LoadingState, Button } from '@/components/ui'
|
|
import { Header, PageContainer } from '@/components/layout/header'
|
|
import { CalendarMonth } from '@/components/calendar/CalendarMonth'
|
|
import { useApp } from '../../provider'
|
|
|
|
export default function CalendarPage() {
|
|
const router = useRouter()
|
|
const { currentWorkspace } = useApp()
|
|
const [currentMonth, setCurrentMonth] = useState(new Date())
|
|
const [selectedDate, setSelectedDate] = useState(new Date())
|
|
const [loading, setLoading] = useState(true)
|
|
const [serverAppointments, setServerAppointments] = useState<any[]>([])
|
|
|
|
// Fetch from IndexedDB for offline support
|
|
const localAppointments = useLiveQuery(
|
|
() =>
|
|
db.appointments
|
|
.where('workspaceId')
|
|
.equals(currentWorkspace.id)
|
|
.and((a) => !a.deletedAt)
|
|
.toArray(),
|
|
[currentWorkspace.id]
|
|
)
|
|
|
|
// Also fetch from server for latest data
|
|
useEffect(() => {
|
|
async function fetchAppointments() {
|
|
try {
|
|
const response = await fetch(
|
|
`/api/workspaces/${currentWorkspace.id}/appointments`
|
|
)
|
|
if (response.ok) {
|
|
const data = await response.json()
|
|
setServerAppointments(data.appointments)
|
|
}
|
|
} catch (err) {
|
|
console.error('Failed to fetch appointments:', err)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
fetchAppointments()
|
|
}, [currentWorkspace.id])
|
|
|
|
// Prefer server data if available
|
|
const appointments = serverAppointments.length > 0 ? serverAppointments : localAppointments || []
|
|
|
|
if (loading && !localAppointments) {
|
|
return (
|
|
<>
|
|
<Header
|
|
title="Calendar"
|
|
showBack
|
|
rightAction={{
|
|
icon: <List className="w-6 h-6 text-secondary-700" />,
|
|
label: 'List view',
|
|
onClick: () => router.push('/appointments'),
|
|
}}
|
|
/>
|
|
<PageContainer>
|
|
<LoadingState message="Loading appointments..." />
|
|
</PageContainer>
|
|
</>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Header
|
|
title="Calendar"
|
|
showBack
|
|
rightAction={{
|
|
icon: <List className="w-6 h-6 text-secondary-700" />,
|
|
label: 'List view',
|
|
onClick: () => router.push('/appointments'),
|
|
}}
|
|
/>
|
|
<PageContainer className="pt-4 space-y-4">
|
|
<Card>
|
|
<CalendarMonth
|
|
appointments={appointments.map((a: any) => ({
|
|
id: a.id,
|
|
title: a.title,
|
|
datetime: a.datetime,
|
|
location: a.location,
|
|
}))}
|
|
selectedDate={selectedDate}
|
|
onDateSelect={setSelectedDate}
|
|
onMonthChange={setCurrentMonth}
|
|
currentMonth={currentMonth}
|
|
/>
|
|
</Card>
|
|
|
|
{/* Add appointment FAB */}
|
|
<div className="fixed bottom-20 right-4 z-30">
|
|
<Button
|
|
onClick={() => router.push('/appointments/new')}
|
|
className="w-14 h-14 rounded-full shadow-lg flex items-center justify-center"
|
|
>
|
|
<Plus className="w-6 h-6" />
|
|
</Button>
|
|
</div>
|
|
</PageContainer>
|
|
</>
|
|
)
|
|
}
|