A local-first personal finance app
Fix #2932: Schedule reset amount to ten (10) when amount is zero (0) (#3732)
lelemm15b2ef159142
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.pngindex fa2f943420..d7fdcf4f75 100644Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.pngindex ba91cd0fa0..a70a6870cd 100644Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.pngindex 5bc5d5a483..11a107a25f 100644Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png differdiff --git a/packages/desktop-client/src/components/schedules/ScheduleDetails.jsx b/packages/desktop-client/src/components/schedules/ScheduleDetails.jsxindex aa4afd3d79..50964d6c45 100644--- a/packages/desktop-client/src/components/schedules/ScheduleDetails.jsx+++ b/packages/desktop-client/src/components/schedules/ScheduleDetails.jsx@@ -102,8 +102,7 @@ export function ScheduleDetails({ id, transaction }) {fields: {payee: schedule._payee,account: schedule._account,- // defalut to a non-zero value so the sign can be changed before the value- amount: schedule._amount || -1000,+ amount: schedule._amount || 0,amountOp: schedule._amountOp || 'isapprox',date: schedule._date,posts_transaction: action.schedule.posts_transaction,diff --git a/packages/desktop-client/src/components/util/AmountInput.tsx b/packages/desktop-client/src/components/util/AmountInput.tsxindex 671be17d9b..1b8fd0df87 100644--- a/packages/desktop-client/src/components/util/AmountInput.tsx+++ b/packages/desktop-client/src/components/util/AmountInput.tsx@@ -55,7 +55,9 @@ export function AmountInput({autoDecimals = false,}: AmountInputProps) {const format = useFormat();- const negative = (initialValue === 0 && zeroSign === '-') || initialValue < 0;+ const [symbol, setSymbol] = useState<'+' | '-'>(+ initialValue === 0 ? zeroSign : initialValue > 0 ? '+' : '-',+ );const initialValueAbsolute = format(Math.abs(initialValue || 0), 'financial');const [value, setValue] = useState(initialValueAbsolute);@@ -73,12 +75,16 @@ export function AmountInput({}, [focused]);function onSwitch() {- fireUpdate(!negative);+ const amount = getAmount();+ if (amount === 0) {+ setSymbol(symbol === '+' ? '-' : '+');+ }+ fireUpdate(amount * -1);}- function getAmount(negate) {- const valueOrInitial = Math.abs(amountToInteger(evalArithmetic(value)));- return negate ? valueOrInitial * -1 : valueOrInitial;+ function getAmount() {+ const signedValued = symbol === '-' ? symbol + value : value;+ return amountToInteger(evalArithmetic(signedValued));}function onInputTextChange(val) {@@ -89,13 +95,19 @@ export function AmountInput({onChangeValue?.(val);}- function fireUpdate(negate) {- onUpdate?.(getAmount(negate));+ function fireUpdate(amount) {+ onUpdate?.(amount);+ if (amount > 0) {+ setSymbol('+');+ } else if (amount < 0) {+ setSymbol('-');+ }}function onInputAmountBlur(e) {if (!ref.current?.contains(e.relatedTarget)) {- fireUpdate(negative);+ const amount = getAmount();+ fireUpdate(amount);}onBlur?.(e);}@@ -109,14 +121,15 @@ export function AmountInput({<Buttonvariant="bare"isDisabled={disabled}- aria-label={`Make ${negative ? 'positive' : 'negative'}`}+ aria-label={`Make ${symbol === '-' ? 'positive' : 'negative'}`}style={{ padding: '0 7px' }}onPress={onSwitch}ref={buttonRef}>- {negative ? (+ {symbol === '-' && (<SvgSubtract style={{ width: 8, height: 8, color: 'inherit' }} />- ) : (+ )}+ {symbol === '+' && (<SvgAdd style={{ width: 8, height: 8, color: 'inherit' }} />)}</Button>@@ -128,7 +141,8 @@ export function AmountInput({inputStyle={inputStyle}onKeyUp={e => {if (e.key === 'Enter') {- fireUpdate(negative);+ const amount = getAmount();+ fireUpdate(amount);}}}onChangeValue={onInputTextChange}diff --git a/upcoming-release-notes/3732.md b/upcoming-release-notes/3732.mdnew file mode 100644index 0000000000..5717114e13--- /dev/null+++ b/upcoming-release-notes/3732.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [lelemm]+---++Fix #2932: Schedule reset amount to ten (10) when amount is zero (0).