Skip to content

Comments

Add coupon redeem logic with VIGYBAG 10% discount validation#2732

Merged
codervivek5 merged 1 commit intocodervivek5:mainfrom
Chavva-Harshita:fix/cart-redeem-button
Feb 14, 2026
Merged

Add coupon redeem logic with VIGYBAG 10% discount validation#2732
codervivek5 merged 1 commit intocodervivek5:mainfrom
Chavva-Harshita:fix/cart-redeem-button

Conversation

@Chavva-Harshita
Copy link
Contributor

@Chavva-Harshita Chavva-Harshita commented Feb 10, 2026

Fixes Issue

Closes #2727

Changes proposed
Implemented coupon redeem functionality in the cart checkout flow
Added validation for a sample redeem code VIGYBAG
Applied a 10% discount when the valid coupon is used
Displayed success message for valid coupon and error message for invalid codes
Ensured coupon input handling is case-insensitive and trimmed for better UX

Note to reviewers:
This implementation currently supports a single sample coupon as per requirement
Logic is kept simple and frontend-only for now
Can be easily extended later to support multiple coupons or backend validation

Summary by CodeRabbit

  • New Features
    • Added coupon redemption functionality to checkout. Users can now enter and apply discount codes with real-time validation feedback. Success or error messages appear immediately to confirm coupon application status.

@vercel
Copy link

vercel bot commented Feb 10, 2026

@Chavva-Harshita is attempting to deploy a commit to the Vivek Prajapati's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Implements coupon redemption functionality in the dashboard cart component by adding state management for coupon input, validation logic that compares against a hardcoded code, and user feedback messages. Resolves the non-functional Redeem button by implementing the missing click handler and validation workflow.

Changes

Cohort / File(s) Summary
Coupon Redemption Feature
src/User/pages/Dashboard/dashboard-cart.jsx
Added internal state for coupon, message, and isApplied. Implemented handleRedeem function with validation logic (non-empty check, case-insensitive comparison against VIGYBAG). Bound coupon input to state and connected Redeem button click to validation. Added conditional feedback message rendering (green on success, red on failure).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

level2, gssoc

Suggested reviewers

  • codervivek5

Poem

