import TabPanel from "@mui/lab/TabPanel"; import React, { useState } from "react"; import AnnouncementsDualButtonWithIcon from "../../Announcements/AnnouncementsDualButtonWithIcon/AnnouncementsDualButtonWithIcon"; import { useTheme } from "@emotion/react"; import { Box, Divider, Stack, Typography } from "@mui/material"; import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined"; import ButtonSpinner from "../../ButtonSpinner"; import PasswordTextField from "../../TextFields/Password/PasswordTextField"; import { editPasswordValidation } from "../../../Validation/validation"; /** * PasswordPanel component manages the form for editing password. * * @returns {JSX.Element} */ const PasswordPanel = () => { const theme = useTheme(); //TODO - use redux loading state //!! - currently all loading buttons are tied to the same state const [isLoading, setIsLoading] = useState(false); const [showPassword, setShowPassword] = useState(false); //for testing, will tweak when I implement redux slice const idToName = { "edit-current-password": "currentPassword", "edit-new-password": "password", "edit-confirm-password": "confirm", }; const [localData, setLocalData] = useState({ currentPassword: "", password: "", confirm: "", }); const [errors, setErrors] = useState({}); const handleChange = (event) => { const { value, id } = event.target; const name = idToName[id]; setLocalData((prev) => ({ ...prev, [name]: value, })); const validation = editPasswordValidation.validate( { [name]: value }, { abortEarly: false, context: { password: localData.password } } ); setErrors((prev) => { const updatedErrors = { ...prev }; if (validation.error) { updatedErrors[name] = validation.error.details[0].message; } else { delete updatedErrors[name]; } return updatedErrors; }); }; const handleSubmit = (event) => { event.preventDefault(); setIsLoading(true); const { error } = editPasswordValidation.validate(localData, { abortEarly: false, context: { password: localData.password }, }); if (error) { const newErrors = {}; error.details.forEach((err) => { newErrors[err.path[0]] = err.message; }); setErrors(newErrors); setIsLoading(false); } else { //TODO - submit logic } setTimeout(() => { setIsLoading(false); }, 2000); }; return (
} subject="SSO login" body="Since you logged in via SSO, you cannot reset or modify your password." />
Current password {errors[idToName["edit-current-password"]] ? ( {errors[idToName["edit-current-password"]]} ) : ( "" )}
New password {errors[idToName["edit-new-password"]] ? ( {errors[idToName["edit-new-password"]]} ) : ( "" )}
Confirm new password {errors[idToName["edit-confirm-password"]] ? ( {errors[idToName["edit-confirm-password"]]} ) : ( "" )}
} body="New password must contain at least 8 characters and must have at least one uppercase letter, one number and one symbol." />
); }; PasswordPanel.propTypes = { // No props are being passed to this component, hence no specific PropTypes are defined. }; export default PasswordPanel;