1- "use client"
2-
3- import { useState } from "react"
1+ import { createInviteLink , getBaseUrl } from "@/lib/utils"
42import { AnonymousAccessToggle } from "./anonymousAccessToggle"
5- import { MemberApprovalRequiredToggle } from "./memberApprovalRequiredToggle"
6- import { InviteLinkToggle } from "./inviteLinkToggle"
7-
8- interface OrganizationAccessSettingsProps {
9- anonymousAccessEnabled : boolean
10- memberApprovalRequired : boolean
11- inviteLinkEnabled : boolean
12- inviteLink : string | null
13- }
3+ import { OrganizationAccessSettingsWrapper } from "./organizationAccessSettingsWrapper"
4+ import { getOrgFromDomain } from "@/data/org"
5+ import { getOrgMetadata } from "@/types"
6+ import { headers } from "next/headers"
7+ import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants"
8+ import { hasEntitlement } from "@sourcebot/shared"
149
15- export function OrganizationAccessSettings ( {
16- anonymousAccessEnabled,
17- memberApprovalRequired,
18- inviteLinkEnabled,
19- inviteLink
20- } : OrganizationAccessSettingsProps ) {
21- const [ showInviteLink , setShowInviteLink ] = useState ( memberApprovalRequired && ! anonymousAccessEnabled )
22- const handleMemberApprovalToggle = ( checked : boolean ) => {
23- setShowInviteLink ( checked )
10+ export async function OrganizationAccessSettings ( ) {
11+ const org = await getOrgFromDomain ( SINGLE_TENANT_ORG_DOMAIN ) ;
12+ if ( ! org ) {
13+ return < div > Error loading organization</ div >
2414 }
2515
16+ const metadata = getOrgMetadata ( org ) ;
17+ const anonymousAccessEnabled = metadata ?. anonymousAccessEnabled ?? false ;
18+
19+ const headersList = headers ( ) ;
20+ const baseUrl = getBaseUrl ( headersList ) ;
21+ const inviteLink = createInviteLink ( baseUrl , org . inviteLinkId )
22+
23+ const hasAnonymousAccessEntitlement = hasEntitlement ( "anonymous-access" ) ;
24+
2625 return (
2726 < div className = "space-y-6" >
2827 < AnonymousAccessToggle
28+ hasAnonymousAccessEntitlement = { hasAnonymousAccessEntitlement }
2929 anonymousAccessEnabled = { anonymousAccessEnabled }
3030 />
3131
32- < div className = { `transition-all duration-300 ease-in-out overflow-hidden max-h-96 opacity-100` } >
33- < MemberApprovalRequiredToggle
34- memberApprovalRequired = { memberApprovalRequired }
35- onToggleChange = { handleMemberApprovalToggle }
36- />
37- </ div >
38-
39- < div className = { `transition-all duration-300 ease-in-out overflow-hidden ${
40- showInviteLink
41- ? 'max-h-96 opacity-100'
42- : 'max-h-0 opacity-0 pointer-events-none'
43- } `} >
44- < InviteLinkToggle
45- inviteLinkEnabled = { inviteLinkEnabled }
46- inviteLink = { inviteLink }
47- />
48- </ div >
32+ < OrganizationAccessSettingsWrapper
33+ memberApprovalRequired = { org . memberApprovalRequired }
34+ inviteLinkEnabled = { org . inviteLinkEnabled }
35+ inviteLink = { inviteLink }
36+ anonymousAccessEnabled = { anonymousAccessEnabled }
37+ />
4938 </ div >
5039 )
5140}
0 commit comments