-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
перешёл на react-hook-form, поправил кастомные элементы
- Loading branch information
Showing
9 changed files
with
184 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,35 +1,54 @@ | ||
import React from 'react'; | ||
import CustomInput from "../../UIComponents/customInput/CustomInput.tsx"; | ||
import React, {FormEvent, useCallback, useState} from 'react'; | ||
|
||
import authStore from "../../store/authStore.ts"; | ||
|
||
import CustomInput from "../../UIComponents/customInput/CustomInput.tsx"; | ||
import CustomCheckbox from "../../UIComponents/customCheckbox/CustomCheckbox.tsx"; | ||
import CustomButton from "../../UIComponents/customButton/CustomButton.tsx"; | ||
|
||
import {useNavigate} from "react-router-dom" | ||
import {observer} from "mobx-react-lite"; | ||
import {useForm} from "react-hook-form"; | ||
|
||
const AuthForm: React.FC = observer(() => { | ||
const AuthForm: React.FC = () => { | ||
const navigateTo = useNavigate() | ||
const {register, handleSubmit} = useForm() | ||
|
||
const [isPasswordShows, setIsPasswordShows] = useState(false) | ||
|
||
const handleOnChangeIsPasswordShows = useCallback((event: FormEvent<HTMLInputElement>) => { | ||
setIsPasswordShows(!event.currentTarget.checked) | ||
}, []) | ||
|
||
return ( | ||
<form className="auth__form"> | ||
<form className="auth__form" onSubmit={handleSubmit((data) => { | ||
console.log(data) | ||
})}> | ||
<h2 className="auth-form-title">ВХОД</h2> | ||
<fieldset className="auth-fields"> | ||
<CustomInput type="email" value={authStore.userLogin} autoFocus={true} placeholder="Логин" | ||
handleOnChange={(e) => { | ||
authStore.changeUserLogin(e) | ||
authStore.changeUserEmail(e) | ||
}}/> | ||
<CustomInput | ||
type={authStore.isPasswordShows ? "text" : "password"} placeholder="Пароль" | ||
value={authStore.userPassword} handleOnChange={(e) => authStore.changeUserPassword(e)}/> | ||
<CustomInput | ||
type="email" | ||
register={register} | ||
name={"userLogin"} | ||
autoFocus={true} | ||
placeholder="Логин" | ||
required={true} | ||
/> | ||
<CustomInput | ||
type={isPasswordShows ? "text" : "password"} | ||
register={register} | ||
name={"userPassword"} | ||
placeholder="Пароль" | ||
required={true} | ||
/> | ||
</fieldset> | ||
<CustomCheckbox text="Показать пароль" id="is-remember" | ||
additionalClassName="is-remember-password__checkbox" | ||
handleOnChange={authStore.changeIsPasswordShows}/> | ||
<CustomButton additionalClassName="auth__btn" text="ВОЙТИ" handleOnClick={() => { | ||
authStore.signIn().then(() => navigateTo('/map')) | ||
}}/> | ||
<CustomCheckbox | ||
text="Показать пароль" | ||
id="is-remember" | ||
additionalClassName="is-remember-password__checkbox" | ||
handleOnChange={handleOnChangeIsPasswordShows} | ||
/> | ||
<input type="submit" className="auth__btn" value="ВОЙТИ"/> | ||
</form> | ||
); | ||
}); | ||
}; | ||
|
||
export default AuthForm; |
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,19 +1,26 @@ | ||
import React from 'react'; | ||
import React, {useCallback} from 'react'; | ||
import './../../styles/authentication.scss' | ||
import CustomButton from "../../UIComponents/customButton/CustomButton.tsx"; | ||
import {useNavigate} from "react-router-dom"; | ||
import AuthForm from "./AuthForm.tsx"; | ||
import {observer} from "mobx-react-lite"; | ||
|
||
const Authentication: React.FC = () => { | ||
const navigateTo = useNavigate() | ||
const Authentication: React.FC = observer(() => { | ||
const navigate = useNavigate() | ||
const handleOnClickBackToWelcomePage = useCallback(() => { | ||
navigate("/") | ||
}, [navigate]) | ||
|
||
return ( | ||
<div className="auth-page"> | ||
<AuthForm/> | ||
<CustomButton additionalClassName="back-to-welcome-page__btn" text="Вернуться обратно" | ||
handleOnClick={() => navigateTo('/')}></CustomButton> | ||
<CustomButton | ||
additionalClassName="back-to-welcome-page__btn" | ||
text="Вернуться обратно" | ||
handleOnClick={handleOnClickBackToWelcomePage} | ||
/> | ||
</div> | ||
); | ||
}; | ||
}); | ||
|
||
export default Authentication; |
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
Oops, something went wrong.