Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

fix: incident reportedBy from currently logged in user ID #2988

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"i18next": "~21.6.0",
"i18next-browser-languagedetector": "~6.1.0",
"i18next-xhr-backend": "~3.2.2",
"install": "~0.13.0",
"json2csv": "~5.0.1",
"lodash": "^4.17.15",
"node-sass": "~7.0.0",
"pouchdb": "~7.2.1",
"lodash": "4.17.15",
"pouchdb-adapter-memory": "~7.2.1",
"pouchdb-authentication": "~1.1.3",
"pouchdb-find": "~7.2.1",
Expand Down Expand Up @@ -69,8 +70,8 @@
"@testing-library/react-hooks": "~7.0.0",
"@testing-library/user-event": "~12.8.3",
"@types/jest": "~27.0.3",
"@types/lodash": "^4.14.150",
"@types/node": "~17.0.0",
"@types/lodash": "4.14.182",
"@types/node": "~15.6.1",
"@types/pouchdb": "~6.4.0",
"@types/react": "~17.0.0",
"@types/react-dom": "~17.0.0",
Expand All @@ -83,7 +84,7 @@
"@types/validator": "~13.7.0",
"@typescript-eslint/eslint-plugin": "~3.10.0",
"@typescript-eslint/parser": "~3.10.0",
"chalk": "^5.0.0",
"chalk": "~4.1.2",
"commitizen": "~4.2.0",
"commitlint-config-cz": "~0.13.0",
"cross-env": "~7.0.0",
Expand Down Expand Up @@ -165,4 +166,4 @@
"jest": {
"restoreMocks": true
}
}
}
2 changes: 2 additions & 0 deletions src/__tests__/incidents/hooks/useReportIncident.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('useReportIncident', () => {
date: subDays(new Date(), 3).toISOString(),
department: 'some department',
description: 'some description',
reportedBy: 'some user',
reportByUserID: 'some id',
} as Incident

const expectedIncident = {
Expand Down
1 change: 0 additions & 1 deletion 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 Down
5 changes: 5 additions & 0 deletions src/incidents/report/ReportIncident.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, Row, Column, Typeahead, Label } from '@hospitalrun/components'
import React, { useState, useEffect } from 'react'
import { useSelector } from 'react-redux'
import { useHistory } from 'react-router-dom'

import useAddBreadcrumbs from '../../page-header/breadcrumbs/useAddBreadcrumbs'
Expand All @@ -11,6 +12,7 @@ import PatientRepository from '../../shared/db/PatientRepository'
import useTranslator from '../../shared/hooks/useTranslator'
import Incident from '../../shared/model/Incident'
import Patient from '../../shared/model/Patient'
import { RootState } from '../../shared/store'
import useReportIncident from '../hooks/useReportIncident'
import { IncidentError } from '../util/validate-incident'

Expand All @@ -19,6 +21,7 @@ const ReportIncident = () => {
const history = useHistory()
const { t } = useTranslator()
const updateTitle = useUpdateTitle()
const { user } = useSelector((state: RootState) => state.user)
useEffect(() => {
updateTitle(t('incidents.reports.new'))
})
Expand All @@ -31,6 +34,8 @@ const ReportIncident = () => {
useAddBreadcrumbs(breadcrumbs)
const [incident, setIncident] = useState({
date: new Date().toISOString(),
reportedBy: user?.fullName, // user is read from redux store state.user and the fullName is used while showing details
reportByUserID: user?.id,
department: '',
category: '',
categoryItem: '',
Expand Down
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
}