-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from shreyas1434shinde/boardEnrollment
Task #1810: Reset password API integration
- Loading branch information
Showing
11 changed files
with
519 additions
and
521 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,114 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
import Typography from '@mui/material/Typography'; | ||
import { useRouter } from 'next/router'; | ||
import Modal from '@mui/material/Modal'; | ||
import { Divider } from '@mui/material'; | ||
import { CentralizedModalProps } from '@/utils/Interfaces'; | ||
import { useTheme } from '@mui/material/styles'; | ||
import { modalStyles } from '@/styles/modalStyles'; | ||
|
||
const CentralizedModal: React.FC<CentralizedModalProps> = ({ | ||
title, | ||
subTitle, | ||
secondary, | ||
primary, | ||
modalOpen, | ||
handlePrimaryButton, | ||
handleSkipButton, | ||
}) => { | ||
const [open, setOpen] = React.useState(modalOpen); | ||
|
||
React.useEffect(() => { | ||
setOpen(modalOpen); | ||
}, [modalOpen]); | ||
const theme = useTheme<any>(); | ||
const handleClose = () => setOpen(false); | ||
const router = useRouter(); | ||
|
||
return ( | ||
<Modal | ||
open={open} | ||
onClose={handleClose} | ||
aria-labelledby="modal-modal-title" | ||
aria-describedby="modal-modal-description" | ||
> | ||
<Box sx={modalStyles}> | ||
<Box sx={{ padding: '16px' }}> | ||
<Box | ||
sx={{ | ||
fontSize: '22px', | ||
color: theme.palette.warning['A200'], | ||
fontWeight: '400', | ||
textAlign: 'center', | ||
}} | ||
> | ||
{title} | ||
</Box> | ||
<Box | ||
sx={{ | ||
fontSize: '16px', | ||
fontWeight: '400', | ||
color: theme, | ||
textAlign: 'center', | ||
pt: '12px', | ||
}} | ||
> | ||
{subTitle} | ||
</Box> | ||
</Box> | ||
<Box sx={{ my: 1.2 }}> | ||
<Divider sx={{ color: theme.palette.warning['A100'] }} /> | ||
</Box> | ||
|
||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
gap: '12px', | ||
my: 2, | ||
}} | ||
> | ||
<Button | ||
sx={{ | ||
width: 'auto', | ||
height: '40px', | ||
fontSize: '14px', | ||
fontWeight: '500', | ||
border: 'none', | ||
color: theme.palette.secondary.main, | ||
'&:hover': { | ||
border: 'none', | ||
backgroundColor: 'transparent', | ||
}, | ||
}} | ||
variant="outlined" | ||
color="primary" | ||
onClick={() => { | ||
handleClose(); | ||
handleSkipButton(); | ||
}} | ||
> | ||
{secondary} | ||
</Button> | ||
<Button | ||
sx={{ | ||
width: '151px', | ||
height: '40px', | ||
fontSize: '14px', | ||
fontWeight: '500', | ||
}} | ||
variant="contained" | ||
color="primary" | ||
onClick={handlePrimaryButton} | ||
> | ||
{primary} | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default CentralizedModal; |
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,217 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
Box, | ||
Button, | ||
IconButton, | ||
InputAdornment, | ||
TextField, | ||
Typography, | ||
} from '@mui/material'; | ||
import { Visibility, VisibilityOff } from '@mui/icons-material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useTheme } from '@mui/material/styles'; | ||
|
||
const PasswordCreate = () => { | ||
const { t } = useTranslation(); | ||
const theme = useTheme<any>(); | ||
|
||
const [password, setPassword] = useState(''); | ||
const [confirmPassword, setConfirmPassword] = useState(''); | ||
const [showPassword, setShowPassword] = useState(false); | ||
const [passwordError, setPasswordError] = useState(false); | ||
const [confirmPasswordError, setConfirmPasswordError] = useState(false); | ||
const [showValidationMessages, setShowValidationMessages] = useState(false); | ||
|
||
const handlePasswordChange = (e: any) => { | ||
const value = e.target.value; | ||
setPassword(value); | ||
setShowValidationMessages(!!value); | ||
validatePassword(value); | ||
}; | ||
|
||
const handleConfirmPasswordChange = (e: any) => { | ||
const value = e.target.value; | ||
setConfirmPassword(value); | ||
setConfirmPasswordError(value !== password); | ||
}; | ||
|
||
const validatePassword = (value: any) => { | ||
const hasUpperCase = /[A-Z]/.test(value); | ||
const hasLowerCase = /[a-z]/.test(value); | ||
const hasNumber = /\d/.test(value); | ||
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(value); | ||
const isValidLength = value.length >= 8; | ||
|
||
const isValid = | ||
hasUpperCase && | ||
hasLowerCase && | ||
hasNumber && | ||
hasSpecialChar && | ||
isValidLength; | ||
setPasswordError(!isValid); | ||
|
||
return isValid; | ||
}; | ||
|
||
const isFormValid = | ||
!passwordError && !confirmPasswordError && password && confirmPassword; | ||
|
||
return ( | ||
<> | ||
<Box | ||
sx={{ | ||
width: '668px', | ||
'@media (max-width: 768px)': { | ||
width: '100%', | ||
}, | ||
'@media (min-width: 900px)': { | ||
width: '100%', | ||
}, | ||
}} | ||
margin={'3.2rem 0 0'} | ||
> | ||
<TextField | ||
id="password" | ||
InputLabelProps={{ | ||
shrink: true, | ||
}} | ||
type={'password'} | ||
value={password} | ||
onChange={handlePasswordChange} | ||
error={passwordError} | ||
FormHelperTextProps={{ | ||
sx: { | ||
color: passwordError ? theme.palette.warning['A200'] : 'inherit', | ||
}, | ||
}} | ||
helperText={passwordError && t('LOGIN_PAGE.YOUR_PASSWORD_NEEDS_TO')} | ||
label={t('LOGIN_PAGE.PASSWORD')} | ||
fullWidth | ||
sx={{ | ||
'.MuiFormHelperText-root.Mui-error': { | ||
color: theme.palette.warning['A200'], | ||
}, | ||
}} | ||
/> | ||
</Box> | ||
|
||
{showValidationMessages && passwordError && ( | ||
<Box sx={{ mt: 1, pl: '16px' }}> | ||
<Typography | ||
variant="body2" | ||
color={passwordError ? 'error' : 'textPrimary'} | ||
sx={{ | ||
color: theme.palette.warning['A200'], | ||
fontSize: '16px', | ||
fontWeight: '400', | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
color: | ||
password.match(/[A-Z]/) && password.match(/[a-z]/) | ||
? theme.palette.success.main | ||
: theme.palette.error.main, | ||
fontSize: '12px', | ||
fontWeight: '400', | ||
}} | ||
> | ||
✓ {t('LOGIN_PAGE.INCLUDE_BOTH')} | ||
</Box> | ||
<Box | ||
sx={{ | ||
color: password.match(/\d/) | ||
? theme.palette.success.main | ||
: theme.palette.error.main, | ||
fontSize: '12px', | ||
fontWeight: '400', | ||
}} | ||
> | ||
✓ {t('LOGIN_PAGE.INCLUDE_NUMBER')} | ||
</Box> | ||
<Box | ||
sx={{ | ||
color: password.match(/[!@#$%^&*(),.?":{}|<>]/) | ||
? theme.palette.success.main | ||
: theme.palette.error.main, | ||
fontSize: '12px', | ||
fontWeight: '400', | ||
}} | ||
> | ||
✓ {t('LOGIN_PAGE.INCLUDE_SPECIAL')} | ||
</Box> | ||
<Box | ||
sx={{ | ||
color: | ||
password.length >= 8 | ||
? theme.palette.success.main | ||
: theme.palette.error.main, | ||
fontSize: '12px', | ||
fontWeight: '400', | ||
}} | ||
> | ||
✓ {t('LOGIN_PAGE.MUST_BE_AT')} | ||
</Box> | ||
</Typography> | ||
</Box> | ||
)} | ||
|
||
<Box | ||
sx={{ | ||
width: '668px', | ||
'@media (max-width: 768px)': { | ||
width: '100%', | ||
}, | ||
'@media (min-width: 900px)': { | ||
width: '100%', | ||
}, | ||
}} | ||
margin={'2rem 0 0'} | ||
> | ||
<TextField | ||
id="confirm-password" | ||
InputLabelProps={{ | ||
shrink: true, | ||
}} | ||
type={'password'} | ||
value={confirmPassword} | ||
onChange={handleConfirmPasswordChange} | ||
error={confirmPasswordError} | ||
helperText={confirmPasswordError && t('LOGIN_PAGE.NOT_MATCH')} | ||
label={t('LOGIN_PAGE.CONFIRM_PASSWORD')} | ||
fullWidth | ||
sx={{ | ||
'.MuiFormHelperText-root.Mui-error': { | ||
color: theme.palette.error.main, | ||
}, | ||
}} | ||
/> | ||
</Box> | ||
|
||
<Box> | ||
<Box | ||
alignContent={'center'} | ||
textAlign={'center'} | ||
marginTop={'2.5rem'} | ||
width={'100%'} | ||
> | ||
<Button | ||
variant="contained" | ||
type="submit" | ||
fullWidth={true} | ||
sx={{ | ||
'@media (min-width: 900px)': { | ||
width: '50%', | ||
}, | ||
}} | ||
disabled={!isFormValid} | ||
> | ||
{t('LOGIN_PAGE.RESET_PASSWORD')} | ||
</Button> | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default PasswordCreate; |
Oops, something went wrong.