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
Cleanup code and fix unit testing
  • Loading branch information
xhefribala committed Sep 9, 2022
commit 25cfd3576e2b5da522716dfffe7b296a188711f5
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: 0 additions & 3 deletions src/incidents/hooks/useReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ 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
4 changes: 2 additions & 2 deletions src/incidents/report/ReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const ReportIncident = () => {
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: '',
reportByUserID: user?.id,
})
})

const [error, setError] = useState<IncidentError | undefined>(undefined)

Expand Down
2 changes: 2 additions & 0 deletions src/user/user-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const getCurrentSession = (username: string): AppThunk => async (dispatch
id: user._id,
givenName: (user as any).metadata.givenName,
familyName: (user as any).metadata.familyName,
fullName: (user as any).metadata.fullName,
},
permissions: initialState.permissions,
}),
Expand All @@ -109,6 +110,7 @@ export const login = (username: string, password: string): AppThunk => async (di
id: user._id,
givenName: (user as any).metadata.givenName,
familyName: (user as any).metadata.familyName,
fullName: (user as any).metadata.fullName,
},
permissions: initialState.permissions,
}),
Expand Down