@metron-labs/quote-react 0.1.72 → 0.1.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { getPricingBreakdown } from "../../util/pricing";
1
2
  import type { CartItem } from "../../util/types";
2
3
  interface BasketStageProps {
3
4
  cart: Record<string, CartItem>;
@@ -10,5 +11,6 @@ interface BasketStageProps {
10
11
  onQuoteRequested?: () => void;
11
12
  internal?: boolean;
12
13
  }
14
+ export declare const orderSummary: (item: CartItem, pricing: ReturnType<typeof getPricingBreakdown>) => string;
13
15
  export default function BasketStage({ cart, onUpdateQty, onUpdateSellUnits, onResolveConversions, onRemove, onBack, onStartNewQuote, onQuoteRequested, internal, }: BasketStageProps): import("react").JSX.Element;
14
16
  export {};
@@ -16,12 +16,17 @@ import ProductImage from "../../util/ProductImage";
16
16
  const VAT_RATE = 0.2; //Flat UK VAT rate, matching fmtCurrency's GBP-only assumption elsewhere in this app.
17
17
  const PAGE_SIZE = 10;
18
18
  const INVALID_EMAIL_MESSAGE = "Enter a valid email address so we can send your quote.";
19
- const orderSummary = (item, pricing) => {
19
+ export const orderSummary = (item, pricing) => {
20
20
  const requested = `${pricing.requestedAmount} ${unitDisplayText(pricing.requestedUnit, pricing.requestedAmount)}`;
21
21
  const order = `${pricing.requiredSellUnits} ${unitDisplayText(pricing.sellUnit, pricing.requiredSellUnits ?? 0)}`;
22
22
  const conversion = item.unitConversions?.find((entry) => entry.requestUom === pricing.requestedUnit);
23
23
  if (conversion && conversion.quantityPerSaleUnit < 1) {
24
- return `${requested} requested → order ${order} (${Math.round(1 / conversion.quantityPerSaleUnit)} ${unitDisplayText(pricing.sellUnit, 2)} per ${unitDisplayText(pricing.requestedUnit, 1)})`;
24
+ // A whole number reads per requested unit ("2 bulk bags per m3"); otherwise per sell unit ("0.75 l per unit", not "1 units per l").
25
+ const perRequested = Math.round(1 / conversion.quantityPerSaleUnit);
26
+ const ratio = Math.abs(perRequested * conversion.quantityPerSaleUnit - 1) < 1e-9
27
+ ? `${perRequested} ${unitDisplayText(pricing.sellUnit, perRequested)} per ${unitDisplayText(pricing.requestedUnit, 1)}`
28
+ : `${conversion.quantityPerSaleUnit} ${unitDisplayText(pricing.requestedUnit, conversion.quantityPerSaleUnit)} per ${unitDisplayText(pricing.sellUnit, 1)}`;
29
+ return `${requested} requested → order ${order} (${ratio})`;
25
30
  }
26
31
  const bulkBagKg = pricing.sellUnit === "bulk bag" ? item.description.match(/(\d+(?:\.\d+)?)\s*kg\b/i) : null;
27
32
  if (bulkBagKg) {
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import UnitLabel from "./UnitLabel";
3
3
  function pluralizeUnit(unit, count) {
4
- if (count === 1 || /^m\d*$/i.test(unit))
4
+ // Unit symbols never take a plural: "800 kg", not "800 kgs".
5
+ if (count === 1 || /^(m\d*|mm|cm|ml|kg|g)$/i.test(unit))
5
6
  return unit;
6
7
  if (/(s|x|z|ch|sh)$/i.test(unit))
7
8
  return `${unit}es`;
@@ -13,7 +14,7 @@ export function unitDisplayText(unit, count) {
13
14
  const normalized = (unit ?? "").trim();
14
15
  if (!normalized || normalized === "-")
15
16
  return "";
16
- const word = /^each$/i.test(normalized) ? "unit" : normalized;
17
+ const word = /^each$/i.test(normalized) ? "unit" : /^l$/i.test(normalized) ? "litre" : normalized;
17
18
  return count != null ? pluralizeUnit(word, count) : word;
18
19
  }
19
20
  export function renderDisplayUnit(unit, count) {