@metron-labs/quote-react 0.1.18 → 0.1.20

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.
@@ -11,6 +11,7 @@ import { clientHeaders, getBoqClientId, readJson } from "../../lib/api/boqClient
11
11
  // ponytail: flat UK VAT rate, matching fmtCurrency's GBP-only assumption elsewhere in this app.
12
12
  const VAT_RATE = 0.2;
13
13
  const PAGE_SIZE = 10;
14
+ const INVALID_EMAIL_MESSAGE = "Enter a valid email address so we can send your quote.";
14
15
  const orderSummary = (item, pricing) => {
15
16
  const requested = `${pricing.requestedAmount} ${unitDisplayText(pricing.requestedUnit, pricing.requestedAmount)}`;
16
17
  const order = `${pricing.requiredSellUnits} ${unitDisplayText(pricing.sellUnit, pricing.requiredSellUnits ?? 0)}`;
@@ -145,7 +146,7 @@ export default function BasketStage({ cart, onUpdateQty, onUpdateSellUnits, onRe
145
146
  async function submitQuoteRequest() {
146
147
  const email = reference.trim();
147
148
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
148
- setQuoteContactError("Enter a valid email address so we can send your better price.");
149
+ setQuoteContactError(INVALID_EMAIL_MESSAGE);
149
150
  return;
150
151
  }
151
152
  setQuoteContactError("");
@@ -161,13 +162,24 @@ export default function BasketStage({ cart, onUpdateQty, onUpdateSellUnits, onRe
161
162
  items: pricedItems.map(({ item, pricing }) => {
162
163
  const quantity = pricing.requiredSellUnits ?? pricing.requestedAmount;
163
164
  const unit = pricing.requiredSellUnits != null ? pricing.sellUnit : pricing.requestedUnit;
164
- return { product_id: item.productId, description: item.description, quantity, unit: unitDisplayText(unit, quantity) };
165
+ return {
166
+ product_id: item.productId,
167
+ description: item.description,
168
+ quantity,
169
+ unit: unitDisplayText(unit, quantity),
170
+ // The price is per sale unit, so it only matches the quantity when that's in sale units.
171
+ unit_price: pricing.requiredSellUnits != null ? pricing.unitPrice : null,
172
+ line_total: pricing.lineTotal,
173
+ };
165
174
  }),
166
175
  }),
167
176
  });
168
177
  if (!res.ok) {
169
178
  const payload = await readJson(res);
170
- setQuoteContactError(res.status === 429 ? "You've sent a few requests already. Please try again in a few minutes." : (payload?.message ?? "Your request couldn't be sent. Please try again."));
179
+ // The API's own message is written for developers (e.g. "items.0: Unrecognized key(s)"),
180
+ // so the customer gets a plain one and the console keeps the detail.
181
+ console.error("Quote request failed", res.status, payload?.message);
182
+ setQuoteContactError(res.status === 429 ? "You've sent a few requests already. Please try again in a few minutes." : "Your request couldn't be sent. Please try again, or contact us if it keeps happening.");
171
183
  return;
172
184
  }
173
185
  setQuoteRequestSent(true);
@@ -224,7 +236,7 @@ export default function BasketStage({ cart, onUpdateQty, onUpdateSellUnits, onRe
224
236
  setReference(e.target.value);
225
237
  if (qzaBasketLayout)
226
238
  setQuoteContactError("");
227
- }, placeholder: qzaBasketLayout ? "you@example.com" : "PO number or job reference" }), qzaBasketLayout && quoteContactError && (_jsx("p", { className: "basket-quote-request-error", role: "alert", children: quoteContactError })), qzaBasketLayout ? (_jsx("button", { type: "button", className: "cta-btn", onClick: () => void submitQuoteRequest(), disabled: quoteRequestSending, "aria-busy": quoteRequestSending, children: _jsx("span", { children: quoteRequestSending ? "Sending…" : "Request our best quote" }) })) : (_jsx("button", { className: "cta-btn", onClick: () => void exportBasketExcel(items), "aria-label": internal ? "Download selection" : "Download basket", children: _jsx("span", { children: internal ? "Download Quote" : "Buy Now" }) })), _jsxs("p", { className: "basket-sidebar-disclaimer", children: [_jsx("span", { "aria-hidden": "true", children: "\u26A0\uFE0F" }), qzaBasketLayout
239
+ }, placeholder: qzaBasketLayout ? "you@example.com" : "PO number or job reference", "aria-invalid": qzaBasketLayout && quoteContactError === INVALID_EMAIL_MESSAGE, "aria-describedby": qzaBasketLayout && quoteContactError ? `${uid}-basket-reference-error` : undefined }), qzaBasketLayout && quoteContactError && (_jsx("p", { id: `${uid}-basket-reference-error`, className: "basket-quote-request-error", role: "alert", children: quoteContactError })), qzaBasketLayout ? (_jsx("button", { type: "button", className: "cta-btn", onClick: () => void submitQuoteRequest(), disabled: quoteRequestSending, "aria-busy": quoteRequestSending, children: _jsx("span", { children: quoteRequestSending ? "Sending…" : "Request our best quote" }) })) : (_jsx("button", { className: "cta-btn", onClick: () => void exportBasketExcel(items), "aria-label": internal ? "Download selection" : "Download basket", children: _jsx("span", { children: internal ? "Download Quote" : "Buy Now" }) })), _jsxs("p", { className: "basket-sidebar-disclaimer", children: [_jsx("span", { "aria-hidden": "true", children: "\u26A0\uFE0F" }), qzaBasketLayout
228
240
  ? "This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve."
229
241
  : "Prices and availability are estimates and should be confirmed before procurement."] })] })] }), _jsx("div", { className: "btn-row results-actions", children: _jsxs("button", { className: "cta-btn cta-btn-secondary", style: { flex: "0 1 30%", gap: 10, justifyContent: "center" }, onClick: onBack, "aria-label": "Back to results", children: [_jsx(BackArrow, {}), _jsx("span", { children: "Back to results" })] }) })] })) })] }) }));
230
242
  }