implemented step 08 by Gemini
addes 2. step of wizard
This commit is contained in:
@ -57,16 +57,36 @@ const App = {
|
||||
},
|
||||
|
||||
syncSelectionWithProject() {
|
||||
if (this.state.project && this.state.project.wizard_data.business_category) {
|
||||
const bc = this.state.project.wizard_data.business_category;
|
||||
this.state.selection.category = bc.group;
|
||||
this.state.selection.subcategory = bc.subcategory;
|
||||
this.state.selection.customDescription = bc.custom_description || '';
|
||||
if (this.state.project && this.state.project.wizard_data) {
|
||||
const wd = this.state.project.wizard_data;
|
||||
|
||||
if (this.state.selection.category) {
|
||||
this.selectCategory(this.state.selection.category);
|
||||
this.state.selection.subcategory = bc.subcategory; // restore after selectCategory resets it
|
||||
this.renderSubcategories(this.state.selection.category);
|
||||
// Step 1
|
||||
if (wd.business_category) {
|
||||
const bc = wd.business_category;
|
||||
this.state.selection.category = bc.group;
|
||||
this.state.selection.subcategory = bc.subcategory;
|
||||
this.state.selection.customDescription = bc.custom_description || '';
|
||||
|
||||
if (this.state.selection.category) {
|
||||
this.selectCategory(this.state.selection.category);
|
||||
this.state.selection.subcategory = bc.subcategory;
|
||||
this.renderSubcategories(this.state.selection.category);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2
|
||||
if (wd.identity) {
|
||||
document.getElementById('business-name').value = wd.identity.business_name || '';
|
||||
document.getElementById('business-tagline').value = wd.identity.tagline || '';
|
||||
document.getElementById('business-description').value = wd.identity.description || '';
|
||||
}
|
||||
if (wd.contact) {
|
||||
document.getElementById('contact-email').value = wd.contact.email || '';
|
||||
document.getElementById('contact-phone').value = wd.contact.phone || '';
|
||||
document.getElementById('contact-address').value = wd.contact.address || '';
|
||||
document.getElementById('contact-city').value = wd.contact.city || '';
|
||||
document.getElementById('contact-facebook').value = wd.contact.socials?.facebook || '';
|
||||
document.getElementById('contact-instagram').value = wd.contact.socials?.instagram || '';
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -145,6 +165,15 @@ const App = {
|
||||
document.getElementById('custom-description').addEventListener('input', (e) => {
|
||||
this.state.selection.customDescription = e.target.value;
|
||||
});
|
||||
|
||||
// Step 2 validation listeners
|
||||
['business-name', 'gdpr-consent', 'contact-email', 'contact-phone'].forEach(id => {
|
||||
const el = document.getElementById(id);
|
||||
if (el) {
|
||||
el.addEventListener('input', () => this.updateUI());
|
||||
el.addEventListener('change', () => this.updateUI());
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
renderCategories() {
|
||||
@ -248,6 +277,53 @@ const App = {
|
||||
alert('Nepodarilo sa uložiť dáta.');
|
||||
return;
|
||||
}
|
||||
} else if (this.state.currentStep === 2) {
|
||||
const businessName = document.getElementById('business-name').value;
|
||||
const tagline = document.getElementById('business-tagline').value;
|
||||
const description = document.getElementById('business-description').value;
|
||||
const email = document.getElementById('contact-email').value;
|
||||
const phone = document.getElementById('contact-phone').value;
|
||||
const address = document.getElementById('contact-address').value;
|
||||
const city = document.getElementById('contact-city').value;
|
||||
const gdpr = document.getElementById('gdpr-consent').checked;
|
||||
|
||||
if (!businessName || !gdpr || (!email && !phone)) {
|
||||
alert('Prosím, vyplňte povinné údaje a zaškrtnite GDPR súhlas.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Save Consent
|
||||
await this.apiCall('saveConsent', {
|
||||
consent_text: document.querySelector('label[for="gdpr-consent"]').textContent
|
||||
});
|
||||
|
||||
// 2. Save Step 2
|
||||
await this.apiCall('saveStep', {
|
||||
step: 2,
|
||||
data: {
|
||||
identity: {
|
||||
business_name: businessName,
|
||||
tagline: tagline,
|
||||
description: description
|
||||
},
|
||||
contact: {
|
||||
email: email,
|
||||
phone: phone,
|
||||
address: address,
|
||||
city: city,
|
||||
socials: {
|
||||
facebook: document.getElementById('contact-facebook').value,
|
||||
instagram: document.getElementById('contact-instagram').value
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Save step 2 failed:', error);
|
||||
alert('Nepodarilo sa uložiť dáta: ' + error.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.state.currentStep < this.state.totalSteps) {
|
||||
@ -267,6 +343,20 @@ const App = {
|
||||
|
||||
btnPrev.disabled = this.state.currentStep === 1;
|
||||
|
||||
// Validation for Next button
|
||||
let nextDisabled = false;
|
||||
if (this.state.currentStep === 1) {
|
||||
nextDisabled = !this.state.selection.category || !this.state.selection.subcategory;
|
||||
} else if (this.state.currentStep === 2) {
|
||||
const name = document.getElementById('business-name').value;
|
||||
const email = document.getElementById('contact-email').value;
|
||||
const phone = document.getElementById('contact-phone').value;
|
||||
const gdpr = document.getElementById('gdpr-consent').checked;
|
||||
nextDisabled = !name || !gdpr || (!email && !phone);
|
||||
}
|
||||
|
||||
btnNext.disabled = nextDisabled;
|
||||
|
||||
if (this.state.currentStep === this.state.totalSteps) {
|
||||
btnNext.textContent = 'Dokončiť';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user