-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from NIAEFEUP/fix/exchange-ui
Improving Exchange UI
- Loading branch information
Showing
8 changed files
with
119 additions
and
87 deletions.
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
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 |
---|---|---|
@@ -1,58 +1,62 @@ | ||
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar" | ||
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuSeparator } from "../ui/dropdown-menu" | ||
import { DropdownMenuSeparator } from "../ui/dropdown-menu" | ||
import { Button } from "../ui/button"; | ||
import { ChevronRightIcon } from "@heroicons/react/24/solid"; | ||
import { ArrowRightStartOnRectangleIcon } from "@heroicons/react/24/solid"; | ||
import { useContext, useState } from "react"; | ||
import { ClipLoader } from "react-spinners"; | ||
import SessionContext from "../../contexts/SessionContext"; | ||
import authService from "../../api/services/authService"; | ||
import studentInfoService from "../../api/services/studentInfo"; | ||
import { HoverCard, HoverCardContent, HoverCardTrigger } from "../ui/hover-card"; | ||
import ScheduleContext from "../../contexts/ScheduleContext"; | ||
|
||
export const HeaderProfileDropdown = () => { | ||
const [loggingOut, setLoggingOut] = useState(false); | ||
|
||
const { user, setSignedIn } = useContext(SessionContext); | ||
const { setExchangeSchedule } = useContext(ScheduleContext); | ||
|
||
const logout = async () => { | ||
setLoggingOut(true); | ||
await authService.logout(user.token, setSignedIn, setLoggingOut); | ||
setExchangeSchedule([]); | ||
await authService.logout(user.token, setSignedIn, setLoggingOut); | ||
} | ||
|
||
return <DropdownMenu> | ||
<DropdownMenuTrigger className="w-full"> | ||
return <HoverCard> | ||
<HoverCardTrigger className="w-fit"> | ||
<Avatar className="border shadow-sm"> | ||
<AvatarImage src={studentInfoService.getStudentPictureUrl(user?.username)} /> | ||
<AvatarFallback>{user ? user.name.charAt(0) : ""}</AvatarFallback> | ||
</Avatar> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="p-4 m-4"> | ||
</HoverCardTrigger> | ||
<HoverCardContent className="w-44 p-4 mx-4"> | ||
<div className="flex flex-col"> | ||
<article className="flex flex-col"> | ||
<p className="text-md font-bold">{user?.name}</p> | ||
<p className="text-sm">{user?.username}</p> | ||
</article> | ||
<DropdownMenuSeparator className="my-2" /> | ||
<Button | ||
variant="ghost" | ||
className="w-full flex flex-row justify-between" | ||
onClick={async () => { | ||
await logout(); | ||
}} | ||
> | ||
<div> | ||
<ClipLoader | ||
className="w-full h-2" | ||
loading={loggingOut} | ||
aria-label="Loading Spinner" | ||
data-testid="loader" | ||
/> | ||
</div> | ||
{!loggingOut && <span>Sair</span>} | ||
<ChevronRightIcon className="w-5 h-5" /> | ||
</Button> | ||
{loggingOut ? | ||
<ClipLoader | ||
className="w-2 h-2 mx-auto" | ||
loading={true} | ||
aria-label="Loading Spinner" | ||
data-testid="loader" | ||
/> | ||
: | ||
<Button | ||
variant="secondary" | ||
className="w-full flex flex-row justify-center gap-2" | ||
onClick={logout} | ||
> | ||
<ArrowRightStartOnRectangleIcon className="w-5 h-5" /> | ||
{!loggingOut && <span>Sair</span>} | ||
</Button> | ||
} | ||
|
||
</div> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</HoverCardContent> | ||
</HoverCard> | ||
} | ||
|
||
|
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from "react" | ||
import * as HoverCardPrimitive from "@radix-ui/react-hover-card" | ||
|
||
import { cn } from '../../utils' | ||
|
||
const HoverCard = HoverCardPrimitive.Root | ||
|
||
const HoverCardTrigger = HoverCardPrimitive.Trigger | ||
|
||
const HoverCardContent = React.forwardRef< | ||
React.ElementRef<typeof HoverCardPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content> | ||
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( | ||
<HoverCardPrimitive.Content | ||
ref={ref} | ||
align={align} | ||
sideOffset={sideOffset} | ||
className={cn( | ||
"z-50 w-64 rounded-md border border-slate-200 bg-white p-4 text-slate-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-50", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName | ||
|
||
export { HoverCard, HoverCardTrigger, HoverCardContent } |
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