From 1e0a88ffaa1ffb715763fd07b1307d883b9295fe Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 14 Aug 2024 14:51:36 -0400 Subject: [PATCH 1/7] 10353-bug: add debounce and deactivate button for new user creation --- .../business/useCases/auth/signUpUserInteractor.ts | 4 ++++ .../CreatePetitionerAccountForm.tsx | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/web-api/src/business/useCases/auth/signUpUserInteractor.ts b/web-api/src/business/useCases/auth/signUpUserInteractor.ts index 87091c8894b..d546e44a9a1 100644 --- a/web-api/src/business/useCases/auth/signUpUserInteractor.ts +++ b/web-api/src/business/useCases/auth/signUpUserInteractor.ts @@ -28,6 +28,10 @@ export const signUpUserInteractor = async ( email: user.email, }); + // Note that this check can fail to catch two (nearly) simultaneous requests, + // and Cognito can therefore create accounts with the same email. + // (See https://stackoverflow.com/questions/50730759/user-pool-allows-two-users-with-same-email-despite-configuration) + // In order to get around it, we need to delete duplicate accounts after they are created. if (existingAccount) { const accountUnconfirmed = existingAccount.accountStatus === UserStatusType.UNCONFIRMED; diff --git a/web-client/src/views/CreatePetitionerAccount/CreatePetitionerAccountForm.tsx b/web-client/src/views/CreatePetitionerAccount/CreatePetitionerAccountForm.tsx index c9971de0789..736cb38d45d 100644 --- a/web-client/src/views/CreatePetitionerAccount/CreatePetitionerAccountForm.tsx +++ b/web-client/src/views/CreatePetitionerAccount/CreatePetitionerAccountForm.tsx @@ -1,6 +1,7 @@ import { Button } from '@web-client/ustc-ui/Button/Button'; import { RequirementsText } from '@web-client/views/CreatePetitionerAccount/RequirementsText'; import { connect } from '@web-client/presenter/shared.cerebral'; +import { debounce } from 'lodash'; import { sequences, state } from '@web-client/presenter/app.cerebral'; import React, { useState } from 'react'; @@ -30,6 +31,12 @@ export const CreatePetitionerAccountForm = connect( }) => { const [inFocusEmail, setInFocusEmail] = useState(true); const [inFocusName, setInFocusName] = useState(true); + const [submitDisabled, setSubmitDisabled] = useState(false); + + const submitFunction = debounce( + () => submitCreatePetitionerAccountFormSequence(), + 500, + ); return ( <> @@ -42,7 +49,8 @@ export const CreatePetitionerAccountForm = connect(
{ e.preventDefault(); - submitCreatePetitionerAccountFormSequence(); + setSubmitDisabled(true); + submitFunction(); }} >