🐰 A coupon lands in the cart, at last,
The Redeem button clicks, no longer steadfast—
VIGYBAG glows green when the code is right,
Or red when it falters in digital light.
The cart's redemption blooms, pure and bright! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding coupon redemption logic with VIGYBAG validation and discount functionality.
Description check ✅ Passed The description covers all required sections including issue reference, changes proposed, and notes to reviewers, though some formatting is informal.
Linked Issues check ✅ Passed The PR implements the coupon validation logic [#2727] and adds UI feedback for both valid and invalid codes, making the Redeem button functional.
Out of Scope Changes check ✅ Passed All changes are within scope: they directly address the non-functional Redeem button by adding the missing click handler and validation logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/User/pages/Dashboard/dashboard-cart.jsx`:
- Line 127: The if-statement checking the coupon value (if
(coupon.trim().toUpperCase() === "VIGYBAG")) is accidentally dedented and should
be indented to match the surrounding block (lines 122–126); update the
indentation of that line so it aligns with the other statements in the same
block (referencing the coupon.trim().toUpperCase() comparison in
dashboard-cart.jsx) to restore consistent visual alignment.
- Around line 121-134: handleRedeem announces a 10% discount but never changes
the OrderSummary total because isApplied isn't passed down and OrderSummary
still uses total = itemsTotal + shipping; fix by wiring the discount into the
pricing flow: compute a discountAmount (e.g., 10% of itemsTotal) in handleRedeem
(or derive a boolean discountApplied from setIsApplied) and pass it as a prop to
OrderSummary (or persist it to Redux if you prefer global state) so OrderSummary
recalculates total = itemsTotal - discountAmount + shipping; also correct the
indentation around the coupon check in handleRedeem and remove the hardcoded
"VIGYBAG" from client-side code—validate the coupon server-side or fetch valid
codes from a secure endpoint instead of embedding the string.
🧹 Nitpick comments (2)
src/User/pages/Dashboard/dashboard-cart.jsx (2)

127-129: Hardcoded coupon code is trivially discoverable in client-side JS.

Any user can open DevTools and find "VIGYBAG" in the bundle. The PR description acknowledges this is frontend-only and a placeholder, which is fine for a demo, but be aware this offers zero actual validation. When extending to real coupons, move validation server-side.


154-162: Feedback message rendering is clean.

Minor UX suggestion: consider clearing the message when the user starts typing a new coupon code (e.g., in the onChange handler), so stale error/success messages don't persist while the user edits their input.

Optional: clear message on input change
-          onChange={(e) => setCoupon(e.target.value)}
+          onChange={(e) => {
+            setCoupon(e.target.value);
+            setMessage("");
+            setIsApplied(false);
+          }}

Comment on lines +121 to +134
const handleRedeem = () => {
if (!coupon.trim()) {
setMessage("Please enter a coupon code");
setIsApplied(false);
return;
}
if (coupon.trim().toUpperCase() === "VIGYBAG") {
setMessage("Coupon applied successfully! 🎉 10% discount added");
setIsApplied(true);
} else {
setMessage("Invalid redeem code ❌");
setIsApplied(false);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the file structure
fd "OrderSummary" --type f 2>/dev/null | head -20

Repository: codervivek5/VigyBag

Length of output: 105


🏁 Script executed:

# Check the dashboard-cart.jsx file directly for context around lines 121-134
wc -l src/User/pages/Dashboard/dashboard-cart.jsx

Repository: codervivek5/VigyBag

Length of output: 110


🏁 Script executed:

# Read the actual lines mentioned in the review
sed -n '117,165p' src/User/pages/Dashboard/dashboard-cart.jsx

Repository: codervivek5/VigyBag

Length of output: 1503


🏁 Script executed:

# Search for OrderSummary and Subtotal components to understand their props
fd -e jsx -e js -e ts | xargs grep -l "OrderSummary\|Subtotal" | head -10

Repository: codervivek5/VigyBag

Length of output: 286


🏁 Script executed:

# Check if discount/coupon state is passed anywhere in the checkout flow
rg -n "isApplied\|discount" src/User/pages/Dashboard/dashboard-cart.jsx -A 2 -B 2

Repository: codervivek5/VigyBag

Length of output: 45


🏁 Script executed:

# Read OrderSummary component to understand its props
cat -n src/User/components/Order/OrderSummary.jsx

Repository: codervivek5/VigyBag

Length of output: 3535


🏁 Script executed:

# Search in dashboard-cart.jsx for how OrderSummary is used
grep -n "OrderSummary\|<Subtotal\|discount\|coupon" src/User/pages/Dashboard/dashboard-cart.jsx

Repository: codervivek5/VigyBag

Length of output: 498


🏁 Script executed:

# Check if there's any discount calculation or application in the checkout process
grep -rn "discount\|coupon" src/User/pages/Order/Checkout.jsx src/User/pages/Order/Cart.jsx 2>/dev/null | head -20

Repository: codervivek5/VigyBag

Length of output: 137


🏁 Script executed:

# Verify OrderSummary is called without props in dashboard-cart.jsx
sed -n '290,310p' src/User/pages/Dashboard/dashboard-cart.jsx

Repository: codervivek5/VigyBag

Length of output: 449


🏁 Script executed:

# Check the exact indentation at line 127 to confirm the issue
sed -n '122,130p' src/User/pages/Dashboard/dashboard-cart.jsx | cat -A

Repository: codervivek5/VigyBag

Length of output: 365


Discount is announced but never actually applied to the order total.

The isApplied state is never passed to OrderSummary, which has no parameters and always calculates total = itemsTotal + shipping without any discount deduction. Users see "10% discount added" while being charged full price.

Also, line 127 has broken indentation (missing leading spaces), and the coupon code "VIGYBAG" is hardcoded in client-side JavaScript, making it trivially discoverable.

The discount logic must be integrated with OrderSummary—either by passing the discount as a prop, storing it in Redux alongside the total, or moving the coupon validation to the backend.

🤖 Prompt for AI Agents
In `@src/User/pages/Dashboard/dashboard-cart.jsx` around lines 121 - 134,
handleRedeem announces a 10% discount but never changes the OrderSummary total
because isApplied isn't passed down and OrderSummary still uses total =
itemsTotal + shipping; fix by wiring the discount into the pricing flow: compute
a discountAmount (e.g., 10% of itemsTotal) in handleRedeem (or derive a boolean
discountApplied from setIsApplied) and pass it as a prop to OrderSummary (or
persist it to Redux if you prefer global state) so OrderSummary recalculates
total = itemsTotal - discountAmount + shipping; also correct the indentation
around the coupon check in handleRedeem and remove the hardcoded "VIGYBAG" from
client-side code—validate the coupon server-side or fetch valid codes from a
secure endpoint instead of embedding the string.

setIsApplied(false);
return;
}
if (coupon.trim().toUpperCase() === "VIGYBAG") {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Indentation inconsistency.

Line 127 is missing leading whitespace, breaking the visual alignment with the surrounding if block (lines 122–126). This appears to be an accidental dedent.

Proposed fix
-if (coupon.trim().toUpperCase() === "VIGYBAG") {
+    if (coupon.trim().toUpperCase() === "VIGYBAG") {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (coupon.trim().toUpperCase() === "VIGYBAG") {
if (coupon.trim().toUpperCase() === "VIGYBAG") {
🤖 Prompt for AI Agents
In `@src/User/pages/Dashboard/dashboard-cart.jsx` at line 127, The if-statement
checking the coupon value (if (coupon.trim().toUpperCase() === "VIGYBAG")) is
accidentally dedented and should be indented to match the surrounding block
(lines 122–126); update the indentation of that line so it aligns with the other
statements in the same block (referencing the coupon.trim().toUpperCase()
comparison in dashboard-cart.jsx) to restore consistent visual alignment.

@vercel
Copy link

vercel bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vigybag Ready Ready Preview, Comment Feb 14, 2026 4:43pm

@codervivek5 codervivek5 merged commit c2a98e7 into codervivek5:main Feb 14, 2026
3 checks passed
@github-actions
Copy link

Congratulations, Your pull request has been successfully merged 🥳🎉 Thank you for your valuable contribution to the project 🚀 Keep contributing!! ✨

📢 Don’t forget to share your VigyBag PR on LinkedIn and tag @VigyBag and me — we’d love to celebrate your achievement with you! 🔗💡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Redeem Button Not Clickable on Cart Page

2 participants