-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add request password request and reset pages
- Loading branch information
Showing
7 changed files
with
211 additions
and
1 deletion.
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,64 @@ | ||
import { useState } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { Button, GraaspLogo } from '@graasp/ui'; | ||
|
||
import { Stack, useTheme } from '@mui/material'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import Typography from '@mui/material/Typography'; | ||
|
||
import { useAuthTranslation } from '../config/i18n'; | ||
import { SIGN_IN_PATH } from '../config/paths'; | ||
import { AUTH } from '../langs/constants'; | ||
import EmailInput from './EmailInput'; | ||
import FullscreenContainer from './FullscreenContainer'; | ||
|
||
const ForgotPassword = () => { | ||
const { t } = useAuthTranslation(); | ||
const theme = useTheme(); | ||
|
||
// enable validation after first click | ||
const [shouldValidate, setShouldValidate] = useState(false); | ||
const [email, setEmail] = useState(''); | ||
|
||
const resetPassword = () => { | ||
setShouldValidate(true); | ||
}; | ||
|
||
const handleKeypress = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
resetPassword(); | ||
} | ||
}; | ||
|
||
return ( | ||
<FullscreenContainer> | ||
{ | ||
<Stack direction="column" alignItems="center" spacing={2}> | ||
<Stack spacing={1}> | ||
<GraaspLogo height={90} sx={{ fill: theme.palette.primary.main }} /> | ||
<Typography variant="h4" component="h2"> | ||
{t(AUTH.FORGOT_PASSWORD_TITLE)} | ||
</Typography> | ||
</Stack> | ||
<FormControl> | ||
<Stack spacing={1}> | ||
<EmailInput | ||
value={email} | ||
setValue={setEmail} | ||
onKeyPress={handleKeypress} | ||
shouldValidate={shouldValidate} | ||
/> | ||
</Stack> | ||
</FormControl> | ||
<Button fullWidth onClick={resetPassword}> | ||
{t(AUTH.FORGOT_PASSWORD_BUTTON)} | ||
</Button> | ||
<Link to={SIGN_IN_PATH}>{t(AUTH.FORGOT_PASSWORD_BACK_BUTTON)}</Link> | ||
</Stack> | ||
} | ||
</FullscreenContainer> | ||
); | ||
}; | ||
|
||
export default ForgotPassword; |
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,123 @@ | ||
import { useState } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { Button, GraaspLogo } from '@graasp/ui'; | ||
|
||
import { Stack, useTheme } from '@mui/material'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import Typography from '@mui/material/Typography'; | ||
|
||
import { useAuthTranslation } from '../config/i18n'; | ||
import { SIGN_IN_PATH } from '../config/paths'; | ||
import { AUTH } from '../langs/constants'; | ||
import { passwordValidator } from '../utils/validation'; | ||
import FullscreenContainer from './FullscreenContainer'; | ||
import StyledTextField from './StyledTextField'; | ||
|
||
const ResetPassword = () => { | ||
const { t } = useAuthTranslation(); | ||
const theme = useTheme(); | ||
|
||
// enable validation after first click | ||
const [passwordError, setPasswordError] = useState<string | null>(null); | ||
const [confirmPasswordError, setConfirmPasswordError] = useState< | ||
string | null | ||
>(null); | ||
const [password, setPassword] = useState(''); | ||
const [confirmPassword, setConfirmPassword] = useState(''); | ||
|
||
const resetPassword = () => { | ||
const checkingPassword = passwordValidator(password); | ||
const checkingConfirmPassword = passwordValidator(confirmPassword); | ||
if (checkingPassword || checkingConfirmPassword) { | ||
if (checkingPassword) { | ||
setPasswordError(checkingPassword); | ||
} | ||
if (checkingConfirmPassword) { | ||
setConfirmPasswordError(checkingConfirmPassword); | ||
} | ||
} else { | ||
setPasswordError(null); | ||
setConfirmPasswordError(null); | ||
// const token = await executeCaptcha( | ||
// isMobile | ||
// ? RecaptchaAction.SignInWithPasswordMobile | ||
// : RecaptchaAction.SignInWithPassword, | ||
// ); | ||
// const result = await (isMobile | ||
// ? mobileSignInWithPassword({ | ||
// email: lowercaseEmail, | ||
// password, | ||
// captcha: token, | ||
// challenge, | ||
// }) | ||
// : signInWithPassword({ | ||
// email: lowercaseEmail, | ||
// password, | ||
// captcha: token, | ||
// url: redirect.url, | ||
// })); | ||
// // successful redirect | ||
// if (result && result.resource) { | ||
// window.location.href = result.resource; | ||
// } | ||
} | ||
}; | ||
|
||
const handleKeypress = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
resetPassword(); | ||
} | ||
}; | ||
|
||
return ( | ||
<FullscreenContainer> | ||
{ | ||
<Stack direction="column" alignItems="center" spacing={2}> | ||
<Stack spacing={1}> | ||
<GraaspLogo height={90} sx={{ fill: theme.palette.primary.main }} /> | ||
<Typography variant="h4" component="h2"> | ||
{t(AUTH.RESET_PASSWORD_TITLE)} | ||
</Typography> | ||
</Stack> | ||
<FormControl> | ||
<Stack spacing={1}> | ||
<StyledTextField | ||
required | ||
label={t(AUTH.PASSWORD_FIELD_LABEL)} | ||
variant="outlined" | ||
value={password} | ||
error={Boolean(passwordError)} | ||
helperText={t(passwordError)} | ||
onChange={(e) => { | ||
setPassword(e.target.value); | ||
}} | ||
type="password" | ||
onKeyDown={handleKeypress} | ||
/> | ||
<StyledTextField | ||
required | ||
label={t(AUTH.CONFIRM_PASSWORD_FIELD_LABEL)} | ||
variant="outlined" | ||
value={confirmPassword} | ||
error={Boolean(confirmPasswordError)} | ||
helperText={t(confirmPasswordError)} | ||
onChange={(e) => { | ||
setConfirmPassword(e.target.value); | ||
}} | ||
type="password" | ||
onKeyDown={handleKeypress} | ||
/> | ||
</Stack> | ||
</FormControl> | ||
<Button fullWidth onClick={resetPassword}> | ||
{t(AUTH.FORGOT_PASSWORD_BUTTON)} | ||
</Button> | ||
<Link to={SIGN_IN_PATH}>{t(AUTH.FORGOT_PASSWORD_BACK_BUTTON)}</Link> | ||
</Stack> | ||
} | ||
</FullscreenContainer> | ||
); | ||
}; | ||
|
||
export default ResetPassword; |
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
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