Skip to content
Merged
8 changes: 8 additions & 0 deletions client/src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ const NavBar = ({ role }) => {
}
}

function handleOpenSettings(e) {
setOpenMenu(e.currentTarget);
}

function handleCloseSettings() {
setOpenMenu(null);
}

// Navigation Bar for standard user type
if (role === "standard_user")
return (
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/administrator/AccountApprovalTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const AccountApprovalTable = () => {
})
.then((data) => setUserData(data))
.catch((err) => {
console.log(err);
console.error("Failed to fetch merchant data.");
});
};

Expand All @@ -49,7 +49,7 @@ const AccountApprovalTable = () => {
fetchMerchants();
})
.catch((err) => {
console.log(err);
console.error("Failed to validate merchant account.");
});
};

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/administrator/AuditLogTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const AuditLogTable = () => {
setLoading(false);
})
.catch((err) => {
console.log(err);
console.error("Failed to fetch log data.");
setLoading(false);
});
}, [
Expand Down
10 changes: 5 additions & 5 deletions client/src/components/administrator/UserManagementTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const UserManagementTable = () => {
setLoading(false);
})
.catch((err) => {
console.log(err);
console.error("Failed to fetch user data.");
setLoading(false);
});
}, [
Expand Down Expand Up @@ -109,7 +109,7 @@ const UserManagementTable = () => {
})
.then((data) => setRoleData(data))
.catch((err) => {
console.log(err);
console.error("Failed to fetch role data.");
});
}, [API_BASE]);

Expand All @@ -123,7 +123,7 @@ const UserManagementTable = () => {
})
.then((data) => setClinicData(data))
.catch(() => {
console.log("Failed to fetch Clinics");
console.error("Failed to fetch clinic data.");
});
}, [API_BASE]);

Expand Down Expand Up @@ -165,7 +165,7 @@ const UserManagementTable = () => {
setNewRole(null);
setRowSelectionModel({ type: "include", ids: new Set() });
} catch (err) {
console.log(err);
console.error("Failed to process request.");
}
};

