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

Testing: Adding ChooseAffiliation component above InstitutionSelect. #403

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 1 addition & 37 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": "^6.1.0",
"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