|
1 | 1 | "use client"; |
2 | 2 |
|
| 3 | +import type { Icon as PhosphorIcon } from "@phosphor-icons/react"; |
3 | 4 | import { |
4 | 5 | BuildingsIcon, |
5 | 6 | EnvelopeIcon, |
6 | 7 | GearIcon, |
7 | 8 | GlobeIcon, |
8 | 9 | KeyIcon, |
9 | | - PlusIcon, |
10 | | - UserPlusIcon, |
11 | 10 | UsersIcon, |
12 | 11 | WarningIcon, |
13 | 12 | } from "@phosphor-icons/react"; |
| 13 | +import { useAtomValue } from "jotai"; |
14 | 14 | import { usePathname } from "next/navigation"; |
15 | | -import { useState } from "react"; |
| 15 | +import { useMemo, useState } from "react"; |
16 | 16 |
|
17 | 17 | import { CreateOrganizationDialog } from "@/components/organizations/create-organization-dialog"; |
18 | 18 | import { InviteMemberDialog } from "@/components/organizations/invite-member-dialog"; |
19 | 19 | import { Button } from "@/components/ui/button"; |
20 | 20 | import { Skeleton } from "@/components/ui/skeleton"; |
21 | | -import { useOrganizations } from "@/hooks/use-organizations"; |
| 21 | +import { |
| 22 | + activeOrganizationAtom, |
| 23 | + isLoadingOrganizationsAtom, |
| 24 | +} from "@/stores/jotai/organizationsAtoms"; |
| 25 | + |
| 26 | +type PageInfo = { |
| 27 | + title: string; |
| 28 | + description: string; |
| 29 | + icon: PhosphorIcon; |
| 30 | + requiresOrg?: boolean; |
| 31 | +}; |
| 32 | + |
| 33 | +const PAGE_INFO_MAP: Record<string, PageInfo> = { |
| 34 | + "/organizations": { |
| 35 | + title: "Organizations", |
| 36 | + description: "Manage your organizations and team collaboration", |
| 37 | + icon: BuildingsIcon, |
| 38 | + }, |
| 39 | + "/organizations/members": { |
| 40 | + title: "Team Members", |
| 41 | + description: "Manage team members and their roles", |
| 42 | + icon: UsersIcon, |
| 43 | + requiresOrg: true, |
| 44 | + }, |
| 45 | + "/organizations/invitations": { |
| 46 | + title: "Pending Invitations", |
| 47 | + description: "View and manage pending team invitations", |
| 48 | + icon: EnvelopeIcon, |
| 49 | + requiresOrg: true, |
| 50 | + }, |
| 51 | + "/organizations/settings": { |
| 52 | + title: "General Settings", |
| 53 | + description: "Manage organization name, slug, and basic settings", |
| 54 | + icon: GearIcon, |
| 55 | + requiresOrg: true, |
| 56 | + }, |
| 57 | + "/organizations/settings/websites": { |
| 58 | + title: "Website Management", |
| 59 | + description: "Manage websites associated with this organization", |
| 60 | + icon: GlobeIcon, |
| 61 | + requiresOrg: true, |
| 62 | + }, |
| 63 | + "/organizations/settings/api-keys": { |
| 64 | + title: "API Keys", |
| 65 | + description: "Create and manage API keys for this organization", |
| 66 | + icon: KeyIcon, |
| 67 | + requiresOrg: true, |
| 68 | + }, |
| 69 | + "/organizations/settings/danger": { |
| 70 | + title: "Danger Zone", |
| 71 | + description: "Irreversible and destructive actions", |
| 72 | + icon: WarningIcon, |
| 73 | + requiresOrg: true, |
| 74 | + }, |
| 75 | +}; |
| 76 | + |
| 77 | +const DEFAULT_PAGE_INFO: PageInfo = { |
| 78 | + title: "Organizations", |
| 79 | + description: "Manage your organizations and team collaboration", |
| 80 | + icon: BuildingsIcon, |
| 81 | +}; |
22 | 82 |
|
23 | 83 | export function OrganizationProvider({ |
24 | 84 | children, |
25 | 85 | }: { |
26 | 86 | children: React.ReactNode; |
27 | 87 | }) { |
28 | | - const { activeOrganization, isLoading } = useOrganizations(); |
| 88 | + // Subscribe directly to atoms - no hook overhead |
| 89 | + const activeOrganization = useAtomValue(activeOrganizationAtom); |
| 90 | + const isLoading = useAtomValue(isLoadingOrganizationsAtom); |
| 91 | + |
29 | 92 | const pathname = usePathname(); |
30 | 93 | const [showCreateDialog, setShowCreateDialog] = useState(false); |
31 | 94 | const [showInviteMemberDialog, setShowInviteMemberDialog] = useState(false); |
32 | 95 |
|
33 | | - const getPageInfo = () => { |
34 | | - if (pathname === "/organizations") { |
35 | | - return { |
36 | | - title: "Organizations", |
37 | | - description: "Manage your organizations and team collaboration", |
38 | | - icon: BuildingsIcon, |
39 | | - }; |
40 | | - } |
41 | | - if (pathname === "/organizations/members") { |
42 | | - return { |
43 | | - title: "Team Members", |
44 | | - description: "Manage team members and their roles", |
45 | | - icon: UsersIcon, |
46 | | - requiresOrg: true, |
47 | | - }; |
48 | | - } |
49 | | - if (pathname === "/organizations/invitations") { |
50 | | - return { |
51 | | - title: "Pending Invitations", |
52 | | - description: "View and manage pending team invitations", |
53 | | - icon: EnvelopeIcon, |
54 | | - requiresOrg: true, |
55 | | - }; |
56 | | - } |
57 | | - if (pathname === "/organizations/settings") { |
58 | | - return { |
59 | | - title: "General Settings", |
60 | | - description: "Manage organization name, slug, and basic settings", |
61 | | - icon: GearIcon, |
62 | | - requiresOrg: true, |
63 | | - }; |
64 | | - } |
65 | | - if (pathname === "/organizations/settings/websites") { |
66 | | - return { |
67 | | - title: "Website Management", |
68 | | - description: "Manage websites associated with this organization", |
69 | | - icon: GlobeIcon, |
70 | | - requiresOrg: true, |
71 | | - }; |
72 | | - } |
73 | | - if (pathname === "/organizations/settings/api-keys") { |
74 | | - return { |
75 | | - title: "API Keys", |
76 | | - description: "Create and manage API keys for this organization", |
77 | | - icon: KeyIcon, |
78 | | - requiresOrg: true, |
79 | | - }; |
80 | | - } |
81 | | - if (pathname === "/organizations/settings/danger") { |
82 | | - return { |
83 | | - title: "Danger Zone", |
84 | | - description: "Irreversible and destructive actions", |
85 | | - icon: WarningIcon, |
86 | | - requiresOrg: true, |
87 | | - }; |
88 | | - } |
89 | | - return { |
90 | | - title: "Organizations", |
91 | | - description: "Manage your organizations and team collaboration", |
92 | | - icon: BuildingsIcon, |
93 | | - }; |
94 | | - }; |
95 | | - |
96 | 96 | const { |
97 | 97 | title, |
98 | 98 | description, |
99 | 99 | icon: Icon, |
100 | 100 | requiresOrg, |
101 | | - } = getPageInfo(); |
| 101 | + } = useMemo(() => PAGE_INFO_MAP[pathname] ?? DEFAULT_PAGE_INFO, [pathname]); |
102 | 102 |
|
103 | 103 | if (isLoading) { |
104 | 104 | return ( |
|
0 commit comments