memos/web/src/components/BindWxOpenIdDialog.tsx
2021-12-09 21:45:48 +08:00

80 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useEffect, useState } from "react";
import { userService } from "../services";
import { showDialog } from "./Dialog";
import toastHelper from "./Toast";
import "../less/change-password-dialog.less";
interface Props extends DialogProps {}
const BindWxOpenIdDialog: React.FC<Props> = ({ destroy }: Props) => {
const [wxOpenId, setWxOpenId] = useState("");
useEffect(() => {
// do nth
}, []);
const handleCloseBtnClick = () => {
destroy();
};
const handleWxOpenIdChanged = (e: React.ChangeEvent<HTMLInputElement>) => {
const text = e.target.value as string;
setWxOpenId(text);
};
const handleSaveBtnClick = async () => {
if (wxOpenId === "") {
toastHelper.error("微信 id 不能为空");
return;
}
try {
await userService.updateWxOpenId(wxOpenId);
userService.doSignIn();
toastHelper.info("绑定成功!");
handleCloseBtnClick();
} catch (error: any) {
toastHelper.error(error);
}
};
return (
<>
<div className="dialog-header-container">
<p className="title-text"> OpenID</p>
<button className="btn close-btn" onClick={handleCloseBtnClick}>
<img className="icon-img" src="/icons/close.svg" />
</button>
</div>
<div className="dialog-content-container">
<p className="tip-text">
<strong>OpenID</strong>
</p>
<label className="form-label input-form-label">
<span className={"normal-text " + (wxOpenId === "" ? "" : "not-null")}> OpenID</span>
<input type="text" value={wxOpenId} onChange={handleWxOpenIdChanged} />
</label>
<div className="btns-container">
<span className="btn cancel-btn" onClick={handleCloseBtnClick}>
</span>
<span className="btn confirm-btn" onClick={handleSaveBtnClick}>
</span>
</div>
</div>
</>
);
};
function showBindWxOpenIdDialog() {
showDialog(
{
className: "bind-wxid-dialog",
},
BindWxOpenIdDialog
);
}
export default showBindWxOpenIdDialog;