From 7859f277ed26b2e935402052c1aadf39f55ec0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Loipf=C3=BChrer?= Date: Mon, 9 May 2022 00:21:21 +0200 Subject: [PATCH] fix weird transaction positions editing --- .../transactions/purchase/PurchaseItems.tsx | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/web/src/components/transactions/purchase/PurchaseItems.tsx b/web/src/components/transactions/purchase/PurchaseItems.tsx index 9dd4767d..9d442ea2 100644 --- a/web/src/components/transactions/purchase/PurchaseItems.tsx +++ b/web/src/components/transactions/purchase/PurchaseItems.tsx @@ -227,17 +227,21 @@ export default function PurchaseItems({ group, transaction }: PropTypes) { ); const [showAdvanced, setShowAdvanced] = useState(false); - const positions = transaction.positions - .map((p) => ({ ...p, is_empty: false })) - .concat([ - { - ...localPositionChanges.empty, - is_empty: true, - }, - ]); + const [positions, setPositions] = useState([]); + + useEffect(() => { + setPositions(transaction.positions + .map((p) => ({ ...p, is_empty: false })) + .concat([ + { + ...localPositionChanges.empty, + is_empty: true, + }, + ])); + }, [transaction, setPositions, localPositionChanges]) // find all accounts that take part in the transaction, either via debitor shares or purchase items - // TODO: should we add creditor items as well? + // TODO: should we add creditor accounts as well? const positionAccounts: Array = Array.from( new Set( positions @@ -538,7 +542,7 @@ export default function PurchaseItems({ group, transaction }: PropTypes) { {transaction.is_wip - ? positions.map((position) => ( + ? positions.map(position => ( )) : positions.map( - (position) => + position => !position.is_empty && ( {position.name}