fix: hide 0 discount, show items col, fix custom rate step#838
fix: hide 0 discount, show items col, fix custom rate step#838santipalenque wants to merge 1 commit intomasterfrom
Conversation
📝 WalkthroughWalkthroughUpdated numeric input precision for custom rate fields from whole numbers to two decimal places, added item count display to sponsor cart table with discount normalization, and enhanced cart reducer to track item quantities with singular/plural formatting. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/reducers/sponsors/sponsor-page-cart-list-reducer.js (1)
54-57:⚠️ Potential issue | 🟡 MinorInconsistent singular/plural handling compared to
RECEIVE_SPONSOR_CART.The
mapFormfunction always uses "items" (plural), butRECEIVE_SPONSOR_CARTat lines 92-94 correctly handles singular/plural. This will display "1 items" instead of "1 item" when there's exactly one item inRECEIVE_CART_AVAILABLE_FORMS.Proposed fix
const mapForm = (formData) => ({ ...formData, - item_count: `${formData.items.length} items` + item_count: `${formData.items.length} ${formData.items.length === 1 ? "item" : "items"}` });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/reducers/sponsors/sponsor-page-cart-list-reducer.js` around lines 54 - 57, mapForm currently always sets item_count to `${formData.items.length} items`, causing "1 items"; update mapForm to mirror the pluralization logic used in RECEIVE_SPONSOR_CART/RECEIVE_CART_AVAILABLE_FORMS by computing const count = formData.items.length and using `${count} ${count === 1 ? 'item' : 'items'}` for item_count so singular/plural is correct.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pages/sponsors/sponsor-cart-tab/components/cart-view.js`:
- Around line 86-89: cartData computation uses cart?.forms.map(...) which will
throw if cart exists but cart.forms is null/undefined; update the expression in
cartData (the cart?.forms.map call) to safely handle missing forms (e.g., guard
with cart?.forms?.map or default to an empty array before mapping) and keep the
same mapping logic that normalizes discount values (the discount field
transformation for each form).
---
Outside diff comments:
In `@src/reducers/sponsors/sponsor-page-cart-list-reducer.js`:
- Around line 54-57: mapForm currently always sets item_count to
`${formData.items.length} items`, causing "1 items"; update mapForm to mirror
the pluralization logic used in
RECEIVE_SPONSOR_CART/RECEIVE_CART_AVAILABLE_FORMS by computing const count =
formData.items.length and using `${count} ${count === 1 ? 'item' : 'items'}` for
item_count so singular/plural is correct.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9ac53825-4b4c-4c34-baf4-56c50b2f90ad
📒 Files selected for processing (3)
src/components/mui/FormItemTable/index.jssrc/pages/sponsors/sponsor-cart-tab/components/cart-view.jssrc/reducers/sponsors/sponsor-page-cart-list-reducer.js
| const cartData = cart?.forms.map((form) => ({ | ||
| ...form, | ||
| discount: form.discount === "0%" ? "" : form.discount | ||
| })); |
There was a problem hiding this comment.
Potential runtime error if cart.forms is undefined.
cart?.forms.map(...) will throw if cart exists but cart.forms is undefined or null. Consider using optional chaining on forms as well.
Proposed fix
- const cartData = cart?.forms.map((form) => ({
+ const cartData = cart?.forms?.map((form) => ({
...form,
discount: form.discount === "0%" ? "" : form.discount
- }));
+ })) ?? [];📝 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.
| const cartData = cart?.forms.map((form) => ({ | |
| ...form, | |
| discount: form.discount === "0%" ? "" : form.discount | |
| })); | |
| const cartData = cart?.forms?.map((form) => ({ | |
| ...form, | |
| discount: form.discount === "0%" ? "" : form.discount | |
| })) ?? []; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/pages/sponsors/sponsor-cart-tab/components/cart-view.js` around lines 86
- 89, cartData computation uses cart?.forms.map(...) which will throw if cart
exists but cart.forms is null/undefined; update the expression in cartData (the
cart?.forms.map call) to safely handle missing forms (e.g., guard with
cart?.forms?.map or default to an empty array before mapping) and keep the same
mapping logic that normalizes discount values (the discount field transformation
for each form).
https://app.clickup.com/t/86b90w3cw
https://app.clickup.com/t/86b90we8p
https://app.clickup.com/t/86b916bzq
Summary by CodeRabbit
New Features
Improvements