Skip to content

Commit a7c01da

Browse files
committed
add tasks button to patient details page
1 parent 39b58b0 commit a7c01da

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

web/components/patients/PatientDetailView.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from '@helpwave/hightide'
3131
import { useTasksContext } from '@/hooks/useTasksContext'
3232
import { DateInput } from '@/components/ui/DateInput'
33-
import { CheckCircle2, ChevronDown, Circle, Clock, MapPin, XIcon } from 'lucide-react'
33+
import { CheckCircle2, ChevronDown, Circle, Clock, MapPin, PlusIcon, XIcon } from 'lucide-react'
3434
import { PatientStateChip } from '@/components/patients/PatientStateChip'
3535
import { PropertyList } from '@/components/PropertyList'
3636
import { LocationSelectionDialog } from '@/components/locations/LocationSelectionDialog'
@@ -139,6 +139,7 @@ export const PatientDetailView = ({
139139
const translation = useTasksTranslation()
140140
const { selectedLocationId } = useTasksContext()
141141
const [taskId, setTaskId] = useState<string | null>(null)
142+
const [isCreatingTask, setIsCreatingTask] = useState(false)
142143
const isEditMode = !!patientId
143144

144145
const { data: patientData, isLoading: isLoadingPatient, refetch } = useGetPatientQuery(
@@ -314,6 +315,17 @@ export const PatientDetailView = ({
314315
<TabView className="h-full flex-col-0">
315316
<Tab label={translation('tasks')} className="h-full overflow-y-auto pr-2">
316317
<div className="flex flex-col gap-4 pt-4">
318+
{isEditMode && (
319+
<div className="mb-2">
320+
<Button
321+
startIcon={<PlusIcon/>}
322+
onClick={() => setIsCreatingTask(true)}
323+
className="w-full"
324+
>
325+
{translation('addTask')}
326+
</Button>
327+
</div>
328+
)}
317329
<div>
318330
<button
319331
onClick={() => setOpenExpanded(!openExpanded)}
@@ -572,18 +584,24 @@ export const PatientDetailView = ({
572584
multiSelect={true}
573585
/>
574586
<SidePanel
575-
isOpen={!!taskId}
587+
isOpen={!!taskId || isCreatingTask}
576588
onClose={() => {
577589
setTaskId(null)
590+
setIsCreatingTask(false)
578591
}}
579-
title={translation('editTask')}
592+
title={taskId ? translation('editTask') : translation('createTask')}
580593
>
581594
<TaskDetailView
582595
taskId={taskId}
596+
initialPatientId={isCreatingTask ? patientId : undefined}
583597
onSuccess={() => {
584598
refetch().catch(console.error)
599+
setIsCreatingTask(false)
600+
}}
601+
onClose={() => {
602+
setTaskId(null)
603+
setIsCreatingTask(false)
585604
}}
586-
onClose={() => setTaskId(null)}
587605
/>
588606
</SidePanel>
589607
</div>

web/components/tasks/TaskDetailView.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ interface TaskDetailViewProps {
3434
taskId: string | null,
3535
onClose: () => void,
3636
onSuccess: () => void,
37+
initialPatientId?: string,
3738
}
3839

39-
export const TaskDetailView = ({ taskId, onClose, onSuccess }: TaskDetailViewProps) => {
40+
export const TaskDetailView = ({ taskId, onClose, onSuccess, initialPatientId }: TaskDetailViewProps) => {
4041
const translation = useTasksTranslation()
4142
const { selectedLocationId } = useTasksContext()
4243
const [isShowingPatientDialog, setIsShowingPatientDialog] = useState<boolean>(false)
@@ -78,7 +79,7 @@ export const TaskDetailView = ({ taskId, onClose, onSuccess }: TaskDetailViewPro
7879
const [formData, setFormData] = useState<Partial<CreateTaskInput & { done: boolean }>>({
7980
title: '',
8081
description: '',
81-
patientId: '',
82+
patientId: initialPatientId || '',
8283
assigneeId: null,
8384
dueDate: null,
8485
done: false,
@@ -94,8 +95,11 @@ export const TaskDetailView = ({ taskId, onClose, onSuccess }: TaskDetailViewPro
9495
dueDate: taskData.task.dueDate ? new Date(taskData.task.dueDate) : null,
9596
done: taskData.task.done || false
9697
})
98+
} else if (initialPatientId && !taskId) {
99+
// Set initial patient ID when creating a new task
100+
setFormData(prev => ({ ...prev, patientId: initialPatientId }))
97101
}
98-
}, [taskData])
102+
}, [taskData, initialPatientId, taskId])
99103

100104
const updateLocalState = (updates: Partial<CreateTaskInput>) => {
101105
setFormData(prev => ({ ...prev, ...updates }))

0 commit comments

Comments
 (0)