Skip to content

Commit

Permalink
properly track if cert is the only category selected and update state…
Browse files Browse the repository at this point in the history
… dropdown accordingly
  • Loading branch information
nicholashibbits committed Feb 6, 2025
1 parent d07be86 commit cb52e5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export default function LicenseCertificationSearchResults() {
const history = useHistory();

const previousRoute = history.location.state?.path;
const previousRouteHome =
previousRoute === '/lc-search' || previousRoute === '/lc-search/';

const {
nameParam,
Expand Down Expand Up @@ -135,12 +137,19 @@ export default function LicenseCertificationSearchResults() {

useEffect(
() => {
const newDropdowns = updateStateDropdown(
let final = updateStateDropdown(
showMultipleNames(filteredResults, nameParam),
filterLocation,
);

setDropdown(newDropdowns);
if (
categoryParams.length === 1 &&
categoryParams[0] === 'certification'
) {
final = updateStateDropdown([null, null]);
}

setDropdown(final);
},
[filterLocation, filteredResults, nameParam],
);
Expand Down Expand Up @@ -189,6 +198,11 @@ export default function LicenseCertificationSearchResults() {
history.push(`/lc-search/results/${id}`);
};

const handleGoHome = e => {
e.preventDefault();
history.push(`/lc-search`);
};

const handleCheckboxGroupChange = e => {
const { name, checked } = e.target;

Expand Down Expand Up @@ -272,10 +286,9 @@ export default function LicenseCertificationSearchResults() {
})
)}
<span className="info-option">
"<strong>{nameParam}</strong>"
{previousRoute !== '/lc-search' && <>,</>}{' '}
"<strong>{nameParam}</strong>"{!previousRouteHome && <>,</>}{' '}
</span>
{previousRoute !== '/lc-search' && (
{!previousRouteHome && (
<span className="info-option">
"
<strong>
Expand Down Expand Up @@ -305,7 +318,7 @@ export default function LicenseCertificationSearchResults() {
!fetchingLc &&
hasFetchedOnce &&
filteredResults.length - 1 <= 0 &&
previousRoute === '/lc-search'
previousRouteHome
) {
return (
<>
Expand All @@ -319,6 +332,7 @@ export default function LicenseCertificationSearchResults() {
We didn't find any results for "<strong>{nameParam}</strong>" Please{' '}
<va-link
href="./" // check link structure
onClick={e => handleGoHome(e)}
text="go back to search"
/>{' '}
and try using different words or checking the spelling of the words
Expand Down
2 changes: 1 addition & 1 deletion src/applications/gi/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ export const updateStateDropdown = (multiples = [], selected = 'all') => {
{ optionValue: 'all', optionLabel: 'All' },
...mappedStates.filter(mappedState =>
multiples.find(
multiple => multiple.state === mappedState.optionValue,
multiple => multiple?.state === mappedState.optionValue,
),
),
],
Expand Down

0 comments on commit cb52e5f

Please sign in to comment.