From 2a0ecfbb71064ecad35969ca34e8e42d9a33ef3f Mon Sep 17 00:00:00 2001 From: James Zheng Date: Sat, 20 Feb 2021 16:09:33 -0800 Subject: [PATCH] fix(fullname): added extractFullName() template fix #2539 --- src/incidents/hooks/useReportIncident.tsx | 2 +- src/incidents/report/ReportIncident.tsx | 4 ++++ src/incidents/view/ViewIncidentDetails.tsx | 4 ++-- src/shared/util/extractFullName.ts | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/shared/util/extractFullName.ts diff --git a/src/incidents/hooks/useReportIncident.tsx b/src/incidents/hooks/useReportIncident.tsx index 329e88f144..51c108ee0b 100644 --- a/src/incidents/hooks/useReportIncident.tsx +++ b/src/incidents/hooks/useReportIncident.tsx @@ -10,12 +10,12 @@ const getIncidentCode = (): string => `I-${shortid.generate()}` export function reportIncident(incident: Incident): Promise { 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) diff --git a/src/incidents/report/ReportIncident.tsx b/src/incidents/report/ReportIncident.tsx index 94795aa98b..d268077d77 100644 --- a/src/incidents/report/ReportIncident.tsx +++ b/src/incidents/report/ReportIncident.tsx @@ -1,5 +1,6 @@ import { Button, Row, Column } from '@hospitalrun/components' import React, { useState, useEffect } from 'react' +import { useSelector } from 'react-redux' import { useHistory } from 'react-router-dom' import useAddBreadcrumbs from '../../page-header/breadcrumbs/useAddBreadcrumbs' @@ -9,6 +10,7 @@ import TextFieldWithLabelFormGroup from '../../shared/components/input/TextField import TextInputWithLabelFormGroup from '../../shared/components/input/TextInputWithLabelFormGroup' import useTranslator from '../../shared/hooks/useTranslator' import Incident from '../../shared/model/Incident' +import { RootState } from '../../shared/store' import useReportIncident from '../hooks/useReportIncident' import { IncidentError } from '../util/validate-incident' @@ -17,6 +19,7 @@ const ReportIncident = () => { const history = useHistory() const { t } = useTranslator() const updateTitle = useUpdateTitle() + const { user } = useSelector((state: RootState) => state.user) useEffect(() => { updateTitle(t('incidents.reports.new')) }) @@ -28,6 +31,7 @@ const ReportIncident = () => { ] useAddBreadcrumbs(breadcrumbs) const [incident, setIncident] = useState({ + reportedBy: user?.id || 'some user', date: new Date().toISOString(), department: '', category: '', diff --git a/src/incidents/view/ViewIncidentDetails.tsx b/src/incidents/view/ViewIncidentDetails.tsx index 56f8690c29..39ca054fe4 100644 --- a/src/incidents/view/ViewIncidentDetails.tsx +++ b/src/incidents/view/ViewIncidentDetails.tsx @@ -7,7 +7,7 @@ import TextFieldWithLabelFormGroup from '../../shared/components/input/TextField import TextInputWithLabelFormGroup from '../../shared/components/input/TextInputWithLabelFormGroup' import useTranslator from '../../shared/hooks/useTranslator' import Permissions from '../../shared/model/Permissions' -import { extractUsername } from '../../shared/util/extractUsername' +import { extractFullName } from '../../shared/util/extractFullname' import useIncident from '../hooks/useIncident' import useResolveIncident from '../hooks/useResolveIncident' @@ -86,7 +86,7 @@ function ViewIncidentDetails(props: Props) {

{t('incidents.reports.reportedBy')}

-
{extractUsername(data.reportedBy)}
+
{extractFullName(data.reportedBy)}
diff --git a/src/shared/util/extractFullName.ts b/src/shared/util/extractFullName.ts new file mode 100644 index 0000000000..f85fa6df13 --- /dev/null +++ b/src/shared/util/extractFullName.ts @@ -0,0 +1,2 @@ +// TODO: extract fullname from userID when we have information on other users +export const extractFullName = (userID: string) => userID