-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add Register and Sign Up forms #9
Conversation
…c_forms_implementation
breakfastField, | ||
onCostChange, | ||
}: AccomodationFieldGroupProps) => { | ||
const [groupState, setGroupState] = useState<GroupState>({ |
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.
It seems like a perfect use case for reducer
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.
Done
app/client/templates/Register.tsx
Outdated
|
||
const [accomodationCostPerGroup, setAccomodationCostPerGroup] = | ||
React.useState( | ||
accomodationCheckboxesGroups.map(({ dinner, accomodation, breakfast }) => |
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.
That looks wrong; why is this a state and not a simple variable?
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.
Refactored, look comment below.
app/client/templates/Register.tsx
Outdated
); | ||
|
||
const [discountPerGroup, setDiscountPerGroup] = React.useState( | ||
accomodationCheckboxesGroups.map(({ accomodation }) => |
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.
This too
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.
Refactored, look comment below.
app/client/templates/Register.tsx
Outdated
), | ||
); | ||
|
||
const generateAccomodationGroupCostCallback = (groupNumber: number) => { |
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.
That whole logic looks weird. What are we trying to do here?
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.
We need custom logic for accomodation checkboxes - if you check accomodation for a given day, then breakfast and dinner will be checked automatically, but you can uncheck them later manually. And if you don't check accomodation for a given day, then breakfast and dinner should be disabled.
At the same time we need to calculate total accomodation costs based on all of these checkboxes. And their state is kept inside the <AccomodationFieldGroup/>
component, so that's why I created this callback, so that the parent gets updates whenever checkboxes are updated.
I refactored this part by synchronizing state of <AccomodationFieldGroup/>
with Reactivated's form state kept inside useForm()
hook in the Register
template. Let me know what you think about this solution.
}, | ||
}); | ||
|
||
useEffect(() => { |
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 don't like this. If we need to keep it synchronized with Reactivated form state, we must change this logic to use those handlers. Currently, we are doing unnecessary rerender just to keep the state synchronized when we can directly operate on main state.
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.
Done, it actually made the code much simpler.
I was struggling to figure out how to work with Reactivated's form state and I think this is the way, thanks for this comment :)
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.
Now it seems great!
This PR contains:
/accounts/signup/
form/accounts/register/
form/accounts/logout
now redirects user to home page after logout instead of showing a separate logout page<CenteredContainer/>
, so that they behave consistently on different screen sizesTODO next: