fix state
All checks were successful
Build and deploy / build-deploy (push) Successful in 1m16s

This commit is contained in:
Ola Malmgren
2026-05-22 23:27:45 +02:00
parent 287e9a2a0e
commit 79616c8fdc

View File

@@ -1,6 +1,6 @@
'use client';
import { useState, useTransition } from 'react';
import { useEffect, useState, useTransition } from 'react';
import { useTranslations, useLocale } from 'next-intl';
import {
setItemFulfillment,
@@ -109,6 +109,13 @@ function FulfillmentRow({
const [delivered, setDelivered] = useState(item.deliveredQuantity);
const [returned, setReturned] = useState(item.returnedQuantity);
// Sync local state when server data refreshes (e.g. after deliver-all /
// return-all bulk actions). Without this, the inputs stay stale until reload.
useEffect(() => {
setDelivered(item.deliveredQuantity);
setReturned(item.returnedQuantity);
}, [item.deliveredQuantity, item.returnedQuantity]);
const outstanding = Math.max(0, delivered - returned);
const dirty =
delivered !== item.deliveredQuantity || returned !== item.returnedQuantity;