2022-01-28 12:34:20 +00:00
import { TextField , Typography } from "@material-ui/core" ;
2022-05-06 08:59:55 +00:00
import { Button } from "@saleor/components/Button" ;
2019-09-02 13:52:43 +00:00
import Form from "@saleor/components/Form" ;
import FormSpacer from "@saleor/components/FormSpacer" ;
2022-05-06 08:59:55 +00:00
import { IconButton } from "@saleor/components/IconButton" ;
import { APP_MOUNT_URI } from "@saleor/config" ;
2022-03-09 08:56:55 +00:00
import { RequestPasswordResetMutation } from "@saleor/graphql" ;
2022-02-01 09:58:06 +00:00
import { SubmitPromise } from "@saleor/hooks/useForm" ;
2019-09-02 13:52:43 +00:00
import { commonMessages } from "@saleor/intl" ;
2022-05-06 08:59:55 +00:00
import { ArrowRightIcon } from "@saleor/macaw-ui" ;
2020-05-14 09:30:32 +00:00
import React from "react" ;
import { FormattedMessage , useIntl } from "react-intl" ;
2019-09-02 13:52:43 +00:00
2022-01-28 12:34:20 +00:00
import useStyles from "../styles" ;
2019-09-02 13:52:43 +00:00
export interface ResetPasswordPageFormData {
email : string ;
}
export interface ResetPasswordPageProps {
2019-09-02 19:23:37 +00:00
disabled : boolean ;
2019-09-04 13:09:19 +00:00
error : string ;
2022-02-01 09:58:06 +00:00
onSubmit : (
data : ResetPasswordPageFormData
2022-03-09 08:56:55 +00:00
) = > SubmitPromise <
RequestPasswordResetMutation [ "requestPasswordReset" ] [ "errors" ]
> ;
2019-09-02 13:52:43 +00:00
}
const ResetPasswordPage : React.FC < ResetPasswordPageProps > = props = > {
2022-05-06 08:59:55 +00:00
const { disabled , error , onSubmit } = props ;
2019-09-02 13:52:43 +00:00
const classes = useStyles ( props ) ;
const intl = useIntl ( ) ;
return (
< Form initial = { { email : "" } } onSubmit = { onSubmit } >
{ ( { change : handleChange , data , submit : handleSubmit } ) = > (
2019-09-03 13:42:15 +00:00
< >
2022-05-06 08:59:55 +00:00
< IconButton className = { classes . backBtn } href = { APP_MOUNT_URI } >
2022-01-28 12:34:20 +00:00
< ArrowRightIcon className = { classes . arrow } / >
< / IconButton >
< Typography variant = "h3" className = { classes . header } >
2022-05-05 07:54:28 +00:00
< FormattedMessage id = "Yy/yDL" defaultMessage = "Reset password" / >
2022-01-28 12:34:20 +00:00
< / Typography >
{ ! ! error && < div className = { classes . panel } > { error } < / div > }
< Typography variant = "caption" color = "textSecondary" >
2022-05-05 07:54:28 +00:00
< FormattedMessage
id = "54M0Gu"
defaultMessage = "Provide us with an email - if we find it in our database we will send you a link to reset your password. You should be able to find it in your inbox in the next couple of minutes."
/ >
2019-09-02 13:52:43 +00:00
< / Typography >
< FormSpacer / >
< TextField
autoFocus
2019-09-02 19:23:37 +00:00
disabled = { disabled }
2019-09-02 13:52:43 +00:00
fullWidth
autoComplete = "username"
label = { intl . formatMessage ( commonMessages . email ) }
name = "email"
onChange = { handleChange }
value = { data . email }
inputProps = { {
2022-02-11 11:28:55 +00:00
"data-test-id" : "email"
2019-09-02 13:52:43 +00:00
} }
/ >
< FormSpacer / >
< Button
2022-02-11 11:28:55 +00:00
data - test - id = "submit"
2019-09-02 13:52:43 +00:00
className = { classes . submit }
2019-09-02 19:23:37 +00:00
disabled = { disabled }
2022-01-28 12:34:20 +00:00
variant = "primary"
2019-09-02 13:52:43 +00:00
onClick = { handleSubmit }
type = "submit"
>
< FormattedMessage
2022-05-05 07:54:28 +00:00
id = "lm9NSK"
2022-01-28 12:34:20 +00:00
defaultMessage = "Send an email with reset link"
2019-09-02 13:52:43 +00:00
description = "password reset, button"
/ >
< / Button >
2019-09-03 13:42:15 +00:00
< / >
2019-09-02 13:52:43 +00:00
) }
< / Form >
) ;
} ;
ResetPasswordPage . displayName = "ResetPasswordPage" ;
export default ResetPasswordPage ;