worldcubeassociation.org icon indicating copy to clipboard operation
worldcubeassociation.org copied to clipboard

Dues calculation no longer takes into account the minimum due amount

Open Jambrose777 opened this issue 3 years ago • 8 comments

Describe the bug The dues estimation on WCA when creating a competition no longer takes into account the minimum due amount (for US it is currently $1). This causes the estimation to be wrong:

image

Jambrose777 avatar Aug 15 '22 16:08 Jambrose777

For context: When you say "no longer", can you confirm that it was correct at some point in the past? Just wondering because we haven't really touched that part of the code in a while.

gregorbg avatar Aug 17 '22 09:08 gregorbg

I am 90% certain it was correct when it was implemented, but not certain.

Jambrose777 avatar Aug 17 '22 15:08 Jambrose777

Hi Jacob, I'm trying to replicate this locally but on my end it took the minimum amount into account:

image

I imagine the comp is GA Cubers Turkey Gobblers 2022? Sorry if this was creepy but I logged into your dummy account on dev to see where exactly the issue is :P. But here it appeared fine.

notrichardpeng avatar Aug 26 '22 19:08 notrichardpeng

Just looked at it. It is correct in production now.

I did repro this by doing the following: Competitions > New competition Fill in country as United States Fill in competitor limit (100) Fill in base registration fee ($5) Notice it does not account for the minimum.

If I had to guess its not taking into account the country when first creating the forum.

Jambrose777 avatar Aug 26 '22 19:08 Jambrose777

I see now. Yeah after hitting "create competition" it becomes correct. I think adding a callback for when country changes can fix this.

notrichardpeng avatar Aug 26 '22 20:08 notrichardpeng

Actually it wouldn't be that easy; getting the country band needs the backend function CountryBand.where, so I don't think it can update dynamically with frontend changes. Maybe the fix here is to just add a note saying something along the lines of "hit Update Competition after changing the country" or "Refresh the page after indicating the country to make estimation accurate"?

notrichardpeng avatar Aug 26 '22 20:08 notrichardpeng

I think this should be possible without saving. Note that fields like the "Country" dropdown or the "Currency code" selector can all be dynamically read and evaluated through jQuery.

Right now, you rely on the @competition object from Ruby to obtain this information. Of course, you have to save before this value updates. Butt what if you use JS to do something like var country = $('select[name="competition[country]"]').val() (and analogously, var currencyCode = $('select[name="competition[currency_code]"]').val())?

Of course, you cannot take those JS variables and stuff them back into the Ruby CountryBand::BANDS hash at runtime. What you can do however, is to dynamically gather all of the various values (currency code, country, competitor limit, etc.) using jQuery, then AJAX them down to the Ruby backend, have the backend do all of the complex computation logic that you're (partially) doing in JS right now, and only handle the actual display logic back in the JS world.

This would also make the code a whole lot cleaner in terms of "separation of concerns". What do you think?

gregorbg avatar Aug 31 '22 01:08 gregorbg

This sounds like a great solution and I don't have oppositions to it. I'll just need some time to implement it.

notrichardpeng avatar Aug 31 '22 20:08 notrichardpeng

One question regarding this is whether a React implementation would change some of the elements described here. For example, we are looking to phase out JQUery. Unless this is a high priority item, perhaps the note to "Refresh the page after indicating the country" is our best interim solution?

dunkOnIT avatar Oct 20 '22 14:10 dunkOnIT

It's been a while, so same question as @dunkOnIT. I think I should still proceed with the jQuery approach? It seems that a React implementation of this page would take considerable effort so I imagine the jQuery/AJAX code could last quite a while.

notrichardpeng avatar Nov 09 '22 04:11 notrichardpeng

There is absolutely no need to move the entire competition form to React just for the sake of resolving this issue. You can stick with the jQuery implementation but clean it up a little. Think of it as groundwork and preparation for the full React migration :)

As to the specific implementation, I would like all of the calculations be handled by the backend. JavaScript should not make any kind of assumptions or if-else-cases on how or when or why or which fee to calculate. The only job of JS should be to bundle all the necessary information so that Ruby can make a well-informed decision, AJAX that information down to an endpoint, let the endpoint handle all of the business logic, and then (more or less) stupidly dsiplay whatever the endpoint returns, without thinking about how or why that result came to be.

EDIT: My favored approach is pretty much completely described in my previous comment at https://github.com/thewca/worldcubeassociation.org/issues/7143#issuecomment-1232354470

gregorbg avatar Nov 09 '22 09:11 gregorbg

Fixed per https://github.com/thewca/worldcubeassociation.org/pull/7377

gregorbg avatar Dec 18 '22 04:12 gregorbg