import React from "react"; import PropTypes from "prop-types"; import { EditButton, ProfileCardWrapper, ProfileCardContainer, ProfileCardHeader, HeaderTitle, EditIcon, ProfileInfoContainer, RemoveButton, RemoveIcon, BlockButton, BlockIcon, ButtonsContainer, BlockLabelIcon, // MessageButton, // MessageIcon, ProfileInfoAndContactContainer, UnblockButton, UnblockIcon, } from "./ProfileCard.styled"; import PersonOutlineIcon from "@mui/icons-material/PersonOutline"; import { useRouteMatch } from "react-router-dom"; import { fetchProfile } from "../../../store/actions/profile/profileActions"; import { useDispatch, useSelector } from "react-redux"; import { useEffect } from "react"; import { selectProfile } from "../../../store/selectors/profileSelectors"; import { selectUserId } from "../../../store/selectors/loginSelectors"; import { fetchProfileOffers } from "../../../store/actions/offers/offersActions"; import ProfileMainInfo from "./ProfileMainInfo/ProfileMainInfo"; import ProfileContact from "./ProfileContact/ProfileContact"; import ProfileStats from "./ProfileStats/ProfileStats"; import { useTranslation } from "react-i18next"; import { selectIsLoadingByActionType } from "../../../store/selectors/loadingSelectors"; import { PROFILE_SCOPE } from "../../../store/actions/profile/profileActionConstants"; import SkeletonProfileCard from "./SkeletonProfileCard/SkeletonProfileCard"; import { useMemo } from "react"; import companyData from "../../../notFoundData/companyData"; import UserLabeledCard from "../LabeledCard/User/UserLabeledCard"; import history from "../../../store/utils/history"; import { HOME_PAGE } from "../../../constants/pages"; import useIsMobile from "../../../hooks/useIsMobile"; import BlockedProfile from "./BlockedProfile/BlockedProfile"; import { toggleDeleteCategoryModal, toggleEditProfileModal, } from "../../../store/actions/modal/modalActions"; import { USERS_BLOCK_TYPE, USERS_DELETE_TYPE, USERS_UNBLOCK_TYPE, } from "../../../constants/adminTypeConstants"; import { Tooltip } from "@mui/material"; const ProfileCard = (props) => { const isLoading = useSelector(selectIsLoadingByActionType(PROFILE_SCOPE)); const routeMatch = useRouteMatch(); const dispatch = useDispatch(); const { isMobile } = useIsMobile(); const profileFromRedux = useSelector(selectProfile); const userId = useSelector(selectUserId); const idProfile = useMemo(() => { return routeMatch.params.idProfile; }, [routeMatch.params.idProfile]); const { t } = useTranslation(); const profile = useMemo(() => { if (profileFromRedux) { if (profileFromRedux._id === routeMatch.params.idProfile) { return profileFromRedux; } } return companyData; }, [profileFromRedux]); const isMyProfile = useMemo( () => userId === idProfile && !props.isAdmin, [userId, idProfile] ); useEffect(() => { if (idProfile?.length > 0) { reFetchProfile(); } }, [idProfile]); useEffect(() => { if (profile && isMyProfile !== undefined) { if (!isMyProfile && profile._blocked && !props.isAdmin) history.push(HOME_PAGE); } }, [profile, isMyProfile, props.isAdmin]); const reFetchProfile = () => { dispatch(fetchProfile(idProfile)); dispatch(fetchProfileOffers(idProfile)); }; let percentOfSucceededExchanges; if (profile?.statistics?.exchanges?.succeeded === 0) { percentOfSucceededExchanges = 0; } else { percentOfSucceededExchanges = Math.ceil( (profile?.statistics?.exchanges?.total / profile?.statistics?.exchanges?.succeeded) * 100 ); } const removeUser = () => { dispatch( toggleDeleteCategoryModal({ customId: profile?._id, type: USERS_DELETE_TYPE, customLabeledCard: , customLabeledCardHeight: "90px", }) ); }; const blockUser = () => { dispatch( toggleDeleteCategoryModal({ customId: profile?._id, type: USERS_BLOCK_TYPE, customLabeledCard: , customLabeledCardHeight: "90px", customLabeledCardIcon: , }) ); }; const unblockUser = () => { dispatch( toggleDeleteCategoryModal({ customId: profile?._id, type: USERS_UNBLOCK_TYPE, customLabeledCard: , customLabeledCardHeight: "90px", }) ); }; const handleEditProfile = () => { if (!profile?._blocked) { dispatch( toggleEditProfileModal({ profile: profile, isAdmin: props.isAdmin, reFetchProfile: reFetchProfile, }) ); } }; return ( <> {isLoading ? ( ) : ( <> {isMyProfile ? t("profile.myProfile") : t("profile.companyProfile")} {profile?._blocked && !isMobile && } {props.isAdmin && ( <> {profile?._blocked ? ( ) : ( )} )} {(isMyProfile || props.isAdmin) && ( )} {profile?._blocked && !props.isAdmin && isMobile && ( )} {/* Profile Main Info */} {/* Profile Contact */} {/* Profile Stats */} )} ); }; ProfileCard.propTypes = { children: PropTypes.node, isAdmin: PropTypes.bool, }; export default ProfileCard;