Skip to content

Commit

Permalink
fixed the reportBy issue HospitalRun#2539
Browse files Browse the repository at this point in the history
  • Loading branch information
Rockingrajat committed Oct 27, 2021
1 parent 40472cb commit b2fd7c1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/incidents/report/ReportIncident.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Report Incident', () => {

userEvent.type(departmentInput, 'Engineering Bay')
expect(departmentInput).toHaveDisplayValue('Engineering Bay')
})
})

it('renders a category form element that allows user input', async () => {
setup([Permissions.ViewIncident, Permissions.ResolveIncident])
Expand Down
3 changes: 2 additions & 1 deletion src/incidents/hooks/useReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import IncidentRepository from '../../shared/db/IncidentRepository'
import Incident from '../../shared/model/Incident'
import validateIncident from '../util/validate-incident'


const getIncidentCode = (): string => `I-${shortid.generate()}`

export function reportIncident(incident: Incident): Promise<Incident> {
const error = validateIncident(incident)

if (isEmpty(error)) {
const updatedIncident: Incident = {
...incident,
code: getIncidentCode(),
status: 'reported',
reportedBy: 'some user',
reportedOn: new Date(Date.now()).toISOString(),
}
return IncidentRepository.save(updatedIncident)
Expand Down
7 changes: 6 additions & 1 deletion src/incidents/report/ReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@ 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?.id || 'some user',
date: new Date().toISOString(),
department: '',
category: '',
Expand Down

0 comments on commit b2fd7c1

Please sign in to comment.