Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/mui/FormItemTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const FormItemTable = ({
label=""
size="small"
inCents
inputProps={{ step: 1 }}
inputProps={{ step: 0.01 }}
/>
</TableCell>
<TableCell
Expand Down
11 changes: 10 additions & 1 deletion src/pages/sponsors/sponsor-cart-tab/components/cart-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const CartView = ({
console.log("PAY INVOICE");
};

const cartData = cart?.forms.map((form) => ({
...form,
discount: form.discount === "0%" ? "" : form.discount
}));
Comment on lines +86 to +89

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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).


const tableColumns = [
{
columnKey: "code",
Expand All @@ -96,6 +101,10 @@ const CartView = ({
columnKey: "addon_name",
header: T.translate("edit_sponsor.cart_tab.add_ons")
},
{
columnKey: "item_count",
header: T.translate("edit_sponsor.cart_tab.items")
},
{
columnKey: "manage_items",
header: "",
Expand Down Expand Up @@ -180,7 +189,7 @@ const CartView = ({
<Paper elevation={0} sx={{ width: "100%", mb: 2 }}>
<MuiTable
columns={tableColumns}
data={cart?.forms}
data={cartData}
options={{}}
onEdit={onEdit}
onDelete={handleDelete}
Expand Down
3 changes: 3 additions & 0 deletions src/reducers/sponsors/sponsor-page-cart-list-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const sponsorPageCartListReducer = (state = DEFAULT_STATE, action) => {
addon_name: form.addon_name || "None",
amount: currencyAmountFromCents(form.net_amount),
discount,
item_count: `${form.items.length} ${
form.items.length === 1 ? "item" : "items"
}`,
items: form.items.map((it) => ({
...it,
custom_rate: currencyAmountFromCents(it.custom_rate || 0)
Expand Down
Loading