@@ -30,7 +30,7 @@ import {
3030} from '@helpwave/hightide'
3131import { useTasksContext } from '@/hooks/useTasksContext'
3232import { 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'
3434import { PatientStateChip } from '@/components/patients/PatientStateChip'
3535import { PropertyList } from '@/components/PropertyList'
3636import { 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 >
0 commit comments