From 554f5caf4c99ece08747cf7eb4cfa52b45282e7f Mon Sep 17 00:00:00 2001
From: Michelle Ho <89873670+michho8@users.noreply.github.com>
Date: Thu, 12 Dec 2024 11:54:43 -1000
Subject: [PATCH] Create the departmental account icon (#112)
---
.../layout/navbar/dept-account-icon.tsx | 66 +++++++++++++++++++
.../components/layout/navbar/navbar-menu.tsx | 2 +-
ui/src/components/layout/navbar/navbar.tsx | 3 +
ui/src/components/modal/dynamic-modal.tsx | 21 ++----
ui/src/lib/access/authorization.ts | 7 ++
ui/src/lib/access/role.ts | 3 +-
.../layout/navbar/dept-account-icon.test.tsx | 31 +++++++++
.../components/layout/navbar/navbar.test.tsx | 19 ++++++
.../components/modal/dynamic-modal.test.tsx | 27 ++++++--
9 files changed, 159 insertions(+), 20 deletions(-)
create mode 100644 ui/src/components/layout/navbar/dept-account-icon.tsx
create mode 100644 ui/tests/components/layout/navbar/dept-account-icon.test.tsx
diff --git a/ui/src/components/layout/navbar/dept-account-icon.tsx b/ui/src/components/layout/navbar/dept-account-icon.tsx
new file mode 100644
index 00000000..7fbdc5f6
--- /dev/null
+++ b/ui/src/components/layout/navbar/dept-account-icon.tsx
@@ -0,0 +1,66 @@
+'use client';
+
+import { useState } from 'react';
+
+import DynamicModal from '@/components/modal/dynamic-modal';
+import { faUser, faSchool } from '@fortawesome/free-solid-svg-icons';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
+import User from '@/lib/access/user';
+import Role from '@/lib/access/role';
+
+const DeptAccountIcon = ({ currentUser }: { currentUser: User }) => {
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const openDepartmentalModal = () => {
+ setIsModalOpen(true);
+ };
+
+ const closeDepartmentalModal = () => {
+ setIsModalOpen(false);
+ };
+
+ return (
+ <>
+ {currentUser.roles.includes(Role.DEPARTMENTAL) && (
+
+
+
+
+
+
+
+
+
+
+ You are not in your personal account
+
+
+
+
+ )}
+ {isModalOpen && (
+
+ )}
+ >
+ );
+};
+
+export default DeptAccountIcon;
diff --git a/ui/src/components/layout/navbar/navbar-menu.tsx b/ui/src/components/layout/navbar/navbar-menu.tsx
index 483e605b..d7d4ec50 100644
--- a/ui/src/components/layout/navbar/navbar-menu.tsx
+++ b/ui/src/components/layout/navbar/navbar-menu.tsx
@@ -1,7 +1,7 @@
'use client';
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet';
-import { User } from 'next-cas-client';
+import User from '@/lib/access/user';
import Link from 'next/link';
import { NavbarLinks } from './navbar-links';
import { useState } from 'react';
diff --git a/ui/src/components/layout/navbar/navbar.tsx b/ui/src/components/layout/navbar/navbar.tsx
index 8382e4bc..e5a0e11d 100644
--- a/ui/src/components/layout/navbar/navbar.tsx
+++ b/ui/src/components/layout/navbar/navbar.tsx
@@ -6,9 +6,11 @@ import NavbarMenu from './navbar-menu';
import TimeoutModal from '@/components/modal/timeout-modal';
import { getUser } from '@/lib/access/user';
import Role from '@/lib/access/role';
+import DeptAccountIcon from '@/components/layout/navbar/dept-account-icon';
const Navbar = async () => {
const currentUser = await getUser();
+
return (
<>
@@ -34,6 +36,7 @@ const Navbar = async () => {
/>
+
{NavbarLinks.filter(
(navbarLink) =>
diff --git a/ui/src/components/modal/dynamic-modal.tsx b/ui/src/components/modal/dynamic-modal.tsx
index d8933183..9db92515 100644
--- a/ui/src/components/modal/dynamic-modal.tsx
+++ b/ui/src/components/modal/dynamic-modal.tsx
@@ -9,41 +9,34 @@ import {
AlertDialogFooter,
AlertDialogCancel
} from '@/components/ui/alert-dialog';
-import { ReactNode, useState } from 'react';
+import { ReactNode } from 'react';
import { Button } from '@/components/ui/button';
const DynamicModal = ({
open,
title,
body,
- buttons
+ buttons,
+ onClose
}: {
open: boolean;
title: string;
body: string;
buttons?: ReactNode[];
+ onClose: () => void;
}) => {
- const [openDynamicModal, setOpenDynamicModal] = useState(open);
-
- /**
- * Closes the modal.
- */
- const close = () => {
- setOpenDynamicModal(false);
- };
-
return (
-
+
{title}
{body}
- close()}>OK
+ OK
{/*Any buttons that should lead the user to a different page.*/}
{buttons?.map((button, index) => (
-