diff --git a/Client/src/Components/Dialog/genericDialog.jsx b/Client/src/Components/Dialog/genericDialog.jsx index 0b37d75e8..e3ebd51b1 100644 --- a/Client/src/Components/Dialog/genericDialog.jsx +++ b/Client/src/Components/Dialog/genericDialog.jsx @@ -12,7 +12,7 @@ const GenericDialog = ({ title, description, open, onClose, theme, children }) = aria-describedby={ariaDescribedBy} open={open} onClose={onClose} - onClick={(e)=>e.stopPropagation()} + onClick={(e) => e.stopPropagation()} > { "edit-confirm-password": "confirm", }; - const errorsMap = { - length: "Must be at least 8 characters long", - uppercase: "Must contain at least one upper character", - lowercase: "Must contain at least one lower character", - number: "Must contain at least one number", - special: "Must contain at least one special character", - different: "Confirm password and password must match", - }; - const [localData, setLocalData] = useState({ password: "", newPassword: "", @@ -151,7 +142,7 @@ const PasswordPanel = () => { autoComplete="current-password" value={localData.password} onChange={handleChange} - error={errorsMap[errors[idToName["edit-current-password"]]]} + error={errors[idToName["edit-current-password"]]} /> { autoComplete="new-password" value={localData.newPassword} onChange={handleChange} - error={errorsMap[errors[idToName["edit-new-password"]]]} + error={errors[idToName["edit-new-password"]]} /> { autoComplete="new-password" value={localData.confirm} onChange={handleChange} - error={errorsMap[errors[idToName["edit-confirm-password"]]]} + error={errors[idToName["edit-confirm-password"]]} /> {Object.keys(errors).length > 0 && ( @@ -218,7 +209,10 @@ const PasswordPanel = () => { type="submit" loading={isLoading} loadingIndicator="Saving..." - disabled={Object.keys(errors).length !== 0 && true} + disabled={ + Object.keys(errors).length !== 0 || + Object.values(localData).filter((value) => value !== "").length === 0 + } sx={{ px: theme.spacing(12), mt: theme.spacing(20), diff --git a/Client/src/Pages/Auth/Login.jsx b/Client/src/Pages/Auth/Login.jsx index 7014e2113..0554ad579 100644 --- a/Client/src/Pages/Auth/Login.jsx +++ b/Client/src/Pages/Auth/Login.jsx @@ -232,14 +232,6 @@ const StepTwo = ({ form, errors, onSubmit, onChange, onBack }) => { const navigate = useNavigate(); const inputRef = useRef(null); - const errorsMap = { - length: "Must be at least 8 characters long", - uppercase: "Must contain at least one upper character", - lowercase: "Must contain at least one lower character", - number: "Must contain at least one number", - special: "Must contain at least one special character", - }; - useEffect(() => { if (inputRef.current) { inputRef.current.focus(); @@ -285,7 +277,7 @@ const StepTwo = ({ form, errors, onSubmit, onChange, onBack }) => { autoComplete="current-password" value={form.password} onChange={onChange} - error={errorsMap[errors.password]} + error={errors.password} ref={inputRef} /> ({ path: error.path[0], - message: error.message, + type: error.type, })); const errorsByPath = errors && - errors.reduce((acc, { path, message }) => { + errors.reduce((acc, { path, type }) => { if (!acc[path]) { acc[path] = []; } - acc[path].push(message); + acc[path].push(type); return acc; }, {}); setErrors(() => (errorsByPath ? { ...errorsByPath } : {})); @@ -55,7 +55,7 @@ function useValidatePassword() { const feedbacks = useMemo( () => ({ - length: getFeedbackStatus(form, errors, "password", "length"), + length: getFeedbackStatus(form, errors, "password", "string.min"), special: getFeedbackStatus(form, errors, "password", "special"), number: getFeedbackStatus(form, errors, "password", "number"), uppercase: getFeedbackStatus(form, errors, "password", "uppercase"), diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js index acc9ea523..7ac5ae40c 100644 --- a/Client/src/Validation/validation.js +++ b/Client/src/Validation/validation.js @@ -16,34 +16,39 @@ const passwordSchema = joi .string() .trim() .min(8) - .messages({ - "string.empty": "empty", - "string.min": "length", - }) .custom((value, helpers) => { if (!/[A-Z]/.test(value)) { - return helpers.message("uppercase"); + return helpers.error("uppercase"); } return value; }) .custom((value, helpers) => { if (!/[a-z]/.test(value)) { - return helpers.message("lowercase"); + return helpers.error("lowercase"); } return value; }) .custom((value, helpers) => { if (!/\d/.test(value)) { - return helpers.message("number"); + return helpers.error("number"); } return value; }) .custom((value, helpers) => { if (!/[!?@#$%^&*()\-_=+[\]{};:'",.<>~`|\\/]/.test(value)) { - return helpers.message("special"); + return helpers.error("special"); } return value; + }) + .messages({ + "string.empty": "Password is required", + "string.min": "Password must be at least 8 characters long", + uppercase: "Password must contain at least one uppercase letter", + lowercase: "Password must contain at least one lowercase letter", + number: "Password must contain at least one number", + special: "Password must contain at least one special character", }); + const credentials = joi.object({ firstName: nameSchema, lastName: nameSchema, @@ -67,15 +72,16 @@ const credentials = joi.object({ confirm: joi .string() .trim() - .messages({ - "string.empty": "empty", - }) .custom((value, helpers) => { const { password } = helpers.prefs.context; if (value !== password) { - return helpers.message("different"); + return helpers.error("different"); } return value; + }) + .messages({ + "string.empty": "empty", + different: "Passwords do not match", }), role: joi.array(), teamId: joi.string().allow("").optional(), @@ -173,5 +179,5 @@ export { monitorValidation, settingsValidation, maintenanceWindowValidation, - advancedSettingsValidation + advancedSettingsValidation, };