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

Add Register and Sign Up forms #9

Merged
merged 22 commits into from
Jul 31, 2024
Merged

Conversation

bartacc
Copy link
Collaborator

@bartacc bartacc commented Jul 24, 2024

This PR contains:

  • Added /accounts/signup/ form
  • Added /accounts/register/ form
  • Removed reCaptcha from sign up form, because the current solution (django-recaptcha) doesn't work well with Reactivated. In order to implement it some custom code on the backend needs to be written, so I will leave that as a separate task for later.
  • /accounts/logout now redirects user to home page after logout instead of showing a separate logout page
  • Privacy Policy, Sign up rules and Terms and Conditions pages now all use <CenteredContainer/>, so that they behave consistently on different screen sizes

TODO next:

  • In register form there needs to be added an "Add organization" button which will show a modal that allows a user to create a new organization. This will involve some async calls to the backend API, so I left that for next PR.

app/client/components/forms/BasicDescription.tsx Outdated Show resolved Hide resolved
app/client/components/forms/BasicFormField.tsx Outdated Show resolved Hide resolved
breakfastField,
onCostChange,
}: AccomodationFieldGroupProps) => {
const [groupState, setGroupState] = useState<GroupState>({
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


const [accomodationCostPerGroup, setAccomodationCostPerGroup] =
React.useState(
accomodationCheckboxesGroups.map(({ dinner, accomodation, breakfast }) =>
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored, look comment below.

);

const [discountPerGroup, setDiscountPerGroup] = React.useState(
accomodationCheckboxesGroups.map(({ accomodation }) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

This too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored, look comment below.

),
);

const generateAccomodationGroupCostCallback = (groupNumber: number) => {
Copy link
Contributor

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?

Copy link
Collaborator Author

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(() => {
Copy link
Contributor

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.

Copy link
Collaborator Author

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 :)

Copy link
Contributor

@Arsenicro Arsenicro left a 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!

@bartacc bartacc merged commit 364ae8b into develop Jul 31, 2024
1 check passed
@bartacc bartacc deleted the bartacc/basic_forms_implementation branch July 31, 2024 18: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.

2 participants