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 ChangePasswordDialog: React.FC = (props: Props) => { const { onClose } = props; const { t } = useTranslation(); const userStore = useUserStore(); const [newPassword, setNewPassword] = useState(""); const [newPasswordAgain, setNewPasswordAgain] = useState(""); const requestState = useLoading(false); const handleCloseBtnClick = () => { onClose(); }; const handleNewPasswordChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setNewPassword(text); }; const handleNewPasswordAgainChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setNewPasswordAgain(text); }; const handleSaveBtnClick = async () => { if (newPassword === "" || newPasswordAgain === "") { toast.error("Please fill all inputs"); return; } if (newPassword !== newPasswordAgain) { toast.error("Not matched"); setNewPasswordAgain(""); return; } requestState.setLoading(); try { userStore.patchUser({ id: userStore.getCurrentUser().id, password: newPassword, }); onClose(); toast("Password changed"); } catch (error: any) { console.error(error); toast.error(error.details); } requestState.setFinish(); }; return (
Change Password
New Password
New Password Again
); }; export default ChangePasswordDialog;