Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WV-166] Fix #3796

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

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

Please comment out console.log's like this in future commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do! Sorry about that. I thought I got them all!

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