import { FaAngleDoubleRight, FaArchive, FaExternalLinkAlt, FaFilePdf, FaTrash, } from "react-icons/fa"; import Link, { LinkState, LinkType } from "../models/link"; import Image from "next/image"; import { BsThreeDots } from "react-icons/bs"; import LinkIcon from "./LinkIcon"; import { useTeamDashboardContext } from "../contexts/teamDashboardContext"; import { useAuth } from "../contexts/authContext"; import { User } from "../models/user"; import { Avatar, Dropdown, Menu, Tooltip } from "antd"; import { useState } from "react"; import SkeletonLoader from "./Loading/skeletonLoader"; import moment from "moment"; import { LinkService } from "../services/linkService"; interface ILinkCardProps { link: Link; } const linkService = new LinkService(); export default function LinkCard(props: ILinkCardProps) { const { currUser } = useAuth(); const { teamUsersMap, user } = useTeamDashboardContext(); const [loading, setLoading] = useState(false); var sender: User; if (props.link.createdByUserId == currUser.uid) { sender = user; } else { sender = teamUsersMap[props.link.createdByUserId]; } var receivers: User[] = props.link.recipients?.reduce((results, userId) => { if (userId in teamUsersMap) { results.push(teamUsersMap[userId]); } // if I am the receiver still add me to the receivers if (userId == currUser.uid) { results.push(user); } return results; }, [] as User[]); async function handleDeleteLink() { setLoading(true); if ( confirm( "Are you sure you want to delete link? It will disappear for all recipients." ) ) { console.log("deleting link"); await linkService.updateLinkState(props.link.id, LinkState.deleted); try { } catch (error) {} } setLoading(false); } async function handleArchivingLink() { setLoading(true); if ( confirm( "Are you sure you want to archive link? It will be in the archive tab." ) ) { await linkService.updateLinkState(props.link.id, LinkState.archived); try { } catch (error) {} } setLoading(false); } if (loading) { return ; } const LinkOptionsMenu = ( } > } > ); const relativeDateTime: string = moment( props.link.createdDate.toDate() ).fromNow(); var receiversNames = "team"; if (receivers) { receiversNames = receivers.map((receiver) => receiver.firstName).join(", "); } return ( {/* attmnt header */} window.open(props.link.link, "_blank")} className="flex flex-row bg-gray-300 bg-opacity-25 py-5 px-3 items-center justify-start hover:cursor-pointer h-full" > {props.link.name} {props.link.description} {/* attachment actions */} {/* attmnt footer */} " + receiversNames + ": " + relativeDateTime } > {receivers ? ( receivers.map((receiverUser, i) => { return ( ); }) ) : ( team )} ); }