Skip to content

Commit

Permalink
Merge pull request #36 from bunsy-0900/feat/ES-723
Browse files Browse the repository at this point in the history
ES-723
  • Loading branch information
ase-101 authored Jan 29, 2024
2 parents e9ee4d0 + 0c3179b commit 6da2669
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
3 changes: 2 additions & 1 deletion signup-ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
3 changes: 2 additions & 1 deletion signup-ui/public/locales/km.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "លេខមិនអាចចាប់ផ្តើមដោយលេខសូន្យបានទេ។បញ្ចូលលេខទូរស័ព្ទដែលត្រឹមត្រូវ។",
Expand Down
8 changes: 5 additions & 3 deletions signup-ui/src/components/resend-attempt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ interface ResendAttemptProps {
currentAttempts: number;
totalAttempts: number;
attemptRetryAfter?: number;
showRetry?: boolean;
}

export const ResendAttempt = ({
currentAttempts,
totalAttempts,
attemptRetryAfter = 5,
attemptRetryAfter = 300,
showRetry = false,
}: ResendAttemptProps) => {
const { t } = useTranslation();
return (
<>
{currentAttempts < totalAttempts && (
<div className="w-max rounded-md bg-[#FFF7E5] p-2 px-8 text-center text-sm font-semibold text-[#8B6105]">
{t("attempts_left", {
{t(showRetry ? "attempts_left_and_retry" : "attempts_left", {
attemptLeft: currentAttempts,
totalAttempt: totalAttempts,
attemptRetryAfter: attemptRetryAfter,
attemptRetryAfter: attemptRetryAfter / 60,
})}
</div>
)}
Expand Down
26 changes: 15 additions & 11 deletions signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {
Error,
GenerateChallengeRequestDto,
ResetPasswordForm,
ResetPasswordPossibleInvalid,
SettingsDto,
VerifyChallengeRequestDto,
ResetPasswordPossibleInvalid,
} from "~typings/types";

import { resetPasswordFormDefaultValues } from "../ResetPasswordPage";
Expand Down Expand Up @@ -129,22 +129,24 @@ 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]);
} else {
setChallengeVerificationError(errors[0]);
}
}

if (errors.length === 0 && response?.status === "SUCCESS") {
setResendAttempts((resendAttempt) => resendAttempt - 1);
restartResendOtpTotalSecs(
getTimeoutTime(settings.response.configs["resend.delay"])
);
}
},
});
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -349,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 && (
<Button
variant="link"
className="m-4 h-4 px-12 text-sm"
Expand Down
24 changes: 16 additions & 8 deletions signup-ui/src/pages/SignUpPage/Otp/Otp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,24 @@ 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]);
} else {
setChallengeVerificationError(errors[0]);
}
}

if (errors.length === 0 && response?.status === "SUCCESS") {
setResendAttempts((resendAttempt) => resendAttempt - 1);
restartResendOtpTotalSecs(
getTimeoutTime(settings.response.configs["resend.delay"])
);
}
},
});
}
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -339,9 +346,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 && (
<Button
variant="link"
className="m-4 h-4 text-sm"
Expand Down
1 change: 1 addition & 0 deletions signup-ui/src/resources.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface Resources {
something_went_wrong: string;
something_went_wrong_detail: string;
attempts_left: string;
attempts_left_and_retry: string;
captcha_token_validation: string;
username_validation: string;
username_lead_zero_validation: string;
Expand Down

0 comments on commit 6da2669

Please sign in to comment.