rmdzav commited on
Commit
f121bbc
·
verified ·
1 Parent(s): fe99e4b

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +94 -41
static/script.js CHANGED
@@ -30,6 +30,47 @@ document.addEventListener('DOMContentLoaded', () => {
30
  let deviceFingerprint = null;
31
  let hasPremium = false;
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  // ========== Toast System ==========
34
  function showToast(message, type = 'info') {
35
  const container = document.getElementById('toast-container');
@@ -144,52 +185,64 @@ document.addEventListener('DOMContentLoaded', () => {
144
  });
145
 
146
  buySubmitBtn.addEventListener('click', async () => {
147
- const name = buyName.value.trim();
148
- const email = buyEmail.value.trim();
149
- const payment = buyPayment.value;
150
 
151
- if (!name) {
152
- showToast('Nama lengkap harus diisi', 'warning');
153
- return;
154
- }
155
- if (!email || !email.includes('@')) {
156
- showToast('Email tidak valid', 'warning');
157
- return;
158
- }
159
- if (!payment) {
160
- showToast('Pilih metode pembayaran', 'warning');
161
- return;
162
- }
163
 
164
- const originalText = buySubmitBtn.textContent;
165
- buySubmitBtn.textContent = 'Memproses...';
166
- buySubmitBtn.disabled = true;
167
 
168
- try {
169
- const res = await fetch('/api/buy-license', {
170
- method: 'POST',
171
- headers: { 'Content-Type': 'application/json' },
172
- body: JSON.stringify({ name, email, payment })
173
- });
174
- const result = await res.json();
175
 
176
- if (result.success) {
177
- buyModal.classList.remove('active');
178
- showToast(`✅ Pesanan berhasil! Lisensi akan dikirim ke ${email}`, 'success');
179
- buyName.value = '';
180
- buyEmail.value = '';
181
- buyPayment.value = '';
182
- } else {
183
- showToast(result.msg || 'Gagal memproses', 'error');
184
- }
185
- } catch (e) {
186
- showToast('Gagal terhubung ke server', 'error');
187
- } finally {
188
- buySubmitBtn.textContent = originalText;
189
- buySubmitBtn.disabled = false;
190
  }
191
- });
192
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  // Close modals on overlay click
194
  document.querySelectorAll('.premium-modal__overlay, .buy-modal__overlay').forEach(overlay => {
195
  overlay.addEventListener('click', () => {
 
30
  let deviceFingerprint = null;
31
  let hasPremium = false;
32
 
33
+ // ========== Custom Select ==========
34
+ const customSelect = document.querySelector('.custom-select');
35
+ const selectTrigger = document.querySelector('.custom-select__trigger');
36
+ const selectOptions = document.querySelectorAll('.custom-select__option');
37
+ const hiddenPaymentInput = document.getElementById('buy-payment');
38
+
39
+ if (customSelect) {
40
+ selectTrigger.addEventListener('click', (e) => {
41
+ e.stopPropagation();
42
+ customSelect.classList.toggle('active');
43
+ });
44
+
45
+ selectOptions.forEach(option => {
46
+ option.addEventListener('click', () => {
47
+ const value = option.getAttribute('data-value');
48
+ const text = option.querySelector('span:last-child').innerText;
49
+ const icon = option.querySelector('.option-icon').innerHTML;
50
+
51
+ // Update trigger text
52
+ selectTrigger.querySelector('span:first-child').innerHTML = `${icon} ${text}`;
53
+
54
+ // Set hidden input value
55
+ hiddenPaymentInput.value = value;
56
+
57
+ // Update selected class
58
+ selectOptions.forEach(opt => opt.classList.remove('selected'));
59
+ option.classList.add('selected');
60
+
61
+ // Close dropdown
62
+ customSelect.classList.remove('active');
63
+ });
64
+ });
65
+
66
+ // Close dropdown when clicking outside
67
+ document.addEventListener('click', (e) => {
68
+ if (!customSelect.contains(e.target)) {
69
+ customSelect.classList.remove('active');
70
+ }
71
+ });
72
+ }
73
+
74
  // ========== Toast System ==========
75
  function showToast(message, type = 'info') {
76
  const container = document.getElementById('toast-container');
 
185
  });
186
 
187
  buySubmitBtn.addEventListener('click', async () => {
188
+ const name = buyName.value.trim();
189
+ const email = buyEmail.value.trim();
190
+ const payment = hiddenPaymentInput.value; // Ambil dari hidden input
191
 
192
+ if (!name) {
193
+ showToast('Nama lengkap harus diisi', 'warning');
194
+ return;
195
+ }
196
+ if (!email || !email.includes('@')) {
197
+ showToast('Email tidak valid', 'warning');
198
+ return;
199
+ }
200
+ if (!payment) {
201
+ showToast('Pilih metode pembayaran', 'warning');
202
+ return;
203
+ }
204
 
205
+ const originalText = buySubmitBtn.textContent;
206
+ buySubmitBtn.textContent = 'Memproses...';
207
+ buySubmitBtn.disabled = true;
208
 
209
+ try {
210
+ const res = await fetch('/api/buy-license', {
211
+ method: 'POST',
212
+ headers: { 'Content-Type': 'application/json' },
213
+ body: JSON.stringify({ name, email, payment })
214
+ });
215
+ const result = await res.json();
216
 
217
+ if (result.success) {
218
+ buyModal.classList.remove('active');
219
+ showToast(`✅ Pesanan berhasil! Lisensi akan dikirim ke ${email}`, 'success');
220
+ // Reset form
221
+ buyName.value = '';
222
+ buyEmail.value = '';
223
+ hiddenPaymentInput.value = '';
224
+ selectTrigger.querySelector('span:first-child').innerHTML = 'Pilih Metode Pembayaran';
225
+ selectOptions.forEach(opt => opt.classList.remove('selected'));
226
+ } else {
227
+ showToast(result.msg || 'Gagal memproses', 'error');
 
 
 
228
  }
229
+ } catch (e) {
230
+ showToast('Gagal terhubung ke server', 'error');
231
+ } finally {
232
+ buySubmitBtn.textContent = originalText;
233
+ buySubmitBtn.disabled = false;
234
+ }
235
+ });
236
+
237
+ buyCancelBtn.addEventListener('click', () => {
238
+ buyModal.classList.remove('active');
239
+ buyName.value = '';
240
+ buyEmail.value = '';
241
+ hiddenPaymentInput.value = '';
242
+ selectTrigger.querySelector('span:first-child').innerHTML = 'Pilih Metode Pembayaran';
243
+ selectOptions.forEach(opt => opt.classList.remove('selected'));
244
+ });
245
+
246
  // Close modals on overlay click
247
  document.querySelectorAll('.premium-modal__overlay, .buy-modal__overlay').forEach(overlay => {
248
  overlay.addEventListener('click', () => {