Feat/add input validation calorie calculator - #936
Open
thatperplextion wants to merge 7 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves client-side UX and data correctness by adding stricter input validation to health calculators and replacing disruptive alert() calls with a reusable Toast notification pattern across key pages.
Changes:
- Add bounded input validation + inline error display to Calorie and BMI calculators.
- Replace
alert(err.message)with Toast-based error notifications in Home/Product/Notes flows. - Add/expand JSDoc comments for several utility helpers and remove noisy debug logs in ExercisePage.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| client/src/utils/rewardsUtils.js | Adds JSDoc documentation for reward tier utilities. |
| client/src/utils/normalizeProduct.js | Adds JSDoc documentation for product ID normalization helper. |
| client/src/utils/getAuthHeaders.js | Adds JSDoc for auth header helper (return type doc needs adjustment for Content-Type). |
| client/src/utils/formatters.js | Adds JSDoc documentation for INR currency formatter. |
| client/src/pages/ProductPage.jsx | Replaces alert() error handling with Toast notifications for cart actions. |
| client/src/pages/NotesPage.jsx | Uses Toast instead of alert() when saving without a title. |
| client/src/pages/HomePage.jsx | Uses Toast instead of alert() for cart-related failures. |
| client/src/pages/ExercisePage.jsx | Removes client-side debug logging and image load warning. |
| client/src/components/CalorieCalculator.jsx | Adds bounded validation and inline error messaging for calculator inputs. |
| client/src/components/BMICalculator.jsx | Adds bounded validation and inline error messaging for calculator inputs (needs result-clearing fix on validation failure). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+122
to
+125
| {error && ( | ||
| <div className="bg-red-50 border border-red-100 text-red-600 px-4 py-3 rounded-lg text-sm"> | ||
| {error} | ||
| </div> |
Comment on lines
29
to
+32
| const handleCalculate = (e) => { | ||
| e.preventDefault(); | ||
| setError(""); | ||
|
|
Comment on lines
+89
to
+93
| {error && ( | ||
| <div className="bg-red-50 border border-red-100 text-red-600 px-4 py-3 rounded-lg text-sm"> | ||
| {error} | ||
| </div> | ||
| )} |
Comment on lines
+147
to
+148
| setToast({ message: err.message || 'Failed to add to cart', type: 'error', visible: true }); | ||
| setTimeout(() => setToast(prev => ({ ...prev, visible: false })), 3000); |
Comment on lines
+283
to
285
| setToast({ message: err.message || 'Failed to add to cart', type: 'error', visible: true }); | ||
| setTimeout(() => setToast(prev => ({ ...prev, visible: false })), 3000); | ||
| } |
Comment on lines
45
to
48
| if (!title.trim()) { | ||
| alert("Please enter a workout title."); | ||
| setToast({ message: 'Please enter a workout title.', type: 'error', visible: true }); | ||
| setTimeout(() => setToast(prev => ({ ...prev, visible: false })), 3000); | ||
| return; |
Comment on lines
+5
to
+10
| /** | ||
| * 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 | ||
| */ |
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