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

Commit

Permalink
feat(viewlab.tsx): added success toast for updated/completed labs
Browse files Browse the repository at this point in the history
  • Loading branch information
anyapawar committed Jul 28, 2020
1 parent 06db065 commit 5d08ccf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
21 changes: 15 additions & 6 deletions src/labs/ViewLab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Row, Column, Badge, Button, Alert } from '@hospitalrun/components'
import { Row, Column, Badge, Button, Alert, Toast } from '@hospitalrun/components'
import format from 'date-fns/format'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -64,17 +64,26 @@ const ViewLab = () => {
}

const onUpdate = async () => {
const onSuccess = () => {
history.push('/labs')
const onSuccess = (update: Lab) => {
history.push(`/labs/${update.id}`)
Toast(
'success',
t('states.success'),
`${t('labs.successfullyUpdated')} ${update.type} ${patient?.fullName}`,
)
}
if (labToView) {
dispatch(updateLab(labToView, onSuccess))
}
}

const onComplete = async () => {
const onSuccess = () => {
history.push('/labs')
const onSuccess = (complete: Lab) => {
history.push(`/labs/${complete.id}`)
Toast(
'success',
t('states.success'),
`${t('labs.successfullyCompleted')} ${complete.type} ${patient?.fullName} `,
)
}

if (labToView) {
Expand Down
16 changes: 11 additions & 5 deletions src/labs/requests/NewLabRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Typeahead, Label, Button, Alert } from '@hospitalrun/components'
import { Typeahead, Label, Button, Alert, Toast } from '@hospitalrun/components'
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
Expand Down Expand Up @@ -40,6 +40,7 @@ const NewLabRequest = () => {
setNewLabRequest((previousNewLabRequest) => ({
...previousNewLabRequest,
patient: patient.id,
fullName: patient.fullName,
}))
}

Expand All @@ -60,12 +61,16 @@ const NewLabRequest = () => {
}

const onSave = async () => {
const newLab = newLabRequest as Lab
const onSuccess = (createdLab: Lab) => {
history.push(`/labs/${createdLab.id}`)
const onSuccessRequest = (newLab: Lab) => {
history.push(`/labs/${newLab.id}`)
Toast(
'success',
t('states.success'),
`${t('lab.successfullyCreated')} ${newLab.type} ${newLab.patient}`,
)
}

dispatch(requestLab(newLab, onSuccess))
dispatch(requestLab(newLabRequest as Lab, onSuccessRequest))
}

const onCancel = () => {
Expand Down Expand Up @@ -114,6 +119,7 @@ const NewLabRequest = () => {
<Button className="mr-2" color="success" onClick={onSave}>
{t('actions.save')}
</Button>

<Button color="danger" onClick={onCancel}>
{t('actions.cancel')}
</Button>
Expand Down

0 comments on commit 5d08ccf

Please sign in to comment.