Skip to content

Commit

Permalink
Merge pull request #243 from shreyas1434shinde/boardEnrollment
Browse files Browse the repository at this point in the history
Task #1810: Reset password API integration
  • Loading branch information
itsvick authored Sep 10, 2024
2 parents 31d6403 + b206913 commit 9b020a4
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 521 deletions.
31 changes: 17 additions & 14 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,23 @@
"CREATE_NEW": "Create a new, strong password that you don't use for other websites",
"NOT_MATCH": "Passwords do not match",
"CHARACTERS_LONG": "Passwords must be at least 8 characters long",
"OLD_PASSWORD": "Old Password",
"NEW_PASSWORD": "New Password",
"CONFIRM_NEW_PASSWORD": "Confirm New Password",
"TROUBLE_LOGIN": "Trouble with logging in?",
"ENTER_USERNAME": "Enter your username or email address and we’ll send you a link to get back into your account.",
"ENTER_USERNAME_PASSWORD": "Enter username or email",
"BACK_TO_LOGIN": "Back to Login",
"CREATE_STRONG_PASSWORD": "Create a strong password",
"YOUR_PASSWORD_NEEDS_TO:": "Your password needs to:",
"INCLUDE_BOTH": "Include both upper case and lower case",
"INCLUDE_NUMBER": "Include at least one number",
"INCLUDE_SPECIAL": "Include at least one special character",
"MUST_BE_AT": "Must be at least 8 characters long",
"OTHER_SETTING": "Other settings"
"OLD_PASSWORD":"Old Password",
"NEW_PASSWORD":"New Password",
"CONFIRM_NEW_PASSWORD":"Confirm New Password",
"TROUBLE_LOGIN":"Trouble with logging in?",
"ENTER_USERNAME":"Enter your username or email address and we’ll send you a link to get back into your account.",
"ENTER_USERNAME_PASSWORD":"Enter username",
"BACK_TO_LOGIN":"Back to Login",
"CREATE_STRONG_PASSWORD":"Create a strong password",
"YOUR_PASSWORD_NEEDS_TO:":"Your password needs to:",
"INCLUDE_BOTH":"Include both upper case and lower case",
"INCLUDE_NUMBER":"Include at least one number",
"INCLUDE_SPECIAL":"Include at least one special character",
"MUST_BE_AT":"Must be at least 8 characters long",
"OTHER_SETTING":"Other settings",
"WELCOME":"Welcome!",
"PLEASE_RESET_YOUR_PASSWORD":"Please reset your password to ensure your account is secure",
"DO_IT_LATER":"I’ll do it later"
},
"DASHBOARD": {
"DASHBOARD": "Dashboard",
Expand Down
114 changes: 114 additions & 0 deletions src/components/CentralizedModal.tsx
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;
217 changes: 217 additions & 0 deletions src/components/PasswordCreate.tsx
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;
Loading

0 comments on commit 9b020a4

Please sign in to comment.