/** * FloatingHelpButton Component * * A floating help button fixed in the top-right corner of the screen. * Automatically determines the help path based on the current route. */ import React from 'react'; import { Link, useLocation } from 'react-router-dom'; import { HelpCircle } from 'lucide-react'; import { useTranslation } from 'react-i18next'; // Map route suffixes to their help page suffixes // These get prefixed appropriately based on context (tenant dashboard or public) const routeToHelpSuffix: Record = { '/': 'dashboard', '/dashboard': 'dashboard', '/scheduler': 'scheduler', '/my-schedule': 'scheduler', '/tasks': 'tasks', '/customers': 'customers', '/services': 'services', '/resources': 'resources', '/locations': 'locations', '/staff': 'staff', '/time-blocks': 'time-blocks', '/my-availability': 'time-blocks', '/messages': 'messages', '/tickets': 'ticketing', '/payments': 'payments', '/contracts': 'contracts', '/contracts/templates': 'contracts', '/automations': 'automations', '/automations/marketplace': 'automations', '/automations/my-automations': 'automations', '/automations/create': 'automations/docs', '/site-editor': 'site-builder', '/gallery': 'site-builder', '/settings': 'settings/general', '/settings/general': 'settings/general', '/settings/resource-types': 'settings/resource-types', '/settings/booking': 'settings/booking', '/settings/appearance': 'settings/appearance', '/settings/branding': 'settings/appearance', '/settings/business-hours': 'settings/business-hours', '/settings/email': 'settings/email', '/settings/email-templates': 'settings/email-templates', '/settings/embed-widget': 'settings/embed-widget', '/settings/staff-roles': 'settings/staff-roles', '/settings/sms-calling': 'settings/communication', '/settings/domains': 'settings/domains', '/settings/api': 'settings/api', '/settings/auth': 'settings/auth', '/settings/billing': 'settings/billing', '/settings/quota': 'settings/quota', }; const FloatingHelpButton: React.FC = () => { const { t } = useTranslation(); const location = useLocation(); // Check if we're on a tenant dashboard route const isOnDashboard = location.pathname.startsWith('/dashboard'); // Get the help path for the current route const getHelpPath = (): string => { // Determine the base help path based on context const helpBase = isOnDashboard ? '/dashboard/help' : '/help'; // Get the route to look up (strip /dashboard prefix if present) const lookupPath = isOnDashboard ? location.pathname.replace(/^\/dashboard/, '') || '/' : location.pathname; // Exact match first if (routeToHelpSuffix[lookupPath]) { return `${helpBase}/${routeToHelpSuffix[lookupPath]}`; } // Try matching with a prefix (for dynamic routes like /customers/:id) const pathSegments = lookupPath.split('/').filter(Boolean); if (pathSegments.length > 0) { // Try progressively shorter paths for (let i = pathSegments.length; i > 0; i--) { const testPath = '/' + pathSegments.slice(0, i).join('/'); if (routeToHelpSuffix[testPath]) { return `${helpBase}/${routeToHelpSuffix[testPath]}`; } } } // Default to the main help page return helpBase; }; const helpPath = getHelpPath(); // Don't show on help pages themselves if (location.pathname.includes('/help')) { return null; } return ( ); }; export default FloatingHelpButton;