-
Notifications
You must be signed in to change notification settings - Fork 166
Lg 6202 add accordion #6338
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
Merged
Merged
Lg 6202 add accordion #6338
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4ab6ce3
lg-6202 - accordion for the password confirm page
peggles2 d101198
remove debugger
peggles2 c5fb915
initial files
peggles2 e4f04e6
cleanup linter errors
peggles2 248f3dc
update code review feedbacks
peggles2 6847826
fix merge conflict
peggles2 06fd1a0
initial load
peggles2 412e4d5
fix styling
peggles2 3f4e58d
changelog: Improvements, Authentication, add accordion to react (LG-6…
peggles2 56c1c62
remove return statement
peggles2 8dec1a6
update accordion language
peggles2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,36 @@ | ||
| import { useRef } from 'react'; | ||
| import type { ReactNode } from 'react'; | ||
| import { useInstanceId } from '@18f/identity-react-hooks'; | ||
|
|
||
| interface AccordionProps { | ||
| header: string; | ||
|
|
||
| children: ReactNode; | ||
| } | ||
|
|
||
| function Accordion({ header, children }: AccordionProps) { | ||
| const uniqueId = useInstanceId(); | ||
| const ref = useRef(null as HTMLDivElement | null); | ||
|
|
||
| return ( | ||
| <div ref={ref}> | ||
| <div className="usa-accordion usa-accordion--bordered"> | ||
| <div className="usa-accordion__heading"> | ||
| <button | ||
| type="button" | ||
| className="usa-accordion__button" | ||
| aria-expanded="false" | ||
| aria-controls={`accordion-${uniqueId}`} | ||
| > | ||
| {header} | ||
| </button> | ||
| </div> | ||
| <div id={`accordion-${uniqueId}`} className="usa-accordion__content usa-prose" hidden> | ||
| {children} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default Accordion; |
This file contains hidden or 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
This file contains hidden or 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
67 changes: 67 additions & 0 deletions
67
app/javascript/packages/verify-flow/steps/password-confirm/password-confirm-step.spec.tsx
This file contains hidden or 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,67 @@ | ||
| import sinon from 'sinon'; | ||
| import * as analytics from '@18f/identity-analytics'; | ||
| import { render } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { t } from '@18f/identity-i18n'; | ||
| import { accordion } from 'identity-style-guide'; | ||
| import PasswordConfirmStep from './password-confirm-step'; | ||
|
|
||
| describe('PasswordConfirmStep', () => { | ||
| before(() => { | ||
| accordion.on(); | ||
| }); | ||
|
|
||
| after(() => { | ||
| accordion.off(); | ||
| }); | ||
|
|
||
| const sandbox = sinon.createSandbox(); | ||
| const DEFAULT_PROPS = { | ||
| onChange() {}, | ||
| onError() {}, | ||
| errors: [], | ||
| toPreviousStep() {}, | ||
| registerField: () => () => {}, | ||
| unknownFieldErrors: [], | ||
| value: {}, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| sandbox.spy(analytics, 'trackEvent'); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sandbox.restore(); | ||
| }); | ||
|
|
||
| it('has a collapsed accordion by default', () => { | ||
| const { getByText } = render(<PasswordConfirmStep {...DEFAULT_PROPS} />); | ||
|
|
||
| const button = getByText(t('idv.messages.review.intro')); | ||
| expect(button.getAttribute('aria-expanded')).to.eq('false'); | ||
| }); | ||
|
|
||
| it('expands accordion when the accordion is clicked on', async () => { | ||
| const toPreviousStep = sinon.spy(); | ||
| const { getByText } = render( | ||
| <PasswordConfirmStep {...DEFAULT_PROPS} toPreviousStep={toPreviousStep} />, | ||
| ); | ||
|
|
||
| const button = getByText(t('idv.messages.review.intro')); | ||
| await userEvent.click(button); | ||
| expect(button.getAttribute('aria-expanded')).to.eq('true'); | ||
| }); | ||
|
|
||
| it('displays user information when the accordion is clicked on', async () => { | ||
| const toPreviousStep = sinon.spy(); | ||
| const { getByText } = render( | ||
| <PasswordConfirmStep {...DEFAULT_PROPS} toPreviousStep={toPreviousStep} />, | ||
| ); | ||
|
|
||
| const button = getByText(t('idv.messages.review.intro')); | ||
| await userEvent.click(button); | ||
|
|
||
| expect(getByText('idv.review.full_name')).to.exist(); | ||
| expect(getByText('idv.review.mailing_address')).to.exist(); | ||
| }); | ||
| }); |
37 changes: 24 additions & 13 deletions
37
app/javascript/packages/verify-flow/steps/password-confirm/password-confirm-step.tsx
This file contains hidden or 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
42 changes: 42 additions & 0 deletions
42
app/javascript/packages/verify-flow/steps/password-confirm/personal-info-summary.tsx
This file contains hidden or 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,42 @@ | ||
| import { parse, format } from 'libphonenumber-js'; | ||
| import { t } from '@18f/identity-i18n'; | ||
|
|
||
| function PersonalInfoSummary({ pii }) { | ||
| const { firstName, lastName, dob, address1, address2, city, state, zipcode, ssn, phone } = pii; | ||
| const phoneNumber = parse(`+1${phone}`); | ||
| const formatted = format(phoneNumber, 'NATIONAL'); | ||
|
|
||
| function getDateFormat(date) { | ||
| date = new Date(date); | ||
| const options = { year: 'numeric', month: 'long', day: 'numeric' }; | ||
| return date.toLocaleDateString(document.documentElement.lang, options); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="padding-x-4"> | ||
| <div className="h6">{t('idv.review.full_name')}</div> | ||
| <div className="h4 text-bold ico-absolute ico-absolute-success"> | ||
| {firstName} {lastName} | ||
| </div> | ||
| <div className="margin-top-4 h6">{t('idv.review.mailing_address')}</div> | ||
| <div className="h4 text-bold ico-absolute ico-absolute-success"> | ||
| {address1} <br /> | ||
| {address2 || ''} | ||
| <br /> | ||
| {city && state ? `${city}, ${state} ${zipcode}` : ''} | ||
| </div> | ||
| <div className="margin-top-4 h6">{t('idv.review.dob')}</div> | ||
| <div className="h4 text-bold ico-absolute ico-absolute-success">{getDateFormat(dob)}</div> | ||
| <div className="margin-top-4 h6">{t('idv.review.ssn')}</div> | ||
| <div className="h4 text-bold ico-absolute ico-absolute-success">{ssn}</div> | ||
| {phone && ( | ||
| <> | ||
| <div className="h6 margin-top-4"> {t('idv.messages.phone.phone_of_record')}</div> | ||
| <div className="h4 text-bold ico-absolute ico-absolute-success">{formatted}</div> | ||
| </> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default PersonalInfoSummary; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch / fix on the duplication of "StepStep" 👍