Expand Down Expand Up @@ -199,7 +199,7 @@ const UserManagementTable = () => {
setUserToDelete(null);
setRowSelectionModel({ type: "include", ids: new Set() }); // Reset the checkbox after deletion.
} catch (error) {
console.error("Delete user error:", error);
console.error("Failed to delete user.");
setSnackbar({ open: true, message: error.message, severity: "error" });
}
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/authentication/CreatePatientForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const CreatePatientForm = () => {
return response.json();
})
.catch((err) => {
console.log("An error has occurred");
console.error("An error has occurred.");
});
setIsLoading(false);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/authentication/PasswordInputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const PasswordInputField = ({
if (!isAltered && !showRequired) {
return null;
}
if (password.length === 0 || password === null || showRequired) {
if (!password || showRequired) {
return "*Required";
}

Expand Down
15 changes: 8 additions & 7 deletions client/src/components/authentication/RegistrationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Logo from "../../assets/WellAiLogoTR.png";
import EmailInputField from "../authentication/EmailInputField";
import PasswordInputField from "../authentication/PasswordInputField";
import PhoneInputField from "../authentication/PhoneInputField";
import { stringEqual } from "../../utils/stringEqual";

const FULL_NAME_MAX_LENGTH = 255;
const ACCOUNT_TYPES = Object.freeze({
Expand Down Expand Up @@ -77,7 +78,7 @@ const RegistrationForm = () => {
})
.then((res) => res.json())
.then((data) => setClinicList(data))
.catch((err) => console.log("An error has occurred"));
.catch((err) => console.error("An error has occurred."));
}, []);

function updateGivenName(e) {
Expand Down Expand Up @@ -134,7 +135,7 @@ const RegistrationForm = () => {
const confirmPasswordInput = e.target.value;
setConfirmPassword(confirmPasswordInput);
setAlertPasswordsDontMatch(
confirmPasswordInput !== passwordState.password ||
!stringEqual(confirmPasswordInput, passwordState.password) ||
confirmPasswordInput === "",
);
}
Expand Down Expand Up @@ -182,7 +183,7 @@ const RegistrationForm = () => {
setAlertPasswordRequired(passwordState === null);
setAlertPasswordsDontMatch(
passwordState === null ||
confirmPassword !== passwordState.password ||
!stringEqual(confirmPassword, passwordState.password) ||
confirmPassword === "",
);
setAlertGenderRequired(genderState === "");
Expand All @@ -194,7 +195,7 @@ const RegistrationForm = () => {
setAlertPasswordRequired(passwordState === null);
setAlertPasswordsDontMatch(
passwordState === null ||
confirmPassword !== passwordState.password ||
!stringEqual(confirmPassword, passwordState.password) ||
confirmPassword === "",
);
setAlertClinicRequired(clinicState === "");
Expand All @@ -214,7 +215,7 @@ const RegistrationForm = () => {
(phoneState === null || phoneState.isValid) &&
passwordState !== null &&
passwordState.isValid &&
passwordState.password === confirmPassword
stringEqual(passwordState.password, confirmPassword)
);
}

Expand All @@ -225,7 +226,7 @@ const RegistrationForm = () => {
(phoneState === null || phoneState.isValid) &&
passwordState !== null &&
passwordState.isValid &&
passwordState.password === confirmPassword &&
stringEqual(passwordState.password, confirmPassword) &&
clinicState !== ""
);
}
Expand Down Expand Up @@ -281,7 +282,7 @@ const RegistrationForm = () => {
setShowFailMessage(false);
})
.catch((error) => {
console.log(error);
console.error("User reigstration requeset failed.");
});
setIsLoading(false);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/healthReport/BloodReportUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const BloodReportUpload = ({ onChange }) => {
const file = e.target.files[0];
await pdfToText(file)
.then((text) => onChange?.(extractPatientInfoAsDict(text)))
.catch((error) => console.error(error));
.catch((error) => console.error("Failed to process blood report."));
}

function extractPatientInfoAsDict(text) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/healthReport/DownloadReportButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const DownloadReportButton = ({
saveAs(blob, fileName);
if (onError) onError?.(null); // Clear previous errors on success
} catch (error) {
console.error("Failed to download report:", error);
console.error("Failed to download report.");
if (onError) onError(error.message);
}
};
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/healthReport/GenerateReportForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const GenerateReportForm = () => {
setWorkingStatus(data.workingStatus);
setRace(data.race);
} catch (err) {
console.log("Failed to fetch patient data.");
console.error("Failed to fetch patient data.");
}
}
fetchPatientData();
Expand Down Expand Up @@ -331,7 +331,7 @@ const GenerateReportForm = () => {
navigate("/report-history"); // Route the user to the Health prediction page after submission
})
.catch((error) => {
console.log("An error has occurred");
console.error("An error has occurred.");
});
}

Expand Down
8 changes: 4 additions & 4 deletions client/src/components/healthReport/MerchantReportForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const MerchantReportForm = () => {
setPatientName(name.name);
}
})
.catch((err) => console.log(err));
.catch((err) => console.error("Failed to fetch patient names."));
}, [defaultSelectedPatient]);

function handleChangeCondition(e) {
Expand Down Expand Up @@ -173,7 +173,7 @@ const MerchantReportForm = () => {
setWorkingStatus(data.workingStatus);
setRace(data.race);
} catch (err) {
console.log("Failed to fetch patient data.");
console.error("Failed to fetch patient data.");
}
}
fetchPatientData();
Expand Down Expand Up @@ -343,7 +343,7 @@ const MerchantReportForm = () => {
return response.json();
})
.catch((error) => {
console.log("Something went wrong.");
console.error("Failed to process request.");
});
navigate("/merchant-reports");
setIsLoading(false);
Expand Down Expand Up @@ -406,7 +406,7 @@ const MerchantReportForm = () => {
}); // Route the user to the Health prediction page after submission
})
.catch((error) => {
console.log("Something went wrong");
console.error("Failed to process request.");
});
}
const HiddenInput = styled("input")({
Expand Down
10 changes: 5 additions & 5 deletions client/src/routes/merchant/MerchantReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ const MerchantReports = () => {
}
})
.catch((err) => {
console.log(err);
});
}, [defaultSelectedPatientId]);
console.error("Failed to fetch report data.");
}, [defaultSelectedPatientId]);
}

