-
Notifications
You must be signed in to change notification settings - Fork 0
Add login page draft #13
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e4e39c0
feat: add basic logic for sing up/sing in. Draft. Saving imtermediateβ¦
Tedzury b2094f1
feat: separating forms to own files. draft. Saving intermediate results
Tedzury 09e9124
fix: pull update from develop branch. Resolve merge conflicts
Tedzury 15ea0c1
feat: add proper routing for auth. Add errors notification during logβ¦
Tedzury 78663b4
feat: add logic for privatge routes and redirection. Separate router β¦
Tedzury 4c251b3
refactor: isolated login and logout logic into auth context component
Tedzury eff4459
fix: pull changes from develop to be up to date. Resolve merge conflict
Tedzury e806562
feat: add layout and translation for login page
Tedzury 0f034c0
feat: add layout for sign up page
Tedzury 8e3612f
feat: add tests for helpers functions
Tedzury 8a22978
feat: add test for login page and private routes
Tedzury 991f2cb
feat: add test for sign up page. Refactor: move web comp mocks to setβ¦
Tedzury 67149be
fix: remove screen.debug
Tedzury a702473
feat: add logic for localizing en/ru for error messages at login and β¦
Tedzury fad8ac2
fix: fix back def lang to en
Tedzury e5208d3
add logic and UI for toggling show/hide password
Tedzury 9b9338b
fix: fix tests setup and icon mock
Tedzury 2dba41c
feat: add some styling and localized toastify notations
Tedzury b5c301d
feat: add variativiry for test error msgs. Centered toastify msg
Tedzury 1557b26
fix:remove commented code
Tedzury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,18 @@ | ||
| import { createHashRouter, RouterProvider } from 'react-router-dom'; | ||
| import { RouterProvider } from 'react-router-dom'; | ||
|
|
||
| import MainLayout from '@/layouts/MainLayout'; | ||
| import LoginPage from '@pages/LoginPage'; | ||
| import MainPage from '@pages/MainPage'; | ||
| import WelcomePage from '@pages/WelcomePage'; | ||
| import router from '@/router/router'; | ||
|
|
||
| import ROUTES from './shared/constatns/routes'; | ||
|
|
||
| const router = createHashRouter([ | ||
| { | ||
| path: '/', | ||
| element: <MainLayout />, | ||
| children: [ | ||
| { | ||
| path: ROUTES.WELCOME_PAGE, | ||
| element: <WelcomePage />, | ||
| }, | ||
| { | ||
| path: ROUTES.LOGIN, | ||
| element: <LoginPage />, | ||
| }, | ||
| { | ||
| path: ROUTES.MAIN, | ||
| element: <MainPage />, | ||
| }, | ||
| ], | ||
| }, | ||
| ]); | ||
| import AuthProvider from './shared/Context/AuthContext'; | ||
| import LanguageProvider from './shared/Context/LanguageContext'; | ||
|
|
||
| const App = () => { | ||
| return <RouterProvider router={router} />; | ||
| return ( | ||
| <AuthProvider> | ||
| <LanguageProvider> | ||
| <RouterProvider router={router} /> | ||
| </LanguageProvider> | ||
| </AuthProvider> | ||
| ); | ||
| }; | ||
|
|
||
| export default App; |
Empty file.
This file contains hidden or 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,12 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { createComponent } from '@lit/react'; | ||
| import { MdOutlinedTextField } from '@material/web/textfield/outlined-text-field'; | ||
|
|
||
| const FormInput = createComponent({ | ||
| react: React, | ||
| tagName: 'md-outlined-text-field', | ||
| elementClass: MdOutlinedTextField, | ||
| }); | ||
|
|
||
| export default FormInput; |
This file contains hidden or 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,28 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { createComponent } from '@lit/react'; | ||
| import { MdIcon } from '@material/web/icon/icon'; | ||
| import { MdIconButton } from '@material/web/iconbutton/icon-button'; | ||
|
|
||
| const Icon = createComponent({ | ||
| react: React, | ||
| tagName: 'md-icon', | ||
| elementClass: MdIcon, | ||
| }); | ||
|
|
||
| const IconSlot = createComponent({ | ||
| react: React, | ||
| tagName: 'md-icon-button', | ||
| elementClass: MdIconButton, | ||
| }); | ||
|
|
||
| const PassVisibilityIcon = ({ onClick }: { onClick: () => void }) => { | ||
| return ( | ||
| <IconSlot toggle slot="trailing-icon" onClick={onClick}> | ||
| <Icon>visibility</Icon> | ||
| <Icon slot="selected">visibility_off</Icon> | ||
| </IconSlot> | ||
| ); | ||
| }; | ||
|
|
||
| export default PassVisibilityIcon; |
This file contains hidden or 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,12 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { createComponent } from '@lit/react'; | ||
| import { MdFilledTonalButton } from '@material/web/button/filled-tonal-button'; | ||
|
|
||
| const SubmitBtn = createComponent({ | ||
| react: React, | ||
| tagName: 'md-filled-tonal-button', | ||
| elementClass: MdFilledTonalButton, | ||
| }); | ||
|
|
||
| export default SubmitBtn; |
This file contains hidden or 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,14 @@ | ||
| import { initializeApp } from 'firebase/app'; | ||
|
|
||
| const firebaseConfig = { | ||
| apiKey: 'AIzaSyAijnqgoeQIQJu_lKQ6fgNC7a0fIEuND2c', | ||
| authDomain: 'graphiql-app-47127.firebaseapp.com', | ||
| projectId: 'graphiql-app-47127', | ||
| storageBucket: 'graphiql-app-47127.appspot.com', | ||
| messagingSenderId: '1033759243197', | ||
| appId: '1:1033759243197:web:3757214e041ae1ab0bf0d4', | ||
| }; | ||
|
|
||
| const initFirebaseApp = () => initializeApp(firebaseConfig); | ||
|
|
||
| export default initFirebaseApp; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Tedzury marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,5 +1,103 @@ | ||
| const LoginPage = () => { | ||
| return <section>Here is my fancy login page!</section>; | ||
| }; | ||
| import { useState } from 'react'; | ||
|
|
||
| export default LoginPage; | ||
| import { yupResolver } from '@hookform/resolvers/yup'; | ||
| import { TextFieldType } from '@material/web/textfield/outlined-text-field'; | ||
| import { getAuth, signInWithEmailAndPassword } from 'firebase/auth'; | ||
| import { useForm } from 'react-hook-form'; | ||
| import { Link, useNavigate } from 'react-router-dom'; | ||
|
|
||
| import PassVisibilityIcon from '@/components/loginReg/PassVisibilityIcon'; | ||
| import AUTH_ERRORS from '@/shared/constants/authErrors'; | ||
| import ROUTES from '@/shared/constants/routes'; | ||
| import { loginValidationSchema } from '@/shared/constants/validationSchema'; | ||
| import useAuth from '@/shared/Context/authHook'; | ||
| import useLanguage from '@/shared/Context/hooks'; | ||
| import notationLocalizer from '@/shared/helpers/notationLocalizer'; | ||
| import switchPassType from '@/shared/helpers/switchPassType'; | ||
| import toastifyNotation from '@/shared/helpers/toastifyNotation'; | ||
| import { ErrorType, TextInputProps } from '@/shared/types'; | ||
| import FormInput from '@components/loginReg/FormInput'; | ||
| import SubmitBtn from '@components/loginReg/SubmitBtn'; | ||
|
|
||
| export default function LoginPage() { | ||
| const navigate = useNavigate(); | ||
| const [passType, setPassType] = useState('password'); | ||
| const { translation, language } = useLanguage(); | ||
| const { title, subtitle, emailPlaceHold, passPlaceHold, btnTitle, linkClue, linkTitle } = translation.loginPage; | ||
| const { logInAuth } = useAuth(); | ||
|
|
||
| const { | ||
| register, | ||
| handleSubmit, | ||
| formState: { errors, isValid }, | ||
| reset, | ||
| } = useForm({ | ||
| resolver: yupResolver(loginValidationSchema), | ||
| mode: 'all', | ||
| }); | ||
|
|
||
| async function onSubmit({ email, password }: { email: string; password: string }) { | ||
| const auth = getAuth(); | ||
| try { | ||
| const { user } = await signInWithEmailAndPassword(auth, email, password); | ||
| if (user) { | ||
| logInAuth(user.email as string); | ||
| reset(); | ||
| navigate(`/${ROUTES.MAIN}`); | ||
| } | ||
| return null; | ||
| } catch (e) { | ||
| if ((e as ErrorType).code === AUTH_ERRORS.INVALID_EMAIL) | ||
| return toastifyNotation(notationLocalizer(language, 'code8')); | ||
| if ((e as ErrorType).code === AUTH_ERRORS.INVALID_PASS) | ||
| return toastifyNotation(notationLocalizer(language, 'code9')); | ||
| return toastifyNotation(notationLocalizer(language, 'code11')); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <section className="mx-5 flex items-center justify-center"> | ||
| <article className="w-[560px] rounded-[30px] bg-surface-container px-7 py-[60px] sm:px-20"> | ||
| <h1 className="text-center text-2xl font-[400] text-on-surface">{title}</h1> | ||
| <h2 className="mt-3 text-center text-base font-[400] text-on-surface-variant">{subtitle}</h2> | ||
| <form noValidate className="mt-8" onSubmit={handleSubmit(onSubmit)}> | ||
| <div className="relative"> | ||
| <FormInput | ||
| style={{ width: '100%' }} | ||
| {...(register('email') as TextInputProps)} | ||
| type="email" | ||
| placeholder={emailPlaceHold} | ||
| label={emailPlaceHold} | ||
| /> | ||
| <p className="absolute left-4 top-[62px] text-sm font-[400] text-on-surface"> | ||
| {notationLocalizer(language, errors.email?.message)} | ||
| </p> | ||
| </div> | ||
| <div className="relative mt-12"> | ||
| <FormInput | ||
| className="w-full" | ||
| {...(register('password') as TextInputProps)} | ||
| type={passType as TextFieldType} | ||
| placeholder={passPlaceHold} | ||
| label={passPlaceHold} | ||
| > | ||
| <PassVisibilityIcon onClick={() => setPassType((prev) => switchPassType(prev))} /> | ||
| </FormInput> | ||
| <p className="absolute left-4 top-[62px] text-sm font-[400] text-on-surface"> | ||
| {notationLocalizer(language, errors.password?.message)} | ||
| </p> | ||
| </div> | ||
| <SubmitBtn className="mt-[52px] w-full" disabled={!isValid}> | ||
| {btnTitle} | ||
| </SubmitBtn> | ||
| </form> | ||
| <p className="mt-8 text-center text-sm font-[400] text-on-surface-variant"> | ||
| {linkClue}{' '} | ||
| <Link className="text-primary" to={`/${ROUTES.AUTH}/${ROUTES.SIGNUP}`}> | ||
| {linkTitle} | ||
| </Link> | ||
| </p> | ||
| </article> | ||
| </section> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.