diff --git a/packages/desktop-client/src/components/budget/index.tsx b/packages/desktop-client/src/components/budget/index.tsx index 3363140e6f73148adb2d0f645537461946cfd6f5..f22090b1f76715aeb1e3154f721e67b9807f39be 100644 --- a/packages/desktop-client/src/components/budget/index.tsx +++ b/packages/desktop-client/src/components/budget/index.tsx @@ -313,7 +313,24 @@ function BudgetInner(props: BudgetProps) { } }; + const groupNameAlreadyExistsNotification = group => { + props.addNotification({ + type: 'error', + message: `A ${group.hidden ? 'hidden ' : ''}’${group.name}’ category group already exists.`, + }); + }; + const onSaveGroup = async group => { + const categories = await props.getCategories(); + const matchingGroups = categories.grouped + .filter(g => g.name.toUpperCase() === group.name.toUpperCase()) + .filter(g => group.id === 'new' || group.id !== g.id); + + if (matchingGroups.length > 0) { + groupNameAlreadyExistsNotification(matchingGroups[0]); + return; + } + if (group.id === 'new') { const id = await props.createGroup(group.name); setIsAddingGroup(false); diff --git a/packages/loot-core/src/server/db/index.ts b/packages/loot-core/src/server/db/index.ts index 3a359f0659093f62b7be827c90252228ec9a40a8..65cae417ca7704e86c7d3e5328062b877b521d94 100644 --- a/packages/loot-core/src/server/db/index.ts +++ b/packages/loot-core/src/server/db/index.ts @@ -304,6 +304,17 @@ export async function getCategoriesGrouped(): Promise< } export async function insertCategoryGroup(group) { + // Don't allow duplicate group + const existingGroup = await first( + `SELECT id, name, hidden FROM category_groups WHERE UPPER(name) = ? and tombstone = 0 LIMIT 1`, + [group.name.toUpperCase()], + ); + if (existingGroup) { + throw new Error( + `A ${existingGroup.hidden ? 'hidden ' : ''}’${existingGroup.name}’ category group already exists.`, + ); + } + const lastGroup = await first(` SELECT sort_order FROM category_groups WHERE tombstone = 0 ORDER BY sort_order DESC, id DESC LIMIT 1 `); diff --git a/upcoming-release-notes/2262.md b/upcoming-release-notes/2262.md new file mode 100644 index 0000000000000000000000000000000000000000..e9bdf249069c8d2d1c3d68abe9c07e59e211fc84 --- /dev/null +++ b/upcoming-release-notes/2262.md @@ -0,0 +1,6 @@ +--- +category: Features +authors: [dhruvramdev] +--- + +Don't allow duplicate category groups \ No newline at end of file