From fc0048e35ff3b8793a4c2af269d871cd93c011b4 Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Fri, 22 Nov 2024 11:18:19 +0100 Subject: [PATCH 1/4] Get Processing Status from Redis into the frontend --- app/controllers/registrations_controller.rb | 1 + app/views/registrations/register.html.erb | 3 ++- .../components/RegistrationsV2/Register/CompetingStep.jsx | 3 ++- .../components/RegistrationsV2/Register/Processing.jsx | 2 +- .../components/RegistrationsV2/Register/StepPanel.jsx | 8 ++++++++ .../components/RegistrationsV2/Register/index.jsx | 4 ++++ config/locales/en.yml | 2 +- 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 5067acffe9..1e84f7877d 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -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 diff --git a/app/views/registrations/register.html.erb b/app/views/registrations/register.html.erb index 1d59ddff2e..9d5d409243 100644 --- a/app/views/registrations/register.html.erb +++ b/app/views/registrations/register.html.erb @@ -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) %> diff --git a/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx b/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx index 7d33e2674b..4aa9d3c3e7 100644 --- a/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx @@ -52,6 +52,7 @@ export default function CompetingStep({ registration, refetchRegistration, qualifications, + isProcessing, }) { const maxEvents = competitionInfo.events_per_registration_limit ?? Infinity; const isRegistered = Boolean(registration); @@ -77,7 +78,7 @@ export default function CompetingStep({ const [hasInteracted, setHasInteracted] = useState(false); const [guests, setGuests] = useState(0); - const [processing, setProcessing] = useState(false); + const [processing, setProcessing] = useState(isProcessing); useEffect(() => { if (isRegistered && registration.competing.registration_status !== 'cancelled') { diff --git a/app/webpacker/components/RegistrationsV2/Register/Processing.jsx b/app/webpacker/components/RegistrationsV2/Register/Processing.jsx index 36effe95b0..8d8bb80522 100644 --- a/app/webpacker/components/RegistrationsV2/Register/Processing.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/Processing.jsx @@ -35,7 +35,7 @@ export default function Processing({ competitionInfo, user, onProcessingComplete {I18n.t('competitions.registration_v2.register.processing_longer')} )} - {data && data.queueCount > 50 && ( + {data && data.queueCount && ( {I18n.t('competitions.registration_v2.register.processing_queue', { queueCount: data.queueCount, diff --git a/app/webpacker/components/RegistrationsV2/Register/StepPanel.jsx b/app/webpacker/components/RegistrationsV2/Register/StepPanel.jsx index 930bc5707b..de7ebd3af9 100644 --- a/app/webpacker/components/RegistrationsV2/Register/StepPanel.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/StepPanel.jsx @@ -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'; @@ -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( @@ -150,6 +157,7 @@ export default function StepPanel({ stripePublishableKey={stripePublishableKey} connectedAccountId={connectedAccountId} qualifications={qualifications} + isProcessing={isProcessing} nextStep={ (overwrites = {}) => setActiveIndex((oldActiveIndex) => { if (overwrites?.refresh) { diff --git a/app/webpacker/components/RegistrationsV2/Register/index.jsx b/app/webpacker/components/RegistrationsV2/Register/index.jsx index 1fadef42e1..bb363bd0af 100644 --- a/app/webpacker/components/RegistrationsV2/Register/index.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/index.jsx @@ -18,6 +18,7 @@ export default function Index({ qualifications, stripePublishableKey = '', connectedAccountId = '', + isProcessing = false, }) { return ( @@ -31,6 +32,7 @@ export default function Index({ stripePublishableKey={stripePublishableKey} connectedAccountId={connectedAccountId} qualifications={qualifications} + isProcessing={isProcessing} /> @@ -46,6 +48,7 @@ function Register({ preferredEvents, connectedAccountId, stripePublishableKey, + isProcessing, }) { const [timerEnded, setTimerEnded] = useState(false); @@ -79,6 +82,7 @@ function Register({ <> Date: Fri, 22 Nov 2024 12:47:34 +0200 Subject: [PATCH 2/4] Update en.yml --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index fd7b828e64..5b2cef4a56 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1911,7 +1911,7 @@ en: waiting_list: "You are on the Waiting List at position %{waiting_list_position}." disclaimer: "Submission of Registration does not mean approval to compete" processing: "Your registration is processing..." - processing_longer: "Your registration has been received, and will be processed soon. Our servers are busy at the moment. You can safely close or refresh this page. (Note: Refreshing won't make anything go faster!)" + processing_longer: "Your registration has been received, and will be processed soon - this can take up to 20 seconds if our servers are busy. You can safely close or refresh this page. (Note: Refreshing won't make anything go faster!)" processing_queue: "Lots of Registrations being processed, %{queueCount} in the queue." event_limit: "This competition limits the amount of events you can register for to %{max_events}." errors: From 571f9a38e24cef9ae0b19f97f9e3bbbb8bc423f3 Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Fri, 22 Nov 2024 12:07:22 +0100 Subject: [PATCH 3/4] only set isProcessing in useEffect --- .../components/RegistrationsV2/Register/CompetingStep.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx b/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx index 4aa9d3c3e7..508f479fab 100644 --- a/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/CompetingStep.jsx @@ -78,7 +78,11 @@ export default function CompetingStep({ const [hasInteracted, setHasInteracted] = useState(false); const [guests, setGuests] = useState(0); - const [processing, setProcessing] = useState(isProcessing); + const [processing, setProcessing] = useState(false); + + useEffect(() => { + setProcessing(isProcessing); + }, [isProcessing]); useEffect(() => { if (isRegistered && registration.competing.registration_status !== 'cancelled') { From f51eec371db6339d1eb7558e98947bfb67664757 Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Fri, 22 Nov 2024 12:31:06 +0100 Subject: [PATCH 4/4] revert changes that are now part of the other PR --- .../components/RegistrationsV2/Register/Processing.jsx | 2 +- config/locales/en.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/webpacker/components/RegistrationsV2/Register/Processing.jsx b/app/webpacker/components/RegistrationsV2/Register/Processing.jsx index 8d8bb80522..36effe95b0 100644 --- a/app/webpacker/components/RegistrationsV2/Register/Processing.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/Processing.jsx @@ -35,7 +35,7 @@ export default function Processing({ competitionInfo, user, onProcessingComplete {I18n.t('competitions.registration_v2.register.processing_longer')} )} - {data && data.queueCount && ( + {data && data.queueCount > 50 && ( {I18n.t('competitions.registration_v2.register.processing_queue', { queueCount: data.queueCount, diff --git a/config/locales/en.yml b/config/locales/en.yml index 5b2cef4a56..6b38d598aa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1911,7 +1911,7 @@ en: waiting_list: "You are on the Waiting List at position %{waiting_list_position}." disclaimer: "Submission of Registration does not mean approval to compete" processing: "Your registration is processing..." - processing_longer: "Your registration has been received, and will be processed soon - this can take up to 20 seconds if our servers are busy. You can safely close or refresh this page. (Note: Refreshing won't make anything go faster!)" + processing_longer: "Processing is taking longer than usual, don't go away!" processing_queue: "Lots of Registrations being processed, %{queueCount} in the queue." event_limit: "This competition limits the amount of events you can register for to %{max_events}." errors: