Skip to content

Commit

Permalink
Add offset support for months
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Dec 11, 2024
1 parent c8132e8 commit 91bf64b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/transactions/add-transaction-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,23 @@ const AddTransactionDialog = ({

useEffect(() => {
if (selectedAccount?.type === 'Credit') {
if (transactionToEdit && date.isSame(dayjs.utc(transactionToEdit.date))) {
setMonth(dayjs.utc(transactionToEdit.billingMonth));
return;
}
let offset = selectedAccount.billingMonthOffset || 0;
if (date.get('date') < selectedAccount?.billingCycle) {
setMonth(date.subtract(1, 'month').startOf('month'));
} else {
setMonth(date.startOf('month'));
offset -= 1;
}
if (category.toLowerCase() === 'credit card bill') {
offset -= 1;
}
setMonth(date.add(offset, 'month').startOf('month'));

} else if (selectedAccount?.type === 'Retirement') {
setMonth(date.subtract(1, 'month').startOf('month'));
}
}, [ date ]);
}, [ transactionToEdit, date, category ]);

const submit = (event) => {
event.preventDefault();
Expand Down

0 comments on commit 91bf64b

Please sign in to comment.