fix: card profile more items

This commit is contained in:
zerosoul
2022-05-27 16:50:54 +08:00
parent e11734e84c
commit e10b7f741e
2 changed files with 38 additions and 12 deletions
+36 -10
View File
@@ -1,6 +1,6 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { useSelector } from "react-redux"; 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 toast from "react-hot-toast";
import Tippy from "@tippyjs/react"; import Tippy from "@tippyjs/react";
import { hideAll } from "tippy.js"; import { hideAll } from "tippy.js";
@@ -12,8 +12,14 @@ import StyledWrapper from "./styled";
import StyledMenu from "../styled/Menu"; import StyledMenu from "../styled/Menu";
import useCopy from "../../hook/useCopy"; import useCopy from "../../hook/useCopy";
import { useRemoveMembersMutation } from "../../../app/services/channel"; import { useRemoveMembersMutation } from "../../../app/services/channel";
import { useLazyDeleteContactQuery } from "../../../app/services/contact";
export default function Profile({ uid = null, type = "embed", cid = null }) { export default function Profile({ uid = null, type = "embed", cid = null }) {
const navigateTo = useNavigate();
const [
removeUser,
{ isSuccess: removeUserSuccess },
] = useLazyDeleteContactQuery();
const [ const [
removeFromChannel, removeFromChannel,
{ isSuccess: removeSuccess }, { isSuccess: removeSuccess },
@@ -28,10 +34,13 @@ export default function Profile({ uid = null, type = "embed", cid = null }) {
}; };
}); });
useEffect(() => { useEffect(() => {
if (removeSuccess) { if (removeSuccess || removeUserSuccess) {
toast.success("Remove Successfully"); toast.success("Remove Successfully");
if (removeUserSuccess) {
navigateTo(`/contacts`);
}
} }
}, [removeSuccess]); }, [removeSuccess, removeUserSuccess]);
if (!data) return null; if (!data) return null;
// console.log("profile", data); // console.log("profile", data);
@@ -48,17 +57,20 @@ export default function Profile({ uid = null, type = "embed", cid = null }) {
copy(email); copy(email);
hideAll(); hideAll();
}; };
const handleRemove = (uid) => { const handleRemove = ({ from = "channel", uid }) => {
removeFromChannel({ id: +cid, members: [+uid] }); const remove = from == "channel" ? removeFromChannel : removeUser;
remove(from == "channel" ? { id: +cid, members: [+uid] } : uid);
hideAll(); hideAll();
}; };
const canCall = type !== "card" && loginUid != uid; const canCall = type == "card" && loginUid != uid;
const canRemoveFromServer = type == "embed" && isAdmin;
const canRemoveFromChannel = const canRemoveFromChannel =
cid && cid &&
!channel?.is_public && !channel?.is_public &&
(isAdmin || channel?.owner == loginUid) && (isAdmin || channel?.owner == loginUid) &&
channel?.owner != uid; channel?.owner != uid;
const hasMore = canCall || email || canRemoveFromChannel; const hasMore =
canCall || email || canRemoveFromChannel || canRemoveFromServer;
return ( return (
<StyledWrapper className={type}> <StyledWrapper className={type}>
<Avatar className="avatar" url={avatar} name={name} /> <Avatar className="avatar" url={avatar} name={name} />
@@ -73,7 +85,7 @@ export default function Profile({ uid = null, type = "embed", cid = null }) {
</li> </li>
</NavLink> </NavLink>
{/* <NavLink to={`#`}> */} {/* <NavLink to={`#`}> */}
{canCall && ( {type == "embed" && (
<li className="icon call" onClick={handleClick}> <li className="icon call" onClick={handleClick}>
<IconCall /> <IconCall />
<span className="txt">Call</span> <span className="txt">Call</span>
@@ -83,12 +95,18 @@ export default function Profile({ uid = null, type = "embed", cid = null }) {
<Tippy <Tippy
disabled={!hasMore} disabled={!hasMore}
interactive interactive
popperOptions={{ strategy: "fixed" }}
placement="bottom-start" placement="bottom-start"
trigger="click" trigger="click"
hideOnClick={true} hideOnClick={true}
content={ content={
<StyledMenu> <StyledMenu>
{canCall && <li className="item">Call</li>} {canCall && (
<li className="item">
{/* <IconCall className="icon" /> */}
Call
</li>
)}
{email && ( {email && (
<li className="item" onClick={handlCopyEmail}> <li className="item" onClick={handlCopyEmail}>
Copy Email Copy Email
@@ -97,11 +115,19 @@ export default function Profile({ uid = null, type = "embed", cid = null }) {
{canRemoveFromChannel && ( {canRemoveFromChannel && (
<li <li
className="item danger" className="item danger"
onClick={handleRemove.bind(null, uid)} onClick={handleRemove.bind(null, { uid })}
> >
Remove from Channel Remove from Channel
</li> </li>
)} )}
{canRemoveFromServer && (
<li
className="item danger"
onClick={handleRemove.bind(null, { from: "server", uid })}
>
Remove from Server
</li>
)}
</StyledMenu> </StyledMenu>
} }
> >
+2 -2
View File
@@ -64,9 +64,9 @@ const StyledWrapper = styled.div`
} }
} }
&.disabled { &.disabled {
color: #ccc; color: #667085;
svg path { svg path {
fill: #ccc; fill: #667085;
} }
} }
.txt { .txt {