-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding
ChooseAffiliation
component above InstitutionSelect
.
- Updating `FlintAlerts`
- Loading branch information
1 parent
2925d15
commit 8c592b2
Showing
17 changed files
with
146 additions
and
473 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/modules/affiliation/components/ChooseAffiliation/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
201
src/modules/affiliation/components/choose-affiliation.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.