import { FC, useEffect, useState } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import clsx from "clsx"; import useLeaveChannel from "@/hooks/useLeaveChannel"; import Modal from "../Modal"; import Button from "../styled/Button"; import StyledModal from "../styled/Modal"; import User from "../User"; interface Props { id: number; closeModal: () => void; withLeave?: boolean; } const TransferOwnerModal: FC = ({ id, closeModal, withLeave = true }) => { const { t } = useTranslation(); const { transferOwner, otherMembers, leaving, leaveChannel, leaveSuccess, transferSuccess, transferring } = useLeaveChannel(id); const [uid, setUid] = useState(null); const navigateTo = useNavigate(); const handleSelectUser = (uid: number) => { setUid(uid); }; const handleTransferAndLeave = async () => { if (!uid) return; await transferOwner(uid); if (withLeave) { await leaveChannel(); } }; useEffect(() => { if (transferSuccess && leaveSuccess) { toast.success("Leave channel successfully!"); closeModal(); navigateTo("/chat"); } }, [leaveSuccess, transferSuccess, withLeave]); if (!id) return null; const operating = leaving || transferring; return ( } >
    {otherMembers.map((id) => { return (
  • ); })}
); }; export default TransferOwnerModal;