From bdba683f0031f28858dd8cf2a970020b9b136e6a Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Mon, 16 Feb 2026 10:02:26 +0530 Subject: [PATCH] fix: enhance OTP sending logic and add success message display --- src/app/auth/otp/otp.component.html | 28 ++++++++++++++++------------ src/app/auth/otp/otp.component.scss | 20 ++++++++++++++++++++ src/app/auth/otp/otp.component.ts | 22 +++++++++++++++++----- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/app/auth/otp/otp.component.html b/src/app/auth/otp/otp.component.html index 315e9a3..1b2d044 100644 --- a/src/app/auth/otp/otp.component.html +++ b/src/app/auth/otp/otp.component.html @@ -2,11 +2,11 @@
@if(!isOtpSent()){ -

🔐 Login

+

🔐 Login

} @if(isOtpSent() && !isVerified()){ -

🔐 OTP Verification

+

🔐 OTP Verification

} @@ -21,19 +21,9 @@ @if (isOtpSent() && !isVerified()) {
-

- OTP sent to {{ emailForm.value.email }} -

-
- @if (isError()) { -
- - {{ message() }} -
- } @@ -47,5 +37,19 @@
} + + @if (isError()) { +
+ + {{ message() }} +
+ } + + @if (!isError() && isOtpSent() && !isVerified()) { +
+ + {{ message() }} +
+ }
\ No newline at end of file diff --git a/src/app/auth/otp/otp.component.scss b/src/app/auth/otp/otp.component.scss index 1678912..2096add 100644 --- a/src/app/auth/otp/otp.component.scss +++ b/src/app/auth/otp/otp.component.scss @@ -170,4 +170,24 @@ button { color: #ccc; font-size: 14px; margin-bottom: 10px; +} + +/* Success banner for OTP sent */ +.success-banner { + display: flex; + align-items: center; + gap: 8px; + background: rgba(120, 255, 140, 0.07); + border: 1px solid rgba(120, 255, 140, 0.25); + border-radius: 8px; + padding: 10px 14px; + margin: 10px 0 10px; + color: #78ff8c; + font-size: 13px; + + i { + font-size: 15px; + flex-shrink: 0; + color: #78ff8c; + } } \ No newline at end of file diff --git a/src/app/auth/otp/otp.component.ts b/src/app/auth/otp/otp.component.ts index d9bf3e2..b97449c 100644 --- a/src/app/auth/otp/otp.component.ts +++ b/src/app/auth/otp/otp.component.ts @@ -48,15 +48,27 @@ export class OtpComponent implements OnInit { if (this.emailForm.invalid) return; const email = this.emailForm.value.email; - this.authService.sendOtp(email).subscribe(() => { - this.isOtpSent.set(true); - this.message.set('OTP sent successfully!'); - this.startTimer(30); // 30 seconds countdown + this.authService.sendOtp(email).subscribe({ + next: () => { + this.isOtpSent.set(true); + this.isError.set(false); + this.message.set(`OTP sent to ${email}.`); + this.startTimer(30); // 30 seconds countdown + }, + error: (err) => { + this.isError.set(true); + if (err.status === 404) { + this.message.set('Email not found. Please check and try again.'); + } else { + this.message.set('Failed to send OTP. Please try again.'); + } + } }); - } +} resendOtp() { if (this.countdown() > 0) return; + this.otpForm.reset(); this.sendOtp(); }