From adce211480df435d3da3e0fcc2131dc3d4b96b68 Mon Sep 17 00:00:00 2001 From: Nora Date: Fri, 26 Jun 2026 06:12:04 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20react-doctor=20js-combine-iterations=207?= =?UTF-8?q?=E2=86=920=20(reduce=20instead=20of=20filter/flatMap+map),=20js?= =?UTF-8?q?-set-map-lookups=201=E2=86=920=20(forEach=20with=20index),=20js?= =?UTF-8?q?-tosorted-immutable=20and=20others?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/communications/contacts.ts | 8 +++--- src/app/admin/v2/stops/page.tsx | 7 +++-- src/app/admin/wholesale/WholesaleClient.tsx | 7 +++-- src/app/api/wholesale/price-sheet/route.ts | 28 +++++++++---------- src/app/roadmap/page.tsx | 7 +++-- .../admin/ShippingFulfillmentPanel.tsx | 13 +++++---- src/components/route-trace/LotDetailPanel.tsx | 7 +++-- src/lib/supabase.ts | 6 ++-- 8 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/actions/communications/contacts.ts b/src/actions/communications/contacts.ts index 9d828ef..49e907d 100644 --- a/src/actions/communications/contacts.ts +++ b/src/actions/communications/contacts.ts @@ -373,14 +373,14 @@ await getSession(); const adminUser = await getAdminUser(); errors: [], }; - for (const entry of settled) { + settled.forEach((entry, i) => { if (entry.status === "rejected") { const err = (entry as PromiseRejectedResult).reason; result.errors.push({ - row: validRows[settled.indexOf(entry)], + row: validRows[i], error: err instanceof Error ? err.message : String(err), }); - continue; + return; } const value = entry.value as | { row: ContactImportEntry; r: { success: boolean; error?: string } } @@ -396,7 +396,7 @@ await getSession(); const adminUser = await getAdminUser(); } else { result.errors.push({ row: value.row, error: value.r.error ?? "Unknown error" }); } - } + }); return { success: true, result }; } diff --git a/src/app/admin/v2/stops/page.tsx b/src/app/admin/v2/stops/page.tsx index ba8d48b..3c99afe 100644 --- a/src/app/admin/v2/stops/page.tsx +++ b/src/app/admin/v2/stops/page.tsx @@ -270,9 +270,10 @@ export default async function StopsV2Page({ actions={} /> - {BUCKET_ORDER.flatMap((bucket) => - grouped[bucket].length > 0 ? [bucket] : [] - ).map((bucket) => ( + {BUCKET_ORDER.reduce((acc, bucket) => { + if (grouped[bucket].length > 0) acc.push(bucket); + return acc; + }, []).map((bucket) => (

- {registrations.flatMap(r => - r.account_status === "pending_approval" ? [r] : [] - ).map(r => ( + {registrations.reduce((acc, r) => { + if (r.account_status === "pending_approval") acc.push(r); + return acc; + }, []).map(r => ( {r.company_name ?? "—"} {r.contact_name ?? "—"}
{r.email} diff --git a/src/app/api/wholesale/price-sheet/route.ts b/src/app/api/wholesale/price-sheet/route.ts index 1ffc123..51d8fba 100644 --- a/src/app/api/wholesale/price-sheet/route.ts +++ b/src/app/api/wholesale/price-sheet/route.ts @@ -72,10 +72,9 @@ export async function POST(req: NextRequest) { const emailSubject = subject?.trim() || `${brandName} Wholesale Price Sheet — ${generatedDate}`; const hasCustomNote = Boolean(customNote?.trim()); - // Build product rows HTML - const productRows = products.flatMap(p => - p.availability === "available" ? [p] : [] - ).map(p => { + // Build product rows HTML (single pass) + const productRowsReducer = products.reduce<{ rows: string[]; text: string[] }>((acc, p) => { + if (p.availability !== "available") return acc; const tiersHtml = p.price_tiers .map(t => { const max = t.max_qty === 0 ? "+" : `-${t.max_qty}`; @@ -83,15 +82,21 @@ export async function POST(req: NextRequest) { }) .join(" | "); - return ` + acc.rows.push(` ${p.name} ${p.description ?? "—"} ${p.unit_type} ${tiersHtml} - `; - }) - .join(""); + `); + + const tiersText = p.price_tiers + .map(t => `${t.min_qty}${t.max_qty === 0 ? "+" : `-${t.max_qty}`}: $${Number(t.price).toFixed(2)}`) + .join(", "); + acc.text.push(`${p.name} (${p.unit_type})\n ${tiersText}`); + return acc; + }, { rows: [], text: [] }); + const productRows = productRowsReducer.rows.join(""); const html = ` @@ -143,12 +148,7 @@ ${hasCustomNote ? `

- p.availability === "available" ? [p] : [] - ).map(p => { - const tiers = p.price_tiers.map(t => `${t.min_qty}${t.max_qty === 0 ? "+" : `-${t.max_qty}`}: $${Number(t.price).toFixed(2)}`).join(", "); - return `${p.name} (${p.unit_type})\n ${tiers}`; - }).join("\n\n")}\n\nGenerated ${generatedDate}. Prices subject to change.`; + const text = `${brandName} Wholesale Price Sheet — ${generatedDate}\n${"=".repeat(50)}\n${hasCustomNote ? `\n${customNote!.trim()}\n\n` : ""}${productRowsReducer.text.join("\n\n")}\n\nGenerated ${generatedDate}. Prices subject to change.`; let enqueued = 0; let failed = 0; diff --git a/src/app/roadmap/page.tsx b/src/app/roadmap/page.tsx index 8699bca..96d7d9a 100644 --- a/src/app/roadmap/page.tsx +++ b/src/app/roadmap/page.tsx @@ -232,9 +232,10 @@ export default function RoadmapPage() { className="w-full px-4 py-3 rounded-xl border border-[#e5e5e5] bg-white text-[#1a1a1a] focus:outline-none focus:ring-2 focus:ring-[#1a4d2e]/50 focus:border-[#1a4d2e] transition-all" > - {CATEGORIES.flatMap(c => - c === "All" ? [] : [c] - ).map((category) => ( + {CATEGORIES.reduce((acc, c) => { + if (c !== "All") acc.push(c); + return acc; + }, []).map((category) => ( ))} diff --git a/src/components/admin/ShippingFulfillmentPanel.tsx b/src/components/admin/ShippingFulfillmentPanel.tsx index 502a02a..9e93343 100644 --- a/src/components/admin/ShippingFulfillmentPanel.tsx +++ b/src/components/admin/ShippingFulfillmentPanel.tsx @@ -42,15 +42,15 @@ type ShippingFulfillmentPanelProps = { canManageOrders: boolean; }; -const SHIPPING_STATUSES = [ +const SHIPPING_STATUSES: Array<{ value: ShippingStatus; label: string }> = [ { value: "pending", label: "Pending" }, { value: "label_created", label: "Label Created" }, { value: "shipped", label: "Shipped" }, { value: "delivered", label: "Delivered" }, { value: "returned", label: "Returned" }, -] as const; +]; -type ShippingStatus = (typeof SHIPPING_STATUSES)[number]["value"]; +type ShippingStatus = "pending" | "label_created" | "shipped" | "delivered" | "returned"; const SERVICE_LABELS: Record = { FEDEX_OVERNIGHT: "FedEx Overnight", @@ -526,9 +526,10 @@ function OrderCard({ /> )} - {SHIPPING_STATUSES.flatMap((s) => - s.value !== order.shipping_status && s.value !== "label_created" ? [s] : [] - ).map((s) => { + {SHIPPING_STATUSES.reduce((acc, s) => { + if (s.value !== order.shipping_status && s.value !== "label_created") acc.push(s); + return acc; + }, []).map((s) => { const isDanger = s.value === "returned"; return ( - {STATUS_FLOW.flatMap((s) => - s !== lot.status ? [s] : [] - ).map((s) => { + {STATUS_FLOW.reduce((acc, s) => { + if (s !== lot.status) acc.push(s); + return acc; + }, []).map((s) => { const c = EVENT_CONFIG[s]; return (