Skip to content

Commit

Permalink
chore: merge main and fix naming to Id
Browse files Browse the repository at this point in the history
  • Loading branch information
DasProffi committed Aug 14, 2023
1 parent dba9c1a commit b7d73dc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 44 deletions.
20 changes: 10 additions & 10 deletions tasks/components/AddPatientModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PropsWithLanguage } from '@helpwave/common/hooks/useTranslation'
import { useTranslation } from '@helpwave/common/hooks/useTranslation'
import type { ConfirmDialogProps } from '@helpwave/common/components/modals/ConfirmDialog'
import { ConfirmDialog } from '@helpwave/common/components/modals/ConfirmDialog'
import type { RoomBedDropDownIDs } from './RoomBedDropDown'
import type { RoomBedDropDownIds } from './RoomBedDropDown'
import { RoomBedDropDown } from './RoomBedDropDown'
import React, { useState } from 'react'
import { Span } from '@helpwave/common/components/Span'
Expand Down Expand Up @@ -35,34 +35,34 @@ const defaultAddPatientModalTranslation: Record<Languages, AddPatientModalTransl
}

export type AddPatientModalProps = ConfirmDialogProps & {
wardID: string
wardId: string
}

/**
* A Modal for adding a Patient
*/
export const AddPatientModal = ({
language,
wardID,
wardId,
title,
onConfirm = noop,
...modalProps
}: PropsWithLanguage<AddPatientModalTranslation, AddPatientModalProps>) => {
const translation = useTranslation(language, defaultAddPatientModalTranslation)
const [dropdownID, setDropdownID] = useState<RoomBedDropDownIDs>({})
const [dropdownId, setDropdownId] = useState<RoomBedDropDownIds>({})
const [patientName, setPatientName] = useState<string>('')
const [touched, setTouched] = useState<boolean>(false)
const assignBedMutation = useAssignBedMutation()
const createPatientMutation = usePatientCreateMutation(patient => {
if (dropdownID.bedID) {
assignBedMutation.mutate({ id: dropdownID.bedID, patientID: patient.id })
if (dropdownId.bedId) {
assignBedMutation.mutate({ id: dropdownId.bedId, patientId: patient.id })
}
})

const minimumNameLength = 4
const trimmedPatientName = patientName.trim()
const validPatientName = trimmedPatientName.length >= minimumNameLength
const validRoomAndBed = dropdownID.roomID && dropdownID.bedID
const validRoomAndBed = dropdownId.roomId && dropdownId.bedId
const isShowingError = touched && !validPatientName

return (
Expand All @@ -88,9 +88,9 @@ export const AddPatientModal = ({
{isShowingError && <Span type="formError">{translation.minimumLength(minimumNameLength)}</Span>}
</div>
<RoomBedDropDown
initialRoomAndBed={dropdownID}
wardID={wardID}
onChange={roomBedDropDownIDs => setDropdownID(roomBedDropDownIDs)}
initialRoomAndBed={dropdownId}
wardId={wardId}
onChange={roomBedDropDownIds => setDropdownId(roomBedDropDownIds)}
isClearable={true}
/>
<Span className={tx({ 'text-hw-warn-400': !validRoomAndBed, 'text-transparent': validRoomAndBed })}>{translation.noBedSelected}</Span>
Expand Down
4 changes: 2 additions & 2 deletions tasks/components/RoomBedDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type RoomBedDropDownIds = {

export type RoomBedDropDownProps = {
initialRoomAndBed: RoomBedDropDownIds,
wardID: string,
wardId: string,
/**
* Only triggers on valid input
*/
Expand Down Expand Up @@ -115,7 +115,7 @@ export const RoomBedDropDown = ({
onChange={value => {
const newSelection = {
...currentSelection,
bedID: value
bedId: value
}
setCurrentSelection(newSelection)
setTouched(true)
Expand Down
10 changes: 5 additions & 5 deletions tasks/components/layout/PatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LoadingAndErrorComponent } from '@helpwave/common/components/LoadingAnd
import { HideableContentSection } from '@helpwave/common/components/HideableContentSection'
import { Draggable } from '../dnd-kit/Draggable'
import { Droppable } from '../dnd-kit/Droppable'
import { WardOverviewContext } from '../../pages/ward/[uuid]'
import { WardOverviewContext } from '../../pages/ward/[id]'
import { AddPatientModal } from '../AddPatientModal'

type PatientListTranslation = {
Expand Down Expand Up @@ -112,7 +112,7 @@ export const PatientList = ({
onConfirm={() => setIsShowingAddPatientModal(0)}
onCancel={() => setIsShowingAddPatientModal(0)}
onBackgroundClick={() => setIsShowingAddPatientModal(0)}
wardID={context.wardID}
wardId={context.wardId}
/>
<div className={tw('flex flex-row gap-x-2 items-center')}>
<Span type="subsectionTitle" className={tw('pr-4')}>{translation.patients}</Span>
Expand Down Expand Up @@ -145,7 +145,7 @@ export const PatientList = ({
{() => (
<div
className={tw('flex flex-row pt-2 border-b-2 justify-between items-center cursor-pointer')}
onClick={() => updateContext({ ...context, patientID: patient.id, roomID: patient.room.id, bedID: patient.bed.id })}
onClick={() => updateContext({ ...context, patientId: patient.id, roomId: patient.room.id, bedId: patient.bed.id })}
>
<Span className={tw('font-space font-bold w-1/3 text-ellipsis')}>{patient.name}</Span>
<div className={tw('flex flex-row flex-1 justify-between items-center')}>
Expand Down Expand Up @@ -180,7 +180,7 @@ export const PatientList = ({
<div
key={patient.id}
className={tw('flex flex-row pt-2 border-b-2 items-center cursor-pointer')}
onClick={() => updateContext({ wardID: context.wardID, patientID: patient.id })}
onClick={() => updateContext({ wardId: context.wardId, patientId: patient.id })}
>
<Span className={tw('font-space font-bold w-1/3 text-ellipsis')}>{patient.name}</Span>
<div className={tw('flex flex-row flex-1 justify-between items-center')}>
Expand Down Expand Up @@ -217,7 +217,7 @@ export const PatientList = ({
<div
key={patient.id}
className={tw('flex flex-row pt-2 border-b-2 justify-between items-center')}
onClick={() => updateContext({ wardID: context.wardID, patientID: patient.id })}
onClick={() => updateContext({ wardId: context.wardId, patientId: patient.id })}
>
<Span className={tw('font-space font-bold')}>{patient.name}</Span>
{ /* TODO implement when backend endpoint exists
Expand Down
47 changes: 20 additions & 27 deletions tasks/pages/ward/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const defaultWardOverviewTranslation = {
export type WardOverviewContextState = {
/**
patient set means creating patient
patientID is the current patient
patientId is the current patient
*/
patient?: PatientDTO,
patientId?: string,
Expand Down Expand Up @@ -99,37 +99,30 @@ const WardOverview: NextPage = ({ language }: PropsWithLanguage<WardOverviewTran
const [contextState, setContextState] = useState<WardOverviewContextState>({
wardId
})
const [draggingRoomID, setDraggingRoomID] = useState<string>()
const [draggingRoomId, setDraggingRoomId] = useState<string>()
const assignBedMutation = useAssignBedMutation(bed => {
if (draggingRoomID) {
if (draggingRoomId) {
setContextState({
...contextState,
bedID: bed.id,
patientID: bed.patientID,
roomID: draggingRoomID,
bedId: bed.id,
patientId: bed.patientId,
roomId: draggingRoomId,
patient: undefined
})
} else {
setContextState({
...contextState,
bedID: bed.id,
patientID: bed.patientID,
bedId: bed.id,
patientId: bed.patientId,
patient: undefined
})
}

setDraggingRoomID(undefined)
setDraggingRoomId(undefined)
})
const unassignMutation = useUnassignMutation()
const dischargeMutation = usePatientDischargeMutation()

const createMutation = usePatientCreateMutation(patient => {
if (contextState.bedID) {
assignBedMutation.mutate({ id: contextState.bedID, patientID: patient.id })
}
setContextState({ ...contextState, patient: undefined })
})

const sensorOptions = { activationConstraint: { distance: 8 } }
const sensors = useSensors(
useSensor(MouseSensor, sensorOptions),
Expand All @@ -151,19 +144,19 @@ const WardOverview: NextPage = ({ language }: PropsWithLanguage<WardOverviewTran
const handleDragEnd = useCallback((event: DragEndEvent) => {
const { active, over } = event
const overData = over?.data.current
const patientID = draggedPatient?.patient?.id ?? draggedPatient?.bed?.patient?.id ?? ''
const patientId = draggedPatient?.patient?.id ?? draggedPatient?.bed?.patient?.id ?? ''
if (overData && active.data.current) {
if (overData.patientListSection) {
// Moving in patientlist
if (overData.patientListSection === 'unassigned') {
unassignMutation.mutate(patientID) // TODO this doesn't work for unassigned patients
unassignMutation.mutate(patientId) // TODO this doesn't work for unassigned patients
} else if (overData.patientListSection === 'discharged') {
dischargeMutation.mutate(patientID)
dischargeMutation.mutate(patientId)
}
} else {
// Moving on bed cards
setDraggingRoomID(overData.room.id)
assignBedMutation.mutate({ id: overData.bed.id, patientID })
setDraggingRoomId(overData.room.id)
assignBedMutation.mutate({ id: overData.bed.id, patientId })
}
}

Expand All @@ -175,7 +168,7 @@ const WardOverview: NextPage = ({ language }: PropsWithLanguage<WardOverviewTran
}, [])

const isShowingPatientDialog = !!contextState.patient
const isShowingPatientList = contextState.patientID === undefined || isShowingPatientDialog
const isShowingPatientList = contextState.patientId === undefined || isShowingPatientDialog

const organizationId = 'org1' // TODO get this information somewhere
useEffect(() => {
Expand Down Expand Up @@ -210,14 +203,14 @@ const WardOverview: NextPage = ({ language }: PropsWithLanguage<WardOverviewTran
if (contextState.patient) {
createMutation.mutate(contextState.patient)
} else {
setContextState({ ...emptyWardOverviewContextState, wardID: contextState.wardID, patient: undefined })
setContextState({ ...emptyWardOverviewContextState, wardId: contextState.wardId, patient: undefined })
}
}}
onCancel={() => {
setContextState({ ...emptyWardOverviewContextState, wardID: contextState.wardID, patient: undefined })
setContextState({ ...emptyWardOverviewContextState, wardId: contextState.wardId, patient: undefined })
}}
onBackgroundClick={() => {
setContextState({ ...emptyWardOverviewContextState, wardID: contextState.wardID, patient: undefined })
setContextState({ ...emptyWardOverviewContextState, wardId: contextState.wardId, patient: undefined })
}}
/>
<WardOverviewContext.Provider value={{ state: contextState, updateContext: setContextState }}>
Expand All @@ -231,12 +224,12 @@ const WardOverview: NextPage = ({ language }: PropsWithLanguage<WardOverviewTran
disableResize={false}
constraints={{ right: { min: '580px' }, left: { min: '33%' } }}
baseLayoutValue="-580px"
left={() => (<WardRoomList key={wardUUID}/>)}
left={() => (<WardRoomList key={wardId}/>)}
right={width =>
isShowingPatientList ? (
<PatientList width={width}/>
) :
contextState.patientID && (
contextState.patientId && (
<div>
<PatientDetail
key={contextState.patient?.id}
Expand Down

0 comments on commit b7d73dc

Please sign in to comment.