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

Get Processing Status from Redis into the frontend #10297

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def register
if current_user
@registration = @competition.registrations.find_or_initialize_by(user_id: current_user.id, competition_id: @competition.id)
@selected_events = @registration.saved_and_unsaved_events.empty? ? @registration.user.preferred_events : @registration.saved_and_unsaved_events
@is_processing = Rails.cache.read(CacheAccess.registration_processing_cache_key(@competition.id, current_user.id)) || false
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/views/registrations/register.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
single: current_user.person&.ranksSingle&.map(&:to_wcif) || [],
average: current_user.person&.ranksAverage&.map(&:to_wcif) || [],
}
}
},
isProcessing: @is_processing,
}) %>
<% else %>
<% if @registration.show_details?(current_user) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function CompetingStep({
registration,
refetchRegistration,
qualifications,
isProcessing,
}) {
const maxEvents = competitionInfo.events_per_registration_limit ?? Infinity;
const isRegistered = Boolean(registration);
Expand Down Expand Up @@ -79,6 +80,10 @@ export default function CompetingStep({

const [processing, setProcessing] = useState(false);
Copy link
Member

@gregorbg gregorbg Nov 22, 2024

Choose a reason for hiding this comment

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

What goes against just using the isProcessing that is passed in from the backend as initial value for this state?

Copy link
Member Author

Choose a reason for hiding this comment

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

When a user refreshes while processing, then processing finishes, react rerenders and it will set it to true again, which will cause it to be stuck in a process -> finish -> process loop

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to fix that with the useEffect, but it still occurs

Copy link
Member

Choose a reason for hiding this comment

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

But the loop is being caused by the useEffect. My point was to remove the useEffect and instead use the initialization value here.

Copy link
Member Author

Choose a reason for hiding this comment

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

it is not. I had it exactly like you proposed previously and it caused the same loop

Copy link
Member Author

Choose a reason for hiding this comment

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

fc0048e
see first commit


useEffect(() => {
setProcessing(isProcessing);
}, [isProcessing]);

useEffect(() => {
if (isRegistered && registration.competing.registration_status !== 'cancelled') {
setComment(registration.competing.comment ?? '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default function StepPanel({
stripePublishableKey,
connectedAccountId,
qualifications,
isProcessing,
}) {
const isRegistered = Boolean(registration) && registration.competing.registration_status !== 'cancelled';
const isAccepted = isRegistered && registration.competing.registration_status === 'accepted';
Expand All @@ -97,6 +98,12 @@ export default function StepPanel({
}, [competitionInfo, isRegistered]);

const [activeIndex, setActiveIndex] = useState(() => {
// skip ahead to competingStep if we are processing
if (isProcessing) {
return steps.findIndex(
(step) => step === competingStepConfig,
);
}
// Don't show payment panel if a user was accepted (for people with waived payment)
if (registrationFinished || isAccepted || isRejected) {
return steps.findIndex(
Expand Down Expand Up @@ -150,6 +157,7 @@ export default function StepPanel({
stripePublishableKey={stripePublishableKey}
connectedAccountId={connectedAccountId}
qualifications={qualifications}
isProcessing={isProcessing}
nextStep={
(overwrites = {}) => setActiveIndex((oldActiveIndex) => {
if (overwrites?.refresh) {
Expand Down
4 changes: 4 additions & 0 deletions app/webpacker/components/RegistrationsV2/Register/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function Index({
qualifications,
stripePublishableKey = '',
connectedAccountId = '',
isProcessing = false,
}) {
return (
<WCAQueryClientProvider>
Expand All @@ -31,6 +32,7 @@ export default function Index({
stripePublishableKey={stripePublishableKey}
connectedAccountId={connectedAccountId}
qualifications={qualifications}
isProcessing={isProcessing}
/>
</ConfirmProvider>
</StoreProvider>
Expand All @@ -46,6 +48,7 @@ function Register({
preferredEvents,
connectedAccountId,
stripePublishableKey,
isProcessing,
}) {
const [timerEnded, setTimerEnded] = useState(false);

Expand Down Expand Up @@ -79,6 +82,7 @@ function Register({
<>
<RegistrationMessage />
<StepPanel
isProcessing={isProcessing}
user={userInfo}
preferredEvents={preferredEvents}
competitionInfo={competitionInfo}
Expand Down