Feat/add input validation bmi calculator - #933
Open
thatperplextion wants to merge 6 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves client-side UX and robustness by adding input validation to the BMI calculator and replacing disruptive alert() error handling with in-app toast notifications, alongside some documentation cleanup and removal of client debug logging.
Changes:
- Add bounded validation + inline error display to
BMICalculator. - Replace
alert(err.message)usage with a reusableToastUI pattern across key pages. - Add/expand JSDoc comments for several utilities and remove noisy client debug logs from
ExercisePage.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| client/src/utils/rewardsUtils.js | Adds JSDoc; reviewed utility logic and flagged invalid-date handling in formatRelativeDate. |
| client/src/utils/normalizeProduct.js | Adds JSDoc clarifying normalization behavior for product identifiers. |
| client/src/utils/getAuthHeaders.js | Adds JSDoc describing dev-token vs Firebase token behavior (with a type syntax issue noted). |
| client/src/utils/formatters.js | Adds JSDoc for INR currency formatter. |
| client/src/pages/ProductPage.jsx | Adds toast notifications for cart-related errors instead of alert(). |
| client/src/pages/NotesPage.jsx | Adds toast notification for empty-title validation instead of alert(). |
| client/src/pages/HomePage.jsx | Adds toast notifications for cart operation failures instead of alert(). |
| client/src/pages/ExercisePage.jsx | Removes client-side debug logging / warning noise. |
| client/src/components/BMICalculator.jsx | Adds bounded input validation and inline error rendering for BMI calculation. |
Suppressed comments (2)
client/src/utils/rewardsUtils.js:72
formatRelativeDatereturns "NaN days ago" whendateValuecannot be parsed into a valid Date (e.g., invalid string). Add a validity check so invalid inputs return an empty string (or another safe fallback).
export const formatRelativeDate = (dateValue) => {
if (!dateValue) return "";
const date = new Date(dateValue);
const today = new Date();
client/src/components/BMICalculator.jsx:57
calculateBMI(w, h)is computed three times in a row. Compute it once and reuse the value to avoid duplicated work and ensure the displayed BMI, category, and recommendation are always derived from the exact same number.
setResult({
bmi: calculateBMI(w, h),
category: getBMICategory(calculateBMI(w, h)),
tdee: calculateTDEE(calculateBMR(w, h, a, formData.gender), activity),
recommendation: getRecommendedCategory(calculateBMI(w, h)),
});
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| const w = parseFloat(formData.weight); | ||
| const h = parseFloat(formData.height); | ||
| const a = parseInt(formData.age); |
| * Returns authentication headers for API requests. | ||
| * In development mode, prefers a local dev token if present. | ||
| * Otherwise, uses Firebase authentication token if user is logged in. | ||
| * @returns {Promise<{Content-Type: string, Authorization?: string}>} Headers object with optional Bearer token |
Comment on lines
281
to
285
| } catch (err) { | ||
| console.error("Add to cart failed:", err); | ||
| alert(err.message); | ||
| setToast({ message: err.message || 'Failed to add to cart', type: 'error', visible: true }); | ||
| setTimeout(() => setToast(prev => ({ ...prev, visible: false })), 3000); | ||
| } |
Comment on lines
+38
to
+40
| // Validation with reasonable bounds | ||
| if (!w || w < 20 || w > 300) { | ||
| setError("Please enter a valid weight between 20kg and 300kg."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 What does this PR do?
A clear summary of the changes made.
🔗 Related Issue
Closes #
🧪 How was this tested?
Describe how you tested your changes (manual steps, screenshots, etc.)
📸 Screenshots (if UI changes)
Before / After screenshots if you changed any UI.
✅ Checklist