fix: remove contact redirect
This commit is contained in:
@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
|
|||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
// import { ContentTypes } from "../../../app/config";
|
// import { ContentTypes } from "../../../app/config";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate, useMatch } from "react-router-dom";
|
||||||
import { hideAll } from "tippy.js";
|
import { hideAll } from "tippy.js";
|
||||||
import { useRemoveMembersMutation } from "../../app/services/channel";
|
import { useRemoveMembersMutation } from "../../app/services/channel";
|
||||||
import { useLazyDeleteContactQuery } from "../../app/services/contact";
|
import { useLazyDeleteContactQuery } from "../../app/services/contact";
|
||||||
@@ -10,7 +10,7 @@ import useCopy from "./useCopy";
|
|||||||
|
|
||||||
export default function useContactOperation({ uid, cid }) {
|
export default function useContactOperation({ uid, cid }) {
|
||||||
const [passedUid, setPassedUid] = useState(undefined);
|
const [passedUid, setPassedUid] = useState(undefined);
|
||||||
|
const isUserDetailPath = useMatch(`/contacts/${uid}`);
|
||||||
const [
|
const [
|
||||||
removeUser,
|
removeUser,
|
||||||
{ isSuccess: removeUserSuccess },
|
{ isSuccess: removeUserSuccess },
|
||||||
@@ -36,11 +36,11 @@ export default function useContactOperation({ uid, cid }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (removeSuccess || removeUserSuccess) {
|
if (removeSuccess || removeUserSuccess) {
|
||||||
toast.success("Remove Successfully");
|
toast.success("Remove Successfully");
|
||||||
if (removeUserSuccess) {
|
if (removeUserSuccess && isUserDetailPath) {
|
||||||
navigateTo(`/contacts`);
|
navigateTo(`/contacts`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [removeSuccess, removeUserSuccess]);
|
}, [removeSuccess, removeUserSuccess, isUserDetailPath]);
|
||||||
const handleRemoveFromChannel = (id) => {
|
const handleRemoveFromChannel = (id) => {
|
||||||
const isNumber = !Number.isNaN(+id);
|
const isNumber = !Number.isNaN(+id);
|
||||||
const finalId = isNumber ? id || passedUid : passedUid;
|
const finalId = isNumber ? id || passedUid : passedUid;
|
||||||
|
|||||||
Reference in New Issue
Block a user