vchikalkin 8a1f6997ea apps/web: remove elements components
define global elements css
2024-05-03 13:38:17 +03:00

42 lines
1.2 KiB
JavaScript

import styles from './Form.module.scss';
import { publicRuntimeConfig } from '@/config/runtime';
import axios from 'axios';
import { useState } from 'react';
const { APP_BASE_PATH } = publicRuntimeConfig;
export function Form() {
const [hasError, setHasError] = useState(false);
return (
<form
className={styles.form}
onSubmit={(e) => {
e.preventDefault();
const login = e.target[0].value;
const password = e.target[1].value;
const data = { login, password };
axios
.post('/login', data)
.then(() => {
const url =
(window.location.pathname.replace(APP_BASE_PATH, '') || '/') +
(window.location.search || '');
window.location.replace(url);
})
.catch(() => {
setHasError(true);
});
}}
>
<input name="login" type="text" placeholder="Логин" required autoComplete="on" />
<input name="password" type="password" placeholder="Пароль" required autoComplete="on" />
{hasError ? <span className="error">Неверный логин или пароль</span> : null}
<button type="submit">Войти</button>
</form>
);
}