Sync thank card sending logic and validation with specifications
This commit is contained in:
@@ -451,11 +451,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
}
|
||||
|
||||
// User state for client-side validation
|
||||
let userCard = {{ (int) auth()->user()->card }};
|
||||
let userFlagSend = {{ (int) auth()->user()->flag_send }};
|
||||
|
||||
$submitBtn.addEventListener('click', function(){
|
||||
if (!validateForm()) { return; }
|
||||
|
||||
const msnv = document.getElementById('receiver').value;
|
||||
const amount = document.getElementById('amount').value;
|
||||
const amount = parseInt(document.getElementById('amount').value, 10);
|
||||
|
||||
if (userCard < 0 || userFlagSend === 0) {
|
||||
showModal('Lỗi gửi thẻ',
|
||||
'Bạn không đủ điều kiện gửi thẻ (Số thẻ < 0 hoặc quyền gửi thẻ bị khóa). Vui lòng liên hệ Admin để được cấp thêm.',
|
||||
false);
|
||||
return;
|
||||
}
|
||||
|
||||
showModal('Xác nhận gửi Thank Card',
|
||||
'Đừng quên hoàn thành Thank Card của bạn nhé!\n Chúng mình sẽ gửi thông báo đến người nhận\nđể họ đến khu vực nhận thư.',
|
||||
@@ -477,6 +488,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('amount').value = '1';
|
||||
document.getElementById('confirm_written').checked = false;
|
||||
|
||||
// Update local JS state
|
||||
userCard -= amount;
|
||||
if (userCard <= 0) {
|
||||
userCard = 0;
|
||||
userFlagSend = 0;
|
||||
}
|
||||
|
||||
// Clear local storage for inputs (but not template)
|
||||
localStorage.removeItem('selectedReceiver');
|
||||
localStorage.removeItem('selectedAmount');
|
||||
|
||||
Reference in New Issue
Block a user