Skip to content

Commit

Permalink
Clear stored state on form reset
Browse files Browse the repository at this point in the history
  • Loading branch information
jantoun-scottlogic committed Aug 6, 2024
1 parent 8a494af commit 045e50b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class MockStorageService {
set(key: string, value: string): void {
this.storage[key] = value;
}

removeItem(key: string): void {
delete this.storage[key];
}
}

describe('CarbonEstimatorFormComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class CarbonEstimatorFormComponent implements OnInit, OnDestroy {

public resetForm() {
this.estimatorForm.reset();
this.storeFormState();
this.clearStoredFormState();
this.formReset.emit();
}

Expand Down Expand Up @@ -310,4 +310,8 @@ export class CarbonEstimatorFormComponent implements OnInit, OnDestroy {
const storedFormState = this.storageService.get('formState');
return storedFormState ? (JSON.parse(storedFormState) as FormState) : null;
}

private clearStoredFormState() {
this.storageService.removeItem('formState');
}
}
6 changes: 5 additions & 1 deletion src/app/services/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class StorageService {
}

set(key: string, value: string): void {
return this.storage.setItem(key, value);
this.storage.setItem(key, value);
}

removeItem(key: string): void {
this.storage.removeItem(key);
}
}

0 comments on commit 045e50b

Please sign in to comment.