Skip to content

Commit

Permalink
Adding ChooseAffiliation component above InstitutionSelect.
Browse files Browse the repository at this point in the history
- Updating `FlintAlerts`
  • Loading branch information
erinesullivan committed Aug 30, 2023
1 parent 2925d15 commit 8c592b2
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 473 deletions.
44 changes: 4 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"qs": "^6.11.2",
"react": "^18.2.0",
"react-autosuggest": "^10.1.0",
"react-cookie": "^4.1.1",
"react-dom": "^18.2.0",
"react-ga": "^3.3.1",
"react-modal": "^3.16.1",
Expand Down
65 changes: 65 additions & 0 deletions src/modules/affiliation/components/ChooseAffiliation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { React, useState } from 'react';

const initialAffiliationState = {
active: localStorage.getItem('affiliation') || undefined,
defaultAffiliation: 'aa',
affiliationOptions: {
aa: 'Ann Arbor',
flint: 'Flint'
}
};

function ChooseAffiliation () {
let activeAffiliation = initialAffiliationState.defaultAffiliation;
// Set default affiliation if query parameter exists
const urlParams = new URLSearchParams(window.location.search);
const affiliationParam = urlParams.get('affiliation');
if (affiliationParam) {
activeAffiliation = affiliationParam;
// Set localStorage
localStorage.setItem('affiliation', affiliationParam);
}
const affiliationLocalStorage = localStorage.getItem('affiliation');
// Set default affiliation if localStorage exists
if (affiliationLocalStorage) {
activeAffiliation = affiliationLocalStorage;
}
const [affiliation, setAffiliation] = useState(activeAffiliation);
const onAffiliationChange = (event) => {
const value = event.target.value;
setAffiliation(value);
urlParams.set('affiliation', value);
window.location.href = `${window.location.origin}${window.location.pathname}?${urlParams.toString()}`;
};

return (
<fieldset className='institution-select-container'>
<legend className='visually-hidden'>Choose Affiliation</legend>
<label
className='institution-select-label institution-select-label-text'
htmlFor='choose-affiliation'
>
Affiliation
</label>
<select
className='dropdown'
id='choose-affiliation'
autoComplete='off'
value={affiliation}
onChange={onAffiliationChange}
aria-describedby='affiliation-description'
>
{Object.keys(initialAffiliationState.affiliationOptions).map((affiliationOption) => {
return (
<option value={affiliationOption} key={`affiliation-${affiliationOption}`}>
{initialAffiliationState.affiliationOptions[affiliationOption]}
</option>
);
})}
</select>
<p className='font-small' id='affiliation-description'>Selecting an affiliation helps us connect you to available online materials licensed for your campus. You can still use Library Search if you're not affiliated with either campus.</p>
</fieldset>
);
}

export { initialAffiliationState, ChooseAffiliation };
201 changes: 0 additions & 201 deletions src/modules/affiliation/components/choose-affiliation.js

This file was deleted.

8 changes: 1 addition & 7 deletions src/modules/affiliation/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import ChooseAffiliation from './components/choose-affiliation';
import { ChooseAffiliation } from './components/ChooseAffiliation';
import affiliationReducer from './reducer';
import { setDefaultAffiliation, setActiveAffilitation } from './actions';

export function affiliationCookieSetter (affiliation) {
if (affiliation) {
document.cookie = `affiliation=${affiliation};path=/`;
}
}

export {
ChooseAffiliation,
affiliationReducer,
Expand Down
Loading

0 comments on commit 8c592b2

Please sign in to comment.