From d6d7d912c0b4378ff47c36edc7ab9f2e24ec89fb Mon Sep 17 00:00:00 2001 From: Nitesh Yadav Date: Tue, 6 Oct 2026 12:39:43 +0530 Subject: [PATCH] fix(savings-product): guard against duplicate submission on create The product name is unique in the database, so a repeat click on Submit while the first request is still in flight fails with a duplicate key error even though the first request already created the product. Disables the button and ignores repeat calls until the request settles; also drops a stray debug console.log from the submit payload. Co-Authored-By: Claude Sonnet 5 --- .../create-saving-product.component.html | 2 +- .../create-saving-product.component.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/products/saving-products/create-saving-product/create-saving-product.component.html b/src/app/products/saving-products/create-saving-product/create-saving-product.component.html index 867619fa8..f60a295f3 100644 --- a/src/app/products/saving-products/create-saving-product/create-saving-product.component.html +++ b/src/app/products/saving-products/create-saving-product/create-saving-product.component.html @@ -144,7 +144,7 @@ } @if (savingProductFormValid && selectedTabIndex === totalTabs - 1) { - diff --git a/src/app/products/saving-products/create-saving-product/create-saving-product.component.ts b/src/app/products/saving-products/create-saving-product/create-saving-product.component.ts index 942b0f195..7207b8d78 100644 --- a/src/app/products/saving-products/create-saving-product/create-saving-product.component.ts +++ b/src/app/products/saving-products/create-saving-product/create-saving-product.component.ts @@ -70,6 +70,10 @@ export class CreateSavingProductComponent { savingProductsTemplate: any; accountingRuleData: string[] = []; selectedTabIndex = 0; + /** Guards against repeat clicks on Submit: the product name is unique in the database, so a + * second request for the same form fails with a duplicate key error even though the first one + * created the product. */ + submitting = false; /** * @param {ActivatedRoute} route Activated Route. @@ -162,8 +166,11 @@ export class CreateSavingProductComponent { } submit() { + if (this.submitting) { + return; + } + this.submitting = true; const savingProduct = this.prepareSavingProductPayload(); - console.log('Saving product submit payload:', savingProduct); this.productsService.createSavingProduct(savingProduct).subscribe({ next: (response: any) => { if (response?.rollbackTransaction) { @@ -181,6 +188,11 @@ export class CreateSavingProductComponent { { relativeTo: this.route } ); } + }, + error: () => { + // the error itself is reported by the global error handler; just let the user correct the + // form and try again + this.submitting = false; } }); }