From 6d157b44f757eb763de5713e12460be38bfc01e5 Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Sat, 14 Mar 2026 20:35:47 -0700 Subject: [PATCH] Add "Start from Scratch" option to setup wizard for new businesses New users without an existing menu to import can now click "Start from Scratch" to enter their business info and get redirected to the Menu Builder. Co-Authored-By: Claude Opus 4.6 --- portal/setup-wizard.html | 174 ++++++++++++++++++++++++++++++++++----- 1 file changed, 153 insertions(+), 21 deletions(-) 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 @@

Let's Setup Your Menu

-

Import your menu from a website URL or upload images/PDFs

+

Import from an existing source, or start from scratch

@@ -832,6 +832,12 @@ Upload Files + @@ -905,6 +911,23 @@ + + + @@ -1341,25 +1364,126 @@ // Switch between URL and file upload tabs function switchImportTab(tab) { - const tabUrl = document.getElementById('tabUrl'); - const tabUpload = document.getElementById('tabUpload'); - const urlPanel = document.getElementById('urlImportPanel'); - const filePanel = document.getElementById('fileUploadPanel'); + const tabs = { + url: document.getElementById('tabUrl'), + upload: document.getElementById('tabUpload'), + scratch: document.getElementById('tabScratch') + }; + const panels = { + url: document.getElementById('urlImportPanel'), + upload: document.getElementById('fileUploadPanel'), + scratch: document.getElementById('scratchPanel') + }; - if (tab === 'url') { - tabUrl.style.background = 'var(--primary)'; - tabUrl.style.color = 'white'; - tabUpload.style.background = 'var(--gray-100)'; - tabUpload.style.color = 'var(--gray-700)'; - urlPanel.style.display = 'block'; - filePanel.style.display = 'none'; - } else { - tabUpload.style.background = 'var(--primary)'; - tabUpload.style.color = 'white'; - tabUrl.style.background = 'var(--gray-100)'; - tabUrl.style.color = 'var(--gray-700)'; - urlPanel.style.display = 'none'; - filePanel.style.display = 'block'; + Object.keys(tabs).forEach(key => { + if (key === tab) { + tabs[key].style.background = 'var(--primary)'; + tabs[key].style.color = 'white'; + panels[key].style.display = 'block'; + } else { + tabs[key].style.background = 'var(--gray-100)'; + tabs[key].style.color = 'var(--gray-700)'; + panels[key].style.display = 'none'; + } + }); + } + + // Start from scratch — skip import, go straight to business info + function startFromScratch() { + config.scratchMode = true; + config.extractedData = { + business: {}, + categories: [], + modifiers: [], + items: [] + }; + + // Hide upload section, show conversation + document.getElementById('uploadSection').style.display = 'none'; + + showBusinessInfoStep(); + } + + // Save business only (scratch mode) then redirect to Menu Builder + async function saveScratchBusiness() { + // Add a default menu name and community meal type + config.extractedData.menuName = 'Main Menu'; + config.extractedData.communityMealType = 1; + + addMessage('ai', ` +

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