Skip to content

Commit

Permalink
[WV-166] Fix (#3796)
Browse files Browse the repository at this point in the history
* [WV-166] changes made in CampaignsHomeLoader.jsx and addressFunctions.js in order to load header/navbar when loading candidates page outside of the country. Instead of routing to -candidates/cs when out of the country will route to /cs

* [WV-166] cleaning up commits etc.
  • Loading branch information
cbarnes0 authored Dec 13, 2023
1 parent 92dab10 commit cbeac88
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/js/common/utils/addressFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ export function convertStateCodeFilterToStateCode (stateCodeFilter) {
return '';
}

export function isValidStateCode (incomingStateCode) {
if (incomingStateCode) {
// Log incoming State Code
console.log('incomingStateCode:', incomingStateCode);
const incomingStateCodeUpper = incomingStateCode.toUpperCase();
const existingStateCodes = Object.keys(stateCodeMap);
return existingStateCodes.indexOf(incomingStateCodeUpper) > -1;
} else {
return false;
}
}

export function getAllStateCodeFilters () {
return Object.keys(stateCodeMap).map((stateCode) => `stateCode${stateCode}`);
}
Expand Down
18 changes: 13 additions & 5 deletions src/js/pages/Campaigns/CampaignsHomeLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import React, { Component, Suspense } from 'react';
import { Helmet } from 'react-helmet-async';
import styled from 'styled-components';
import { convertStateCodeToStateText, convertStateTextToStateCode } from '../../common/utils/addressFunctions';
import { convertStateCodeToStateText, convertStateTextToStateCode, isValidStateCode } from '../../common/utils/addressFunctions';
import historyPush from '../../common/utils/historyPush';
import { isWebApp } from '../../common/utils/isCordovaOrWebApp';
import { renderLog } from '../../common/utils/logging';
Expand Down Expand Up @@ -117,10 +117,18 @@ class CampaignsHomeLoader extends Component {
}

getStateNamePathnameFromStateCode = (stateCode) => {
const stateName = convertStateCodeToStateText(stateCode);
const stateNamePhrase = `${stateName}-candidates`;
const stateNamePhraseLowerCase = stateNamePhrase.replaceAll(/\s+/g, '-').toLowerCase();
return `/${stateNamePhraseLowerCase}/cs/`;
if (isValidStateCode(stateCode)) {
const stateName = convertStateCodeToStateText(stateCode);
if (stateName) {
const stateNamePhrase = `${stateName}-candidates`;
const stateNamePhraseLowerCase = stateNamePhrase.replaceAll(/\s+/g, '-').toLowerCase();
return `/${stateNamePhraseLowerCase}/cs/`;
} else {
return '/cs';
}
} else {
return '/cs';
}
}

getTopPadding = () => {
Expand Down

0 comments on commit cbeac88

Please sign in to comment.