import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import { useUserStore } from "@/store/module"; import { useTranslate } from "@/utils/i18n"; import { generateDialog } from "./Dialog"; import Icon from "./Icon"; interface Props extends DialogProps { user: User; } const ChangeMemberPasswordDialog: React.FC = (props: Props) => { const { user: propsUser, destroy } = props; const t = useTranslate(); const userStore = useUserStore(); const [newPassword, setNewPassword] = useState(""); const [newPasswordAgain, setNewPasswordAgain] = useState(""); useEffect(() => { // do nth }, []); const handleCloseBtnClick = () => { destroy(); }; 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(t("message.fill-all")); return; } if (newPassword !== newPasswordAgain) { toast.error(t("message.new-password-not-match")); setNewPasswordAgain(""); return; } try { await userStore.patchUser({ id: propsUser.id, password: newPassword, }); toast(t("message.password-changed")); handleCloseBtnClick(); } catch (error: any) { console.error(error); toast.error(error.response.data.message); } }; return ( <>

{t("setting.account-section.change-password")} ({propsUser.username})

{t("auth.new-password")}

{t("auth.repeat-new-password")}

{t("common.cancel")} {t("common.save")}
); }; function showChangeMemberPasswordDialog(user: User) { generateDialog( { className: "change-member-password-dialog", dialogName: "change-member-password-dialog", }, ChangeMemberPasswordDialog, { user } ); } export default showChangeMemberPasswordDialog;