diff --git a/src/applications/vaos/referral-appointments/ConfirmApprovedPage.jsx b/src/applications/vaos/referral-appointments/ConfirmApprovedPage.jsx index 87e061f0baf8..68b1b4af4aea 100644 --- a/src/applications/vaos/referral-appointments/ConfirmApprovedPage.jsx +++ b/src/applications/vaos/referral-appointments/ConfirmApprovedPage.jsx @@ -1,5 +1,10 @@ import React, { useState, useEffect } from 'react'; +import { useHistory } from 'react-router-dom'; +import { useDispatch } from 'react-redux'; + import ReferralLayout from './components/ReferralLayout'; +import { routeToPreviousReferralPage } from './flow'; +import { setFormCurrentPage } from './redux/actions'; const staticData = { typeOfCare: 'Primary Care', @@ -22,6 +27,9 @@ const getData = (typeOfData = 'static') => { }; export default function ConfirmApprovedPage() { + const history = useHistory(); + const dispatch = useDispatch(); + const [confirmedData, setConfirmedData] = useState(0); // on react component mount, fetch data @@ -29,6 +37,13 @@ export default function ConfirmApprovedPage() { setConfirmedData(getData()); }, []); + useEffect( + () => { + dispatch(setFormCurrentPage('confirmAppointment')); + }, + [location, dispatch], + ); + return (
@@ -103,7 +118,16 @@ export default function ConfirmApprovedPage() {
{confirmedData.details}

- + { + e.preventDefault(); + routeToPreviousReferralPage(history, 'confirmAppointment'); + }} + /> { e.preventDefault(); - dispatch(routeToPreviousReferralPage(history, currentPage)); + routeToPreviousReferralPage(history, currentPage); }} /> diff --git a/src/applications/vaos/referral-appointments/flow.js b/src/applications/vaos/referral-appointments/flow.js index 6dea85bfe1af..807c27308872 100644 --- a/src/applications/vaos/referral-appointments/flow.js +++ b/src/applications/vaos/referral-appointments/flow.js @@ -71,7 +71,14 @@ export function routeToPreviousReferralPage( current, referralId = null, ) { - return routeToPageInFlow(history, current, 'previous', referralId); + let resolvedReferralId = referralId; + // Give the router some context to keep the user in the same referral when navigating back if not + // explicitly passed + if (!referralId && history.location?.search) { + const params = new URLSearchParams(history.location.search); + resolvedReferralId = params.get('id'); + } + return routeToPageInFlow(history, current, 'previous', resolvedReferralId); } export function routeToNextReferralPage(history, current, referralId = null) {