Skip to content
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

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно тут стоит добавить пропс type. И тогда можно будет метод handleSubmit переименовать в trySingIn.

handleSubmit просто не дает понимания что конкретно произойдет по клику, кроме того, что он будет обработан)

className={'link-button'}
text={'Регистрация'}
useFixWidth={true}
onClick={() => {
navigate('/sign-up')
}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как будто это не кнопка, а ссылка.

/>
</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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно стоит уточнить у @Timur233.

У нас такой класс есть в grid-system. Не создает ли это проблем.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не создаёт, потому что используется в конкретном месте в SignIn.scss

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Значит ты теряешь возможность использовать .row из grid-system в SignIn.scss. Что, возможно, потенциальная проблема.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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;
}
}
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
Loading
Loading