diff --git a/src/common/component/Profile/index.js b/src/common/component/Profile/index.js index 1e5ea694..09c9fd72 100644 --- a/src/common/component/Profile/index.js +++ b/src/common/component/Profile/index.js @@ -1,6 +1,6 @@ import { useEffect } from "react"; import { useSelector } from "react-redux"; -import { NavLink } from "react-router-dom"; +import { NavLink, useNavigate } from "react-router-dom"; import toast from "react-hot-toast"; import Tippy from "@tippyjs/react"; import { hideAll } from "tippy.js"; @@ -12,8 +12,14 @@ import StyledWrapper from "./styled"; import StyledMenu from "../styled/Menu"; import useCopy from "../../hook/useCopy"; import { useRemoveMembersMutation } from "../../../app/services/channel"; +import { useLazyDeleteContactQuery } from "../../../app/services/contact"; export default function Profile({ uid = null, type = "embed", cid = null }) { + const navigateTo = useNavigate(); + const [ + removeUser, + { isSuccess: removeUserSuccess }, + ] = useLazyDeleteContactQuery(); const [ removeFromChannel, { isSuccess: removeSuccess }, @@ -28,10 +34,13 @@ export default function Profile({ uid = null, type = "embed", cid = null }) { }; }); useEffect(() => { - if (removeSuccess) { + if (removeSuccess || removeUserSuccess) { toast.success("Remove Successfully"); + if (removeUserSuccess) { + navigateTo(`/contacts`); + } } - }, [removeSuccess]); + }, [removeSuccess, removeUserSuccess]); if (!data) return null; // console.log("profile", data); @@ -48,17 +57,20 @@ export default function Profile({ uid = null, type = "embed", cid = null }) { copy(email); hideAll(); }; - const handleRemove = (uid) => { - removeFromChannel({ id: +cid, members: [+uid] }); + const handleRemove = ({ from = "channel", uid }) => { + const remove = from == "channel" ? removeFromChannel : removeUser; + remove(from == "channel" ? { id: +cid, members: [+uid] } : uid); hideAll(); }; - const canCall = type !== "card" && loginUid != uid; + const canCall = type == "card" && loginUid != uid; + const canRemoveFromServer = type == "embed" && isAdmin; const canRemoveFromChannel = cid && !channel?.is_public && (isAdmin || channel?.owner == loginUid) && channel?.owner != uid; - const hasMore = canCall || email || canRemoveFromChannel; + const hasMore = + canCall || email || canRemoveFromChannel || canRemoveFromServer; return ( @@ -73,7 +85,7 @@ export default function Profile({ uid = null, type = "embed", cid = null }) { {/* */} - {canCall && ( + {type == "embed" && (
  • Call @@ -83,12 +95,18 @@ export default function Profile({ uid = null, type = "embed", cid = null }) { - {canCall &&
  • Call
  • } + {canCall && ( +
  • + {/* */} + Call +
  • + )} {email && (
  • Copy Email @@ -97,11 +115,19 @@ export default function Profile({ uid = null, type = "embed", cid = null }) { {canRemoveFromChannel && (
  • Remove from Channel
  • )} + {canRemoveFromServer && ( +
  • + Remove from Server +
  • + )} } > diff --git a/src/common/component/Profile/styled.js b/src/common/component/Profile/styled.js index f3e69c2d..8b247160 100644 --- a/src/common/component/Profile/styled.js +++ b/src/common/component/Profile/styled.js @@ -64,9 +64,9 @@ const StyledWrapper = styled.div` } } &.disabled { - color: #ccc; + color: #667085; svg path { - fill: #ccc; + fill: #667085; } } .txt {