-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SOK-15] Login Page #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import '../../scss/form-mixin'; | ||
|
||
.login-page { | ||
@include page-background-layout(); | ||
@include form-styles(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,84 @@ | ||
import { useState } from 'react' | ||
import './SignIn.scss' | ||
import React, { useState } from 'react' | ||
import { useAppDispatch } from '@/store' | ||
import { signInUser } from '@/store/reducers/auth-reducer' | ||
import { Button } from '@/components/ui/Button/Button' | ||
import { useSearchParams } from 'react-router-dom' | ||
import { Link } from 'react-router-dom' | ||
import { useNavigate } from 'react-router-dom' | ||
import { toast } from 'react-toastify' | ||
import { Form } from '@/components/ui/Form/Form' | ||
import { Input } from '@/components/ui/Input/Input' | ||
import { CustomPageTitle } from '@/components/ui/CustomPageTitle/CustomPageTitle' | ||
import SiteLogo from '@/assets/images/site-logo.svg' | ||
|
||
export const SignIn = () => { | ||
const [form, setForm] = useState({ login: '', password: '' }) | ||
const [searchParams] = useSearchParams() | ||
const [query] = useState(searchParams.get('redirectUrl')) | ||
const [userData, setUserData] = useState({ login: '', password: '' }) | ||
const [error, setError] = useState<string | null>(null) | ||
const navigate = useNavigate() | ||
const dispatch = useAppDispatch() | ||
|
||
const handleForm = (name: string, value: string) => { | ||
setForm({ ...form, [name]: value }) | ||
} | ||
const handleInputChange = | ||
(field: string) => (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setUserData(prevData => ({ | ||
...prevData, | ||
[field]: event.target.value, | ||
})) | ||
} | ||
|
||
const handleSubmit = () => { | ||
dispatch(signInUser({ form: form, query: query })) | ||
dispatch(signInUser({ form: userData })) | ||
.unwrap() | ||
.then(() => { | ||
navigate('/game') | ||
}) | ||
.catch((error?: any, code?: any) => { | ||
toast.error(error.reason) | ||
.catch((_error?: any, _code?: any) => { | ||
setError('Ошибка входа в аккаунт!') | ||
}) | ||
} | ||
|
||
return ( | ||
<> | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault() | ||
}}> | ||
<label> | ||
<span>Логин</span> | ||
<input | ||
onChange={e => handleForm('login', e.target.value)} | ||
type="text" | ||
name={'login'} | ||
value={form.login} | ||
/> | ||
</label> | ||
<label> | ||
<span>Пароль</span> | ||
<input | ||
onChange={e => handleForm('password', e.target.value)} | ||
type="password" | ||
name={'password'} | ||
value={form.password} | ||
/> | ||
</label> | ||
<Button | ||
text={'войти'} | ||
useFixWidth={true} | ||
onClick={() => handleSubmit()} | ||
<div className={'login-page'}> | ||
<Link className="login-page__link" to="/"> | ||
<img | ||
src={SiteLogo} | ||
className="login-page__link__image" | ||
alt="Falcon Tanks Logo" | ||
draggable="false" | ||
/> | ||
</form> | ||
<Button | ||
text={'Регистрация'} | ||
useFixWidth={true} | ||
onClick={() => { | ||
navigate('/sign-up') | ||
}} | ||
/> | ||
</> | ||
</Link> | ||
<div className="container"> | ||
<div className={'row'}> | ||
<div className={'column col-6'}> | ||
<CustomPageTitle className={'login-page__title'} text={'Вход'} /> | ||
<Form className={'login-page__login-form'}> | ||
<Input | ||
className={'login'} | ||
name={'login'} | ||
placeholder={'Логин'} | ||
onChange={handleInputChange('login')} | ||
/> | ||
<Input | ||
className={'password'} | ||
name={'password'} | ||
type={'password'} | ||
placeholder={'Пароль'} | ||
onChange={handleInputChange('password')} | ||
/> | ||
{error && ( | ||
<div className={'login-page__error-message'}>{error}</div> | ||
)} | ||
</Form> | ||
<Button text={'Войти'} useFixWidth={true} onClick={handleSubmit} /> | ||
<Button | ||
className={'link-button'} | ||
text={'Регистрация'} | ||
useFixWidth={true} | ||
onClick={() => { | ||
navigate('/sign-up') | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Как будто это не кнопка, а ссылка. |
||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
@import 'vars'; | ||
|
||
@mixin page-background-layout( | ||
$background-image: ( | ||
$img_login-background, | ||
$img_page_background_left, | ||
), | ||
$background-repeat: ( | ||
no-repeat, | ||
no-repeat, | ||
), | ||
$background-size: ( | ||
contain, | ||
auto, | ||
), | ||
$background-position: ( | ||
left bottom, | ||
right bottom, | ||
) | ||
) { | ||
background-image: $background-image; | ||
background-repeat: $background-repeat; | ||
background-size: $background-size; | ||
background-position: $background-position; | ||
} | ||
|
||
@mixin form-styles { | ||
height: 100vh; | ||
display: flex; | ||
justify-content: flex-end; | ||
|
||
.container { | ||
margin-top: auto; | ||
margin-bottom: auto; | ||
width: 768px; | ||
|
||
.row { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Возможно стоит уточнить у @Timur233. У нас такой класс есть в grid-system. Не создает ли это проблем. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не создаёт, потому что используется в конкретном месте в There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Значит ты теряешь возможность использовать There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Так я изменяю его в конкретном месте, так же как и ширину контейнера выше например |
||
justify-content: end; | ||
|
||
.column { | ||
.custom-button { | ||
margin: 0 auto; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&__link { | ||
position: absolute; | ||
left: 0; | ||
|
||
&__image { | ||
margin-left: 25%; | ||
width: 150px; | ||
} | ||
} | ||
|
||
&__title { | ||
margin-bottom: 48px; | ||
} | ||
|
||
.form-fields { | ||
display: flex; | ||
flex-direction: column; | ||
width: 301px; | ||
margin: 0 auto 48px; | ||
|
||
.input-wrapper { | ||
margin-bottom: 16px; | ||
|
||
.input-default { | ||
width: 100%; | ||
} | ||
|
||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
|
||
&__error-message { | ||
color: $error-color; | ||
text-wrap: wrap; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Возможно тут стоит добавить пропс
type
. И тогда можно будет методhandleSubmit
переименовать вtrySingIn
.handleSubmit
просто не дает понимания что конкретно произойдет по клику, кроме того, что он будет обработан)