diff --git a/portal/setup-wizard.html b/portal/setup-wizard.html index 49bf0c6..d5b5e71 100644 --- a/portal/setup-wizard.html +++ b/portal/setup-wizard.html @@ -813,7 +813,7 @@
Import your menu from a website URL or upload images/PDFs
+Import from an existing source, or start from scratch
Saving your business information...
+ + `); + + try { + const response = await fetch(`${config.apiBaseUrl}/setup/saveWizard.php`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + businessId: config.businessId || 0, + menuId: 0, + userId: config.userId, + data: config.extractedData, + tempFolder: null + }) + }); + + const responseText = await response.text(); + let result; + try { + result = JSON.parse(responseText); + } catch (e) { + throw new Error('Invalid response from server'); + } + + if (!result.OK) { + const errorMsg = result.errors && result.errors.length > 0 + ? result.errors.join('; ') + : (result.MESSAGE || 'Save failed'); + throw new Error(errorMsg); + } + + const summary = result.summary || result.SUMMARY || {}; + const finalBusinessId = summary.businessId || summary.BUSINESSID || summary.businessid || config.businessId; + + localStorage.setItem('payfrit_portal_business', finalBusinessId); + + // Upload header image if one was selected + if (config.headerImageFile && finalBusinessId) { + try { + const formData = new FormData(); + formData.append('BusinessID', finalBusinessId); + formData.append('header', config.headerImageFile); + + const headerResp = await fetch(`${config.apiBaseUrl}/menu/uploadHeader.php`, { + method: 'POST', + body: formData + }); + const headerResult = await headerResp.json(); + if (!headerResult.OK) { + console.error('Header upload failed:', headerResult.MESSAGE); + } + } catch (headerErr) { + console.error('Header upload error:', headerErr); + } + } + + showToast('Business created! Redirecting to Menu Builder...', 'success'); + + setTimeout(() => { + window.location.href = '/portal/menu-builder.html'; + }, 1500); + + } catch (err) { + console.error('Save error:', err); + showToast('Error: ' + err.message, 'error'); + // Remove the loading message and show retry + addMessage('ai', ` +Something went wrong: ${err.message}
+ + `); } } @@ -2657,12 +2781,20 @@ } function confirmHeaderImage() { - showCategoriesStep(); + if (config.scratchMode) { + saveScratchBusiness(); + } else { + showCategoriesStep(); + } } function skipHeaderImage() { config.headerImageFile = null; - showCategoriesStep(); + if (config.scratchMode) { + saveScratchBusiness(); + } else { + showCategoriesStep(); + } } // Step 2: Categories