Skip to content

Commit

Permalink
Merge pull request #14 from Timur233/SOK-15_login_page
Browse files Browse the repository at this point in the history
[SOK-15] Login Page
  • Loading branch information
VladToby authored Oct 10, 2024
2 parents fde4655 + 37b1fd4 commit a54e23e
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 51 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/client/src/pages/Profile/Profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
display: flex;

&__profile-container {
background-image: $img_profile_background_left;
background-image: $img_page_background_left;
background-repeat: no-repeat;
background-position: right bottom;
position: relative;
Expand Down
6 changes: 6 additions & 0 deletions packages/client/src/pages/SignIn/SignIn.scss
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();
}
110 changes: 62 additions & 48 deletions packages/client/src/pages/SignIn/SignIn.tsx
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>
)
}
85 changes: 85 additions & 0 deletions packages/client/src/scss/form-mixin.scss
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;
}
}
3 changes: 2 additions & 1 deletion packages/client/src/scss/vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ $f_default-font-family: 'Roboto', sans-serif;
// images
$img_default-background: url('@/assets/images/page-background.png');
$img_profile_background_right: url('@/assets/images/profile-background-right.png');
$img_profile_background_left: url('@/assets/images/tank-dead.png');
$img_page_background_left: url('@/assets/images/tank-dead.png');
$img_login-background: url('@/assets/images/login-page-sidebar.png');

// main colors
$primary-color: #839d22;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/store/reducers/auth-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type TypeSignInForm = {

export const signInUser = createAsyncThunk(
'AuthUser/signInUser',
async (data: { form: TypeSignInForm; query?: string | null }, thunkAPI) => {
async (data: { form: TypeSignInForm }, thunkAPI) => {
try {
const response = await backendApi({
method: 'post',
Expand Down

0 comments on commit a54e23e

Please sign in to comment.