@@ -10,18 +10,22 @@ export class ResendOtp {
1010 submitButtonId = 'auth_submit' ,
1111 attemptsDisplayId = 'remaining-attempts' ,
1212 codeInputId = 'auth_code' ,
13- maxAttempts = 5
13+ maxAttempts = 5 ,
1414 } = options ;
1515
1616 this . btn = button ;
1717 this . hint = document . getElementById ( hintId ) ;
1818 this . submitBtn = document . getElementById ( submitButtonId ) ;
1919 this . attemptsDisplay = document . getElementById ( attemptsDisplayId ) ;
2020 this . codeInput = document . getElementById ( codeInputId ) ;
21- this . maxAttempts = maxAttempts ;
2221
2322 this . cooldownSeconds = Number ( button . dataset . cooldown || 60 ) ;
23+ this . maxAttempts = maxAttempts ;
2424 this . url = button . dataset . url ;
25+ this . textDefault = button . dataset . textDefault ;
26+ this . textSending = button . dataset . textSending ;
27+ this . textError = button . dataset . textError ;
28+ this . textCountdown = button . dataset . textCountdown ;
2529 this . storageKey = `otp_resend_until_${ this . url } ` ;
2630
2731 this . timer = null ;
@@ -39,10 +43,9 @@ export class ResendOtp {
3943 }
4044
4145 async resend ( ) {
42- console . log ( 'Resend OTP code requested' ) ;
4346 if ( this . btn . disabled ) return ;
4447
45- this . lock ( 'Sending…' ) ;
48+ this . lock ( this . textSending ) ;
4649
4750 try {
4851 await fetch ( this . url , {
@@ -59,7 +62,7 @@ export class ResendOtp {
5962 } catch ( e ) {
6063 console . error ( e ) ;
6164 this . unlock ( ) ;
62- this . setHint ( 'Could not resend code.' ) ;
65+ this . setHint ( this . textError ) ;
6366 }
6467 }
6568
@@ -90,7 +93,6 @@ export class ResendOtp {
9093
9194 startCooldown ( until ) {
9295 clearInterval ( this . timer ) ;
93- console . log ( `Starting OTP resend cooldown until ${ new Date ( until ) . toISOString ( ) } ` ) ;
9496 const tick = ( ) => {
9597 const remaining = Math . ceil ( ( until - Date . now ( ) ) / 1000 ) ;
9698
@@ -99,7 +101,7 @@ export class ResendOtp {
99101 this . unlock ( ) ;
100102 clearInterval ( this . timer ) ;
101103 } else {
102- this . lock ( `Resend in ${ remaining } s` ) ;
104+ this . lock ( this . textCountdown . replace ( '%d' , remaining ) ) ;
103105 }
104106 } ;
105107
@@ -114,7 +116,7 @@ export class ResendOtp {
114116
115117 unlock ( ) {
116118 this . btn . disabled = false ;
117- this . btn . textContent = 'Resend code' ;
119+ this . btn . textContent = this . textDefault ;
118120 }
119121
120122 setHint ( text ) {
@@ -134,7 +136,6 @@ export class ResendOtp {
134136 }
135137
136138 restoreOnRefresh ( ) {
137- console . log ( 'Restoring OTP resend cooldown if needed' ) ;
138139 const until = this . getStoredUntil ( ) ;
139140 if ( until && until > Date . now ( ) ) {
140141 this . startCooldown ( until ) ;
0 commit comments