umami/src/components/hooks/useTeamUrl.ts

18 lines
412 B
TypeScript
Raw Normal View History

2024-02-03 01:49:17 +00:00
import { usePathname } from 'next/navigation';
2024-02-05 02:03:26 +00:00
export function useTeamUrl(): {
2024-02-03 01:49:17 +00:00
teamId?: string;
renderTeamUrl: (url: string) => string;
} {
const pathname = usePathname();
const [, teamId] = pathname.match(/^\/teams\/([a-f0-9-]+)/) || [];
function renderTeamUrl(url: string) {
return teamId ? `/teams/${teamId}${url}` : url;
}
return { teamId, renderTeamUrl };
}
2024-02-05 02:03:26 +00:00
export default useTeamUrl;