import { Button, Input, Tooltip } from "@mui/joy"; import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import toast from "react-hot-toast"; import { useAppSelector } from "../store"; import { showCommonDialog } from "../components/Alert"; import { userService } from "../services"; import Icon from "../components/Icon"; import copy from "copy-to-clipboard"; import ChangePasswordDialog from "../components/ChangePasswordDialog"; interface State { showChangePasswordDialog: boolean; } const UserDetail: React.FC = () => { const navigate = useNavigate(); const { user } = useAppSelector((state) => state.user); const [state, setState] = useState({ showChangePasswordDialog: false, }); useEffect(() => { if (!userService.getState().user) { navigate("/user/auth"); return; } }, []); const handleChangePasswordBtnClick = async () => { setState({ ...state, showChangePasswordDialog: true, }); }; const handleCopyOpenIdBtnClick = async () => { if (!user?.openId) { toast.error("OpenID not found"); return; } copy(user.openId); toast.success("OpenID copied"); }; const handleResetOpenIdBtnClick = async () => { showCommonDialog({ title: "Reset Open API", content: "❗️The existing API will be invalidated and a new one will be generated, are you sure you want to reset?", style: "warning", onConfirm: async () => { await userService.patchUser({ id: user?.id as UserId, resetOpenId: true, }); }, }); }; return ( <>

{user?.displayName}

Email: {user?.email}

Password:
{/* Do not display open api related field right now. */} {false && (
OpenID:
)}
{state.showChangePasswordDialog && ( { setState({ ...state, showChangePasswordDialog: false, }); }} /> )} ); }; export default UserDetail;