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 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -144,7 +144,7 @@
|
|||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
@if (savingProductFormValid && selectedTabIndex === totalTabs - 1) {
|
@if (savingProductFormValid && selectedTabIndex === totalTabs - 1) {
|
||||||
<button mat-raised-button color="primary" (click)="submit()">
|
<button mat-raised-button color="primary" [disabled]="submitting" (click)="submit()">
|
||||||
<i class="fas fa-check" style="margin-right: 8px"></i>
|
<i class="fas fa-check" style="margin-right: 8px"></i>
|
||||||
{{ 'labels.buttons.Submit' | translate }}
|
{{ 'labels.buttons.Submit' | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
+13
-1
@@ -70,6 +70,10 @@ export class CreateSavingProductComponent {
|
|||||||
savingProductsTemplate: any;
|
savingProductsTemplate: any;
|
||||||
accountingRuleData: string[] = [];
|
accountingRuleData: string[] = [];
|
||||||
selectedTabIndex = 0;
|
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.
|
* @param {ActivatedRoute} route Activated Route.
|
||||||
@@ -162,8 +166,11 @@ export class CreateSavingProductComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
|
if (this.submitting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.submitting = true;
|
||||||
const savingProduct = this.prepareSavingProductPayload();
|
const savingProduct = this.prepareSavingProductPayload();
|
||||||
console.log('Saving product submit payload:', savingProduct);
|
|
||||||
this.productsService.createSavingProduct(savingProduct).subscribe({
|
this.productsService.createSavingProduct(savingProduct).subscribe({
|
||||||
next: (response: any) => {
|
next: (response: any) => {
|
||||||
if (response?.rollbackTransaction) {
|
if (response?.rollbackTransaction) {
|
||||||
@@ -181,6 +188,11 @@ export class CreateSavingProductComponent {
|
|||||||
{ relativeTo: this.route }
|
{ 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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user