2019-06-19 14:40:52 +00:00
|
|
|
import Button from "@material-ui/core/Button";
|
2019-10-30 14:34:24 +00:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2019-06-19 14:40:52 +00:00
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
import Typography from "@material-ui/core/Typography";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-29 10:55:56 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import Form from "@saleor/components/Form";
|
|
|
|
import { FormSpacer } from "@saleor/components/FormSpacer";
|
2019-08-29 10:55:56 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export interface FormData {
|
|
|
|
email: string;
|
|
|
|
password: string;
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
2019-06-19 14:40:52 +00:00
|
|
|
buttonContainer: {
|
|
|
|
display: "flex",
|
2019-09-05 14:05:56 +00:00
|
|
|
justifyContent: "flex-end"
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
|
|
|
link: {
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
cursor: "pointer",
|
|
|
|
textAlign: "center"
|
|
|
|
},
|
|
|
|
loginButton: {
|
|
|
|
width: 140
|
|
|
|
},
|
|
|
|
panel: {
|
|
|
|
"& span": {
|
|
|
|
color: theme.palette.error.contrastText
|
|
|
|
},
|
|
|
|
background: theme.palette.error.main,
|
2019-10-28 16:16:49 +00:00
|
|
|
borderRadius: theme.spacing(),
|
|
|
|
marginBottom: theme.spacing(3),
|
|
|
|
padding: theme.spacing(1.5)
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
2019-10-30 14:34:24 +00:00
|
|
|
}),
|
|
|
|
{ name: "LoginCard" }
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
export interface LoginCardProps {
|
2019-06-19 14:40:52 +00:00
|
|
|
error: boolean;
|
|
|
|
disableLoginButton: boolean;
|
|
|
|
onPasswordRecovery: () => void;
|
|
|
|
onSubmit?(event: FormData);
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const LoginCard: React.FC<LoginCardProps> = props => {
|
|
|
|
const { error, disableLoginButton, onPasswordRecovery, onSubmit } = props;
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const classes = useStyles(props);
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form initial={{ email: "", password: "" }} onSubmit={onSubmit}>
|
|
|
|
{({ change: handleChange, data, submit: handleSubmit }) => (
|
|
|
|
<>
|
|
|
|
{error && (
|
|
|
|
<div className={classes.panel}>
|
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage defaultMessage="Sorry, your username and/or password are incorrect. Please try again." />
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
2019-10-30 14:34:24 +00:00
|
|
|
)}
|
|
|
|
<TextField
|
|
|
|
autoFocus
|
|
|
|
fullWidth
|
|
|
|
autoComplete="username"
|
|
|
|
label={intl.formatMessage(commonMessages.email)}
|
|
|
|
name="email"
|
|
|
|
onChange={handleChange}
|
|
|
|
value={data.email}
|
|
|
|
inputProps={{
|
|
|
|
"data-tc": "email"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
fullWidth
|
|
|
|
autoComplete="password"
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Password"
|
|
|
|
})}
|
|
|
|
name="password"
|
|
|
|
onChange={handleChange}
|
|
|
|
type="password"
|
|
|
|
value={data.password}
|
|
|
|
inputProps={{
|
|
|
|
"data-tc": "password"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<div className={classes.buttonContainer}>
|
|
|
|
<Button
|
|
|
|
className={classes.loginButton}
|
|
|
|
color="primary"
|
|
|
|
disabled={disableLoginButton}
|
|
|
|
variant="contained"
|
|
|
|
onClick={handleSubmit}
|
|
|
|
type="submit"
|
|
|
|
data-tc="submit"
|
|
|
|
>
|
|
|
|
<FormattedMessage defaultMessage="Login" description="button" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<FormSpacer />
|
|
|
|
<Typography className={classes.link} onClick={onPasswordRecovery}>
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Reset your password"
|
|
|
|
description="button"
|
|
|
|
/>
|
|
|
|
</Typography>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
LoginCard.displayName = "LoginCard";
|
|
|
|
export default LoginCard;
|