-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: Настроить структуру auth route ( #41 ) #54
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
9 commits
Select commit
Hold shift + click to select a range
ad64b92
feat(web): настроить алиасы
Fing0r 9b14667
feat(web): добавить AuthLayout
Fing0r 74e1023
feat(web): добавить login page
Fing0r e42942c
feat(web): добавить register page
Fing0r c65ccf3
fix(web): удалить пример authorization
Fing0r 56d7827
fix(web): удалить неиспользуемый импорт
Fing0r 387fc0b
fix(web): обернуть компоненты формы в тег form с хендлером
Fing0r edb905d
fix(web): добавить стили на теге form в login и register page
Fing0r d176346
fix(web): заменить autoComplete='off' на autoComplete='email' в форме…
Fing0r 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 'use client' | ||
|
|
||
| import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@repo/ui' | ||
|
|
||
| interface Props { | ||
| title?: React.ReactNode | ||
| children: React.ReactNode | ||
| footer?: React.ReactNode | ||
| } | ||
|
|
||
| const AuthFormLayout = (props: Props) => { | ||
| const { title, children, footer } = props | ||
|
|
||
| return ( | ||
| <Card className='w-full max-w-sm'> | ||
| <CardHeader> | ||
| <CardTitle>{title}</CardTitle> | ||
| </CardHeader> | ||
| <CardContent>{children}</CardContent> | ||
| <CardFooter>{footer}</CardFooter> | ||
| </Card> | ||
| ) | ||
| } | ||
|
|
||
| export { AuthFormLayout } |
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,20 @@ | ||
| import { FEATURES } from '@/hooks/use-feature-flag' | ||
| import { notFound } from 'next/navigation' | ||
|
|
||
| import { HStack } from '@repo/ui' | ||
|
|
||
| interface Props { | ||
| children: React.ReactNode | ||
| } | ||
|
|
||
| export default function AuthLayout({ children }: Props) { | ||
| if (!FEATURES.AUTH) { | ||
| notFound() | ||
| } | ||
|
|
||
| return ( | ||
| <HStack align='center' justify='center' className='min-h-screen bg-foreground'> | ||
| {children} | ||
| </HStack> | ||
| ) | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 'use client' | ||
|
|
||
| import { Button, Form } from '@repo/ui' | ||
|
|
||
| import { AuthFormLayout } from '../auth-form-layout' | ||
| import { LoginForm } from './login-form' | ||
| import { LoginFormValues, useLoginForm } from './use-login-form' | ||
|
|
||
| export default function LoginPage() { | ||
| const form = useLoginForm() | ||
|
|
||
| const onSubmit = async (data: LoginFormValues) => { | ||
| console.log(data) | ||
| } | ||
|
|
||
| return ( | ||
| <Form {...form}> | ||
| <form onSubmit={form.handleSubmit(onSubmit)} className='w-full max-w-sm'> | ||
| <AuthFormLayout | ||
| title='Войдите в свой аккаунт' | ||
| footer={ | ||
| <Button | ||
| disabled={form.formState.isSubmitting} | ||
| type='submit' | ||
| variant='default' | ||
| className='w-full' | ||
| > | ||
| Войти | ||
| </Button> | ||
| } | ||
| > | ||
| <LoginForm /> | ||
| </AuthFormLayout> | ||
| </form> | ||
| </Form> | ||
| ) | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 'use client' | ||
|
|
||
| import { Button, Form } from '@repo/ui' | ||
|
|
||
| import { AuthFormLayout } from '../auth-form-layout' | ||
| import { RegisterForm } from './register-form' | ||
| import { RegisterFormValues, useRegisterForm } from './use-register-form' | ||
|
|
||
| export default function RegisterPage() { | ||
| const form = useRegisterForm() | ||
|
|
||
| const onSubmit = async (data: RegisterFormValues) => { | ||
| console.log(data) | ||
| } | ||
|
|
||
| return ( | ||
| <Form {...form}> | ||
| <form onSubmit={form.handleSubmit(onSubmit)} className='w-full max-w-sm'> | ||
| <AuthFormLayout | ||
| title='Регистрация' | ||
| footer={ | ||
| <Button | ||
| disabled={form.formState.isSubmitting} | ||
| type='submit' | ||
| variant='default' | ||
| className='w-full' | ||
| > | ||
| Зарегистрироваться | ||
| </Button> | ||
| } | ||
| > | ||
| <RegisterForm /> | ||
| </AuthFormLayout> | ||
| </form> | ||
| </Form> | ||
| ) | ||
| } |
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,78 @@ | ||
| 'use client' | ||
|
|
||
| import { useFormContext } from 'react-hook-form' | ||
|
|
||
| import { | ||
| FormControl, | ||
| FormField, | ||
| FormItem, | ||
| FormLabel, | ||
| FormMessage, | ||
| Input, | ||
| VStack, | ||
| } from '@repo/ui' | ||
|
|
||
| import { RegisterFormValues } from './use-register-form' | ||
|
|
||
| const RegisterForm = () => { | ||
| const { control } = useFormContext<RegisterFormValues>() | ||
|
|
||
| return ( | ||
| <VStack> | ||
| <FormField | ||
| control={control} | ||
| name='email' | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Почта</FormLabel> | ||
| <FormControl> | ||
| <Input {...field} autoComplete='email' /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| <FormField | ||
| control={control} | ||
| name='name' | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Имя</FormLabel> | ||
| <FormControl> | ||
| <Input {...field} /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| <FormField | ||
| control={control} | ||
| name='password' | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Пароль</FormLabel> | ||
| <FormControl> | ||
| <Input {...field} type='password' autoComplete='new-password' /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| <FormField | ||
| control={control} | ||
| name='confirmPassword' | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Подтверждение пароля</FormLabel> | ||
| <FormControl> | ||
| <Input {...field} type='password' autoComplete='new-password' /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| </VStack> | ||
| ) | ||
| } | ||
|
|
||
| export { RegisterForm } |
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,40 @@ | ||
| 'use client' | ||
|
|
||
| import { standardSchemaResolver } from '@hookform/resolvers/standard-schema' | ||
| import { useForm } from 'react-hook-form' | ||
| import { z } from 'zod' | ||
|
|
||
| const formSchema = z | ||
| .object({ | ||
| email: z.email({ | ||
| message: 'Пожалуйста, введите правильный адрес электронной почты.', | ||
| }), | ||
| name: z.string().min(2, { | ||
| message: 'Имя должно содержать не менее 2 символов.', | ||
| }), | ||
| password: z.string().min(8, { | ||
| message: 'Пароль должен содержать не менее 8 символов.', | ||
| }), | ||
| confirmPassword: z.string().min(8, { | ||
| message: 'Пароль должен содержать не менее 8 символов.', | ||
| }), | ||
| }) | ||
| .refine((data) => data.password === data.confirmPassword, { | ||
| message: 'Пароли не совпадают.', | ||
| path: ['confirmPassword'], | ||
| }) | ||
|
|
||
| export type RegisterFormValues = z.infer<typeof formSchema> | ||
|
|
||
| const useRegisterForm = () => | ||
| useForm<RegisterFormValues>({ | ||
| resolver: standardSchemaResolver(formSchema), | ||
| defaultValues: { | ||
| email: '', | ||
| password: '', | ||
| confirmPassword: '', | ||
| name: '', | ||
| }, | ||
| }) | ||
|
|
||
| export { useRegisterForm } |
24 changes: 0 additions & 24 deletions
24
apps/web/app/authorization/authorization-dialog-layout.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.