diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx index 8675561..cd144f6 100644 --- a/src/pages/Login.jsx +++ b/src/pages/Login.jsx @@ -24,7 +24,9 @@ const setUser = (user) =>{ export default function Login() { const [loader, setLoader] = useState(false); + const [isErrorVisible, setErrorVisible] = useState(false); const history = useHistory(); + const [form] = Form.useForm(); const logoIcon = АСБ @@ -38,26 +40,65 @@ export default function Login() { }catch(e){ if(e.status === 400) openNotificationError(e.message) - console.error(`Error ${e}`) + console.error(`Error ${e}`) + + setErrorVisible(true) + form.validateFields() setLoader(false) } } + + const showError = (isErrorVisible, errorObj) => { + if (isErrorVisible) + return Promise.reject(errorObj) + + return Promise.resolve() + } return (
-
+ - }/> + rules={[ + { required: true, message: 'Пожалуйста введите имя!' }, + () => ({ + validator() { + return showError(isErrorVisible, new Error('Неправильные логин или пароль!')) + } + }) + ]} + > + } + onChange={() => { + setErrorVisible(false) + form.validateFields() + }} + /> ({ + validator() { + return showError(isErrorVisible) + } + }) + ]} > - }/> + } + onChange={() => { + setErrorVisible(false) + form.validateFields() + }} + />