Refactored old validation from profile and password forms, fixed alert text

This commit is contained in:
Daniel Cojocea committed 2024-07-15 20:51:18 -04:00
1 parent 2a77c3fc12
commit d39a716ab6
6 files changed
+37 -70

No files matched your search

@@ -4,7 +4,7 @@ import { useTheme } from "@emotion/react";
import { Box, Divider, Stack, Typography } from "@mui/material";
import ButtonSpinner from "../../ButtonSpinner";
import Field from "../../Inputs/Field";
import { editPasswordValidation } from "../../../Validation/validation";
import { credentials } from "../../../Validation/validation";
import Alert from "../../Alert";
import { update } from "../../../Features/Auth/authSlice";
import { useDispatch, useSelector } from "react-redux";
@@ -44,9 +44,9 @@ const PasswordPanel = () => {
[name]: value,
}));
const validation = editPasswordValidation.validate(
const validation = credentials.validate(
{ [name]: value },
{ abortEarly: false, context: { newPassword: localData.newPassword } }
{ abortEarly: false, context: { password: localData.newPassword } }
);
setErrors((prev) => {
@@ -64,9 +64,9 @@ const PasswordPanel = () => {
const handleSubmit = async (event) => {
event.preventDefault();
const { error } = editPasswordValidation.validate(localData, {
const { error } = credentials.validate(localData, {
abortEarly: false,
context: { newPassword: localData.newPassword },
context: { password: localData.newPassword },
});
if (error) {
@@ -7,10 +7,7 @@ import Button from "../../Button";
import Avatar from "../../Avatar";
import Field from "../../Inputs/Field";
import ImageField from "../../Inputs/Image";
import {
editProfileValidation,
imageValidation,
} from "../../../Validation/validation";
import { credentials, imageValidation } from "../../../Validation/validation";
import { useDispatch, useSelector } from "react-redux";
import {
clearAuthState,
@@ -66,7 +63,7 @@ const ProfilePanel = () => {
[name]: value,
}));
validateField({ [name]: value }, editProfileValidation, name);
validateField({ [name]: value }, credentials, name);
};
// Handles image file
@@ -165,8 +162,8 @@ const ProfilePanel = () => {
localData.file === undefined
) {
createToast({
variant: "warning",
body: "Unable to update profile: No changes detected.",
variant: "info",
body: "Unable to update profile — no changes detected.",
hasIcon: false,
});
setErrors({ unchanged: "unable to update profile" });