toggle update

This commit is contained in:
2026-10-06 12:20:13 +05:30
parent a764df225f
commit 990dd0dc23

View File

@@ -158,8 +158,22 @@ export function ProductDrawer({
const [scoreError, setScoreError] = useState<string | null>(null);
const showScore = useMutation({
/*
The PRODUCT's tenant, not the branch scope's.
`useBranchScope` reads `user?.tenantid ?? 0`, so a session whose record
carries no tenant hands this a 0 — and the service refuses that outright,
which until recently failed in silence. The product row already names its
own tenant, the toggle's own guard requires it to be there before the
switch renders at all, and a per-product write is scoped by the product.
One source, and it is the one that cannot be absent.
*/
mutationFn: (show: boolean) =>
productsApi.setShowHealthScore(tenantid as number, product.productid, show),
productsApi.setShowHealthScore(
product.tenantid ?? (tenantid as number),
product.productid,
show,
),
onMutate: (show: boolean) => {
setScoreError(null);
setScoreShown(show);