Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(user): add layout for sign forms
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Feb 20, 2019
1 parent 9daad77 commit 76ef718
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 51 deletions.
8 changes: 8 additions & 0 deletions front/src/features/landing/features/SignForm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.container {
max-width: 300px;
}

.card {
display: grid;
gap: 16px;
}
47 changes: 25 additions & 22 deletions front/src/features/landing/features/sign-in/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { useCallback } from 'react'
import { Field, Form } from 'react-final-form'
import { Form } from 'react-final-form'
import { useMappedState } from 'redux-react-hook'

import { useSignIn } from '@front/domain/user/hooks/useSignIn'
import { getSignInFetching } from '@front/domain/user/selectors/getSignInFetching'
import { Input } from '@front/features/final-form'
import { pushRoute } from '@front/pushRoute'
import { InputType } from '@front/ui/atoms/input/InputType'
import { Label } from '@front/ui/atoms/label'
import { LoadingButton } from '@front/ui/atoms/loading-button'
import { Card } from '@front/ui/molecules/card'

import * as styles from '../SignForm.css'

export const SignIn = () => {
const signIn = useSignIn()
Expand All @@ -20,27 +26,24 @@ export const SignIn = () => {
return (
<Form onSubmit={onSubmit}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<h2>Sign-in</h2>

<div>
<label>Email</label>
<Field
name="email"
component="input"
placeholder="email@example.com"
type="email"
/>
</div>

<div>
<label>Password</label>
<Field name="password" component="input" type="password" />
</div>

<LoadingButton fethcing={fetching} submit>
Sign-in
</LoadingButton>
<form onSubmit={handleSubmit} className={styles.container}>
<Card title="Sign-in" className={styles.card}>
<Label text="Email">
<Input
name="email"
type={InputType.Email}
placeholder="email@example.com"
/>
</Label>

<Label text="Password">
<Input name="password" type={InputType.Password} />
</Label>

<LoadingButton fethcing={fetching} submit>
Sign-in
</LoadingButton>
</Card>
</form>
)}
</Form>
Expand Down
56 changes: 29 additions & 27 deletions front/src/features/landing/features/sign-up/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { useCallback } from 'react'
import { Field, Form } from 'react-final-form'
import { Form } from 'react-final-form'
import { useMappedState } from 'redux-react-hook'

import { useSignUp } from '@front/domain/user/hooks/useSignUp'
import { getSignUpFetching } from '@front/domain/user/selectors/getSignUpFetching'
import { Input } from '@front/features/final-form'
import { pushRoute } from '@front/pushRoute'
import { InputType } from '@front/ui/atoms/input/InputType'
import { Label } from '@front/ui/atoms/label'
import { LoadingButton } from '@front/ui/atoms/loading-button'
import { Card } from '@front/ui/molecules/card'

import * as styles from '../SignForm.css'

export const SignUp = () => {
const signUp = useSignUp()
Expand All @@ -20,32 +26,28 @@ export const SignUp = () => {
return (
<Form onSubmit={onSubmit}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<h2>Sign-up</h2>

<div>
<label>Email</label>
<Field
name="email"
component="input"
placeholder="email@example.com"
type="email"
/>
</div>

<div>
<label>Password</label>
<Field name="password" component="input" type="password" />
</div>

<div>
<label>Again =) (fake!)</label>
<Field name="password-again" component="input" type="password" />
</div>

<LoadingButton fethcing={fetching} submit>
Sign-up
</LoadingButton>
<form onSubmit={handleSubmit} className={styles.container}>
<Card title="Sign-up" className={styles.card}>
<Label text="Email">
<Input
name="email"
type={InputType.Email}
placeholder="email@example.com"
/>
</Label>

<Label text="Password">
<Input name="password" type={InputType.Password} />
</Label>

<Label text="Repeat password">
<Input name="password-repeat" type={InputType.Password} />
</Label>

<LoadingButton fethcing={fetching} submit>
Sign-up
</LoadingButton>
</Card>
</form>
)}
</Form>
Expand Down
12 changes: 10 additions & 2 deletions front/src/ui/atoms/input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Input as AntInput } from 'antd'
import { ChangeEvent, useCallback } from 'react'

import { resolveType } from './helpers/resolveType'
import { InputProps } from './InputProps'
import { InputType } from './InputType'

export const Input = ({ onChange, ...props }: InputProps) => {
export const Input = ({
onChange,
type = InputType.Default,
...props
}: InputProps) => {
const handleChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
if (onChange) {
Expand All @@ -13,5 +19,7 @@ export const Input = ({ onChange, ...props }: InputProps) => {
[onChange],
)

return <AntInput onChange={handleChange} {...props} />
return (
<AntInput type={resolveType(type)} onChange={handleChange} {...props} />
)
}
3 changes: 3 additions & 0 deletions front/src/ui/atoms/input/InputProps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { InputProps as AntInputProps } from 'antd/lib/input'
import { InputHTMLAttributes } from 'react'

import { InputType } from './InputType'

type HTMLInputProps = Pick<
InputHTMLAttributes<HTMLInputElement>,
'placeholder' | 'value'
Expand All @@ -10,6 +12,7 @@ type AntProps = Pick<AntInputProps, 'addonBefore' | 'addonAfter'>

interface OwnProps {
onChange?: (v?: string | undefined) => void
type?: InputType
}

export type InputProps = HTMLInputProps & AntProps & OwnProps
5 changes: 5 additions & 0 deletions front/src/ui/atoms/input/InputType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum InputType {
Default,
Email,
Password,
}
8 changes: 8 additions & 0 deletions front/src/ui/atoms/input/helpers/resolveType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { InputType } from '../InputType'

export const resolveType = (type: InputType): string =>
({
[InputType.Default]: '',
[InputType.Email]: 'email',
[InputType.Password]: 'password',
}[type])

0 comments on commit 76ef718

Please sign in to comment.