import { useIntl } from "react-intl"; import { ProForm, ProFormText } from "@ant-design/pro-components"; import { message } from "antd"; import { useNavigate } from "react-router-dom"; import { useAppDispatch } from "../../../hooks"; import { IUser, signIn, TO_HOME } from "../../../reducers/current-user"; import { get, post } from "../../../request"; interface IFormData { email: string; password: string; } interface ISignInResponse { ok: boolean; message: string; data: string; } interface IUserResponse { ok: boolean; message: string; data: IUser; } interface ISignInRequest { username: string; password: string; } const Widget = () => { const intl = useIntl(); const dispatch = useAppDispatch(); const navigate = useNavigate(); return ( onFinish={async (values: IFormData) => { // TODO console.log(values); const user = { username: values.email, password: values.password, }; const signin = await post( "/v2/auth/signin", user ); if (signin.ok) { console.log("token", signin.data); localStorage.setItem("token", signin.data); get("/v2/auth/current").then((json) => { if (json.ok) { dispatch(signIn([json.data, signin.data])); navigate(TO_HOME); } else { console.error(json.message); } }); message.success(intl.formatMessage({ id: "flashes.success" })); } else { message.error(signin.message); } }} > ); }; export default Widget;