diff --git a/src/stores/Auth.js b/src/stores/Auth.js index 1ad725a..d8cac0a 100644 --- a/src/stores/Auth.js +++ b/src/stores/Auth.js @@ -19,12 +19,7 @@ class Auth { return fetchJSON(fetchUrl) .then(json => { if (json.errcode == 0) { - runInAction(() => { - this.login = { - userId: json.Result.WU_LMI_SN, - username: json.Result.WU_UserName, - } - }); + return json.Result.WU_LMI_SN; } else { throw new Error(json.errmsg + ': ' + json.errcode); } @@ -48,6 +43,7 @@ class Auth { cityId: json.Result.citysn } }); + return json.Result.LoginName; } else { throw new Error(json.errmsg + ': ' + json.errcode); } diff --git a/src/views/Login.jsx b/src/views/Login.jsx index 794b571..f28c6e2 100644 --- a/src/views/Login.jsx +++ b/src/views/Login.jsx @@ -1,20 +1,44 @@ +import { useNavigate } from "react-router-dom"; import { Button, Checkbox, Form, Input, Row, App } from 'antd'; import { useStore } from '@/stores/StoreContext.js'; function Login() { const { authStore } = useStore(); + const navigate = useNavigate(); const { notification } = App.useApp(); const onFinish = (values) => { - console.log('Success:', values); - authStore.valdateUserPassword(values.username, values.password); + authStore.valdateUserPassword(values.username, values.password) + .then((userId) => { + authStore.fetchUserDetail(userId) + .then((user) => { + // navigate(-1) is equivalent to hitting the back button. + navigate("/reservation/newest"); + }) + .catch(ex => { + notification.error({ + message: `Notification`, + description: ex.message, + placement: 'top', + duration: 4, + }); + }); + }) + .catch(ex => { + notification.error({ + message: `Notification`, + description: ex.message, + placement: 'top', + duration: 4, + }); + }); }; const onFinishFailed = (errorInfo) => { console.log('Failed:', errorInfo); }; - + return (
- - Remember me -