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

Commit

Permalink
fix: reset lab state when navigation from lab form (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomastomaslol committed Aug 5, 2020
1 parent 4463220 commit aa8e2ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/labs/lab-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ export const requestLab = (newLab: Lab, onSuccess?: (lab: Lab) => void): AppThun
}
}

export const resetLab = (): AppThunk => async (dispatch) => {
const labRequestError: Error = {}
dispatch(requestLabError(labRequestError))
dispatch(fetchLabStart())
}

export const cancelLab = (labToCancel: Lab, onSuccess?: (lab: Lab) => void): AppThunk => async (
dispatch,
) => {
Expand Down
8 changes: 6 additions & 2 deletions src/labs/requests/NewLabRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Typeahead, Label, Button, Alert } from '@hospitalrun/components'
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useHistory } from 'react-router-dom'

Expand All @@ -12,7 +12,7 @@ import useTranslator from '../../shared/hooks/useTranslator'
import Lab from '../../shared/model/Lab'
import Patient from '../../shared/model/Patient'
import { RootState } from '../../shared/store'
import { requestLab } from '../lab-slice'
import { requestLab, resetLab } from '../lab-slice'

const NewLabRequest = () => {
const { t } = useTranslator()
Expand All @@ -28,6 +28,10 @@ const NewLabRequest = () => {
status: 'requested',
})

useEffect(() => {
dispatch(resetLab())
}, [dispatch])

const breadcrumbs = [
{
i18nKey: 'labs.requests.new',
Expand Down

1 comment on commit aa8e2ed

@vercel
Copy link

@vercel vercel bot commented on aa8e2ed Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.