diff --git a/client/src/Components/ManagerDashboard.js b/client/src/Components/ManagerDashboard.js
index 632e1cb..e76e099 100644
--- a/client/src/Components/ManagerDashboard.js
+++ b/client/src/Components/ManagerDashboard.js
@@ -38,7 +38,8 @@ function ManagerDashboard() {
const [newPassword, setNewPassword] = useState("");
const [confirmNewPassword, setConfirmNewPassword] = useState("");
const [showPasswordTooltip, setShowPasswordTooltip] = useState(false);
- const [showConfirmPasswordTooltip, setShowConfirmPasswordTooltip] = useState(false);
+ const [showConfirmPasswordTooltip, setShowConfirmPasswordTooltip] =
+ useState(false);
const [passwordFocused, setPasswordFocused] = useState(false);
const [confirmPasswordFocused, setConfirmPasswordFocused] = useState(false);
const [statistics, setStatistics] = useState({
@@ -158,7 +159,7 @@ function ManagerDashboard() {
const regex = /^\d{0,6}(\.\d{0,2})?$/;
if (regex.test(value)) {
// Trim leading zeroes
- value = value.replace(/^0+(?!\.|$)/, '');
+ value = value.replace(/^0+(?!\.|$)/, "");
setAccountFormData({
...accountFormData,
salary: value,
@@ -184,11 +185,15 @@ function ManagerDashboard() {
return;
}
if (!validateSalary(accountFormData.salary)) {
- alert("Salary must be a number with 2 to 6 digits before the decimal and up to 2 digits after the decimal.");
+ alert(
+ "Salary must be a number with 2 to 6 digits before the decimal and up to 2 digits after the decimal."
+ );
return;
}
if (!validateStartDate(accountFormData.startDate)) {
- alert("Start date must be within the last 5 years and not more than 1 year ahead.");
+ alert(
+ "Start date must be within the last 5 years and not more than 1 year ahead."
+ );
return;
}
const response = await axios.post(
@@ -204,7 +209,7 @@ function ManagerDashboard() {
},
{ withCredentials: true }
);
- console.log("Registration response:", response.data);
+ // console.log("Registration response:", response.data);
setOneTimePassword(response.data.oneTimePassword);
setShowPasswordModal(true);
alert("Employee added successfully!");
@@ -239,7 +244,7 @@ function ManagerDashboard() {
},
{ withCredentials: true }
);
- console.log("Registration response:", res.data);
+ // console.log("Registration response:", res.data);
setOneTimePassword(res.data.oneTimePassword);
setShowPasswordModal(true);
alert("Supplier added successfully!");
@@ -268,11 +273,15 @@ function ManagerDashboard() {
return;
}
if (!validateSalary(accountFormData.salary)) {
- alert("Salary must be a number with 2 to 6 digits before the decimal and up to 2 digits after the decimal.");
+ alert(
+ "Salary must be a number with 2 to 6 digits before the decimal and up to 2 digits after the decimal."
+ );
return;
}
if (!validateStartDate(accountFormData.startDate)) {
- alert("Start date must be within the last 5 years and not more than 1 year ahead.");
+ alert(
+ "Start date must be within the last 5 years and not more than 1 year ahead."
+ );
return;
}
if (accountType === "supplier") {
@@ -284,7 +293,7 @@ function ManagerDashboard() {
},
{ withCredentials: true }
);
- console.log("Registration response:", res.data);
+ // console.log("Registration response:", res.data);
setOneTimePassword(res.data.oneTimePassword);
setShowPasswordModal(true);
alert("Supplier added successfully!");
@@ -302,7 +311,7 @@ function ManagerDashboard() {
},
{ withCredentials: true }
);
- console.log("Registration response:", response.data);
+ // console.log("Registration response:", response.data);
setOneTimePassword(response.data.oneTimePassword);
setShowPasswordModal(true);
alert("Employee added successfully!");
@@ -341,18 +350,18 @@ function ManagerDashboard() {
e.preventDefault();
// Log the form values first
- console.log("Form Values:", {
- categoryId: e.target.categoryId.value,
- productName: e.target.productName.value,
- productDescription: e.target.productDescription.value,
- brand: e.target.brand.value,
- pictureUrl: e.target.pictureUrl.value,
- quantity: e.target.quantity.value,
- reorderLevel: e.target.reorderLevel.value,
- // reorderQuantity: e.target.reorderQuantity.value,
- price: e.target.price.value,
- weight: e.target.weight.value,
- });
+ // console.log("Form Values:", {
+ // categoryId: e.target.categoryId.value,
+ // productName: e.target.productName.value,
+ // productDescription: e.target.productDescription.value,
+ // brand: e.target.brand.value,
+ // pictureUrl: e.target.pictureUrl.value,
+ // quantity: e.target.quantity.value,
+ // reorderLevel: e.target.reorderLevel.value,
+ // // reorderQuantity: e.target.reorderQuantity.value,
+ // price: e.target.price.value,
+ // weight: e.target.weight.value,
+ // });
const productData = {
categoryId: Number(e.target.categoryId.value), // Changed to Number()
@@ -368,11 +377,11 @@ function ManagerDashboard() {
};
// Log the formatted data
- console.log("Formatted Product Data:", productData);
+ // console.log("Formatted Product Data:", productData);
try {
// Log the request
- console.log("Sending request to:", "http://localhost:8080/products");
+ // console.log("Sending request to:", "http://localhost:8080/products");
const response = await axios.post(
"http://localhost:8080/products",
@@ -386,7 +395,7 @@ function ManagerDashboard() {
);
// Log the response
- console.log("Server Response:", response);
+ // console.log("Server Response:", response);
if (response.status === 201) {
toggleCreateProductModal();
@@ -472,7 +481,7 @@ function ManagerDashboard() {
const handleDeleteProduct = async (productId) => {
if (window.confirm("Are you sure you want to delete this product?")) {
try {
- console.log("Attempting to delete product:", productId);
+ // console.log("Attempting to delete product:", productId);
if (!productId) {
throw new Error("Invalid product ID");
@@ -541,7 +550,7 @@ function ManagerDashboard() {
weight: Number(editingProduct.WEIGHT),
};
- console.log("Sending update with data:", formData); // Debug log
+ // console.log("Sending update with data:", formData); // Debug log
const response = await axios.put(
`http://localhost:8080/products/${editingProduct.ID}`,
@@ -576,6 +585,30 @@ function ManagerDashboard() {
}
};
+ const handlePriceChange = (e) => {
+ let value = e.target.value;
+ const regex = /^\d{0,3}(\.\d{0,2})?$/;
+ if (regex.test(value)) {
+ value = value.replace(/[+-]/g, ""); // Prevent typing positive or negative signs
+ setEditingProduct({
+ ...editingProduct,
+ PRICE: value,
+ });
+ }
+ };
+
+ const handleWeightChange = (e) => {
+ let value = e.target.value;
+ const regex = /^\d{0,3}(\.\d{0,2})?$/;
+ if (regex.test(value)) {
+ value = value.replace(/[+-]/g, ""); // Prevent typing positive or negative signs
+ setEditingProduct({
+ ...editingProduct,
+ WEIGHT: value,
+ });
+ }
+ };
+
useEffect(() => {
const fetchAllSales = async () => {
try {
@@ -829,12 +862,23 @@ function ManagerDashboard() {
};
const isSupplierFormValid = () => {
- return (
- validateEmail(accountFormData.email) &&
- accountFormData.supplierName
- );
+ return validateEmail(accountFormData.email) && accountFormData.supplierName;
};
+ // var out = document.querySelector(".foo");
+
+ // if (out) { // Check if the element with class .foo exists
+ // console.log(out); // Log the element to the console
+ // let text = out.textContent; // Get the inner HTML of the element
+ // console.log(text); // Log the inner HTML
+
+ // let str = text.replace(/(.{20})/g, '
'); // Replace every 10 characters with
+ // out.innerHTML = str; // Set the modified HTML back to the element
+ // console.log("Found!");
+ // } else {
+ // console.log("Element with class '.foo' not found.");
+ // }
+
return (