|
89 | 89 | const modalShortage = document.getElementById("shop-modal-shortage"); |
90 | 90 | const modalForm = document.getElementById("shop-modal-form"); |
91 | 91 | const modalItemId = document.getElementById("shop-modal-item-id"); |
| 92 | + const modalCategory = document.getElementById("shop-modal-category"); |
92 | 93 | const modalVariant = document.getElementById("shop-modal-variant"); |
| 94 | + const modalQuantity = document.getElementById("shop-modal-quantity"); |
93 | 95 | const modalBuy = document.getElementById("shop-modal-buy"); |
94 | 96 | const userBalance = Number(modal?.dataset.userBalance || 0); |
95 | 97 |
|
|
109 | 111 | const name = modal.dataset.itemName || "Item"; |
110 | 112 | const qty = Math.max(1, Number(modalQty?.value || 1)); |
111 | 113 | const totalBolts = baseBolts * qty; |
| 114 | + const totalGrant = grant * qty; |
112 | 115 | if (modalPrice) modalPrice.textContent = String(totalBolts); |
113 | 116 | if (modalDesc) { |
114 | | - modalDesc.textContent = `This item provide a ${grant}$ HCB card grant to spend on a ${name}. Quantity: ${qty}.`; |
| 117 | + modalDesc.textContent = `This provides a $${totalGrant} HCB card grant to spend on a ${name}. Quantity: ${qty}.`; |
115 | 118 | } |
116 | | - // enable/disable buy based on computed total bolts |
117 | | - const canBuy = Boolean(modalItemId?.value) && userBalance >= totalBolts; |
| 119 | + // Sync quantity to hidden form field |
| 120 | + if (modalQuantity) modalQuantity.value = String(qty); |
| 121 | + // Enable buy if user has enough balance (category/variant are always set for grant items) |
| 122 | + const hasValidSelection = Boolean(modalCategory?.value) || Boolean(modalItemId?.value); |
| 123 | + const canBuy = hasValidSelection && userBalance >= totalBolts; |
118 | 124 | if (modalBuy) modalBuy.disabled = !canBuy; |
119 | 125 | if (modalWarning) { |
120 | 126 | const shortage = Math.max(0, totalBolts - userBalance); |
|
129 | 135 | const display = data.display || (data.name ? `${data.name}_${variantLower}` : 'Item'); |
130 | 136 | modalTitle.textContent = display; |
131 | 137 | modalImage.src = data.img || "/images/signin/hackclub.svg"; |
132 | | - // store computation inputs on modal dataset |
| 138 | + // Store computation inputs on modal dataset |
133 | 139 | modal.dataset.baseBolts = String(Number(data.bolts || 0)); |
134 | 140 | modal.dataset.grant = String(Number(data.grant || 0)); |
135 | 141 | modal.dataset.itemName = data.name || "Item"; |
136 | | - // reset qty to 1 each open |
| 142 | + // Reset qty to 1 each open |
137 | 143 | if (modalQty) modalQty.value = "1"; |
138 | | - // compute totals, description, and buy state |
| 144 | + // Set hidden form fields |
| 145 | + if (modalItemId) modalItemId.value = data.itemId || ""; |
| 146 | + if (modalCategory) modalCategory.value = data.name || ""; |
| 147 | + if (modalVariant) modalVariant.value = data.variant || ""; |
| 148 | + if (modalQuantity) modalQuantity.value = "1"; |
| 149 | + // Compute totals, description, and buy state |
139 | 150 | updateModalTotals(); |
140 | | - modalItemId.value = data.itemId || ""; |
141 | | - modalVariant.value = data.variant || ""; |
142 | 151 | modal.classList.remove("modal--hidden"); |
143 | 152 | } |
144 | 153 |
|
|
0 commit comments