-
Notifications
You must be signed in to change notification settings - Fork 4
feat: use N/A for items without rate #836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React from "react"; | ||
| import { Typography } from "@mui/material"; | ||
| import ErrorIcon from "@mui/icons-material/Error"; | ||
| import T from "i18n-react/dist/i18n-react"; | ||
|
|
||
| const UnderlyingAlertNote = ({ showAdditionalItems }) => { | ||
| if (!showAdditionalItems) return null; | ||
|
|
||
| return ( | ||
| <Typography | ||
| variant="body2" | ||
| component="p" | ||
| sx={{ color: "error.warning", fontSize: "0.8rem" }} | ||
| > | ||
| <ErrorIcon | ||
| color="error" | ||
| sx={{ | ||
| fontSize: "1rem", | ||
| top: "0.2rem", | ||
| position: "relative" | ||
| }} | ||
| />{" "} | ||
| {T.translate("edit_sponsor.cart_tab.edit_form.additional_info")} | ||
| </Typography> | ||
| ); | ||
| }; | ||
|
|
||
| export default UnderlyingAlertNote; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { epochToMomentTimeZone } from "openstack-uicore-foundation/lib/utils/methods"; | ||
| import { MILLISECONDS_IN_SECOND } from "../../../utils/constants"; | ||
|
|
||
| export const getCurrentApplicableRate = (timeZone, rateDates) => { | ||
| const now = epochToMomentTimeZone( | ||
| Math.floor(new Date() / MILLISECONDS_IN_SECOND), | ||
| timeZone | ||
| ); | ||
|
|
||
| const earlyBirdEnd = epochToMomentTimeZone( | ||
| rateDates.early_bird_end_date, | ||
| timeZone | ||
| )?.endOf("day"); | ||
| const onsiteStart = epochToMomentTimeZone( | ||
| rateDates.onsite_price_start_date, | ||
| timeZone | ||
| )?.startOf("day"); | ||
| const onsiteEnd = epochToMomentTimeZone( | ||
| rateDates.onsite_price_end_date, | ||
| timeZone | ||
| )?.endOf("day"); | ||
|
|
||
| if (earlyBirdEnd && now.isSameOrBefore(earlyBirdEnd)) return "early_bird"; | ||
| if (onsiteStart && now.isSameOrBefore(onsiteStart)) return "standard"; | ||
| if (!onsiteEnd || now.isSameOrBefore(onsiteEnd)) return "onsite"; | ||
| return "expired"; | ||
| }; | ||
|
|
||
| export const isItemAvailable = (item, currentApplicableRate) => | ||
| item.rates?.[currentApplicableRate] != null; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,29 +21,23 @@ import { | |||||||||||||||||
| TableCell, | ||||||||||||||||||
| TableContainer, | ||||||||||||||||||
| TableHead, | ||||||||||||||||||
| TableRow, | ||||||||||||||||||
| Typography | ||||||||||||||||||
| TableRow | ||||||||||||||||||
| } from "@mui/material"; | ||||||||||||||||||
| import EditIcon from "@mui/icons-material/Edit"; | ||||||||||||||||||
| import SettingsIcon from "@mui/icons-material/Settings"; | ||||||||||||||||||
| import ErrorIcon from "@mui/icons-material/Error"; | ||||||||||||||||||
| import T from "i18n-react/dist/i18n-react"; | ||||||||||||||||||
| import { currencyAmountFromCents } from "openstack-uicore-foundation/lib/utils/money"; | ||||||||||||||||||
| import { epochToMomentTimeZone } from "openstack-uicore-foundation/lib/utils/methods"; | ||||||||||||||||||
| import { | ||||||||||||||||||
| DISCOUNT_TYPES, | ||||||||||||||||||
| MILLISECONDS_IN_SECOND, | ||||||||||||||||||
| ONE_HUNDRED | ||||||||||||||||||
| } from "../../../utils/constants"; | ||||||||||||||||||
| import { DISCOUNT_TYPES, ONE_HUNDRED } from "../../../utils/constants"; | ||||||||||||||||||
| import GlobalQuantityField from "./components/GlobalQuantityField"; | ||||||||||||||||||
| import ItemTableField from "./components/ItemTableField"; | ||||||||||||||||||
| import MuiFormikSelect from "../formik-inputs/mui-formik-select"; | ||||||||||||||||||
| import MuiFormikPriceField from "../formik-inputs/mui-formik-pricefield"; | ||||||||||||||||||
| import MuiFormikDiscountField from "../formik-inputs/mui-formik-discountfield"; | ||||||||||||||||||
| import UnderlyingAlertNote from "./components/UnderlyingAlertNote"; | ||||||||||||||||||
|
|
||||||||||||||||||
| const FormItemTable = ({ | ||||||||||||||||||
| data, | ||||||||||||||||||
| rateDates, | ||||||||||||||||||
| currentApplicableRate, | ||||||||||||||||||
| timeZone, | ||||||||||||||||||
| values, | ||||||||||||||||||
| onNotesClick, | ||||||||||||||||||
|
|
@@ -55,33 +49,6 @@ const FormItemTable = ({ | |||||||||||||||||
| const fixedColumns = 10; | ||||||||||||||||||
| const totalColumns = extraColumns.length + fixedColumns; | ||||||||||||||||||
|
|
||||||||||||||||||
| const currentApplicableRate = useMemo(() => { | ||||||||||||||||||
| const now = epochToMomentTimeZone( | ||||||||||||||||||
| Math.floor(new Date() / MILLISECONDS_IN_SECOND), | ||||||||||||||||||
| timeZone | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| const earlyBirdEndOfDay = epochToMomentTimeZone( | ||||||||||||||||||
| rateDates.early_bird_end_date, | ||||||||||||||||||
| timeZone | ||||||||||||||||||
| )?.endOf("day"); | ||||||||||||||||||
| const standardEndOfDay = epochToMomentTimeZone( | ||||||||||||||||||
| rateDates.standard_price_end_date, | ||||||||||||||||||
| timeZone | ||||||||||||||||||
| )?.endOf("day"); | ||||||||||||||||||
| const onsiteEndOfDay = epochToMomentTimeZone( | ||||||||||||||||||
| rateDates.onsite_price_end_date, | ||||||||||||||||||
| timeZone | ||||||||||||||||||
| )?.endOf("day"); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (earlyBirdEndOfDay && now.isSameOrBefore(earlyBirdEndOfDay)) | ||||||||||||||||||
| return "early_bird"; | ||||||||||||||||||
| if (standardEndOfDay && now.isSameOrBefore(standardEndOfDay)) | ||||||||||||||||||
| return "standard"; | ||||||||||||||||||
| if (!onsiteEndOfDay || now.isSameOrBefore(onsiteEndOfDay)) return "onsite"; | ||||||||||||||||||
| return "expired"; | ||||||||||||||||||
| }, [rateDates, timeZone]); | ||||||||||||||||||
|
|
||||||||||||||||||
| const calculateQuantity = useCallback( | ||||||||||||||||||
| (row) => { | ||||||||||||||||||
| const qtyEXC = extraColumns.filter((exc) => exc.type === "Quantity"); | ||||||||||||||||||
|
|
@@ -105,10 +72,14 @@ const FormItemTable = ({ | |||||||||||||||||
| const qty = | ||||||||||||||||||
| values[`i-${row.form_item_id}-c-global-f-quantity`] || | ||||||||||||||||||
| calculateQuantity(row); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (currentApplicableRate === "expired") return 0; | ||||||||||||||||||
|
|
||||||||||||||||||
| const customRate = values[`i-${row.form_item_id}-c-global-f-custom_rate`]; | ||||||||||||||||||
| const rate = customRate || row.rates[currentApplicableRate]; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (rate == null || qty == null) return 0; | ||||||||||||||||||
|
Comment on lines
78
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Inspect custom-rate fallback in FormItemTable:"
sed -n '68,92p' src/components/mui/FormItemTable/index.js
echo
echo "Inspect price field implementation to verify whether 0 is stored as number/string:"
fd 'mui-formik-pricefield.*' src --exec sed -n '1,220p' {}Repository: fntechgit/summit-admin Length of output: 2931 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== Search for other uses of customRate in the codebase ==="
rg "custom_rate|customRate" src --type js -B 2 -A 2 | head -100
echo
echo "=== Check for validation or constraint on custom_rate ==="
rg "custom_rate" src --type js | grep -i "validat\|required\|constraint\|min\|max" || echo "No validation constraints found"
echo
echo "=== Check FormItemTable context for business logic ==="
sed -n '1,120p' src/components/mui/FormItemTable/index.js | tail -50Repository: fntechgit/summit-admin Length of output: 9587 Use nullish coalescing to respect explicit Line 79 uses Proposed fix- const rate = customRate || row.rates[currentApplicableRate];
+ const rate = customRate ?? row.rates?.[currentApplicableRate];📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| return qty * rate; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -127,6 +98,11 @@ const FormItemTable = ({ | |||||||||||||||||
| return requiredFields.length > 0 && hasMissingFields; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| const formatRate = (rate) => { | ||||||||||||||||||
| if (rate == null) return T.translate("general.n_a"); | ||||||||||||||||||
| return currencyAmountFromCents(rate); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| const totalAmount = useMemo(() => { | ||||||||||||||||||
| const subtotal = data.reduce((acc, row) => acc + calculateRowTotal(row), 0); | ||||||||||||||||||
| const discount = | ||||||||||||||||||
|
|
@@ -135,7 +111,7 @@ const FormItemTable = ({ | |||||||||||||||||
| : subtotal * (values.discount_amount / ONE_HUNDRED / ONE_HUNDRED); // bps to fraction | ||||||||||||||||||
|
|
||||||||||||||||||
| return subtotal - Math.round(discount); | ||||||||||||||||||
| }, [data, valuesStr]); | ||||||||||||||||||
| }, [data, valuesStr, currentApplicableRate]); | ||||||||||||||||||
|
|
||||||||||||||||||
| const handleEdit = (row) => { | ||||||||||||||||||
| onNotesClick(row); | ||||||||||||||||||
|
|
@@ -190,29 +166,11 @@ const FormItemTable = ({ | |||||||||||||||||
| <TableCell>{row.code}</TableCell> | ||||||||||||||||||
| <TableCell sx={{ position: "relative" }}> | ||||||||||||||||||
| <div>{row.name}</div> | ||||||||||||||||||
| {hasItemFields(row) && itemFieldsIncomplete(row) && ( | ||||||||||||||||||
| <Typography | ||||||||||||||||||
| variant="body2" | ||||||||||||||||||
| component="p" | ||||||||||||||||||
| sx={{ | ||||||||||||||||||
| color: "warning.main", | ||||||||||||||||||
| fontSize: "0.6em", | ||||||||||||||||||
| position: "absolute" | ||||||||||||||||||
| }} | ||||||||||||||||||
| > | ||||||||||||||||||
| <ErrorIcon | ||||||||||||||||||
| color="warning" | ||||||||||||||||||
| sx={{ | ||||||||||||||||||
| fontSize: "1.4em", | ||||||||||||||||||
| top: "0.2em", | ||||||||||||||||||
| position: "relative" | ||||||||||||||||||
| }} | ||||||||||||||||||
| />{" "} | ||||||||||||||||||
| {T.translate( | ||||||||||||||||||
| "edit_sponsor.cart_tab.edit_form.additional_info" | ||||||||||||||||||
| )} | ||||||||||||||||||
| </Typography> | ||||||||||||||||||
| )} | ||||||||||||||||||
| <UnderlyingAlertNote | ||||||||||||||||||
| showAdditionalItems={ | ||||||||||||||||||
| hasItemFields(row) && itemFieldsIncomplete(row) | ||||||||||||||||||
| } | ||||||||||||||||||
| /> | ||||||||||||||||||
| </TableCell> | ||||||||||||||||||
| <TableCell> | ||||||||||||||||||
| <MuiFormikPriceField | ||||||||||||||||||
|
|
@@ -229,19 +187,21 @@ const FormItemTable = ({ | |||||||||||||||||
| opacity: currentApplicableRate === "early_bird" ? 1 : "38%" | ||||||||||||||||||
| }} | ||||||||||||||||||
| > | ||||||||||||||||||
| {currencyAmountFromCents(row.rates.early_bird)} | ||||||||||||||||||
| {formatRate(row.rates.early_bird)} | ||||||||||||||||||
| </TableCell> | ||||||||||||||||||
| <TableCell | ||||||||||||||||||
| sx={{ | ||||||||||||||||||
| opacity: currentApplicableRate === "standard" ? 1 : "38%" | ||||||||||||||||||
| }} | ||||||||||||||||||
| > | ||||||||||||||||||
| {currencyAmountFromCents(row.rates.standard)} | ||||||||||||||||||
| {formatRate(row.rates.standard)} | ||||||||||||||||||
| </TableCell> | ||||||||||||||||||
| <TableCell | ||||||||||||||||||
| sx={{ opacity: currentApplicableRate === "onsite" ? 1 : "38%" }} | ||||||||||||||||||
| sx={{ | ||||||||||||||||||
| opacity: currentApplicableRate === "onsite" ? 1 : "38%" | ||||||||||||||||||
| }} | ||||||||||||||||||
| > | ||||||||||||||||||
| {currencyAmountFromCents(row.rates.onsite)} | ||||||||||||||||||
| {formatRate(row.rates.onsite)} | ||||||||||||||||||
| </TableCell> | ||||||||||||||||||
| {extraColumns.map((exc) => ( | ||||||||||||||||||
| <TableCell key={`datacell-${row.form_item_id}-${exc.type_id}`}> | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.