2024-06-10 09:43:10 +00:00
|
|
|
"use client";
|
|
|
|
|
2024-05-08 17:31:20 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-05-28 06:20:04 +00:00
|
|
|
// icons
|
|
|
|
import { LucideIcon, Users } from "lucide-react";
|
|
|
|
// ui
|
|
|
|
import { Avatar, AvatarGroup } from "@plane/ui";
|
2024-01-31 10:06:55 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useMember } from "@/hooks/store";
|
2024-01-31 10:06:55 +00:00
|
|
|
|
|
|
|
type AvatarProps = {
|
|
|
|
showTooltip: boolean;
|
|
|
|
userIds: string | string[] | null;
|
2024-05-28 06:20:04 +00:00
|
|
|
icon?: LucideIcon;
|
2024-01-31 10:06:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const ButtonAvatars: React.FC<AvatarProps> = observer((props) => {
|
2024-05-28 06:20:04 +00:00
|
|
|
const { showTooltip, userIds, icon: Icon } = props;
|
2024-01-31 10:06:55 +00:00
|
|
|
// store hooks
|
|
|
|
const { getUserDetails } = useMember();
|
|
|
|
|
|
|
|
if (Array.isArray(userIds)) {
|
|
|
|
if (userIds.length > 0)
|
|
|
|
return (
|
|
|
|
<AvatarGroup size="md" showTooltip={!showTooltip}>
|
|
|
|
{userIds.map((userId) => {
|
|
|
|
const userDetails = getUserDetails(userId);
|
|
|
|
|
|
|
|
if (!userDetails) return;
|
|
|
|
return <Avatar key={userId} src={userDetails.avatar} name={userDetails.display_name} />;
|
|
|
|
})}
|
|
|
|
</AvatarGroup>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if (userIds) {
|
|
|
|
const userDetails = getUserDetails(userIds);
|
|
|
|
return <Avatar src={userDetails?.avatar} name={userDetails?.display_name} size="md" showTooltip={!showTooltip} />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-10 09:43:10 +00:00
|
|
|
return Icon ? <Icon className="h-3 w-3 flex-shrink-0" /> : <Users className="h-3 w-3 flex-shrink-0" />;
|
2024-01-31 10:06:55 +00:00
|
|
|
});
|