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

fix: reportBy issue #2539 #2809

Closed
wants to merge 1 commit into from
Closed
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
fixed the reportBy issue #2539
  • Loading branch information
Rockingrajat committed Oct 27, 2021
commit b2fd7c1734fe224d8f351e21e411514f6689a70e
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