1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/user/ForgottenPassword/ForgottenPassword.tsx
olav 24c11332b5 chore: update MUI to v5 (#923)
* refactor: update mui packages

* refactor: run mui codemods

* refactor: format files after codemods

* refactor: fix broken types

* refactor: clean up theme

* refactor: fix broken tests

* refactor: replace @mui/styles with tss-react

* refactor: move breakpoints into classes for tss

* refactor: fix crash on missing feature description

* refactor: remove void classNames

* refactor: adjust styles to new defaults

* refactor: remove broken rollout slider e2e test

* refactor: fix duplicate e2e testid

* refactor: update makeStyles after rebase

* refactor: add missing snapshot after rebase

* refactor: fix TableCellSortable focus styles

* refactor: use 1.4 as the default line-height

* refactor: hide webkit search field icons

* refactor: fix select box label

* refactor: make AutocompleteBox smaller

* refactor: make heading smaller

* refactor: fix toast close icon color

* refactor: update snapshots

* refactor: add missing test event awaits

* refactor: fix default button line-height
2022-05-02 15:52:41 +02:00

137 lines
5.1 KiB
TypeScript

import { Button, TextField, Typography } from '@mui/material';
import { AlertTitle, Alert } from '@mui/material';
import classnames from 'classnames';
import { SyntheticEvent, useState } from 'react';
import { Link } from 'react-router-dom';
import { useThemeStyles } from 'themes/themeStyles';
import useLoading from 'hooks/useLoading';
import { FORGOTTEN_PASSWORD_FIELD } from 'utils/testIds';
import { formatApiPath } from 'utils/formatPath';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import DividerText from 'component/common/DividerText/DividerText';
import StandaloneLayout from '../common/StandaloneLayout/StandaloneLayout';
import { useStyles } from './ForgottenPassword.styles';
const ForgottenPassword = () => {
const [email, setEmail] = useState('');
const [attempted, setAttempted] = useState(false);
const [loading, setLoading] = useState(false);
const [attemptedEmail, setAttemptedEmail] = useState('');
const { classes: themeStyles } = useThemeStyles();
const { classes: styles } = useStyles();
const ref = useLoading(loading);
const onClick = async (e: SyntheticEvent) => {
e.preventDefault();
setLoading(true);
setAttemptedEmail(email);
const path = formatApiPath('auth/reset/password-email');
await fetch(path, {
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({ email }),
});
setAttempted(true);
setLoading(false);
};
return (
<StandaloneLayout>
<div
className={classnames(
themeStyles.contentSpacingY,
themeStyles.flexColumn,
styles.forgottenPassword
)}
ref={ref}
>
<h2
className={classnames(
themeStyles.title,
themeStyles.textCenter
)}
data-loading
>
Forgotten password
</h2>
<ConditionallyRender
condition={attempted}
show={
<Alert severity="success" data-loading>
<AlertTitle>Attempted to send email</AlertTitle>
We've attempted to send a reset password email to:
<strong className={styles.email}>
{attemptedEmail}
</strong>
If you did not receive an email, please verify that
you typed in the correct email, and contact your
administrator to make sure that you are in the
system.
</Alert>
}
/>
<form
onSubmit={onClick}
className={classnames(
themeStyles.contentSpacingY,
themeStyles.flexColumn
)}
>
<Typography
variant="body1"
data-loading
className={themeStyles.textCenter}
>
Please provide your email address. If it exists in the
system we'll send a new reset link.
</Typography>
<TextField
variant="outlined"
size="small"
placeholder="email"
type="email"
data-loading
data-testid={FORGOTTEN_PASSWORD_FIELD}
value={email}
onChange={e => {
setEmail(e.target.value);
}}
/>
<Button
variant="contained"
type="submit"
data-loading
color="primary"
className={styles.button}
disabled={loading}
>
<ConditionallyRender
condition={!attempted}
show={<span>Submit</span>}
elseShow={<span>Try again</span>}
/>
</Button>
<DividerText text="Or log in" />
<Button
type="submit"
data-loading
variant="outlined"
className={styles.button}
disabled={loading}
component={Link}
to="/login"
>
Log in
</Button>
</form>
</div>
</StandaloneLayout>
);
};
export default ForgottenPassword;