Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
sidebar
  • Loading branch information
DandelionWithLute committed Feb 20, 2024
1 parent 7cf9cf5 commit 73031ad
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
src/components/sidebar
sideBarLogo =
user?.Agency.SubAccount.find((subaccount) => subaccount.id === id)
?.subAccountLogo || user.Agency.agencyLogo;
delete question mark(?):The object might be undefined
delete another option:Type string | undefined is not assignable to the variable.

Array.prototype.find()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

agency/[agencyId]
let allNoti: any = []
const notifications = await getNotificationAndUser(agencyId)
Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/agency/[agencyId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const layout = async ({

return (
<div className="h-screen overflow-hidden">
<Sidebar />
<Sidebar id={params.agencyId} type="agency" />
<div className="md:pl-[300px]">
<InfoBar />
<div className="relative">
Expand Down
71 changes: 65 additions & 6 deletions src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,68 @@
import React from 'react'
import { getAuthUserDetails } from "@/lib/queries";
import React from "react";
import MenuOptions from "./menuOptions";

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 && 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;
})
);

const Sidebar = () => {
return (
<div>Sidebar</div>
)
}
<>
<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
export default Sidebar;
Empty file.
33 changes: 33 additions & 0 deletions src/components/sidebar/menuOptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";
import {
SubAccount,
AgencySidebarOption,
SubAccountSidebarOption,
} from "@prisma/client";
import React 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) => {


return <div>menuOptions</div>;
};

export default MenuOptions;

0 comments on commit 73031ad

Please sign in to comment.