Skip to content

Commit ff6ff62

Browse files
committed
Add 'My Company' tab for company members in bottom nav
1 parent 3881714 commit ff6ff62

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import authOptions from "@/app/api/auth/[...nextauth]/authOptions";
2+
import BlankPageWithMessage from "@/components/BlankPageMessage";
3+
import UserSignOut from "@/components/UserSignOut";
4+
import { UserService } from "@/services/UserService";
5+
import { isCompany } from "@/utils/utils";
6+
import { getServerSession } from "next-auth";
7+
import { redirect } from "next/navigation";
8+
9+
export default async function MyCompany() {
10+
const session = (await getServerSession(authOptions))!;
11+
const user = await UserService.getMe(session!.cannonToken);
12+
if (!user) return <UserSignOut />;
13+
14+
if (!isCompany(user.role)) {
15+
return (
16+
<BlankPageWithMessage message="You do not have access to this page." />
17+
);
18+
}
19+
20+
if (!user.company || user.company.length <= 0) {
21+
return (
22+
<BlankPageWithMessage message="You are not associated to any company." />
23+
);
24+
}
25+
26+
redirect(`companies/${user.company[0].company}`);
27+
}

src/app/(authenticated)/qr/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CompanyService } from "@/services/CompanyService";
1010
import { convertToAppRole, isCompany } from "@/utils/utils";
1111
import Link from "next/link";
1212
import { ScanQrCode } from "lucide-react";
13+
import BlankPageWithMessage from "@/components/BlankPageMessage";
1314

1415
export default async function QR() {
1516
const session = await getServerSession(authOptions);
@@ -20,12 +21,13 @@ export default async function QR() {
2021
const userQRCode: string | null = await UserService.getQRCode(
2122
session!.cannonToken
2223
);
23-
if (!userQRCode) return <div>Unable to get QR-Code</div>;
24+
if (!userQRCode)
25+
return <BlankPageWithMessage message="Unable to get QR code." />;
2426

2527
let company: Company | null = null;
2628
if (isCompany(user.role)) {
2729
// assumes that cannon api only provides the company associated with the current edition
28-
if (user.company?.length) {
30+
if (user.company && user.company.length > 0) {
2931
company = await CompanyService.getCompany(user.company[0].company);
3032
} else {
3133
await demoteMe(session!.cannonToken);
@@ -93,4 +95,5 @@ const demoteMe = async (cannonToken: string) => {
9395
revalidateTag("modified-me");
9496
redirect("/");
9597
}
98+
return null;
9699
};

src/components/BottomNavbar/NavbarItem.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,59 @@ import { usePathname } from "next/navigation";
66

77
export type NavbarItemKey = keyof typeof navbarItems;
88

9-
interface NavbarIconProps {
9+
interface NavbarItemProps {
1010
name: NavbarItemKey;
11+
user: User;
1112
}
1213

1314
const navbarItems = {
1415
home: {
1516
title: "Home",
1617
icon: Home,
1718
route: "/home",
19+
isSelected: (currPath: string, _: User) => currPath === "/home",
1820
},
1921
schedule: {
2022
title: "Schedule",
2123
icon: Calendar,
2224
route: "/schedule",
25+
isSelected: (currPath: string, _: User) => currPath === "/schedule",
2326
},
2427
profile: {
2528
title: "Profile",
2629
icon: User,
2730
route: "/profile",
31+
isSelected: (currPath: string, _: User) => currPath === "/profile",
2832
},
2933
connections: {
3034
title: "Connections",
3135
icon: Users,
3236
route: "/profile/connections",
37+
isSelected: (currPath: string, _: User) =>
38+
currPath === "/profile/connections",
3339
},
3440
companies: {
3541
title: "Companies",
3642
icon: Building,
3743
route: "/companies",
44+
isSelected: (currPath: string, _: User) => currPath === "/companies",
45+
},
46+
myCompany: {
47+
title: "My Company",
48+
icon: Building,
49+
route: "/my-company",
50+
isSelected: (currPath: string, user: User) => {
51+
if (!user.company || user.company.length <= 0) return false;
52+
return currPath === `/companies/${user.company[0].company}`;
53+
},
3854
},
3955
};
4056

41-
export default function NavbarItem({ name }: NavbarIconProps) {
42-
const { title, icon: Icon, route } = navbarItems[name];
57+
export default function NavbarItem({ name, user }: NavbarItemProps) {
58+
const { title, icon: Icon, route, isSelected } = navbarItems[name];
4359

4460
const currPath = usePathname();
45-
const selected = route === currPath;
61+
const selected = isSelected(currPath, user);
4662

4763
return (
4864
<Link

src/components/BottomNavbar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import QRCodeButton from "./QRCodeButton";
1010

1111
const navbarItemKeysByRole: Record<UserRole, NavbarItemKey[]> = {
1212
Attendee: ["home", "schedule", "profile"],
13-
Company: ["home", "connections", "profile"],
13+
Company: ["home", "connections", "myCompany", "profile"],
1414
Member: ["home", "schedule", "companies", "profile"],
1515
Admin: ["home", "schedule", "companies", "profile"],
1616
};
@@ -25,7 +25,7 @@ export default async function BottomNavbar() {
2525
<div className="sticky z-10 bottom-0 left-0 right-0 bg-sinfo-primary pb-safe">
2626
<div className="relative container mx-auto flex h-navbar flex-row">
2727
{navbarItemKeysByRole[convertToAppRole(user.role)].map((k) => (
28-
<NavbarItem key={k} name={k} />
28+
<NavbarItem key={k} name={k} user={user} />
2929
))}
3030
<QRCodeButton />
3131
</div>

0 commit comments

Comments
 (0)