import { useFormik } from 'formik'; import * as yup from 'yup'; import * as React from "react"; import * as HttpUtils from "utils/HttpUtils"; import * as UrlUtils from "utils/ApiPathConst"; import { useNavigate } from "react-router-dom"; import { Grid, Typography, Button, // RadioGroup, Dialog, DialogTitle, DialogContent, DialogActions, Stack, // InputLabel, // OutlinedInput, FormHelperText, TextField, IconButton, InputAdornment, // Box, // FormControl } from '@mui/material'; import Loadable from 'components/Loadable'; const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' // import ForwardIcon from '@mui/icons-material/Forward'; import MainCard from 'components/MainCard'; import {PNSPS_LONG_BUTTON_THEME} from "themes/buttonConst"; import {ThemeProvider} from "@emotion/react"; import {FormattedMessage, useIntl} from "react-intl"; import { EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons'; import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; import { useDispatch } from "react-redux"; import { handleLogoutFunction} from 'auth/index'; import { isPasswordExpiry } from "utils/Utils"; import usePageTitle from "components/usePageTitle"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const Index = () => { usePageTitle("userChangePassword"); const dispatch = useDispatch() const navigate = useNavigate() const [showPassword, setShowPassword] = React.useState(false); const [showNewPassword, setShowNewPassword] = React.useState(false); const [showConfirmPassword, setshowConfirmPassword] = React.useState(false); const [isLoading, setLoding] = React.useState(true); const [isChanged, setIsChanged] = React.useState(false); const [comfirmChangeMessage, setComfirmChangeMessage] = React.useState(false); const [expiryErr, setExpiryErr] = React.useState(false); const [expiryErrText, setExpiryErrText] = React.useState(""); const [changePasswordValues, setChangePasswordValues] = React.useState(); const intl = useIntl(); React.useEffect(() => { setLoding(false) }, []); const goLogin = (values) =>{ // console.log(values) setComfirmChangeMessage(false) HttpUtils.post({ url: UrlUtils.PATCH_CHANGE_PASSWORD, params:{ password: values.password, newPassword: values.newPassword }, onSuccess: function (){ setIsChanged(true); }, onError:function (error) { // console.log(error.response.data); setExpiryErrText(intl.formatMessage({ id: error.response.data.error })) setExpiryErr(true) // window.location.assign("/iamsmart/loginFail"); } }); } const BackgroundHead = { backgroundImage: `url(${titleBackgroundImg})`, width: 'auto', height: 'auto', backgroundSize: 'contain', backgroundRepeat: 'no-repeat', backgroundColor: '#0C489E', backgroundPosition: 'right' } const handleClickShowPassword = () => { setShowPassword(!showPassword); }; const handleClickShowNewPassword = () => { setShowNewPassword(!showNewPassword); }; const handleClickShowConfirmPassword = () => { setshowConfirmPassword(!showConfirmPassword); }; const handleMouseDownPassword = (event) => { event.preventDefault(); }; const handleMouseDownNewPassword = (event) => { event.preventDefault(); }; const changePassword = ( // value ) => { // const temp = strengthIndicator(value); // setLevel(strengthColorChi(temp)); }; const logout = () => { dispatch(handleLogoutFunction()); navigate('/login'); }; const formik = useFormik({ enableReinitialize: true, initialValues: { // username: '', password: '', newPassword: '', confirmPassword: '', // emailVerifyHash: '', }, validationSchema: yup.object().shape({ // emailVerifyHash: yup.string().required(intl.formatMessage({id: 'requireSecurityCode'})), // username: yup.string().required(intl.formatMessage({id: 'requireUsername'})), password: yup.string().min(8, intl.formatMessage({id: 'atLeast8CharPassword'})) .required(intl.formatMessage({id: 'requirePassword'})) .matches(/^\S*$/, { message: (intl.formatMessage({id: 'noSpacePassword'}))}) .matches(/^(?=.*[a-z])/, { message: intl.formatMessage({id: 'atLeastOneSmallLetter'})}) .matches(/^(?=.*[A-Z])/, { message: intl.formatMessage({id: 'atLeastOneCapLetter'})}) .matches(/^(?=.*[0-9])/, { message: intl.formatMessage({id: 'atLeast1Number'})}) .matches(/^(?=.*\W)/, { message: intl.formatMessage({id: 'atLeast1SpecialChar'})}), newPassword: yup.string().min(8, intl.formatMessage({id: 'atLeast8CharPassword'})) .required(intl.formatMessage({id: 'requirePassword'})) .matches(/^\S*$/, { message: (intl.formatMessage({id: 'noSpacePassword'}))}) .matches(/^(?=.*[a-z])/, { message: intl.formatMessage({id: 'atLeastOneSmallLetter'})}) .matches(/^(?=.*[A-Z])/, { message: intl.formatMessage({id: 'atLeastOneCapLetter'})}) .matches(/^(?=.*[0-9])/, { message: intl.formatMessage({id: 'atLeast1Number'})}) .matches(/^(?=.*\W)/, { message: intl.formatMessage({id: 'atLeast1SpecialChar'})}), confirmPassword: yup.string().min(8, intl.formatMessage({id: 'atLeast8CharPassword'})) .required(intl.formatMessage({id: 'pleaseConfirmPassword'})) .oneOf([yup.ref('newPassword'), null], intl.formatMessage({id: 'samePassword'})), }), onSubmit: values => { // console.log(values) setChangePasswordValues(values) setComfirmChangeMessage(true) } }); const handleCCPChange = (e) => { e.preventDefault(); }; return ( isLoading ? : *': { flexGrow: 1, flexBasis: '50%' } }} content={false} border={false} boxShadow > { !isChanged ? {isPasswordExpiry()? : } { formik.handleChange(e); changePassword(e.target.value); }} id="password" type={showPassword ? 'text' : 'password'} name="password" label={intl.formatMessage({id: 'oldPassword'}) + ":"} placeholder={intl.formatMessage({id: 'oldPassword'})} // defaultValue={formik.values.password.trim()} value={formik.values.password.trim()} error={Boolean(formik.touched.password && formik.errors.password)} onBlur={formik.handleBlur} inputProps={{ onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); } }, }} InputLabelProps={{ shrink: true }} InputProps={{ endAdornment:( {showPassword ? : } ) }} /> {formik.touched.password && formik.errors.password && ( {formik.errors.password} )} { formik.handleChange(e); changePassword(e.target.value); }} id="newPassword" type={showNewPassword ? 'text' : 'password'} name="newPassword" label={intl.formatMessage({id: 'newPassword'}) + ":"} placeholder={intl.formatMessage({id: 'newPassword'})} // defaultValue={formik.values.password.trim()} value={formik.values.newPassword.trim()} error={Boolean(formik.touched.newPassword && formik.errors.newPassword)} onBlur={formik.handleBlur} inputProps={{ onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); } }, }} InputLabelProps={{ shrink: true }} InputProps={{ endAdornment:( {showNewPassword ? : } ) }} /> {formik.touched.newPassword && formik.errors.newPassword && ( {formik.errors.newPassword} )} { formik.handleChange(e); // changePassword(e.target.value); }} id="confirmPassword" type={showConfirmPassword ? 'text' : 'password'} name="confirmPassword" label={intl.formatMessage({id: 'confirmNewPassword'}) + ":"} placeholder={intl.formatMessage({id: 'confirmNewPassword'})} // defaultValue={formik.values.confirmPassword.trim()} value={formik.values.confirmPassword.trim()} error={Boolean(formik.touched.confirmPassword && formik.errors.confirmPassword)} onBlur={formik.handleBlur} onCut={handleCCPChange} onCopy={handleCCPChange} onPaste={handleCCPChange} inputProps={{ maxLength: 50, onKeyDown: (e) => { // console.log(e) if (e.key === 'Enter') { e.preventDefault(); } }, }} InputLabelProps={{ shrink: true }} InputProps={{ endAdornment:( {showConfirmPassword ? : } ) }} /> {formik.touched.confirmPassword && formik.errors.confirmPassword && ( {formik.errors.confirmPassword} )} • • • • • goLogin()} > setComfirmChangeMessage(false)} PaperProps={{ sx: { minWidth: '40vw', maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' }, maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' } } }} > setComfirmChangeMessage(false)}> goLogin(changePasswordValues)}> setExpiryErr(false)} PaperProps={{ sx: { minWidth: '40vw', maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' }, maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' } } }} > { expiryErrText } setExpiryErr(false)}> : {/* Submit */} logout()}> } ); }; export default Index;