// Fetch the merchant reports
useEffect(() => {
Expand All @@ -104,7 +104,7 @@ const MerchantReports = () => {
})
.then((res) => res.json())
.then((data) => setReportData(data))
.catch((err) => console.log(err));
.catch((err) => console.error("Failed to fetch report health data."));
}, [selectedDate]);

// Delete report data
Expand All @@ -129,7 +129,7 @@ const MerchantReports = () => {
setReportDates(patientReports);
setSelectedDate(patientReports[0]);
} catch (err) {
console.log(err);
console.error("Failed to delete report data.");
}
// Close Dialog
setDeleteDialogOpen(false);
Expand Down
4 changes: 2 additions & 2 deletions client/src/routes/merchant/PatientManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const PatientManagement = () => {
setTotalPatients(data.totalPatients || 0);
})
.catch((err) => {
console.log("An error has occurred");
console.error("An error has occurred.");
});
}, [
API_BASE,
Expand All @@ -148,7 +148,7 @@ const PatientManagement = () => {
})
.then((response) => response.json())
.catch((err) => {
console.log("An error has occurred");
console.error("An error has occurred.");
});
fetchPatients();
setDeleteDialogOpen(false);
Expand Down
3 changes: 1 addition & 2 deletions client/src/routes/standardUser/HealthAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ const HealthAnalytics = () => {
throw new Error("Network response was not ok");
}
const data = await response.json();
//console.log("Fetched data:", data); // Log fetched data
setHealthData(data);
} catch (error) {
console.error("Failed to fetch health analytics data:", error);
console.error("Failed to fetch health analytics data.");
}
};

Expand Down
9 changes: 4 additions & 5 deletions client/src/routes/standardUser/ReportHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ const AIHealthPrediction = () => {

if (data.length > 0) {
setSelectedDate(data[0]);
console.log("The selected date is:", data[0]);
}
})
.catch((err) => console.log(err));
.catch((err) => console.error("Failed to fetch health data dates."));
}, []);

useEffect(() => {
Expand All @@ -75,7 +74,7 @@ const AIHealthPrediction = () => {
})
.then((res) => res.json())
.then((data) => setReportData(data))
.catch((err) => console.log(err));
.catch((err) => console.error("Failed to fetch report data."));
}, [selectedDate]);

// Delete report data
Expand All @@ -90,9 +89,9 @@ const AIHealthPrediction = () => {
})
.then((res) => res.json())
.then((data) => setReportData(data))
.catch((err) => console.log(err));
.catch(() => console.error("Failed to delete report data."));
} catch (err) {
console.log(err);
console.error("Failed to delete report data.");
}
// Reload reports
fetchReportDates();
Expand Down
5 changes: 3 additions & 2 deletions client/src/routes/standardUser/UserSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useNavigate } from "react-router-dom";
import PhoneInputField from "../../components/authentication/PhoneInputField";
import ConfirmationDialog from "../../components/dialog/confirmationDialog";
import { UserContext } from "../../utils/UserContext";
import { stringEqual } from "../../utils/stringEqual";

/**
* A page that provides the tools for a user to securely update their
Expand Down Expand Up @@ -153,7 +154,7 @@ const UserSettings = () => {
return response.json();
})
.catch((error) => {
console.log("Failed to change password");
console.error("Failed to change password.");
});
}

Expand Down Expand Up @@ -498,7 +499,7 @@ const UserSettings = () => {
const Password = () => {
const mismatch =
passwordData.confirmPassword &&
passwordData.newPassword !== passwordData.confirmPassword;
!stringEqual(passwordData.newPassword, passwordData.confirmPassword);
const disabled =
!passwordData.currentPassword || !passwordData.newPassword || mismatch;
return (
Expand Down
18 changes: 18 additions & 0 deletions client/src/utils/stringEqual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Compares two strings in constant time using XOR.
*
* @param {string} a - The first string to compare
* @param {string} b - The second string to compare
*
* @returns {boolean} True if the strings are equal, false otherwise
*/
export function stringEqual(a, b) {
if (a.length !== b.length) {
return false;
}
let diff = 0;
for (let i = 0; i < a.length; i++) {
diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
}
return diff === 0;
}
Loading
Loading