SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
import { profileDropdownItems } from '@react/shared/constants/navigation';
import { useAuthCtx } from '@react/shared/contexts/auth.context';
import { useGetUserSettings } from '@react/shared/hooks/useUserSettings';
import { IMembershipTeam } from '@react/shared/types/entities';
import { PAGE_TITLE_MAP } from '@shared/constants/general';
import { userSettingKeys } from '@shared/userSettingKeys';
import { PluginComponents } from '@src/react/shared/plugins/PluginComponents';
import { PluginTarget } from '@src/react/shared/plugins/Plugins';
import { useEffect, useMemo, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { UserAvatar } from './UserAvatar';
export const TopbarPrimary = () => {
const [isLoading, setIsLoading] = useState(true);
const { userInfo, userTeams, getPageAccess } = useAuthCtx();
const [profilePages, setProfilePages] = useState(
profileDropdownItems().filter((p) => {
return (
p.url !== '/teams/settings' && p.url !== '/teams/members' && getPageAccess(p.url)?.read
);
}),
);
const { data: userSettings } = useGetUserSettings(userSettingKeys.USER_TEAM);
const currTeam = useMemo(() => {
return userSettings
? userTeams?.find?.((team: IMembershipTeam) => team.id === userSettings.userSelectedTeam)
: null;
}, [userSettings, userTeams]);
const location = useLocation();
// Function to get title based on current path
const getPageTitle = () => {
if (isLoading) return '';
// Find the matching path prefix
const matchingPath = Object.keys(PAGE_TITLE_MAP).find((path) =>
location.pathname.startsWith(path),
);
if (!matchingPath) return '';
// Special case for agents path - customize with team name
if (matchingPath === '/agents') {
// Handle redundant "Team" text when team name already ends with "Team"
if (currTeam?.name) {
const teamName = currTeam.name;
const endsWithTeam = teamName?.trim()?.toLowerCase()?.endsWith('team');
// If team name ends with "Team", just append "Dashboard"
// Otherwise, append "Team Dashboard"
const suffix = endsWithTeam ? 'Dashboard' : PAGE_TITLE_MAP[matchingPath];
return `${teamName}'s ${suffix}`;
}
return `Your ${PAGE_TITLE_MAP[matchingPath]}`;
}
return PAGE_TITLE_MAP[matchingPath];
};
useEffect(() => {
if (userTeams?.length && userSettings?.userSelectedTeam) {
const currTeam = userTeams?.filter?.((t) => t.id === userSettings?.userSelectedTeam)?.[0];
if (!currTeam?.parentId) {
setProfilePages(
profileDropdownItems().filter(
(p) => p.url !== '/teams/settings' && getPageAccess(p.url)?.read,
),
);
} else {
setProfilePages(
profileDropdownItems().filter((p) => {
return (
p.url !== '/teams/members' &&
p.url !== '/teams/settings' &&
p.url !== '/teams/roles' &&
getPageAccess(p.url)?.read
);
// }
}),
);
}
}
}, [userSettings, userTeams]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (userInfo?.user) setIsLoading(false);
}, [userInfo?.user]);
return (
<nav
id="primary-topbar"
className="flex items-center justify-between mx-auto pl-16 pr-8 md:pl-8 flex-col md:flex-row h-[6rem] md:h-[5.5rem] w-full"
>
<div className="max-w-[240px] sm:max-w-[463px] font-inter text-xl leading-[48px] text-[#242424] truncate ">
{getPageTitle()}
</div>
<div className="flex items-center gap-4 pb-1 md:pb-0">
{/* <TeamSwitch /> */}
<PluginComponents targetId={PluginTarget.TopMenuItem} />
<UserAvatar user={userInfo?.user} profilePages={profilePages} />
</div>
</nav>
);
};