mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-18 03:30:39 +09:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
|
|
import { PageTabBar } from "@/components/PageTabBar";
|
||
|
|
import { Tabs } from "@/components/ui/tabs";
|
||
|
|
import { useLocation, useNavigate } from "@/lib/router";
|
||
|
|
|
||
|
|
const items = [
|
||
|
|
{ value: "general", label: "General", href: "/company/settings" },
|
||
|
|
{ value: "access", label: "Access", href: "/company/settings/access" },
|
||
|
|
{ value: "invites", label: "Invites", href: "/company/settings/invites" },
|
||
|
|
] as const;
|
||
|
|
|
||
|
|
type CompanySettingsTab = (typeof items)[number]["value"];
|
||
|
|
|
||
|
|
export function getCompanySettingsTab(pathname: string): CompanySettingsTab {
|
||
|
|
if (pathname.includes("/company/settings/access")) {
|
||
|
|
return "access";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (pathname.includes("/company/settings/invites")) {
|
||
|
|
return "invites";
|
||
|
|
}
|
||
|
|
|
||
|
|
return "general";
|
||
|
|
}
|
||
|
|
|
||
|
|
export function CompanySettingsNav() {
|
||
|
|
const location = useLocation();
|
||
|
|
const navigate = useNavigate();
|
||
|
|
const activeTab = getCompanySettingsTab(location.pathname);
|
||
|
|
|
||
|
|
function handleTabChange(value: string) {
|
||
|
|
const nextTab = items.find((item) => item.value === value);
|
||
|
|
if (!nextTab || nextTab.value === activeTab) return;
|
||
|
|
navigate(nextTab.href);
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Tabs value={activeTab} onValueChange={handleTabChange}>
|
||
|
|
<PageTabBar
|
||
|
|
items={items.map(({ value, label }) => ({ value, label }))}
|
||
|
|
value={activeTab}
|
||
|
|
onValueChange={handleTabChange}
|
||
|
|
align="start"
|
||
|
|
/>
|
||
|
|
</Tabs>
|
||
|
|
);
|
||
|
|
}
|