Skip to content

Commit

Permalink
Dependents | 94154: Fix redirect looping (#33787)
Browse files Browse the repository at this point in the history
  • Loading branch information
Midge-dev authored Dec 31, 2024
1 parent d714d73 commit a328413
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
47 changes: 33 additions & 14 deletions src/applications/686c-674/containers/App.jsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
import React from 'react';
import { connect } from 'react-redux';
import RoutedSavableApp from 'platform/forms/save-in-progress/RoutedSavableApp';
import { VA_FORM_IDS } from '@department-of-veterans-affairs/platform-forms/constants';
// import manifest from '../manifest.json';
import { useBrowserMonitoring } from '~/platform/utilities/real-user-monitoring';
import { useFeatureToggle } from '~/platform/utilities/feature-toggles';
import manifest from '../manifest.json';
import formConfig from '../config/form';
import { DOC_TITLE } from '../config/constants';

function App({ location, children, isLoading, featureToggles, savedForms }) {
function App({
location,
children,
isLoggedIn,
isLoading,
vaFileNumber,
featureToggles,
}) {
const { TOGGLE_NAMES } = useFeatureToggle();
useBrowserMonitoring({
location,
toggleName: TOGGLE_NAMES.disablityBenefitsBrowserMonitoringEnabled,
});

// Must match the H1
document.title = DOC_TITLE;

// Handle loading
if (isLoading || !featureToggles || featureToggles.loading) {
return <va-loading-indicator message="Loading your information..." />;
}

const flipperV2 = featureToggles.vaDependentsV2;
const hasV1Form = savedForms.some(
form => form.form === VA_FORM_IDS.FORM_21_686C,
);
const hasV2Form = savedForms.some(
form => form.form === VA_FORM_IDS.FORM_21_686CV2,
);

const shouldUseV2 = hasV2Form || (flipperV2 && !hasV1Form);
if (!shouldUseV2) {
if (!featureToggles.vaDependentsV2) {
window.location.href = '/view-change-dependents/add-remove-form-21-686c/';
return <></>;
}

return (
const content = (
<article id="form-686c" data-location={`${location?.pathname?.slice(1)}`}>
<RoutedSavableApp formConfig={formConfig} currentLocation={location}>
{children}
</RoutedSavableApp>
</article>
);

// If on intro page, just return
if (location.pathname === '/introduction') {
return content;
}

// If a user is not logged in OR
// a user is logged in, but hasn't gone through va file number validation
// redirect them to the introduction page.
if (
!isLoggedIn ||
(isLoggedIn && !vaFileNumber?.hasVaFileNumber?.VALIDVAFILENUMBER)
) {
document.location.replace(`${manifest.rootUrl}`);
return (
<va-loading-indicator message="Redirecting to introduction page..." />
);
}

return content;
}

const mapStateToProps = state => {
Expand Down
14 changes: 2 additions & 12 deletions src/applications/disability-benefits/686c-674/containers/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import RoutedSavableApp from 'platform/forms/save-in-progress/RoutedSavableApp';
import { VA_FORM_IDS } from '@department-of-veterans-affairs/platform-forms/constants';
import { useBrowserMonitoring } from '~/platform/utilities/real-user-monitoring';
import { useFeatureToggle } from '~/platform/utilities/feature-toggles';
import manifest from '../manifest.json';
Expand All @@ -15,7 +14,6 @@ function App({
isLoading,
vaFileNumber,
featureToggles,
savedForms,
}) {
const { TOGGLE_NAMES } = useFeatureToggle();
useBrowserMonitoring({
Expand All @@ -31,16 +29,7 @@ function App({
return <va-loading-indicator message="Loading your information..." />;
}

const flipperV2 = featureToggles.vaDependentsV2;
const hasV1Form = savedForms.some(
form => form.form === VA_FORM_IDS.FORM_21_686C,
);
const hasV2Form = savedForms.some(
form => form.form === VA_FORM_IDS.FORM_21_686CV2,
);

const shouldUseV2 = hasV2Form || (flipperV2 && !hasV1Form);
if (shouldUseV2) {
if (featureToggles.vaDependentsV2) {
window.location.href =
'/view-change-dependents/add-remove-form-21-686c-v2/';
return <></>;
Expand All @@ -52,6 +41,7 @@ function App({
</RoutedSavableApp>
</article>
);

// If on intro page, just return
if (location.pathname === '/introduction') {
return content;
Expand Down

0 comments on commit a328413

Please sign in to comment.