fix: erros on console on dialogs
This commit is contained in:
1 parent
4f647028e7
commit
3709e09ef7
6 files changed
+34
-42
No files matched your search
@@ -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()}
|
||||
>
|
||||
<Stack
|
||||
gap={theme.spacing(2)}
|
||||
@@ -62,7 +62,8 @@ GenericDialog.propTypes = {
|
||||
open: PropTypes.bool.isRequired,
|
||||
onClose: PropTypes.func.isRequired,
|
||||
theme: PropTypes.object.isRequired,
|
||||
children: PropTypes.element.isRequired,
|
||||
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
|
||||
.isRequired,
|
||||
};
|
||||
|
||||
export { GenericDialog };
|
||||
@@ -51,7 +51,6 @@ Dialog.propTypes = {
|
||||
title: PropTypes.string.isRequired,
|
||||
description: PropTypes.string,
|
||||
open: PropTypes.bool.isRequired,
|
||||
onClose: PropTypes.func.isRequired,
|
||||
theme: PropTypes.object.isRequired,
|
||||
onCancel: PropTypes.func.isRequired,
|
||||
confirmationButtonLabel: PropTypes.string.isRequired,
|
||||
|
||||
@@ -29,15 +29,6 @@ const PasswordPanel = () => {
|
||||
"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"]]}
|
||||
/>
|
||||
</Stack>
|
||||
<Stack
|
||||
@@ -174,7 +165,7 @@ const PasswordPanel = () => {
|
||||
autoComplete="new-password"
|
||||
value={localData.newPassword}
|
||||
onChange={handleChange}
|
||||
error={errorsMap[errors[idToName["edit-new-password"]]]}
|
||||
error={errors[idToName["edit-new-password"]]}
|
||||
/>
|
||||
</Stack>
|
||||
<Stack
|
||||
@@ -197,7 +188,7 @@ const PasswordPanel = () => {
|
||||
autoComplete="new-password"
|
||||
value={localData.confirm}
|
||||
onChange={handleChange}
|
||||
error={errorsMap[errors[idToName["edit-confirm-password"]]]}
|
||||
error={errors[idToName["edit-confirm-password"]]}
|
||||
/>
|
||||
</Stack>
|
||||
{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),
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
<Stack
|
||||
|
||||
@@ -39,15 +39,15 @@ function useValidatePassword() {
|
||||
const { error } = credentials.validate(validateValue, validateOptions);
|
||||
const errors = error?.details.map((error) => ({
|
||||
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"),
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
Reference in new issue
Block a user