-
Notifications
You must be signed in to change notification settings - Fork 897
refactor(site): SignInForm without wrapper component #558
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
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b3bdf83
Remove wrapper from SignInForm
presleyp d2741c3
Spruce up tests
presleyp 918dd80
Add util for form props
presleyp 73df2da
Add back trim
presleyp e1e12d8
Add unit tests
presleyp 108c77e
Lint, type fixes
presleyp 50e6e0c
Pascal case for language
presleyp 17bc113
Arrow functions
presleyp c5619f8
Target text in e2e
presleyp 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
Lint, type fixes
- Loading branch information
commit 108c77e727127e1b201301f79c51fedf49b12f65
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
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 |
---|---|---|
@@ -1,25 +1,37 @@ | ||
import { FormikContextType } from "formik/dist/types" | ||
import { FormikContextType, getIn } from "formik" | ||
import { ChangeEvent, ChangeEventHandler, FocusEventHandler } from "react" | ||
|
||
export * from "./FormCloseButton" | ||
export * from "./FormSection" | ||
export * from "./FormDropdownField" | ||
export * from "./FormTextField" | ||
export * from "./FormTitle" | ||
|
||
export function getFormHelpers<T>(form: FormikContextType<T>, name: keyof T) { | ||
const touched = form.touched[name] | ||
const errors = form.errors[name] | ||
return { | ||
...form.getFieldProps(name), | ||
id: name, | ||
error: touched && Boolean(errors), | ||
helperText: touched && errors | ||
} | ||
interface FormHelpers { | ||
name: string | ||
onBlur: FocusEventHandler | ||
onChange: ChangeEventHandler | ||
id: string | ||
value?: string | number | ||
error: boolean | ||
helperText?: string | ||
} | ||
|
||
export function getFormHelpers<T>(form: FormikContextType<T>, name: string): FormHelpers { | ||
// getIn is a util function from Formik that gets at any depth of nesting, and is necessary for the types to work | ||
const touched = getIn(form.touched, name) | ||
const errors = getIn(form.errors, name) | ||
return { | ||
...form.getFieldProps(name), | ||
id: name, | ||
error: touched && Boolean(errors), | ||
helperText: touched && errors, | ||
} | ||
} | ||
|
||
export function onChangeTrimmed<T>(form: FormikContextType<T>) { | ||
return (event: React.ChangeEvent<HTMLInputElement>) => { | ||
event.target.value = event?.target?.value?.trim() | ||
export function onChangeTrimmed<T>(form: FormikContextType<T>): (event: ChangeEvent<HTMLInputElement>) => void { | ||
return (event: ChangeEvent<HTMLInputElement>): void => { | ||
event.target.value = event.target.value.trim() | ||
form.handleChange(event) | ||
} | ||
} | ||
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.
praise: nice, this approach seems great to me.
Question on code conventions --> are we going to adopt using
function
instead ofconst
arrow fns for pure functions in v2? Stylistically, it's my preference too. WDYT?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.
I've always preferred arrow functions but I don't know if there's a good reason to anymore. I think you just have to use
function
for generics. What do you prefer about them?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.
These can be safely ported over to arrow fns:
Uh oh!
There was an error while loading. Please reload this page.
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.
Simply the style: when all fns look the same, my brain is happy. I dislike missing braces/early returns and having to scan the difference between a non-fn
const
and a fnconst
.Visualized, I mean:
My brain has to do extra processing to understand version 2, even though it's shorter in length. I think this is due to how much I can "read between the lines". In version one, things are blocked in a way that's easy for me to interpret in the background; ultimately I think I "absorb more information per eye scan" or something like that. In the second version, I often find myself double-passing/re-reading some blocks to understand the big picture.
I won't die on any of these hills, because my brain and its preferences don't get to dictate these things; we make those decisions together as a team. At the end of the day, consistency is best to shoot for, and we already use the arrow fns, so I think we should convert these over to be arrow fns.
The only time we should reach for
function
is for special cases around scopingthis
inside thefunction
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.
Oh thanks, didn't know the trick for making the generic work with an arrow function. But yeah I see your point! I'm down to switch to
function
.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.
I'm going to put this issue on the list of things to discuss at a future FE V and stick to arrows for now.