fix(price-check): keep the badge in step with the line's stored intel

The line's ai_item_insights can change under the badge (the assistant
fills the line, the operator saves it) and router.refresh() keeps the
component mounted, so the badge would keep showing the intel it read
at mount. Mirror the prop into local state instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dave 2026-10-24 21:59:56 +02:00
parent 9b3f30a01f
commit 8ef10f9f75

View file

@ -24,7 +24,7 @@
* the line afterwards.
*/
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { Loader2, RefreshCw, Tags } from "lucide-react";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
@ -117,6 +117,14 @@ export function PriceCheckMarker({
const [refreshing, setRefreshing] = useState(false);
const [error, setError] = useState<string | null>(null);
// The line's stored intel can change under us (the assistant fills
// the line, the operator saves it). Keep the badge in step with it.
useEffect(() => {
const next = asIntel(intel);
// eslint-disable-next-line react-hooks/set-state-in-effect -- mirror the line's stored intel into local state
if (next) setData(next);
}, [intel]);
const check = buildPriceCheck(data, {
cost_price,
selling_price,