-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create the departmental account icon #112
Merged
JorWo
merged 1 commit into
uhawaii-system-its-ti-iam:main
from
michho8:dev-michelleh-1835
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) && ( | ||
<div | ||
onClick={openDepartmentalModal} | ||
className="flex justify-center items-center rounded-full | ||
h-[45px] w-[45px] bg-seafoam mx-auto relative lg:ml-24" | ||
> | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger> | ||
<FontAwesomeIcon aria-label="user" icon={faUser} width={14} height={16} /> | ||
<div | ||
className="bg-blue-background rounded-full flex justify-center | ||
items-center h-[20px] w-[25px] absolute left-7 bottom-0" | ||
> | ||
<FontAwesomeIcon | ||
icon={faSchool} | ||
size="sm" | ||
aria-label="Departmental Account Icon" | ||
inverse | ||
/> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
<p>You are not in your personal account</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
</div> | ||
)} | ||
{isModalOpen && ( | ||
<DynamicModal | ||
open={isModalOpen} | ||
title={'Warning'} | ||
body={'You are not in your personal account.'} | ||
buttons={[]} | ||
michho8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onClose={closeDepartmentalModal} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default DeptAccountIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ui/tests/components/layout/navbar/dept-account-icon.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import DeptAccountIcon from '@/components/layout/navbar/dept-account-icon'; | ||
import User, { AnonymousUser } from '@/lib/access/user'; | ||
import * as NextCasClient from 'next-cas-client/app'; | ||
import Role from '@/lib/access/role'; | ||
|
||
const testUser: User = JSON.parse(process.env.TEST_USER_A as string); | ||
jest.mock('next-cas-client/app'); | ||
|
||
describe('Dept Account Icon', () => { | ||
it('should render the Departmental Account icon and open warning modal when clicked on', () => { | ||
testUser.roles = [Role.DEPARTMENTAL]; | ||
render(<DeptAccountIcon currentUser={testUser} />); | ||
|
||
fireEvent.focus(document); | ||
expect(screen.getByLabelText('Departmental Account Icon')).toBeInTheDocument(); | ||
|
||
fireEvent.click(screen.getByLabelText('Departmental Account Icon')); | ||
expect(screen.getByRole('alertdialog', { name: 'Warning' })).toBeInTheDocument(); | ||
expect(screen.getByRole('alertdialog')).toHaveTextContent('You are not in your personal account'); | ||
}); | ||
|
||
it('should not render the Departmental Account icon for other roles', () => { | ||
jest.spyOn(NextCasClient, 'getCurrentUser').mockResolvedValue(AnonymousUser); | ||
testUser.roles = [Role.ANONYMOUS, Role.ADMIN, Role.UH, Role.OWNER]; | ||
render(<DeptAccountIcon currentUser={testUser} />); | ||
|
||
fireEvent.focus(document); | ||
expect(screen.queryByRole('button', { name: 'Departmental Account Icon' })).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try h-6 w-6 for the width and height, let me know if you think it looks better. The school icon looks off center.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using h-6 and w-6 will make the blue background into more a circular shape. I like this one more than how it looked before with it being more oval-shaped.