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

Fix user login #2987

Closed
wants to merge 16 commits into from
Closed
Prev Previous commit
Next Next commit
fixed user login issue
  • Loading branch information
xhefribala committed Sep 6, 2022
commit 17fb52c3f4a5ebb5450ed35432747cc9874ec799
6 changes: 4 additions & 2 deletions src/incidents/hooks/useReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ 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',
//reportedBy: 'some user',
reportedOn: new Date(Date.now()).toISOString(),
}
return IncidentRepository.save(updatedIncident)
Expand All @@ -31,4 +33,4 @@ export default function useReportIncident() {
},
throwOnError: true,
})
}
}
9 changes: 7 additions & 2 deletions 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', //user is read from redux store state.user and the id is used while showing details
date: new Date().toISOString(),
department: '',
category: '',
Expand Down Expand Up @@ -179,4 +184,4 @@ const ReportIncident = () => {
)
}

export default ReportIncident
export default ReportIncident