Skip to content

Geoff signup validation #277

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

Open
wants to merge 18 commits into
base: development
Choose a base branch
from
Open

Conversation

GMorse19
Copy link
Member

Ticket: ROAM-45

The functionality is there, but this PR could use some refactoring. I'll comment on some areas that I'm looking to address.

I believe any of the styling defects can be addressed when ROAM-47 is updated to reflect the new Figma drawings.

@GMorse19 GMorse19 added the help wanted Extra attention is needed label Sep 10, 2020
@GMorse19 GMorse19 self-assigned this Sep 10, 2020
@@ -35,7 +35,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "CI= react-scripts build",
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this needed? I changed this while testing out netlify.

Copy link
Member

Choose a reason for hiding this comment

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

what does this line do?

Copy link
Member Author

Choose a reason for hiding this comment

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

When I was originally trying to get netlify working, I found this fix. Apparently it prevents warnings from creating a fatal error in the build process. This link explains it some.

}
}
// Set state of all fields using helper functions
Copy link
Member Author

Choose a reason for hiding this comment

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

I was looking into a cleaner way to do this. The checkValid() function checks the state of all the fields at once. I'm looking into just checking the specific fields that are being altered. Maybe a helper function? Or possibly a naming convention that would allow for easier refactoring?

@@ -43,7 +119,6 @@ class HeaderSignUp extends Component {
.then(() => history.push('/first-signin'))
.catch(error => {
console.error(error)
this.setState({ email: '', username: '', password: '', passwordConfirmation: '' })
Copy link
Member Author

Choose a reason for hiding this comment

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

This cleared the form after an error. I removed it so the user has an opportunity to alter their inputs.

@@ -62,7 +160,7 @@ class HeaderSignUp extends Component {
<Form.Group controlId="username" className="mt-4">
<TextField
fullWidth={true}
className="account-info"
className={!usernameVal ? 'account-info-signup-red username input' : 'account-info-signup username input'}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using the class here to change the color of the form border. Red for invalid and Green for Valid. This will most likely be unnecessary when we implement the new figma drawings.

src={'red-x.svg'}
alt='red-x'
className={!usernameVal ? 'red-x' : 'green-check'}
onMouseEnter={!usernameVal ? () => this.onHover(this.state.openUser, 'openUser') : undefined}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using hover to display the error messages. It works well for the web browser, but we may want to implement an onClick also. For mobile it may be essential.

@@ -35,7 +35,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "CI= react-scripts build",
Copy link
Member

Choose a reason for hiding this comment

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

what does this line do?

passwordNumber: false,
passwordConfirmation: '',
passwordConfirmationVal: false,
property: document.documentElement.style.setProperty('--border-show', 'none')
Copy link
Member

Choose a reason for hiding this comment

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

what is document.documentElement.style.setProperty('--border-show', 'none')?

Copy link
Member Author

Choose a reason for hiding this comment

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

I meant to comment on this. I'm using a CSS variable to change the border from 'none' to 'show' upon submit. This line resets the border display to 'none' when first loading the signup page. Without it, if you left the signup page and came back the borders would still be showing. We probably won't need the CSS variable when we implement the newer wire frames, but I wanted to leave it in for now... just in case.

Copy link
Member

Choose a reason for hiding this comment

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

If you want this code to execute on load, why don't we add this to componentDidMount()

Do we need to save property to state?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm setting state on line 83
this.setState({ property: document.documentElement.style.setProperty('--border-show', 'solid') })
Do you think it would still be a better idea to use componentDidMount()?

I was planning on addressing this issue when tackling the new wireframes. I'm not 100% sure we'll need this functionality at all. Most likely, we can just remove it.

handleChange = event => this.setState({
[event.target.name]: event.target.value
})
handleChange = event => {
Copy link
Member

Choose a reason for hiding this comment

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

This code is difficult to follow and somewhat repetitive. How can we refactor? What are we trying to accomplish with this function?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted the ability to check username and email while the user is typing. I only need to do this on two of the four form fields. The other two form fields still need the checkValid function. I went with the conditional to get this to work, but I would love to clean it up some.

The two api calls for checkname() and checkemail() are what drove me to do it this way originally. I may be able to rename the functions and condense down one of the conditionals, but I'll have to play with some ideas. I'm open to suggestions.

Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored the api calls so we can send two arguments. This allowed for the refactoring of handleChange a bit.

Maybe we can still do something with () => { this.checkValid()? I was toying with the idea of placing it once at the end of the function, but I'm having trouble thinking of a way to call the api only when necessary.

}
export const passwordConfirmationTest = (pw, pw2) => {
return pw === pw2
}
Copy link
Member

Choose a reason for hiding this comment

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

can we consolidate this into a single function that will check all inputs and return an object with the relevant errors? For example, if invalid username length but everything else okay, return { usernameLength: true }

Then call this function on every input change (handleChange) and update this.state.errors with the output

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I will try something along those lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

I began dabbling with this issue a little and came across this link.

It discusses the pros and cons of an object of functions or multiple functions. It doesn't solve this particular issue, but I thought it was interesting. It did lead to this bit of brilliance, though.

This

import {
  emailTest,
  emailValid,
  usernameTest,
  usernameLength,
  passwordTest,
  passwordLength,
  passwordCapital,
  passwordLower,
  passwordSpecial,
  passwordNumber,
  passwordConfirmationTest
} from '../../helpers/signUpValidation'

To This

import * as validations from '../../../helpers/signUpValidation'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants