Skip to content

A local-first personal finance app

:bug: (autocomplete) show 'create payee' only if no payee matched (#881)

Matiss Janis Aboltins82482f418292
diff --git a/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js b/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js
index f381d2a365..888217e6cf 100644
--- a/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js
+++ b/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js
@@ -85,21 +85,21 @@ export default function PayeeAutocomplete({
? allOptions.filter(item => value.includes(item.value))
: allOptions.find(item => item.value === value)
}
- isValidNewOption={input => input && !focusTransferPayees}
+ isValidNewOption={input => {
+ if (focusTransferPayees || !input) {
+ return false;
+ }
+
+ const lowercaseInput = input.toLowerCase();
+ const hasExistingOption = allOptions.some(
+ option => option.label.toLowerCase() === lowercaseInput,
+ );
+
+ return !hasExistingOption;
+ }}
isMulti={multi}
onSelect={onSelect}
onCreateOption={async selectedValue => {
- const existingOption = allOptions.find(option =>
- option.label.toLowerCase().includes(selectedValue?.toLowerCase()),
- );
-
- // Prevent creating duplicates
- if (existingOption) {
- onSelect(existingOption.value);
- return;
- }
-
- // This is actually a new option, so create it
onSelect(await dispatch(createPayee(selectedValue)));
}}
createOptionPosition="first"
diff --git a/upcoming-release-notes/881.md b/upcoming-release-notes/881.md
new file mode 100644
index 0000000000..6c3510c504
--- /dev/null
+++ b/upcoming-release-notes/881.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [MatissJanis]
+---
+
+Autocomplete: do not show "create payee" option if the typed-in payee is an exact match of an existing payee