Skip to content
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

Staff Avatar Hover Cards #1441

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 83 additions & 17 deletions epictrack-web/src/components/myWorkplans/Card/CardFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
import { Avatar, AvatarGroup, Button, Grid } from "@mui/material";
import {
Avatar,
AvatarGroup,
Box,
Button,
Grid,
ListItem,
avatarGroupClasses,
} from "@mui/material";
import { Palette } from "../../../styles/theme";
import { ETCaption1, ETCaption2, ETParagraph } from "../../shared";
import Icons from "../../icons";
import { IconProps } from "../../icons/type";
import { CardProps } from "./type";
import { useNavigate } from "react-router-dom";
import React from "react";
import UserMenu from "../../shared/userMenu/UserMenu";
import RenderSurplus from "./RenderSurplus";
import { Staff } from "../../../models/staff";

const EyeIcon: React.FC<IconProps> = Icons["EyeIcon"];

const CardFooter = ({ workplan }: CardProps) => {
const navigate = useNavigate();
const [staffHover, setStaffHover] = React.useState<any>(null);
const [userMenuAnchorEl, setUserMenuAnchorEl] =
React.useState<null | HTMLElement>(null);
const team_lead = workplan.staff_info.find((staff: any) => {
if (staff.role.name === "Team Lead") {
return staff.staff.full_name;
}
return false;
});

const handleCloseUserMenu = (event: React.MouseEvent<HTMLElement>) => {
setUserMenuAnchorEl(null);
setStaffHover(null);
};

const handleOpenUserMenu = (
event: React.MouseEvent<HTMLElement>,
staff: any
) => {
setStaffHover(staff);
setUserMenuAnchorEl(event.currentTarget);
};

return (
<Grid
container
Expand All @@ -27,7 +55,7 @@ const CardFooter = ({ workplan }: CardProps) => {
borderTop: `1px solid var(--neutral-background-dark, #DBDCDC)`,
padding: "16px 32px",
alignItems: "center",
height: "80px",
// height: "80px",
}}
>
<Grid item>
Expand Down Expand Up @@ -68,23 +96,61 @@ const CardFooter = ({ workplan }: CardProps) => {
<ETCaption1 color={Palette.neutral.main}>STAFF</ETCaption1>
</Grid>
<Grid item>
<AvatarGroup max={4}>
<AvatarGroup
spacing={1}
max={4}
renderSurplus={(surplus: number) => (
<RenderSurplus
renderSurplus={surplus}
staff={workplan.staff_info as unknown as Staff[]}
/>
)}
sx={{
[`& .${avatarGroupClasses.avatar}`]: {
width: "24px",
height: "24px",
},
}}
>
{workplan.staff_info.map((staff: any) => {
return (
<Avatar
key={staff.staff.id}
sx={{
bgcolor: Palette.neutral.bg.main,
color: Palette.neutral.dark,
lineHeight: "12px",
width: "24px",
height: "24px",
}}
>
<ETCaption2
bold
>{`${staff.staff.first_name[0]}${staff.staff.last_name[0]}`}</ETCaption2>
</Avatar>
<>
<Avatar
key={staff.staff.id}
sx={{
bgcolor: Palette.neutral.bg.main,
color: Palette.neutral.dark,
lineHeight: "12px",
width: "24px",
height: "24px",
}}
onMouseEnter={(event) => {
event.stopPropagation();
event.preventDefault();
handleOpenUserMenu(event, staff.staff);
}}
// onMouseLeave={handleCloseUserMenu}
>
<ETCaption2
bold
>{`${staff.staff.first_name[0]}${staff.staff.last_name[0]}`}</ETCaption2>
</Avatar>
<UserMenu
onMouseLeave={handleCloseUserMenu}
anchorEl={userMenuAnchorEl}
email={staffHover?.email || ""}
phone={staffHover?.phone || ""}
position={staffHover?.position?.name || ""}
firstName={staffHover?.first_name || ""}
lastName={staffHover?.last_name || ""}
onClose={handleCloseUserMenu}
origin={{ vertical: "top", horizontal: "left" }}
sx={{
pointerEvents: "none",
}}
id={staff.staff.id}
/>
</>
);
})}
</AvatarGroup>
Expand Down
99 changes: 99 additions & 0 deletions epictrack-web/src/components/myWorkplans/Card/RenderSurplus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import {
Avatar,
Grid,
Menu,
MenuItem,
PopoverOrigin,
Typography,
} from "@mui/material";
import { Staff } from "../../../models/staff";
import React from "react";
import { ETCaption2 } from "../../shared";
import { Palette } from "../../../styles/theme";

interface RenderSurplusProps {
renderSurplus: number;
staff: any[];
}

const RenderSurplus = ({ renderSurplus, staff }: RenderSurplusProps) => {
const [userListAnchor, setUserListAnchor] =
React.useState<null | HTMLElement>(null);

const remainingStaff = staff.slice(renderSurplus - 1);

const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement>) => {
setUserListAnchor(event.currentTarget);
};

const handleCloseUserMenu = () => {
setUserListAnchor(null);
};

return (
<>
<Avatar
onMouseEnter={(event) => {
event.stopPropagation();
event.preventDefault();
handleOpenUserMenu(event);
}}
>
<Typography sx={{ textAlign: "center" }}>...</Typography>
</Avatar>
<Menu
open={Boolean(userListAnchor)}
onMouseLeave={handleCloseUserMenu}
anchorEl={userListAnchor}
anchorOrigin={{ vertical: "top", horizontal: "left" }}
onClose={handleCloseUserMenu}
sx={{
mt: "2.5rem",
}}
PaperProps={{
style: {
pointerEvents: "none",
width: 320,
boxShadow: "0px 12px 24px 0px rgba(0, 0, 0, 0.10)",
},
}}
MenuListProps={{
style: {
paddingTop: 0,
paddingBottom: 0,
pointerEvents: "auto",
},
}}
>
{remainingStaff.map((staffObject: any) => {
return (
<MenuItem>
<Avatar
sx={{
bgcolor: Palette.neutral.bg.main,
color: Palette.neutral.dark,
width: "32px",
height: "32px",
padding: "4px 8px",
marginRight: "8px",
}}
>
<ETCaption2>{`${staffObject?.staff?.first_name[0]}${staffObject?.staff?.last_name[0]}`}</ETCaption2>
</Avatar>
<Grid container direction={"column"}>
<Grid item>
<ETCaption2 bold>{staffObject?.staff?.full_name}</ETCaption2>
</Grid>
<Grid item>
<ETCaption2>{staffObject?.staff?.position?.name}</ETCaption2>
</Grid>
</Grid>
</MenuItem>
);
})}
</Menu>
</>
);
};

export default RenderSurplus;
2 changes: 2 additions & 0 deletions epictrack-web/src/components/shared/userMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const UserMenu = (props: UserMenuProps) => {
phone,
origin,
id,
onMouseLeave,
} = props;
const menuOrigin = React.useMemo(() => {
if (origin === undefined)
Expand All @@ -60,6 +61,7 @@ const UserMenu = (props: UserMenuProps) => {
transformOrigin={menuOrigin}
open={Boolean(anchorEl)}
onClose={onClose}
onMouseLeave={onMouseLeave}
PaperProps={{
style: {
pointerEvents: "none",
Expand Down
1 change: 1 addition & 0 deletions epictrack-web/src/components/shared/userMenu/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface UserMenuProps {
origin?: PopoverOrigin;
sx?: SxProps;
id?: string;
onMouseLeave?: (event: React.MouseEvent<HTMLElement>) => any;
}
Loading