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

[Orders Page] Fix Confirmation modals do not auto-close #13004

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chahmedejaz
Copy link
Collaborator

@chahmedejaz chahmedejaz commented Nov 27, 2024

What? Why?

  • Context: Order cancel error  #12982 (comment)
  • This PR fixes auto-close functionality for all the Orders Page confirmation modals after the confirmation.
  • Moreover, it also fixes the flatpickr invalid locale hu error as mentioned in the issue

What should we test?

  • Validate that you can cancel the order
  • And after cancelation, the modal is closed automatically
  • Along with the above, please validate the following modals such that when you click confirm, they get closed automatically after the intended operation (operation's validity is out of the scope of this issue, we just need to validate whether the modal automatically closes or not).
    • Resend Confirmation
    • Send Invoice Confirmation
  • Lastly, please validate that in the Hungarian locale, when you use any date picker (e.g. on the Order Cycles Page), you can view the calender in the Hungarian locale, and no error should be displayed on the console related to flatpickr.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

- Execute the close method only when the current context modal is opened
// Only execute close if there is an open modal
if (!document.querySelector("body").classList.contains('modal-open')) return;
// Only execute close if the current modal is open
if (!this.modalTarget.classList.contains('in')) return;
Copy link
Collaborator Author

@chahmedejaz chahmedejaz Nov 27, 2024

Choose a reason for hiding this comment

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

This close function is executed whenever the modal:close event is triggered.
On the Orders page, we have 3 confirmation modals e.g.

  • Resend Confirmation
  • Send Invoice Confirmation
  • Cancel Order Confirmation

Consider the scenario where the Cancel Order Confirmation Modal is confirmed, then the modal:close event triggers. This close function gets triggered 3 times for each confirmation modal in sequential order (Resend Confirmation Modal -> Send Invoice Confirmation -> Cancel Order Confirmation) as each is listening for this event.
On the first close execution (for Resend Confirmation Modal), the modal-open class is removed from the body as per Line#20.
So, on further executions (for Send Invoice Confirmation and Cancel Order Confirmation), the existing guard condition would always be true, causing the method to return without any close operation. Further to this point, no other confirmation modal will be closed on the page.
So, updating the guard condition such that the close function only triggers if the current modal is opened.
I hope this explanation makes sense, please let me know if I'm missing something.

Copy link
Member

Choose a reason for hiding this comment

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

Great, it looks like a good change, because it's working more directly on the element associated with the controller, instead of accessing the global context which is generally a bad idea.

@@ -36,6 +37,7 @@ export default class extends Flatpickr {
sv: sv,
tr: tr,
en: en,
hu: hu,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixes the flatpickr invalid locale hu error as mentioned in the issue

Copy link
Member

Choose a reason for hiding this comment

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

Good work.
I think this would be worth mentioning on this page: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Internationalisation-%28i18n%29

It would be a helpful tip for someone when they're adding a new language.

@chahmedejaz chahmedejaz changed the title Fix Confirmation modals do not auto-close [Orders Page] Fix Confirmation modals do not auto-close Nov 27, 2024
@chahmedejaz chahmedejaz marked this pull request as ready for review November 27, 2024 22:58
@chahmedejaz chahmedejaz added bug-s4 The bug is annoying, but doesn't prevent from using the platform. Not so many users are impacted. user facing changes Thes pull requests affect the user experience labels Nov 27, 2024
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Thank you!

The missing locale will probably happen again with new instances. But we don't want to add too many locales to the JS either. It increases the size and other instances don't need it. It would be great to have a more flexible solution where we set the locale on demand and load it from a CDN.

@dacook dacook self-requested a review November 28, 2024 02:09
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great work, and good support. When it's a simple fix it's great to act straight away 👍

// Only execute close if there is an open modal
if (!document.querySelector("body").classList.contains('modal-open')) return;
// Only execute close if the current modal is open
if (!this.modalTarget.classList.contains('in')) return;
Copy link
Member

Choose a reason for hiding this comment

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

Great, it looks like a good change, because it's working more directly on the element associated with the controller, instead of accessing the global context which is generally a bad idea.

@@ -36,6 +37,7 @@ export default class extends Flatpickr {
sv: sv,
tr: tr,
en: en,
hu: hu,
Copy link
Member

Choose a reason for hiding this comment

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

Good work.
I think this would be worth mentioning on this page: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Internationalisation-%28i18n%29

It would be a helpful tip for someone when they're adding a new language.

@chahmedejaz
Copy link
Collaborator Author

The missing locale will probably happen again with new instances. But we don't want to add too many locales to the JS either. It increases the size and other instances don't need it. It would be great to have a more flexible solution where we set the locale on demand and load it from a CDN.

Yes Maikel, I strongly agree with this. Maybe in the future, we could incorporate it.

@chahmedejaz
Copy link
Collaborator Author

Good work.
I think this would be worth mentioning on this page: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Internationalisation-%28i18n%29
It would be a helpful tip for someone when they're adding a new language.

Sure, David, let me add that. Thanks.

@chahmedejaz
Copy link
Collaborator Author

David, It's added in the documentation here now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-s4 The bug is annoying, but doesn't prevent from using the platform. Not so many users are impacted. user facing changes Thes pull requests affect the user experience
Projects
Status: Test Ready 🧪
Development

Successfully merging this pull request may close these issues.

Order cancel error
3 participants