|  | 
| 28 | 28 |  {#if loginFlow === 'email'} | 
| 29 | 29 |  {#if otpId}  | 
| 30 | 30 |  <input type="number" placeholder="Enter OTP" class="w-100 mb-4" bind:value={otp}/> | 
| 31 |  | - <button type="button" class="btn btn-primary w-100" disabled={!!!otp} on:click={verifyOtp}>Verify OTP</button> | 
|  | 31 | + <button type="button" class="btn btn-primary w-100 {verifyOtp ? 'dot-loader' : ''}" disabled={!!!otp} on:click={verifyOtp}> | 
|  | 32 | + {#if verifyOtp}  | 
|  | 33 | + Verifying OTP | 
|  | 34 | + {:else} | 
|  | 35 | + Verify OTP | 
|  | 36 | + {/if} | 
|  | 37 | + </button> | 
| 32 | 38 |  {:else} | 
| 33 | 39 |  <input type="email" placeholder="Enter Email" class="w-100 mb-4" bind:value={email}/> | 
| 34 |  | - <button type="button" class="btn btn-primary w-100" disabled={!!!email} on:click={sendOtp}>Send OTP</button> | 
|  | 40 | + <button type="button" class="btn btn-primary w-100 {sendingOtp ? 'dot-loader' : ''}" disabled={!!!email} on:click={sendOtp}> | 
|  | 41 | + {#if sendingOtp}  | 
|  | 42 | + Sending OTP | 
|  | 43 | + {:else} | 
|  | 44 | + Send Otp | 
|  | 45 | + {/if} | 
|  | 46 | + </button> | 
| 35 | 47 |  {/if} | 
| 36 | 48 |  {:else} | 
| 37 | 49 |  {#if otpId}  | 
| 38 | 50 |  <input type="number" placeholder="Enter OTP" class="w-100 mb-4" bind:value={otp}/> | 
| 39 |  | - <button type="button" class="btn btn-primary w-100" disabled={!!!otp} on:click={verifyOtp}>Verify OTP</button> | 
|  | 51 | + <button type="button" class="btn btn-primary w-100 {verifyOtp ? 'dot-loader' : ''}" disabled={!!!otp} on:click={verifyOtp}> | 
|  | 52 | + {#if verifyingOtp}  | 
|  | 53 | + Verifying OTP | 
|  | 54 | + {:else} | 
|  | 55 | + Verify OTP | 
|  | 56 | + {/if} | 
|  | 57 | + </button> | 
| 40 | 58 |  {:else} | 
| 41 | 59 |  <input type="number" placeholder="Enter 10 digit Mobile Number" class="w-100 mb-4" bind:value={mobile}/> | 
| 42 |  | - <button type="button" class="btn btn-primary w-100" disabled={!!!mobile} on:click={sendOtp}>Send OTP</button> | 
|  | 60 | + <button type="button" class="btn btn-primary w-100 {sendingOtp ? 'dot-loader' : ''}" disabled={!!!mobile} on:click={sendOtp}> | 
|  | 61 | + {#if sendingOtp}  | 
|  | 62 | + Sending OTP | 
|  | 63 | + {:else} | 
|  | 64 | + Send Otp | 
|  | 65 | + {/if} | 
|  | 66 | + </button> | 
| 43 | 67 |  {/if} | 
| 44 | 68 |  {/if} | 
| 45 | 69 | 
 | 
|  | 
| 129 | 153 |  let otp = null | 
| 130 | 154 |  let otpId = null; | 
| 131 | 155 |  let errorMessage = null | 
|  | 156 | + let sendingOtp = false | 
|  | 157 | + let verifyingOtp = false | 
| 132 | 158 |  let loginFlow = 'email' | 
| 133 | 159 |  let showLoginPrompt = localStorage.getItem('cb_login_prompt') === 'true' ? true : false | 
| 134 | 160 |  let googleLoginUrl = appSubdomain.includes('localhost') ? `http://localhost:3838/login/google/v2?redirect_uri=http://${appSubdomain}${pathname}&client=localhost&client_id=1234567890` : isStaging ? `https://account.codingblocks.xyz/login/google/v2?redirect_uri=https://${appSubdomain}.codingblocks.xyz${pathname}&client=${appSubdomain}-codingblocks&client_id=1` : `https://account.codingblocks.com/login/google/v2?redirect_uri=https://${appSubdomain}.codingblocks.com${pathname}&client=${appSubdomain === 'cricket' ? 'cricket-quiz-iccwc23' : appSubdomain}-codingblocks&client_id=${clientIdMap[appSubdomain]}` | 
| 135 | 161 |  let facebookLoginUrl = appSubdomain.includes('localhost') ? `http://localhost:3838/login/facebook/v2?redirect_uri=http://${appSubdomain}${pathname}&client=localhost&client_id=1234567890` : isStaging ? `https://account.codingblocks.xyz/login/facebook/v2?redirect_uri=https://${appSubdomain}.codingblocks.xyz${pathname}&client=${appSubdomain}-codingblocks&client_id=1` : `https://account.codingblocks.com/login/facebook/v2?redirect_uri=https://${appSubdomain}.codingblocks.com${pathname}&client=${appSubdomain === 'cricket' ? 'cricket-quiz-iccwc23': appSubdomain}-codingblocks&client_id=${clientIdMap[appSubdomain]}` | 
| 136 | 162 |  | 
| 137 | 163 |  async function sendOtp() { | 
| 138 | 164 |  errorMessage = null | 
|  | 165 | + sendingOtp = true | 
| 139 | 166 |  const response = await fetch((loginFlow === 'email' ? apiMap.sendOtpEmail[appSubdomain] : apiMap.sendOtpMobile[appSubdomain]) || 'http://localhost:3000/api/jwt/otp', { | 
| 140 | 167 |  method: 'POST', | 
| 141 | 168 |  headers: { | 
|  | 
| 148 | 175 |  }) | 
| 149 | 176 |  }) | 
| 150 | 177 |  if(response.ok) { | 
|  | 178 | + sendingOtp = false | 
| 151 | 179 |  let { id, Details } = await response.json() | 
| 152 | 180 |  otpId = id || Details | 
| 153 | 181 |  } else { | 
|  | 182 | + sendingOtp = false | 
| 154 | 183 |  const { message, Details } = await response.json() | 
| 155 | 184 |  if(message || Details) { | 
| 156 | 185 |  errorMessage = message || Details | 
|  | 
| 160 | 189 |  | 
| 161 | 190 |  async function verifyOtp() { | 
| 162 | 191 |  errorMessage = null | 
|  | 192 | + verifyingOtp = true | 
| 163 | 193 |  | 
| 164 | 194 |  const response = await fetch((loginFlow === 'email' ? apiMap.verifyOtpEmail[appSubdomain] : apiMap.verifyOtpMobile[appSubdomain]) || 'http://localhost:3000/api/jwt/otp/verify', { | 
| 165 | 195 |  method: 'POST', | 
|  | 
| 176 | 206 |  }) | 
| 177 | 207 |  | 
| 178 | 208 |  if(response.ok) { | 
|  | 209 | + verifyingOtp = false | 
| 179 | 210 |  window.location = window.location.origin + '?flow=login' | 
| 180 | 211 |  } else { | 
|  | 212 | + verifyingOtp = false | 
| 181 | 213 |  const { message, Details } = await response.json() | 
| 182 | 214 |  if(message || Details) { | 
| 183 | 215 |  errorMessage = message || Details | 
|  | 
| 295 | 327 |  .social-media-logo { | 
| 296 | 328 |  width: 15px; | 
| 297 | 329 |  } | 
|  | 330 | + | 
|  | 331 | + .dot-loader::after{ | 
|  | 332 | + animation: dots 3s linear infinite; | 
|  | 333 | + content: ''; | 
|  | 334 | + } | 
|  | 335 | + | 
|  | 336 | + @keyframes dots { | 
|  | 337 | + 25% {content: '.'} | 
|  | 338 | + 50% { content: '..'} | 
|  | 339 | + 75% {content: '...'} | 
|  | 340 | + 100% { content: ''} | 
|  | 341 | + } | 
|  | 342 | + | 
| 298 | 343 | </style> | 
0 commit comments