Skip to content

Feat/add input validation bmi calculator - #933

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

Feat/add input validation bmi calculator#933
thatperplextion wants to merge 6 commits into
parthbuilds-community:mainfrom
thatperplextion:feat/add-input-validation-bmi-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:35
@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 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 reusable Toast UI 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

  • formatRelativeDate returns "NaN days ago" when dateValue cannot 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.");
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