Merge pull request #1429 from escapade-mckv/user-onboarding-flow

fix
This commit is contained in:
Bobbie 2025-08-23 11:52:18 +05:30 committed by GitHub
commit ae8ed8fdb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 50 additions and 5 deletions

View File

@ -58,6 +58,38 @@ const useAgentConfigTourStore = create<AgentConfigTourState>()(
)
);
const areAllTourTargetsReady = (): boolean => {
const requiredTargets = [
'[data-tour="agent-header"]',
'[data-tour="model-section"]',
'[data-tour="system-prompt"]',
'[data-tour="tools-section"]',
'[data-tour="integrations-section"]',
'[data-tour="knowledge-section"]',
'[data-tour="playbooks-section"]',
'[data-tour="triggers-section"]',
'[data-tour="preview-agent"]',
];
return requiredTargets.every(selector => {
const element = document.querySelector(selector);
return element !== null;
});
};
const waitForTourTargets = (): Promise<void> => {
return new Promise((resolve) => {
const checkTargets = () => {
if (areAllTourTargetsReady()) {
resolve();
} else {
setTimeout(checkTargets, 100);
}
};
checkTargets();
});
};
export const useAgentConfigTour = () => {
const {
toursEnabled,
@ -79,11 +111,23 @@ export const useAgentConfigTour = () => {
useEffect(() => {
if (toursEnabled && !hasSeenTour && !run) {
const timer = setTimeout(() => {
startTour();
}, 500);
const startTourWhenReady = async () => {
try {
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 10000)
);
return () => clearTimeout(timer);
await Promise.race([waitForTourTargets(), timeoutPromise]);
setTimeout(() => {
startTour();
}, 300);
} catch (error) {
console.warn('Tour targets not ready within timeout, skipping tour');
}
};
startTourWhenReady();
}
}, [toursEnabled, hasSeenTour, run, startTour]);
@ -91,6 +135,7 @@ export const useAgentConfigTour = () => {
if (typeof window !== 'undefined') {
(window as any).agentConfigTour = {
resetTour,
checkTargetsReady: areAllTourTargetsReady,
getState: () => ({
hasSeenTour,
run,