1- import React from "react"
1+ import React , { useState } from "react"
22import { Avatar , AvatarFallback , AvatarImage } from "@/components/ui/avatar"
33import { Button } from "@/components/ui/button"
44import { Building2 , Users , Package , Lock , Globe2 , Settings } from "lucide-react"
55import { cn } from "@/lib/utils"
66import { PublicOrgSchema } from "fake-snippets-api/lib/db/schema"
77import { useGlobalStore } from "@/hooks/use-global-store"
8+ import { useLocation } from "wouter"
89
910interface OrganizationHeaderProps {
1011 organization : PublicOrgSchema
1112 isCurrentUserOrganization ?: boolean
1213 className ?: string
14+ showActions ?: boolean
1315}
1416
1517export const OrganizationHeader : React . FC < OrganizationHeaderProps > = ( {
1618 organization,
1719 className,
20+ showActions = true ,
1821} ) => {
1922 const session = useGlobalStore ( ( s ) => s . session )
23+ const [ , navigate ] = useLocation ( )
24+ const canManageOrg =
25+ organization . user_permissions ?. can_manage_org ||
26+ organization . owner_account_id === session ?. account_id
27+
28+ const handleSettingsClick = ( ) => {
29+ navigate ( `/${ organization . name } /settings` )
30+ }
2031 return (
2132 < div className = { cn ( "bg-white border-b border-gray-200" , className ) } >
2233 < div className = "container mx-auto px-6 py-6" >
@@ -40,17 +51,21 @@ export const OrganizationHeader: React.FC<OrganizationHeaderProps> = ({
4051 </ Avatar >
4152
4253 < div >
43- { organization . owner_account_id === session ?. account_id && (
44- < div className = "flex flex-col items-center gap-3 mb-3" >
45- < h1 className = "font-bold text-gray-900 text-xl" >
46- { organization . name }
47- </ h1 >
48- < Button variant = "outline" size = "sm" >
54+ < div className = "flex flex-col items-center gap-3 mb-3" >
55+ < h1 className = "font-bold text-gray-900 text-xl" >
56+ { organization . name }
57+ </ h1 >
58+ { canManageOrg && showActions && (
59+ < Button
60+ variant = "outline"
61+ size = "sm"
62+ onClick = { handleSettingsClick }
63+ >
4964 < Settings className = "mr-2 h-4 w-4" />
5065 Settings
5166 </ Button >
52- </ div >
53- ) }
67+ ) }
68+ </ div >
5469
5570 < div className = "grid grid-cols-2 md:flex flex-wrap justify-center gap-4 text-sm" >
5671 < div className = "flex items-center gap-1.5 text-gray-600" >
@@ -63,20 +78,6 @@ export const OrganizationHeader: React.FC<OrganizationHeaderProps> = ({
6378 < span className = "font-medium" > 2</ span >
6479 < span > packages</ span >
6580 </ div >
66- < div className = "flex items-center gap-1.5 text-gray-600" >
67- < Building2 className = "h-3.5 w-3.5" />
68- < span > Organization</ span >
69- </ div >
70- < div className = "flex items-center gap-1.5 text-gray-600" >
71- { organization . is_personal_org ? (
72- < Lock className = "h-3.5 w-3.5" />
73- ) : (
74- < Globe2 className = "h-3.5 w-3.5" />
75- ) }
76- < span >
77- { organization . is_personal_org ? "Personal" : "Public" }
78- </ span >
79- </ div >
8081 </ div >
8182 </ div >
8283 </ div >
@@ -106,8 +107,8 @@ export const OrganizationHeader: React.FC<OrganizationHeaderProps> = ({
106107 < h1 className = "font-bold text-gray-900 text-2xl md:text-3xl truncate" >
107108 { organization . name }
108109 </ h1 >
109- { organization . owner_account_id === session ?. account_id && (
110- < Button variant = "outline" >
110+ { canManageOrg && showActions && (
111+ < Button variant = "outline" onClick = { handleSettingsClick } >
111112 < Settings className = "mr-2 h-4 w-4" />
112113 Settings
113114 </ Button >
@@ -129,16 +130,6 @@ export const OrganizationHeader: React.FC<OrganizationHeaderProps> = ({
129130 < Building2 className = "h-4 w-4" />
130131 < span > Organization</ span >
131132 </ div >
132- < div className = "flex items-center gap-2" >
133- { organization . is_personal_org ? (
134- < Lock className = "h-4 w-4" />
135- ) : (
136- < Globe2 className = "h-4 w-4" />
137- ) }
138- < span >
139- { organization . is_personal_org ? "Personal" : "Public" }
140- </ span >
141- </ div >
142133 </ div >
143134 </ div >
144135 </ div >
0 commit comments