This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(LoginPage): add reusable Login page
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// @flow | ||
|
||
import * as React from "react"; | ||
|
||
import { FormCard, FormTextInput, StandaloneFormPage } from "../../../"; | ||
import withTouchedErrors from "../../../helpers/withTouchedErrors.react"; | ||
|
||
import defaultStrings from "./LoginPage.strings"; | ||
import type { stringTypes } from "./LoginPage.strings"; | ||
|
||
type fieldTypes = {| | ||
email?: string, | ||
password?: string, | ||
|}; | ||
|
||
type touchedTypes = {| | ||
email?: boolean, | ||
password?: boolean, | ||
|}; | ||
|
||
type Props = {| | ||
+strings?: stringTypes, | ||
+action?: string, | ||
+method?: string, | ||
+onSubmit?: Function, | ||
+onChange?: (SyntheticInputEvent<HTMLInputElement>) => void, | ||
+onBlur?: (SyntheticInputEvent<HTMLInputElement>) => void, | ||
+values?: fieldTypes, | ||
+errors?: fieldTypes, | ||
+touched?: touchedTypes, | ||
|}; | ||
|
||
/** | ||
* A login page | ||
* Can be easily wrapped with form libraries like formik and redux-form | ||
*/ | ||
function LoginPage(props: Props): React.Node { | ||
const { | ||
action, | ||
method, | ||
onSubmit, | ||
onChange, | ||
onBlur, | ||
values, | ||
strings = {}, | ||
errors, | ||
} = props; | ||
|
||
return ( | ||
<StandaloneFormPage> | ||
<FormCard | ||
buttonText={strings.buttonText || defaultStrings.buttonText} | ||
title={strings.title || defaultStrings.title} | ||
onSubmit={onSubmit} | ||
action={action} | ||
method={method} | ||
> | ||
<FormTextInput | ||
name="email" | ||
label={strings.emailLabel || defaultStrings.emailLabel} | ||
placeholder={ | ||
strings.emailPlaceholder || defaultStrings.emailPlaceholder | ||
} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={values && values.email} | ||
error={errors && errors.email} | ||
/> | ||
<FormTextInput | ||
name="password" | ||
type="password" | ||
label={strings.passwordLabel || defaultStrings.passwordLabel} | ||
placeholder={ | ||
strings.passwordPlaceholder || defaultStrings.passwordPlaceholder | ||
} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={values && values.password} | ||
error={errors && errors.password} | ||
/> | ||
</FormCard> | ||
</StandaloneFormPage> | ||
); | ||
} | ||
|
||
const LoginPageWithTouchedErrors: React.ComponentType< | ||
Props | ||
> = withTouchedErrors(["email", "password"])(LoginPage); | ||
|
||
export default LoginPageWithTouchedErrors; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@flow | ||
const strings = { | ||
title: "Login to your Account", | ||
buttonText: "Login", | ||
emailLabel: "Email Address", | ||
emailPlaceholder: "Enter email", | ||
passwordLabel: "Password", | ||
passwordPlaceholder: "Password", | ||
}; | ||
|
||
export default strings; | ||
|
||
export type stringTypes = { [$Keys<typeof strings>]: string }; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import LoginPage from "./LoginPage.react"; | ||
|
||
export default LoginPage; |