Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Incident - reportedBy store the currently logged in user id #3

Merged
merged 9 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}