generated from yandex-praktikum/client-server-template-with-vite
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Timur233/SOK-15_login_page
[SOK-15] Login Page
- Loading branch information
Showing
7 changed files
with
157 additions
and
51 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters