import { Button, Input, Modal, ModalDialog } from "@mui/joy"; import { useState } from "react"; import { toast } from "react-hot-toast"; import { useTranslation } from "react-i18next"; import useLoading from "../hooks/useLoading"; import useUserStore from "../stores/v1/user"; import Icon from "./Icon"; interface Props { onClose: () => void; } const EditUserinfoDialog: React.FC = (props: Props) => { const { onClose } = props; const { t } = useTranslation(); const userStore = useUserStore(); const currentUser = userStore.getCurrentUser(); const [email, setEmail] = useState(currentUser.email); const [nickname, setNickname] = useState(currentUser.nickname); const requestState = useLoading(false); const handleCloseBtnClick = () => { onClose(); }; const handleEmailChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setEmail(text); }; const handleNicknameChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setNickname(text); }; const handleSaveBtnClick = async () => { if (email === "" || nickname === "") { toast.error("Please fill all fields"); return; } requestState.setLoading(); try { await userStore.patchUser({ id: currentUser.id, email, nickname, }); onClose(); toast("User information updated"); } catch (error: any) { console.error(error); toast.error(error.details); } requestState.setFinish(); }; return (
Edit Userinfo
{t("common.email")}
{t("user.nickname")}
); }; export default EditUserinfoDialog;