Skip to content

Commit

Permalink
fix: consider income in recent envelopes
Browse files Browse the repository at this point in the history
With this, income is considered in the recent envelopes.

In the recent envelopes, income is represented as a recent envelope with the ID `null`.

Therefore, we need to check for this specific case and not use it as suggestion when it is the first
in the list of recent envelopes.

We also need to remove it from the recent envelopes list.
  • Loading branch information
morremeyer committed Aug 4, 2024
1 parent dccdbbd commit cfc58c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/components/TransactionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,19 @@ const TransactionForm = ({ budget, setNotification }: Props) => {
// Fetch the recent envelopes and suggest the first one
// as the Envelope to use for this transaction
envelopePromises.push(
get(account.links.recentEnvelopes).then(data => {
setRecentEnvelopes(data)
if (data.length) {
valuesToUpdate.envelopeId = data[0].id
get(account.links.recentEnvelopes).then(
(data: RecentEnvelope[]) => {
// We use the first envelope in recent envelopes as suggestion
// if its ID is not null. If its ID is null, income is the most
// common "envelope" for this account, so we don't set it.
if (data.length && data[0].id !== null) {
valuesToUpdate.envelopeId = data[0].id
}

// Remove income from the recent envelopes
setRecentEnvelopes(data.filter(e => e.id !== null))
}
})
)
)
} else if (!account.external) {
setRecentEnvelopes([])
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,5 @@ export type QuickAllocationMode =

export type RecentEnvelope = {
name: string
id: UUID
id: UUID | null
}

0 comments on commit cfc58c7

Please sign in to comment.