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

Commit

Permalink
fix(patient): fix lint erros on generalinformation
Browse files Browse the repository at this point in the history
  • Loading branch information
kumikokashii committed Jun 17, 2020
1 parent 1b288b5 commit 5ad51ac
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/patients/GeneralInformation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Panel, Checkbox, Alert } from '@hospitalrun/components'
import { startOfDay, subYears, differenceInYears } from 'date-fns'
import React from 'react'
import React, { ReactElement } from 'react'
import { useTranslation } from 'react-i18next'

import DatePickerWithLabelFormGroup from '../components/input/DatePickerWithLabelFormGroup'
Expand Down Expand Up @@ -29,11 +29,11 @@ interface Props {
error?: Error
}

const GeneralInformation = (props: Props) => {
const GeneralInformation = (props: Props): ReactElement => {
const { t } = useTranslation()
const { patient, isEditable, onChange, error } = props

const onFieldChange = (name: string, value: string | ContactInfoPiece[]) => {
const onFieldChange = (name: string, value: string | boolean | ContactInfoPiece[]) => {
if (onChange) {
const newPatient = {
...patient,
Expand All @@ -49,6 +49,16 @@ const GeneralInformation = (props: Props) => {
return startOfDay(dateOfBirth).toISOString()
}

const onApproximateAgeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.currentTarget
onFieldChange('dateOfBirth', guessDateOfBirthFromApproximateAge(value))
}

const onUnknownDateOfBirthChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { checked } = event.currentTarget
onFieldChange('isApproximateDateOfBirth', checked)
}

return (
<div>
<Panel title={t('patient.basicInformation')} color="primary" collapsible>
Expand Down Expand Up @@ -139,12 +149,7 @@ const GeneralInformation = (props: Props) => {
type="number"
value={`${differenceInYears(new Date(Date.now()), new Date(patient.dateOfBirth))}`}
isEditable={isEditable}
onChange={(event) =>
onFieldChange(
'dateOfBirth',
guessDateOfBirthFromApproximateAge(event.currentTarget.value),
// eslint-disable-next-line
)}
onChange={onApproximateAgeChange}
/>
) : (
<DatePickerWithLabelFormGroup
Expand All @@ -171,10 +176,7 @@ const GeneralInformation = (props: Props) => {
label={t('patient.unknownDateOfBirth')}
name="unknown"
disabled={!isEditable}
onChange={
(event) => onFieldChange('isApproximateDateOfBirth', event.currentTarget.value)
// eslint-disable-next-line react/jsx-curly-newline
}
onChange={onUnknownDateOfBirthChange}
/>
</div>
</div>
Expand Down

0 comments on commit 5ad51ac

Please sign in to comment.