Skip to content

Commit

Permalink
Merge pull request #3 from xhefribala/fixUserLogin
Browse files Browse the repository at this point in the history
Fix Incident - reportedBy store the currently logged in user id
  • Loading branch information
bennymelb authored Sep 9, 2022
2 parents 2e29420 + 03d1bbd commit 7f3f3f8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/__tests__/incidents/hooks/useReportIncident.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('useReportIncident', () => {
date: subDays(new Date(), 3).toISOString(),
department: 'some department',
description: 'some description',
} as Incident
reportedBy: 'some user',
reportByUserID: 'some id',
} as Incident

const expectedIncident = {
...givenIncidentRequest,
Expand Down
3 changes: 1 addition & 2 deletions src/incidents/hooks/useReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function reportIncident(incident: Incident): Promise<Incident> {
...incident,
code: getIncidentCode(),
status: 'reported',
reportedBy: 'some user',
reportedOn: new Date(Date.now()).toISOString(),
}
return IncidentRepository.save(updatedIncident)
Expand All @@ -31,4 +30,4 @@ export default function useReportIncident() {
},
throwOnError: true,
})
}
}
12 changes: 9 additions & 3 deletions src/incidents/report/ReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,36 @@ import Incident from '../../shared/model/Incident'
import Patient from '../../shared/model/Patient'
import useReportIncident from '../hooks/useReportIncident'
import { IncidentError } from '../util/validate-incident'
import {useSelector } from 'react-redux'
import { RootState } from '../../shared/store'

const ReportIncident = () => {
const [mutate] = useReportIncident()
const history = useHistory()
const { t } = useTranslator()
const updateTitle = useUpdateTitle()
const {user} = useSelector((state: RootState) => state.user)

useEffect(() => {
updateTitle(t('incidents.reports.new'))
})
const breadcrumbs = [
{
i18nKey: 'incidents.reports.new',
i18nKey: 'incidents.reports.new',
location: `/incidents/new`,
},
]
useAddBreadcrumbs(breadcrumbs)
const [incident, setIncident] = useState({
reportedBy: user?.fullName, //user is read from redux store state.user and the fullName is used while showing details
reportByUserID: user?.id,
date: new Date().toISOString(),
department: '',
category: '',
categoryItem: '',
description: '',
patient: '',
})
})

const [error, setError] = useState<IncidentError | undefined>(undefined)

Expand Down Expand Up @@ -179,4 +185,4 @@ const ReportIncident = () => {
)
}

export default ReportIncident
export default ReportIncident
1 change: 1 addition & 0 deletions src/shared/model/Incident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export default interface Incident extends AbstractDBModel {
status: 'reported' | 'resolved'
resolvedOn: string
patient?: string
reportByUserID: string
}

0 comments on commit 7f3f3f8

Please sign in to comment.