feat: implement alias strategy for receipt import with user-scoped and global fallback, enhance validation and normalization, and update UI components
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-09 23:41:42 +02:00
parent b342de906e
commit 65137b41fb
17 changed files with 388 additions and 67 deletions
+39
View File
@@ -0,0 +1,39 @@
const ignoredReceiptAliasPatterns = [
/^rabatt\b/,
/^summa\b/,
/^moms\b/,
/^pant\b/,
/^att\s+betala\b/,
/^totalt\b/,
/^kort\b/,
/^kontant\b/,
/^willys\s+plus\s*[:\-]?\b/,
];
export function normalizeReceiptAliasName(value: string | null | undefined): string {
return (value ?? '').trim().toLowerCase().replace(/\s+/g, ' ');
}
export function isIgnoredReceiptAliasName(value: string | null | undefined): boolean {
const normalized = normalizeReceiptAliasName(value);
if (!normalized) return false;
return ignoredReceiptAliasPatterns.some((pattern) => pattern.test(normalized));
}
export function validateReceiptAliasName(value: string | null | undefined): string | null {
const normalized = normalizeReceiptAliasName(value);
if (!normalized) {
return 'Alias får inte vara tomt.';
}
if (!/[a-z0-9åäö]/.test(normalized)) {
return 'Alias måste innehålla bokstäver eller siffror.';
}
if (ignoredReceiptAliasPatterns.some((pattern) => pattern.test(normalized))) {
return 'Aliaset ser ut som en kvittorad som ska ignoreras och kan inte sparas.';
}
return null;
}