Skip to content

Commit 005df0a

Browse files
anuragSharma1112anuragsharma
andauthored
Send otp button issues fixed (#89)
* Send OTP button issue fixed * Send OTP button issue fixed --------- Co-authored-by: anuragsharma <anurag.s@gmail.com>
1 parent 69b4d51 commit 005df0a

5 files changed

Lines changed: 36 additions & 13 deletions

File tree

web-backend/src/main/java/com/statusneo/vms/service/OtpService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public VerificationResult generateOtp(Visit visit, boolean resetAttempts, boolea
107107
// Check cooldown (skip if bypassCooldown requested)
108108
if (!bypassCooldown && latestOtp.getCreatedAt().plusMinutes(RESEND_COOLDOWN_MINUTES).isAfter(LocalDateTime.now())) {
109109
return new VerificationResult(false, true,
110-
"Please wait before requesting a new OTP.");
110+
"Incorrect OTP Check and try again");
111111
}
112112

113113
// Check resend limit

web-backend/src/main/jte/index.jte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@
155155
<div class="flex justify-center pt-4">
156156
<button type="submit"
157157
id="send-otp-btn"
158-
class="px-8 py-4 bg-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors min-w-48 text-lg relative flex items-center justify-center">
159-
<span class="htmx-indicator:hidden">Send OTP</span>
158+
disabled class="px-8 py-4 bg-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors min-w-48 text-lg relative flex items-center justify-center"> <span class="htmx-indicator:hidden">Send OTP</span>
160159
<span class="htmx-indicator absolute inset-0 flex items-center justify-center">
161160
<svg class="inline animate-spin h-5 w-5 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
162161
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
@@ -179,22 +178,22 @@
179178
<!-- Removed a small duplicate autocomplete handler here in favor of the more complete handlers below -->
180179

181180
<script>
182-
// Form validation (host optional)
181+
// Form validation (host is not mandatory)
183182
function validateForm() {
184183
const name = document.getElementById('name').value;
185184
const email = document.getElementById('email').value;
186185
const phone = document.getElementById('phone').value;
187186
const company = document.getElementById('company').value;
188-
// host is optional, do not require hostId to enable send
189187
190188
const isValid = name && email && phone && company;
191189
document.getElementById('send-otp-btn').disabled = !isValid;
192190
}
193191
194-
// Attach validation to all inputs that are required
195192
document.querySelectorAll('input[required]').forEach(input => {
196193
input.addEventListener('input', validateForm);
197194
});
195+
196+
validateForm();
198197
</script>
199198

200199
<script>

web-backend/src/main/resources/templates/index-th.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ <h1 class="text-3xl font-bold text-gray-800 mb-2">Visitor Check-in</h1>
137137
<!-- Submit Button -->
138138
<div class="flex justify-center pt-4">
139139
<button type="submit"
140-
class="px-8 py-4 bg-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors min-w-48 text-lg
141-
flex items-center justify-center"> <span class="htmx-indicator:hidden">Send OTP</span>
140+
id="send-otp-btn" disabled class="px-8 py-4 bg-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors min-w-48 text-lg
141+
flex items-center justify-center"> <span class="htmx-indicator:hidden">Send OTP</span>
142142
<span class="htmx-indicator">
143143
</span>
144144
</button>
@@ -178,6 +178,27 @@ <h1 class="text-3xl font-bold text-gray-800 mb-2">Visitor Check-in</h1>
178178
document.getElementById('host-results').classList.add('hidden');
179179
}
180180
</script>
181+
<script>
182+
// Form validation (host is not mandatory)
183+
function validateForm() {
184+
const name = document.getElementById('name').value;
185+
const email = document.getElementById('email').value;
186+
const phone = document.getElementById('phone').value;
187+
const company = document.getElementById('company').value;
188+
189+
const isValid = name && email && phone && company;
190+
document.getElementById('send-otp-btn').disabled = !isValid;
191+
}
192+
193+
document.querySelectorAll('input[required]').forEach(input => {
194+
input.addEventListener('input', validateForm);
195+
});
196+
197+
validateForm();
198+
</script>
199+
200+
</body>
201+
</html>
181202
</body>
182203
</html>
183204

web-backend/src/main/resources/templates/visitor.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ <h1 class="text-3xl font-bold text-gray-800 mb-2">Visitor Check-in</h1>
113113

114114
<!-- Submit Button -->
115115
<div class="flex justify-center pt-4">
116-
<button type="submit"
117-
class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline-->
118-
flex items-center justify-center"> Send OTP
119-
</button>
116+
<button type="button"
117+
id="send-otp-btn"
118+
disabled onclick="handleSendOTP()"
119+
class="px-8 py-4 bg-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors min-w-48 text-lg relative flex items-center justify-center">
120+
Send OTP </button>
120121
</div>
121122
</div>
122123
</form>
@@ -160,6 +161,8 @@ <h1 class="text-3xl font-bold text-gray-800 mb-2">Visitor Check-in</h1>
160161
input.addEventListener('input', validateForm);
161162
});
162163

164+
validateForm();
165+
163166
// Host search functionality
164167
const hostSearchInput = document.getElementById('host-search');
165168
const hostResults = document.getElementById('host-results');

web-backend/src/test/java/com/statusneo/vms/service/OtpServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void testGenerateOtpFailsDueToCooldown() {
109109
VerificationResult result = otpService.generateOtp(testVisit);
110110

111111
assertFalse(result.success());
112-
assertEquals("Please wait before requesting a new OTP.", result.message());
112+
assertEquals("Incorrect OTP Check and try again", result.message());
113113
verify(emailService, never()).sendEmail(any());
114114
}
115115

0 commit comments

Comments
 (0)