Skip to content

Commit

Permalink
Initialized sidebar and menu-option, update user org layout
Browse files Browse the repository at this point in the history
  • Loading branch information
yashdev9274 committed May 9, 2024
1 parent c9e3ffe commit 505bb7d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/app/(main)/agency/[agencyId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'

type Props = {
children: React.ReactNode
params: { agencyId: string }
}

const layout = ({ children, params }: Props) => {
return (
<div>layout</div>
)
}

export default layout;
71 changes: 71 additions & 0 deletions src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { getAuthUserDetails } from '@/lib/queries'
import { off } from 'process'
import React from 'react'
import MenuOptions from './menu-options'

type Props = {
id: string
type: 'agency' | 'subaccount'
}

const Sidebar = async ({ id, type }: Props) => {
const user = await getAuthUserDetails()
if (!user) return null

if (!user.Agency) return

const details =
type === 'agency'
? user?.Agency
: user?.Agency.SubAccount.find((subaccount) => subaccount.id === id)

const isWhiteLabeledAgency = user.Agency.whiteLabel
if (!details) return

let sideBarLogo = user.Agency.agencyLogo || '/assets/plura-logo.svg'

if (!isWhiteLabeledAgency) {
if (type === 'subaccount') {
sideBarLogo =
user?.Agency.SubAccount.find((subaccount) => subaccount.id === id)
?.subAccountLogo || user.Agency.agencyLogo
}
}

const sidebarOpt =
type === 'agency'
? user.Agency.SidebarOption || []
: user.Agency.SubAccount.find((subaccount) => subaccount.id === id)
?.SidebarOption || []

const subaccounts = user.Agency.SubAccount.filter((subaccount) =>
user.Permissions.find(
(permission) =>
permission.subAccountId === subaccount.id && permission.access
)
)

return (
<>
<MenuOptions
defaultOpen={true}
details={details}
id={id}
sidebarLogo={sideBarLogo}
sidebarOpt={sidebarOpt}
subAccounts={subaccounts}
user={user}
/>
<MenuOptions
details={details}
id={id}
sidebarLogo={sideBarLogo}
sidebarOpt={sidebarOpt}
subAccounts={subaccounts}
user={user}
/>
</>
)
}

export default Sidebar
46 changes: 46 additions & 0 deletions src/components/sidebar/menu-options.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
import {
Agency,
AgencySidebarOption,
SubAccount,
SubAccountSidebarOption,
} from '@prisma/client'
import { useEffect, useMemo, useState } from 'react'

type Props = {

defaultOpen?: boolean
subAccounts: SubAccount[]
sidebarOpt: AgencySidebarOption[] | SubAccountSidebarOption[]
sidebarLogo: string
details: any
user: any
id: string
}

const MenuOptions = ({
details,
id,
sidebarLogo,
sidebarOpt,
subAccounts,
user,
defaultOpen,
}: Props) => {
// const { setOpen } = useModal()
const [isMounted, setIsMounted] = useState(false)

const openState = useMemo(
() => (defaultOpen ? { open: true } : {}),
[defaultOpen]
)

useEffect(() => {
setIsMounted(true)
}, [])

return (
<div>MenuOptions</div>
)
}
export default MenuOptions;

0 comments on commit 505bb7d

Please sign in to comment.