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

[Profile Page] Auth Token #2249

Merged
merged 3 commits into from
Jul 31, 2024
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
6 changes: 3 additions & 3 deletions cypress/e2e/filing/Filing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,22 @@ describe('Complete Profile Page', () => {
'[style="color: black; text-decoration: none; cursor: pointer;"]',
).click()
cy.get('.institution_info_container > input').click({ multiple: true })
cy.get('.profile_form_container > button').click()
cy.get('.profile_save_container > button').click()
cy.wait(1000)

cy.get('.alert-heading').contains(
'An institution must be associated with your account.',
)
})

it('User gets redirected to complete profile page due to now associated LEIs on their account', () => {
it('User gets redirected to complete profile page due to no associated LEIs on their account', () => {
cy.visit(`${HOST}/filing/${latestFilingPeriod}/institutions`)
cy.wait(5000)

cy.url().should('contains', '/filing/profile')

cy.get('.institution_info_container > input').click({ multiple: true })
cy.get('.profile_form_container > button').click()
cy.get('.profile_save_container > button').click()
cy.wait(1000)

// Back button verifies that the institution was re-added to the account
Expand Down
62 changes: 58 additions & 4 deletions src/filing/profile/CompleteProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import jwtDecode from 'jwt-decode'
import { forceRefreshToken } from '../utils/keycloak'
import { shouldFetchInstitutions } from '../actions/shouldFetchInstitutions'
import { MissingInstitutionsBanner } from '../institutions/MissingInstitutionsBanner'
import Icon from '../../common/uswds/components/Icon'

const CompleteProfile = (props) => {
const dispatch = useDispatch()
Expand All @@ -36,6 +37,8 @@ const CompleteProfile = (props) => {
const [loading, setLoading] = useState(false)
const [displayNotification, setDisplayNotification] = useState(false)
const [errorFromAPI, setErrorFromAPI] = useState(false)
const [copiedAuthToken, setCopiedAuthToken] = useState(false)
const [showSettingsMenu, setShowSettingsMenu] = useState(false)

if (!user) {
return <Redirect to={`/filing/${props.config.defaultPeriod}`} />
Expand Down Expand Up @@ -126,6 +129,15 @@ const CompleteProfile = (props) => {
}
}

const copyAuthTokenFromKeyCloak = () => {
navigator.clipboard.writeText(AccessToken.get()).then(() => {
setCopiedAuthToken(true)
setTimeout(() => {
setCopiedAuthToken(false)
}, 2000)
})
}

return (
<div className='App'>
<ShowUserName isLoggedIn={getKeycloak().authenticated} />
Expand Down Expand Up @@ -214,15 +226,57 @@ const CompleteProfile = (props) => {
)}

<div className='missing_institutions_banner_container'>
{((institutions?.fetched && associatedInstitutions?.length !== 0) ||
{((institutions?.fetched &&
associatedInstitutions?.length !== 0) ||
errorFromAPI) && (
<MissingInstitutionsBanner leis={unregisteredInstitutions} />
)}
</div>

<button type='submit' disabled={!userIsEditingForm}>
Save
</button>
<div className='profile_save_container'>
<button type='submit' disabled={!userIsEditingForm}>
Save
</button>

<div
className='profile_settings'
onMouseEnter={() => setShowSettingsMenu(true)}
onMouseLeave={() => setShowSettingsMenu(false)}
>
<Icon
iconName='settings'
styleIcon={{ height: '22px', width: '22px' }}
/>
<p>Developer Settings</p>

{showSettingsMenu && (
<div className='profile_settings_menu'>
<div
className='menu_item'
onClick={copyAuthTokenFromKeyCloak}
>
{copiedAuthToken ? (
<>
<Icon
iconName='check'
styleIcon={{ height: '20px', width: '20px' }}
/>
<p>Token Copied</p>
</>
) : (
<>
<Icon
iconName='code'
styleIcon={{ height: '20px', width: '20px' }}
/>
<p>Copy Auth Token</p>
</>
)}
</div>
</div>
)}
</div>
</div>
</form>
</>
)}
Expand Down
45 changes: 45 additions & 0 deletions src/filing/profile/Profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,51 @@
margin-bottom: 0;
}

.profile_save_container {
display: flex;
justify-content: space-between;
align-items: center;
}

.profile_settings {
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
margin-top: 35px;
margin-right: 8px;
position: relative;
}

.profile_settings p {
font-size: 18px;
}

.profile_settings_menu {
width: 180px;
height: 40px;
display: flex;
align-items: center;
padding-left: 10px;
border: 1px solid black;
border-radius: 5px;
background-color: #f7f8f9;
position: absolute;
top: 100%;
left: 0;
z-index: 1;
}

.profile_settings_menu .menu_item {
display: flex;
align-items: center;
gap: 5px;
}

.menu_item p {
font-size: 16px;
}

/* Associated Instutions CSS */
.associated_insitutions_container h1 {
font-size: 18px;
Expand Down