import { BsThreeDots } from "react-icons/bs"; import { FaArchive, FaBell, FaCalendarDay, FaClock, FaLink, FaPlus, } from "react-icons/fa"; import { IoTimer } from "react-icons/io5"; import Room, { RoomStatus, RoomType } from "../models/room"; import RoomTypeTag from "./RoomTypeTag"; import Image from "next/image"; import { useAuth } from "../contexts/authContext"; import { Avatar, Divider, Dropdown, Menu, Popover, Tooltip } from "antd"; import { UserOutlined, AntDesignOutlined } from "@ant-design/icons"; import { useTeamDashboardContext } from "../contexts/teamDashboardContext"; import { User, UserStatus } from "../models/user"; import RoomService from "../services/roomService"; import toast from "react-hot-toast"; import { useState } from "react"; import SkeletonLoader from "./Loading/skeletonLoader"; import { useKeyboardContext } from "../contexts/keyboardContext"; import UserService from "../services/userService"; import Moment from "react-moment"; import moment from "moment"; interface IRoomCardProps { room: Room; updateRoomHandler: Function; } const roomService = new RoomService(); const userService = new UserService(); const today = new Date(); export default function RoomCard(props: IRoomCardProps) { const { currUser } = useAuth(); const { teamUsersMap, user } = useTeamDashboardContext(); const [loading, setLoading] = useState(false); var isUserInRoom: boolean; if (props.room.membersInRoom?.includes(currUser.uid)) { isUserInRoom = true; } // first array of all members invited var allMembersInvited = props.room.members?.reduce((results, userId) => { if (userId in teamUsersMap) { results.push(teamUsersMap[userId]); } if (userId == currUser.uid) { results.push(user); } return results; }, [] as User[]); // second array of all members in room var allMembersInRoom = props.room.membersInRoom?.reduce((results, userId) => { if (userId in teamUsersMap) { results.push(teamUsersMap[userId]); } if (userId == currUser.uid) { results.push(user); } return results; }, [] as User[]); // third array all members invited and not in the array of users in room const allMembersInvitedButNotInRoom = allMembersInvited.filter( (invitedMember) => { if (allMembersInRoom.some((user) => user.id === invitedMember.id)) { /* vendors contains the element we're looking for */ return false; } return true; } ); // show members who are in the invite list but not already in the room const membersInvited = () => { if (allMembersInvited?.length == 0) { return; } const listOfNames = allMembersInvited .map((user) => user.nickName) .join(", "); return ( {allMembersInvitedButNotInRoom.map((user, i) => { return ( ); })} ); }; const membersInRoom = () => { if (allMembersInRoom?.length == 0) { return; } const listOfNames = allMembersInRoom .map((user) => user.nickName) .join(", "); return ( {allMembersInRoom.map((user, i) => { return ( ); })} ); }; async function handleLeavingRoom() { setLoading(true); try { // filter current membersInRoom and return new array const newMembersInRoom = props.room.membersInRoom.filter( (memberId) => memberId != currUser.uid ); // update the room with room id to have a new array of userIds await roomService.updateMembersInRoom(props.room.id, newMembersInRoom); // change curr user status to free now await userService.updateUserStatus(currUser.uid, UserStatus.online); } catch (error) { console.error(error); toast.error("unable to leave room...something went wrong"); } setLoading(false); } async function handleJoiningRoom() { setLoading(true); try { // update members in room const newMembersInRoom = [...props.room.membersInRoom, currUser.uid]; // update the room with room id to have a new array of userIds await roomService.updateMembersInRoom(props.room.id, newMembersInRoom); // change curr user status to free now await userService.updateUserStatus(currUser.uid, UserStatus.busy); // then window.open to room's link window.open(props.room.link, "_blank"); } catch (error) { console.error(error); toast.error("unable to leave room...something went wrong"); } setLoading(false); } async function handleArchivingRoom() { if ( confirm( "Are you sure you want to archive room? It will be added to the archived tab." ) ) { console.log("archiving room"); try { const newRoom: Room = { ...props.room }; newRoom.status = RoomStatus.archived; newRoom.membersInRoom = []; await roomService.updateRoom(newRoom); } catch (error) {} } } if (loading) { return ; } async function handleUpdateRoom() { props.updateRoomHandler(props.room.id); } const RoomOptionsMenu = ( Archive Room ); const AgendaContent = (
{props.room.description}
); // handle specifics for a scheduled room var dateTimeScheduled = null; var isPastRoom = false; // signal user to archive this room if it's past if (props.room.type == RoomType.scheduled) { dateTimeScheduled = props.room.scheduledDateTime.toDate(); // check if the moment date scheduled is future or past if (moment(today).diff(moment(dateTimeScheduled)) > 0) { isPastRoom = true; } } function renderTopRightCardInfo() { if (props.room.type == RoomType.scheduled && props.room.scheduledDateTime) { return ( <> ); } } if (props.room.status == RoomStatus.archived) { return ( <> {membersInvited()} {/* header */} {/* meeting details */} {props.room.name} {props.room.description} {/* all invited members who are not in the room already */} {/* room status and link(s) */} {renderTopRightCardInfo()} {props.room.approximateDateTime} {/* room attachments */} {props.room.attachments && props.room.attachments.length > 0 ? ( ) : ( <> )} {/* footer */} ); } return ( {/* header */} {/* meeting details */} {props.room.name} {props.room.description} {/* badges and tags */} {/* scrum */} {/* all invited members who are not in the room already */} {membersInvited()} {/* room status and link(s) */} {renderTopRightCardInfo()} {props.room.approximateDateTime} {/* room attachments */} {props.room.attachments && props.room.attachments.length > 0 ? ( ) : ( )} {/* footer */} {membersInRoom()} {/* tell them to archive if it's past */} {isPastRoom ? ( ) : ( <> )} {isUserInRoom ? ( ) : ( )} ); }