From d7b190a522eca3fdff4199ae08adacf7143a9b72 Mon Sep 17 00:00:00 2001 From: Bunsy Date: Fri, 26 Jan 2024 13:24:48 +0700 Subject: [PATCH 1/3] feat: subtract attempt on success Signed-off-by: Bunsy --- .../src/pages/ResetPasswordPage/Otp/Otp.tsx | 23 +++++++++++-------- signup-ui/src/pages/SignUpPage/Otp/Otp.tsx | 21 +++++++++++------ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx b/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx index d3639b7f..71b2ad09 100644 --- a/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx +++ b/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx @@ -30,9 +30,9 @@ import { Error, GenerateChallengeRequestDto, ResetPasswordForm, + ResetPasswordPossibleInvalid, SettingsDto, VerifyChallengeRequestDto, - ResetPasswordPossibleInvalid, } from "~typings/types"; import { resetPasswordFormDefaultValues } from "../ResetPasswordPage"; @@ -129,15 +129,10 @@ export const Otp = ({ methods, settings }: OtpProps) => { }; return generateChallengeMutation.mutate(generateChallengeRequestDto, { - onSuccess: ({ errors }) => { + onSuccess: ({ response, errors }) => { pinInputRef.current?.clear(); setValue("otp", "", { shouldValidate: true }); - setResendAttempts((resendAttempt) => resendAttempt - 1); - restartResendOtpTotalSecs( - getTimeoutTime(settings.response.configs["resend.delay"]) - ); - if (errors && errors.length > 0) { if (errors[0].errorCode === "invalid_transaction") { setCriticalError(errors[0]); @@ -145,6 +140,13 @@ export const Otp = ({ methods, settings }: OtpProps) => { setChallengeVerificationError(errors[0]); } } + + if (errors.length === 0 && response?.status === "SUCCESS") { + setResendAttempts((resendAttempt) => resendAttempt - 1); + restartResendOtpTotalSecs( + getTimeoutTime(settings.response.configs["resend.delay"]) + ); + } }, }); } @@ -204,9 +206,10 @@ export const Otp = ({ methods, settings }: OtpProps) => { onSuccess: ({ errors }) => { if (errors.length > 0) { if ( - ["invalid_transaction", ...ResetPasswordPossibleInvalid].includes( - errors[0].errorCode - ) + [ + "invalid_transaction", + ...ResetPasswordPossibleInvalid, + ].includes(errors[0].errorCode) ) { setCriticalError(errors[0]); } else { diff --git a/signup-ui/src/pages/SignUpPage/Otp/Otp.tsx b/signup-ui/src/pages/SignUpPage/Otp/Otp.tsx index db62dcb3..6d015781 100644 --- a/signup-ui/src/pages/SignUpPage/Otp/Otp.tsx +++ b/signup-ui/src/pages/SignUpPage/Otp/Otp.tsx @@ -125,15 +125,10 @@ export const Otp = ({ methods, settings }: OtpProps) => { }; return generateChallengeMutation.mutate(generateChallengeRequestDto, { - onSuccess: ({ errors }) => { + onSuccess: ({ response, errors }) => { pinInputRef.current?.clear(); setValue("otp", "", { shouldValidate: true }); - setResendAttempts((resendAttempt) => resendAttempt - 1); - restartResendOtpTotalSecs( - getTimeoutTime(settings.response.configs["resend.delay"]) - ); - if (errors && errors.length > 0) { if (errors[0].errorCode === "invalid_transaction") { setCriticalError(errors[0]); @@ -141,6 +136,13 @@ export const Otp = ({ methods, settings }: OtpProps) => { setChallengeVerificationError(errors[0]); } } + + if (errors.length === 0 && response?.status === "SUCCESS") { + setResendAttempts((resendAttempt) => resendAttempt - 1); + restartResendOtpTotalSecs( + getTimeoutTime(settings.response.configs["resend.delay"]) + ); + } }, }); } @@ -194,7 +196,12 @@ export const Otp = ({ methods, settings }: OtpProps) => { return verifyChallengeMutation.mutate(verifyChallengeRequestDto, { onSuccess: ({ errors }) => { if (errors.length > 0) { - if (["already-registered", "identifier_already_registered"].includes(errors[0].errorCode)) { + if ( + [ + "already-registered", + "identifier_already_registered", + ].includes(errors[0].errorCode) + ) { setStep(SignUpStep.PhoneStatus); } else if (errors[0].errorCode === "invalid_transaction") { setCriticalError(errors[0]); From b3f451538de98473a5bd86dfc8147f5cbeacd64d Mon Sep 17 00:00:00 2001 From: Bunsy Date: Fri, 26 Jan 2024 13:31:05 +0700 Subject: [PATCH 2/3] fix: convert otp blocked to minutes Signed-off-by: Bunsy --- signup-ui/src/components/resend-attempt.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/signup-ui/src/components/resend-attempt.tsx b/signup-ui/src/components/resend-attempt.tsx index a428f452..64fa451c 100644 --- a/signup-ui/src/components/resend-attempt.tsx +++ b/signup-ui/src/components/resend-attempt.tsx @@ -9,7 +9,7 @@ interface ResendAttemptProps { export const ResendAttempt = ({ currentAttempts, totalAttempts, - attemptRetryAfter = 5, + attemptRetryAfter = 300, }: ResendAttemptProps) => { const { t } = useTranslation(); return ( @@ -19,7 +19,7 @@ export const ResendAttempt = ({ {t("attempts_left", { attemptLeft: currentAttempts, totalAttempt: totalAttempts, - attemptRetryAfter: attemptRetryAfter, + attemptRetryAfter: attemptRetryAfter / 60, })} )} From 0c3179ba7c09ca7c7a72a77bc1996ea507f026c6 Mon Sep 17 00:00:00 2001 From: bunsy23 Date: Mon, 29 Jan 2024 07:29:09 +0700 Subject: [PATCH 3/3] feat: show retry after countdown is zero Signed-off-by: bunsy23 --- signup-ui/public/locales/en.json | 3 ++- signup-ui/public/locales/km.json | 3 ++- signup-ui/src/components/resend-attempt.tsx | 4 +++- signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx | 3 ++- signup-ui/src/pages/SignUpPage/Otp/Otp.tsx | 3 ++- signup-ui/src/resources.d.ts | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/signup-ui/public/locales/en.json b/signup-ui/public/locales/en.json index 2e285463..a5b54e36 100644 --- a/signup-ui/public/locales/en.json +++ b/signup-ui/public/locales/en.json @@ -62,7 +62,8 @@ "page_under_construction_detail": "Our experts are working hard to make this page available. Meanwhile, we request you to please visit after some time.", "something_went_wrong": "Something went wrong!", "something_went_wrong_detail": "Our experts are working hard to make things working again.", - "attempts_left": "{attemptLeft, plural, =0 {0 of {totalAttempt} attempts left. Please try again after {attemptRetryAfter} minutes.} other {{attemptLeft} of {totalAttempt} attempts left}}", + "attempts_left": "{attemptLeft, plural, =0 {0 of {totalAttempt} attempts left} other {{attemptLeft} of {totalAttempt} attempts left}}", + "attempts_left_and_retry": "{attemptLeft, plural, =0 {0 of {totalAttempt} attempts left. Please try again after {attemptRetryAfter} minutes.} other {{attemptLeft} of {totalAttempt} attempts left}}", "captcha_token_validation": "Please verify that you are a human.", "username_validation": "Enter a valid username", "username_lead_zero_validation": "Number cannot start with zero. Enter a valid mobile number.", diff --git a/signup-ui/public/locales/km.json b/signup-ui/public/locales/km.json index efac5a54..c9bdb9ea 100644 --- a/signup-ui/public/locales/km.json +++ b/signup-ui/public/locales/km.json @@ -62,7 +62,8 @@ "page_under_construction_detail": "អ្នកជំនាញកំពុងធ្វើការដើម្បីឱ្យទំព័រនេះអាចប្រើប្រាស់បាន។ សូមចូលម្ដងទៀតនៅពេលក្រោយ។", "something_went_wrong": "មានអ្វីមួយខុសប្រក្រតី!", "something_went_wrong_detail": "អ្នកជំនាញកំពុងធ្វើការដើម្បីឱ្យអ្វីៗដំណើរការឡើងវិញ។", - "attempts_left": "{attemptLeft, plural, =0 {ការព្យាយាមនៅសល់ 0 នៃ {totalAttempt}។ សូមព្យាយាមម្តងទៀតនៅ {attemptRetryAfter} នាទីបន្ទាប់។} other {ការព្យាយាមនៅសល់ {attemptLeft} នៃ {totalAttempt}}}", + "attempts_left": "{attemptLeft, plural, =0 {ការព្យាយាមនៅសល់ 0 នៃ {totalAttempt}} other {ការព្យាយាមនៅសល់ {attemptLeft} នៃ {totalAttempt}}}", + "attempts_left_and_retry": "{attemptLeft, plural, =0 {ការព្យាយាមនៅសល់ 0 នៃ {totalAttempt}។ សូមព្យាយាមម្តងទៀតនៅ {attemptRetryAfter} នាទីបន្ទាប់។} other {ការព្យាយាមនៅសល់ {attemptLeft} នៃ {totalAttempt}}}", "captcha_token_validation": "សូមបញ្ជាក់ថាអ្នកជាមនុស្ស", "username_validation": "សូមបញ្ចូលឈ្មោះអ្នកប្រើប្រាស់ត្រឹមត្រូវ", "username_lead_zero_validation": "លេខមិនអាចចាប់ផ្តើមដោយលេខសូន្យបានទេ។បញ្ចូលលេខទូរស័ព្ទដែលត្រឹមត្រូវ។", diff --git a/signup-ui/src/components/resend-attempt.tsx b/signup-ui/src/components/resend-attempt.tsx index 64fa451c..cef25ff8 100644 --- a/signup-ui/src/components/resend-attempt.tsx +++ b/signup-ui/src/components/resend-attempt.tsx @@ -4,19 +4,21 @@ interface ResendAttemptProps { currentAttempts: number; totalAttempts: number; attemptRetryAfter?: number; + showRetry?: boolean; } export const ResendAttempt = ({ currentAttempts, totalAttempts, attemptRetryAfter = 300, + showRetry = false, }: ResendAttemptProps) => { const { t } = useTranslation(); return ( <> {currentAttempts < totalAttempts && (
- {t("attempts_left", { + {t(showRetry ? "attempts_left_and_retry" : "attempts_left", { attemptLeft: currentAttempts, totalAttempt: totalAttempts, attemptRetryAfter: attemptRetryAfter / 60, diff --git a/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx b/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx index 71b2ad09..59b9c120 100644 --- a/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx +++ b/signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx @@ -352,9 +352,10 @@ export const Otp = ({ methods, settings }: OtpProps) => { currentAttempts={resendAttempts} totalAttempts={settings.response.configs["resend.attempts"]} attemptRetryAfter={settings.response.configs["otp.blocked"]} + showRetry={resendAttempts === 0 && resendOtpTotalSecs === 0} /> )} - {resendAttempts === 0 && ( + {resendAttempts === 0 && resendOtpTotalSecs === 0 && (