Skip to content

Feat/add input validation calorie calculator - #936

Open
thatperplextion wants to merge 7 commits into
parthbuilds-community:mainfrom
thatperplextion:feat/add-input-validation-calorie-calculator
Open

Feat/add input validation calorie calculator#936
thatperplextion wants to merge 7 commits into
parthbuilds-community:mainfrom
thatperplextion:feat/add-input-validation-calorie-calculator

Conversation

@thatperplextion

Copy link
Copy Markdown

📋 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

  • I've read the CONTRIBUTING guide
  • My code follows the project's style guidelines
  • I've tested my changes locally
  • I've linked the related issue
  • I haven't introduced any new secrets or API keys

Copilot AI lite review requested due to automatic review settings August 9, 2026 10:38
@github-actions github-actions Bot added bug Something isn't working enhancement New feature or request refactor Improve code without changing functionality UI UI-related improvements including layouts, responsiveness, styling, animations, and UX enhancements. frontend labels Aug 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request frontend refactor Improve code without changing functionality UI UI-related improvements including layouts, responsiveness, styling, animations, and UX enhancements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants