From 0a285776c75c473783ed0a46dfc2fdffe27009f0 Mon Sep 17 00:00:00 2001 From: Horacio Daniel Ros Date: Tue, 28 Jul 2026 19:14:34 -0300 Subject: [PATCH] refactor: simplify StepEngine action logic and add public link display after onboarding completion --- server/src/index.ts | 7 --- .../components/StepEngine/StepEngine.tsx | 62 +++++++++++++------ 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index 757f6cf..914f648 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -46,13 +46,6 @@ app.use( app.use(json()); -app.use((req, _res, next) => { - if (req.path === '/companies/create') { - require('fs').writeFileSync('request_log.json', JSON.stringify({ body: req.body, headers: req.headers }, null, 2)); - } - next(); -}); - RegisterRoutes(app); app.use(function errorHandler( diff --git a/txclient/src/app/admin/assistant/components/StepEngine/StepEngine.tsx b/txclient/src/app/admin/assistant/components/StepEngine/StepEngine.tsx index 39016cb..e7ee9ff 100644 --- a/txclient/src/app/admin/assistant/components/StepEngine/StepEngine.tsx +++ b/txclient/src/app/admin/assistant/components/StepEngine/StepEngine.tsx @@ -40,6 +40,7 @@ interface StepEngineProps { export default function StepEngine({ flowId, action, initialCompanyId, initialEmployeeId }: StepEngineProps) { const router = useRouter(); const SessionInfo = useSessionStore(); + const isStandaloneAction = Boolean(action && action !== "new-org"); const [currentStepIndex, setCurrentStepIndex] = useState(0); const [imageError, setImageError] = useState(false); @@ -51,6 +52,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm const [orgDescription, setOrgDescription] = useState(""); const [isCreating, setIsCreating] = useState(false); const [createdCompanyId, setCreatedCompanyId] = useState(null); + const [showOnboardingPublicLink, setShowOnboardingPublicLink] = useState(false); // State for Location const [street, setStreet] = useState(""); @@ -487,7 +489,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm }; const proceedNext = () => { - if (action) { + if (isStandaloneAction) { handleActionSuccess(); } else { handleNext(); @@ -554,6 +556,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm const newCompanyId = company?.id || company?._id; if (newCompanyId) { setCreatedCompanyId(newCompanyId); + setSelectedOrganization(company); } else { console.error("No se pudo obtener el ID de la organización creada", company); } @@ -601,7 +604,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm zipCode: zipCode, latitude: latitude, longitude: longitude, - onboardingStep: action ? undefined : currentStepIndex + 1, + onboardingStep: isStandaloneAction ? undefined : currentStepIndex + 1, sessionUser: SessionInfo.userId }); proceedNext(); // Move to Step 5 (Contact) @@ -690,7 +693,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm } // Finish Org Onboarding - if (action) { handleActionSuccess(); } else { router.push("/admin/assistant?flow=onboarding-service"); } + if (isStandaloneAction) { handleActionSuccess(); } else { router.push("/admin/assistant?flow=onboarding-service"); } } catch (error: any) { console.error("Error actualizando apariencia:", error); alert(error?.message || "Hubo un error al guardar la configuración de apariencia."); @@ -1351,7 +1354,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm description={`¿Dónde queda "${orgName}"? Esto es crucial para que tus clientes te encuentren.`} onNext={handleUpdateLocation} disableNext={isCreating} - nextLabel={isCreating ? "Guardando..." : (action ? "Guardar Cambios" : "Siguiente")} + nextLabel={isCreating ? "Guardando..." : (isStandaloneAction ? "Guardar Cambios" : "Siguiente")} >
{ setPreviewServices(res || []); }); - } else if (action) { + } else if (isStandaloneAction) { handleActionSuccess(); } else { router.push("/admin/assistant?flow=onboarding-schedule"); @@ -2048,10 +2051,10 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm } catch (e) { console.error("Error setting onboarding completed", e); } - if (action) { + if (isStandaloneAction) { handleActionSuccess(); } else { - setIsSuccess(true); + setShowOnboardingPublicLink(true); } } catch (error: any) { console.error("Error creando horarios:", error); @@ -4079,8 +4082,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm }; const getSelectedOrganizationSlug = () => { - if (!selectedOrganization) return ""; - return selectedOrganization.slug || (selectedOrganization.name ? getSlug(selectedOrganization.name) : ""); + return selectedOrganization?.slug || getSlug(selectedOrganization?.name || orgName || ""); }; const getPublicLink = () => { @@ -4108,7 +4110,8 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm } }; - const renderPublicLinkFlow = () => { + const renderPublicLinkFlow = (options?: { onboardingCompletion?: boolean }) => { + const isOnboardingCompletion = options?.onboardingCompletion === true; const publicLink = getPublicLink(); const publicLinkQrUrl = getPublicLinkQrUrl(); const orgSlug = getSelectedOrganizationSlug(); @@ -4118,13 +4121,21 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm isActive={true} title="Link público y código QR" description="Compartí este enlace para que tus clientes entren directo a la página pública de reservas de la organización. También podés usar el código QR en redes, vidriera o piezas impresas." - onNext={() => router.push("/admin/assistant")} - nextLabel="Volver al asistente" + onNext={() => { + if (isOnboardingCompletion) { + setShowOnboardingPublicLink(false); + setIsSuccess(true); + return; + } + + router.push("/admin/assistant"); + }} + nextLabel={isOnboardingCompletion ? "Finalizar" : "Volver al asistente"} topAccessory={} >
- Organización: {selectedOrganization?.name || "Sin organización seleccionada"} + Organización: {selectedOrganization?.name || orgName || "Sin organización seleccionada"} {orgSlug && (
Slug público: {orgSlug} @@ -4904,6 +4915,21 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm return renderOnboardingOrgFlow(); // Default to org flow }; + if (showOnboardingPublicLink) { + return ( +
+
+
+ Configuración de Negocio +
+
+
+ {renderPublicLinkFlow({ onboardingCompletion: true })} +
+
+ ); + } + if (isSuccess) { const getSuccessMessage = () => { if (action === "new-service") return "Has agregado tu nuevo servicio exitosamente."; @@ -4917,7 +4943,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm if (flowId === "notifications") return "La configuración de notificaciones se ha guardado exitosamente."; if (flowId === "whatsapp-bot") return "Tu bot de WhatsApp está configurado y funcionando. Tus clientes recibirán notificaciones automáticas por WhatsApp."; if (flowId === "open-reservation-periods") return "El período de reservas fue extendido exitosamente."; - if (action) return "Tus cambios se han guardado exitosamente."; + if (isStandaloneAction) return "Tus cambios se han guardado exitosamente."; return "Has configurado exitosamente tu negocio. Todo está listo para que empieces a recibir reservas y gestionar tu agenda como un profesional."; }; @@ -4971,7 +4997,7 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm