mirror of
https://github.com/Tony0410/nextstep.git
synced 2026-05-25 05:41:39 +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>
89 lines
1.8 KiB
TypeScript
89 lines
1.8 KiB
TypeScript
'use client'
|
|
|
|
import { createContext, useContext, useEffect, useState, useCallback } from 'react'
|
|
import { startAutoSync, stopAutoSync, sync } from '@/lib/sync'
|
|
|
|
interface User {
|
|
id: string
|
|
email: string
|
|
name: string
|
|
}
|
|
|
|
interface Workspace {
|
|
id: string
|
|
name: string
|
|
role: string
|
|
clinicPhone: string | null
|
|
emergencyPhone: string | null
|
|
largeTextMode: boolean
|
|
quietHoursStart: string | null
|
|
quietHoursEnd: string | null
|
|
}
|
|
|
|
interface AppContextType {
|
|
user: User
|
|
workspaces: Workspace[]
|
|
currentWorkspace: Workspace
|
|
setCurrentWorkspaceId: (id: string) => void
|
|
refreshData: () => Promise<void>
|
|
}
|
|
|
|
const AppContext = createContext<AppContextType | null>(null)
|
|
|
|
export function useApp() {
|
|
const context = useContext(AppContext)
|
|
if (!context) {
|
|
throw new Error('useApp must be used within AppProvider')
|
|
}
|
|
return context
|
|
}
|
|
|
|
interface AppProviderProps {
|
|
children: React.ReactNode
|
|
user: User
|
|
workspaces: Workspace[]
|
|
initialWorkspaceId: string
|
|
}
|
|
|
|
export function AppProvider({
|
|
children,
|
|
user,
|
|
workspaces,
|
|
initialWorkspaceId,
|
|
}: AppProviderProps) {
|
|
const [currentWorkspaceId, setCurrentWorkspaceId] = useState(initialWorkspaceId)
|
|
|
|
const currentWorkspace = workspaces.find((w) => w.id === currentWorkspaceId) || workspaces[0]
|
|
|
|
// Start auto-sync when workspace changes
|
|
useEffect(() => {
|
|
if (currentWorkspaceId) {
|
|
startAutoSync(currentWorkspaceId)
|
|
}
|
|
|
|
return () => {
|
|
stopAutoSync()
|
|
}
|
|
}, [currentWorkspaceId])
|
|
|
|
const refreshData = useCallback(async () => {
|
|
if (currentWorkspaceId) {
|
|
await sync(currentWorkspaceId)
|
|
}
|
|
}, [currentWorkspaceId])
|
|
|
|
return (
|
|
<AppContext.Provider
|
|
value={{
|
|
user,
|
|
workspaces,
|
|
currentWorkspace,
|
|
setCurrentWorkspaceId,
|
|
refreshData,
|
|
}}
|
|
>
|
|
{children}
|
|
</AppContext.Provider>
|
|
)
|
|
}
|