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

[Task] [User Profile] useRef in Step1FormErrorHeader #145

Merged
merged 25 commits into from
Jan 11, 2024

Conversation

shindigira
Copy link
Contributor

@shindigira shindigira commented Jan 5, 2024

close #102

Changes

  • Upon submission invalidation, the user's view is smooth scrolled to the Step1FormErrorHeader
  • utilized useRef in Step1FormErrorHeader to focus an error element

How to Test

  • In the Complete your Use Profile click the submit button
  • Ensure no regressions when clicking on the error links; should focus and smooth scroll to the appropriate item.

Screenshot

Screenshot 2024-01-05 at 3 30 11 PM

Changes:
- utilized useRef in Step1FormErrorHeader to focus an error element
@@ -152,11 +153,10 @@ function Step1Form(): JSX.Element {
// https://github.com/cfpb/sbl-frontend/issues/135
await auth.signinSilent();
window.location.href = '/landing';
// navigate('/landing')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// navigate('/landing')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the issue is solved, navigating should done this way. Using window.location.href causes a hard refresh.
I'm keeping the comment here since it will eventually be uncommented.

Copy link
Contributor

@meissadia meissadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

When there are errors upon clicking Submit, would it make sense to focus on the "There was a problem completing your profile" box that lists all of the errors? That way users get the overview of what needs to be corrected before they will be able to proceed.

@shindigira
Copy link
Contributor Author

shindigira commented Jan 5, 2024

Nice!

When there are errors upon clicking Submit, would it make sense to focus on the "There was a problem completing your profile" box that lists all of the errors? That way users get the overview of what needs to be corrected before they will be able to proceed.

Good thinking. I will add this to this PR.

@shindigira
Copy link
Contributor Author

@meissadia Added an additional UX of a smooth scrolling to the error heading after hitting the submit button (if there are errors).

Please re-review and focus that part of this PR.

Copy link
Contributor

@meissadia meissadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shindigira I've pulled the latest but the app is crashing:

Screenshot 2024-01-08 at 4 45 06 PM

I don't see errorFormReference defined anywhere in the project.

@shindigira
Copy link
Contributor Author

@shindigira I've pulled the latest but the app is crashing:

Screenshot 2024-01-08 at 4 45 06 PM

I don't see errorFormReference defined anywhere in the project.

@meissadia Removed that. Should work now! Thanks for the catch.

Copy link
Contributor

@billhimmelsbach billhimmelsbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some great stuff in here @shindigira!

I don't want to hold up this PR, but the "useRef" part you've added still uses document.querySelector when creating the ref, instead of a declarative approach using refs. The react-hook-form documentation has an example on their FAQ page that they recommend for scrolling an input into view that uses the declarative ref approach.

https://www.react-hook-form.com/faqs/#Howtosharerefusage

I don't want to hold up this PR, and there's more code to write with this approach, but when I think about using refs declaratively, this is the kind of approach I was imagining.

@shindigira
Copy link
Contributor Author

shindigira commented Jan 9, 2024

There's some great stuff in here @shindigira!

I don't want to hold up this PR, but the "useRef" part you've added still uses document.querySelector when creating the ref, instead of a declarative approach using refs. The react-hook-form documentation has an example on their FAQ page that they recommend for scrolling an input into view that uses the declarative ref approach.

https://www.react-hook-form.com/faqs/#Howtosharerefusage

I don't want to hold up this PR, and there's more code to write with this approach, but when I think about using refs declaratively, this is the kind of approach I was imagining.

That approach you linked is not dynamic by having to manually declare each ref top-level. Could keep an array or map object of refs (e.g. useRef(refArray.map(() => createRef()))) in Step1Form1 but would rather keep it as is.

@shindigira shindigira requested a review from meissadia January 10, 2024 22:13
@shindigira shindigira changed the base branch from main to 85-dsr-userprofile January 10, 2024 23:08
@billhimmelsbach
Copy link
Contributor

That approach you linked is not dynamic by having to manually declare each ref top-level. Could keep an array or map object of refs (e.g. useRef(refArray.map(() => createRef()))) in Step1Form1 but would rather keep it as is.

I think I'd prefer it then if you just go back to using document.querySelector without refs since the code now is confusing to me, since you're setting something that should be declarative with an imperative query of the document body. Generally we want to avoid imperative code with react, but if you don't want to for this PR, let's just leave it one or the other.

@shindigira
Copy link
Contributor Author

shindigira commented Jan 11, 2024

That approach you linked is not dynamic by having to manually declare each ref top-level. Could keep an array or map object of refs (e.g. useRef(refArray.map(() => createRef()))) in Step1Form1 but would rather keep it as is.

I think I'd prefer it then if you just go back to using document.querySelector without refs since the code now is confusing to me, since you're setting something that should be declarative with an imperative query of the document body. Generally we want to avoid imperative code with react, but if you don't want to for this PR, let's just leave it one or the other.

Reverted; and I agree about avoiding imperative code.

@shindigira shindigira merged commit 4fad441 into 85-dsr-userprofile Jan 11, 2024
shindigira added a commit that referenced this pull request Jan 11, 2024
* refactor: Utilized DSR AlertFieldLevel in NoDatabaseResultError

* refactor: created a const for the sblhelp link

* refactor: InputEntry utilizes DSR's TextInput

* refactor: Utilized DSR AlertFieldLevel in InputErrorMessage

* dev: placed a way to destroy the login creds during development

* refactor: auto-format

* chore: removed import

* refactor: Utilized TextIntroduction in Step1FormHeader and resolved TS errors in Associated

* fix: RSSD not RSS

* chore: changed type to null

* chore: changed TAX ID to TIN

* feat: email text instead of disabled input

* style: adjusted spacing styles on User Profile

* chore: added TODO

* refactor: updated content text to the figma

* chore: added TODO comment

* styling: updated Checkbox, 01-09-24 Figma updates to spacing and content text

* styling: additional spacing changes

* style: px to rem button group

* chore: updated to latest DSR package

* fix: disabled user name and LOG OUT during profile-form view

* comment: indicated workaround for red checkbox border

* style: removed input border under red border during an error

* chore: remove unused classes

* style: updated content text, removed App.less

* style: fixed tailwind overriding styles by removing @tailwind directives

* style: fixed tailwind overriding styles by removing @tailwind base directive

* chore: updated denied email notification based on figma

* style: uses the listlink in the step1formerrorheader

* style: moved error within well

* style: small em to rem fix

* style: style mt fix

* fix: merge conflicts

* style: style updated spacings

* style: spacing 2

* fix: removed unused variable

* [Task] [User Profile] useRef in Step1FormErrorHeader (#145)

* feat: utilized useRef in Step1FormErrorHeader

Changes:
- utilized useRef in Step1FormErrorHeader to focus an error element

* fix: lint errors

* chore: moved function to profileformutils

* feat: added back scroll animation to step1formerrorheader

* chore: remove unused useref

* fix: removed unused var

* refactor: added type to submitprofile

* chore: pulled in 85 and fixed merge conflicts

* fix: resolved conflicts 2

* revert: reverted to document.querySelector use

* fix: resolved merge conflicts

* style: fix gray/red border

* style: remove periods from error header text

* chore: removed class attribute

* chore: package fix

* chore: CFPB package update

* chore: updated content text - checkbox well
@meissadia meissadia deleted the 102-useref-user-profile-header branch February 14, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] [User Profile] Use useRef in the User Profile Header
3 participants