| | |
| | | }; |
| | | |
| | | this.forms = this.container.querySelectorAll('form'); |
| | | this.popup = new window.jvbPopup({ |
| | | this.popup = window.jvbPopup.registerPopup({ |
| | | toggle: this.toggle, |
| | | popup: this.container, |
| | | name: 'Referral Box', |
| | |
| | | this.tabs = null; |
| | | |
| | | if (this.container.querySelector('nav.tabs')) { |
| | | this.tabs = new window.jvbTabs(this.container, {updateURL: false}); |
| | | this.tabs = window.jvbTabs.registerTab(this.container, {updateURL: false}); |
| | | } |
| | | |
| | | |
| | |
| | | btn.remove(); |
| | | }); |
| | | } |
| | | this.formController = null; |
| | | } |
| | | |
| | | initStore() { |
| | |
| | | referral_code: formData.get('referral_code') |
| | | }; |
| | | |
| | | if (formData.get('cf-turnstile-response')) { |
| | | data['cf-turnstile-response'] = formData.get('cf-turnstile-response'); |
| | | const turnstileInput = form.querySelector('input[name="cf-turnstile-response"]'); |
| | | if (turnstileInput && turnstileInput.value) { |
| | | data['cf-turnstile-response'] = turnstileInput.value; |
| | | } |
| | | |
| | | if (!data.name || !data.email || !data.referral_code) { |
| | |
| | | } else if (form.id === 'login-form') { |
| | | let data = { |
| | | type: 'login', |
| | | email: formData.get('login_email'), |
| | | user_email: formData.get('login_email'), |
| | | context: { |
| | | redirect_to: window.location.href + '?seeReferral=1' |
| | | } |
| | | }; |
| | | if (formData.get('cf-turnstile-response')) { |
| | | data['cf-turnstile-response'] = formData.get('cf-turnstile-response'); |
| | | const turnstileInput = form.querySelector('input[name="cf-turnstile-response"]'); |
| | | if (turnstileInput && turnstileInput.value) { |
| | | data['cf-turnstile-response'] = turnstileInput.value; |
| | | } |
| | | if (!data.email) { |
| | | if (!data['user_email']) { |
| | | result.message = 'Please fill in your email'; |
| | | } else { |
| | | result = await this.makeRequest('magic', data); |
| | | result = await this.makeRequest('auth/magic', data); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | async makeRequest(endpoint, data) { |
| | | const validEndpoints = [ |
| | | 'magic', |
| | | 'auth/magic', |
| | | 'auth/register' |
| | | ]; |
| | | |
| | |
| | | return { success: false, message: 'Invalid endpoint' }; |
| | | } |
| | | |
| | | const response = await fetch(`${jvbSettings.api}${endpoint}`, { |
| | | const response = await window.auth.fetch(`${jvbSettings.api}${endpoint}`, { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | 'X-WP-Nonce': window.auth.getNonce(), |
| | | }, |
| | | body: JSON.stringify(data) |
| | | }); |
| | | |
| | | // Add error handling to see the actual response |
| | | if (!response.ok) { |
| | | const errorText = await response.text(); |
| | | console.error('Error response:', response.status, errorText); |