Skip to content

Commit 6b446c2

Browse files
Merge pull request #3633 from alberto-art3ch/WEB-954/migrate-subscription-management-savings-clients
WEB-954: Migrate Subscription management : clients and savings
2 parents bb13ed6 + 80ccc8e commit 6b446c2

72 files changed

Lines changed: 743 additions & 635 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
*/
88

99
import { ChangeDetectionStrategy, Component, Input, OnInit, inject } from '@angular/core';
10-
import {
11-
UntypedFormBuilder,
12-
UntypedFormControl,
13-
UntypedFormGroup,
14-
Validators,
15-
ReactiveFormsModule
16-
} from '@angular/forms';
10+
import { FormBuilder, FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
1711
import { Datatables } from 'app/core/utils/datatables';
1812
import { SettingsService } from 'app/settings/settings.service';
1913
import { MatCheckbox } from '@angular/material/checkbox';
@@ -35,14 +29,14 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
3529
changeDetection: ChangeDetectionStrategy.OnPush
3630
})
3731
export class ClientDatatableStepComponent implements OnInit {
38-
private formBuilder = inject(UntypedFormBuilder);
32+
private formBuilder = inject(FormBuilder);
3933
private settingsService = inject(SettingsService);
4034
private datatableService = inject(Datatables);
4135

4236
/** Input Fields Data */
4337
@Input() datatableData: any;
4438
/** Create Input Form */
45-
datatableForm: UntypedFormGroup;
39+
datatableForm: FormGroup;
4640

4741
datatableInputs: any = [];
4842

@@ -53,12 +47,12 @@ export class ClientDatatableStepComponent implements OnInit {
5347
input.controlName = this.getInputName(input);
5448
if (!input.isColumnNullable) {
5549
if (this.isNumeric(input.columnDisplayType)) {
56-
inputItems[input.controlName] = new UntypedFormControl(0, [Validators.required]);
50+
inputItems[input.controlName] = new FormControl(0, [Validators.required]);
5751
} else {
58-
inputItems[input.controlName] = new UntypedFormControl('', [Validators.required]);
52+
inputItems[input.controlName] = new FormControl('', [Validators.required]);
5953
}
6054
} else {
61-
inputItems[input.controlName] = new UntypedFormControl('');
55+
inputItems[input.controlName] = new FormControl('');
6256
}
6357
});
6458
this.datatableForm = this.formBuilder.group(inputItems);

src/app/clients/client-stepper/client-family-members-step/client-family-member-dialog/client-family-member-dialog.component.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
*/
88

99
/** Angular Imports */
10-
import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
10+
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
11+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1112
import {
1213
MatDialogRef,
1314
MAT_DIALOG_DATA,
1415
MatDialogTitle,
1516
MatDialogActions,
1617
MatDialogClose
1718
} from '@angular/material/dialog';
18-
import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
19+
import { FormGroup, FormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
1920

2021
/** Custom Services */
2122
import { SettingsService } from 'app/settings/settings.service';
@@ -41,16 +42,17 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
4142
})
4243
export class ClientFamilyMemberDialogComponent implements OnInit {
4344
dialogRef = inject<MatDialogRef<ClientFamilyMemberDialogComponent>>(MatDialogRef);
44-
private formBuilder = inject(UntypedFormBuilder);
45+
private formBuilder = inject(FormBuilder);
4546
private dateUtils = inject(Dates);
4647
data = inject(MAT_DIALOG_DATA);
4748
private settingsService = inject(SettingsService);
49+
private destroyRef = inject(DestroyRef);
4850

4951
/** Maximum Due Date allowed. */
5052
maxDate = new Date();
5153

5254
/** Add/Edit family member form. */
53-
familyMemberForm: UntypedFormGroup;
55+
familyMemberForm: FormGroup;
5456

5557
ngOnInit() {
5658
this.maxDate = this.settingsService.businessDate;
@@ -72,14 +74,17 @@ export class ClientFamilyMemberDialogComponent implements OnInit {
7274
}
7375

7476
// Add subscription to date of birth changes to update age
75-
this.familyMemberForm.get('dateOfBirth').valueChanges.subscribe((dateOfBirth: any) => {
76-
if (dateOfBirth) {
77-
const age = this.calculateAge(dateOfBirth);
78-
this.familyMemberForm.get('age').setValue(age);
79-
} else {
80-
this.familyMemberForm.get('age').setValue('');
81-
}
82-
});
77+
this.familyMemberForm
78+
.get('dateOfBirth')
79+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
80+
.subscribe((dateOfBirth: any) => {
81+
if (dateOfBirth) {
82+
const age = this.calculateAge(dateOfBirth);
83+
this.familyMemberForm.get('age').setValue(age);
84+
} else {
85+
this.familyMemberForm.get('age').setValue('');
86+
}
87+
});
8388

8489
// If a date of birth is already set, calculate the age
8590
const currentDob = this.familyMemberForm.get('dateOfBirth').value;

src/app/clients/client-stepper/client-general-step/client-general-step.component.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,16 @@
1010
import {
1111
ChangeDetectionStrategy,
1212
Component,
13-
OnInit,
14-
OnDestroy,
13+
DestroyRef,
14+
EventEmitter,
1515
Input,
16+
OnInit,
1617
Output,
17-
EventEmitter,
1818
inject
1919
} from '@angular/core';
20-
import {
21-
UntypedFormBuilder,
22-
UntypedFormGroup,
23-
Validators,
24-
UntypedFormControl,
25-
ReactiveFormsModule
26-
} from '@angular/forms';
27-
import { Subject } from 'rxjs';
28-
import { filter, switchMap, takeUntil } from 'rxjs/operators';
20+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
21+
import { FormBuilder, FormGroup, Validators, FormControl, ReactiveFormsModule } from '@angular/forms';
22+
import { filter, switchMap } from 'rxjs/operators';
2923
import { ClientsService } from 'app/clients/clients.service';
3024
import { Dates } from 'app/core/utils/dates';
3125
import { LegalFormId } from 'app/clients/models/legal-form.enum';
@@ -59,15 +53,13 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
5953
],
6054
changeDetection: ChangeDetectionStrategy.OnPush
6155
})
62-
export class ClientGeneralStepComponent implements OnInit, OnDestroy {
63-
private formBuilder = inject(UntypedFormBuilder);
56+
export class ClientGeneralStepComponent implements OnInit {
57+
private formBuilder = inject(FormBuilder);
6458
private dateUtils = inject(Dates);
6559
private settingsService = inject(SettingsService);
6660
private clientService = inject(ClientsService);
6761
externalNationalIdService = inject(ExternalNationalIdService);
68-
69-
/** Subject to trigger unsubscription on destroy */
70-
private destroy$ = new Subject<void>();
62+
private destroyRef = inject(DestroyRef);
7163

7264
@Output() legalFormChangeEvent = new EventEmitter<{ legalForm: number }>();
7365

@@ -82,7 +74,7 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
8274
/** Client Template */
8375
@Input() clientTemplate: any;
8476
/** Create Client Form */
85-
createClientForm: UntypedFormGroup;
77+
createClientForm: FormGroup;
8678

8779
/** Office Options */
8880
officeOptions: any;
@@ -176,23 +168,23 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
176168
buildDependencies() {
177169
this.createClientForm
178170
.get('legalFormId')
179-
.valueChanges.pipe(takeUntil(this.destroy$))
171+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
180172
.subscribe((legalFormId: number) => {
181173
this.legalFormChangeEvent.emit({ legalForm: legalFormId });
182174
if (legalFormId === LegalFormId.PERSON) {
183175
this.createClientForm.removeControl('fullname');
184176
this.createClientForm.removeControl('clientNonPersonDetails');
185177
this.createClientForm.addControl(
186178
'firstname',
187-
new UntypedFormControl('', [
179+
new FormControl('', [
188180
Validators.required,
189181
Validators.pattern('(^[A-z]).*')
190182
])
191183
);
192-
this.createClientForm.addControl('middlename', new UntypedFormControl('', Validators.pattern('(^[A-z]).*')));
184+
this.createClientForm.addControl('middlename', new FormControl('', Validators.pattern('(^[A-z]).*')));
193185
this.createClientForm.addControl(
194186
'lastname',
195-
new UntypedFormControl('', [
187+
new FormControl('', [
196188
Validators.required,
197189
Validators.pattern('(^[A-z]).*')
198190
])
@@ -203,7 +195,7 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
203195
this.createClientForm.removeControl('lastname');
204196
this.createClientForm.addControl(
205197
'fullname',
206-
new UntypedFormControl('', [
198+
new FormControl('', [
207199
Validators.required,
208200
Validators.pattern('(^[A-z]).*')
209201
])
@@ -226,20 +218,20 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
226218
this.createClientForm.get('legalFormId').patchValue(LegalFormId.PERSON);
227219
this.createClientForm
228220
.get('active')
229-
.valueChanges.pipe(takeUntil(this.destroy$))
221+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
230222
.subscribe((active: boolean) => {
231223
if (active) {
232-
this.createClientForm.addControl('activationDate', new UntypedFormControl('', Validators.required));
224+
this.createClientForm.addControl('activationDate', new FormControl('', Validators.required));
233225
} else {
234226
this.createClientForm.removeControl('activationDate');
235227
}
236228
});
237229
this.createClientForm
238230
.get('addSavings')
239-
.valueChanges.pipe(takeUntil(this.destroy$))
231+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
240232
.subscribe((active: boolean) => {
241233
if (active) {
242-
this.createClientForm.addControl('savingsProductId', new UntypedFormControl('', Validators.required));
234+
this.createClientForm.addControl('savingsProductId', new FormControl('', Validators.required));
243235
} else {
244236
this.createClientForm.removeControl('savingsProductId');
245237
}
@@ -249,18 +241,13 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
249241
.valueChanges.pipe(
250242
filter((officeId: number) => !!officeId),
251243
switchMap((officeId: number) => this.clientService.getClientWithOfficeTemplate(officeId)),
252-
takeUntil(this.destroy$)
244+
takeUntilDestroyed(this.destroyRef)
253245
)
254246
.subscribe((clientTemplate: any) => {
255247
this.staffOptions = clientTemplate.staffOptions;
256248
});
257249
}
258250

259-
ngOnDestroy() {
260-
this.destroy$.next();
261-
this.destroy$.complete();
262-
}
263-
264251
getDateLabel(legalFormId: number, values: string[]): string {
265252
return legalFormId === LegalFormId.PERSON ? values[0] : values[1];
266253
}

src/app/clients/clients-view/address-tab/address-tab.component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88

99
/** Angular Imports */
10-
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
10+
import { ChangeDetectionStrategy, Component, DestroyRef, inject } from '@angular/core';
11+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1112
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
12-
import { UntypedFormGroup } from '@angular/forms';
13+
import { FormGroup } from '@angular/forms';
1314
import { ActivatedRoute } from '@angular/router';
1415
import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base';
1516
import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base';
@@ -65,6 +66,7 @@ export class AddressTabComponent {
6566
private dialog = inject(MatDialog);
6667
private translateService = inject(TranslateService);
6768
private postalCodeLookup = inject(PostalCodeLookupService);
69+
private destroyRef = inject(DestroyRef);
6870

6971
/** Client Address Data */
7072
clientAddressData: any;
@@ -82,14 +84,14 @@ export class AddressTabComponent {
8284
* @param {TranslateService} translateService Translate Service.
8385
*/
8486
constructor() {
85-
this.route.data.subscribe(
86-
(data: { clientAddressData: any; clientAddressFieldConfig: any; clientAddressTemplateData: any }) => {
87+
this.route.data
88+
.pipe(takeUntilDestroyed(this.destroyRef))
89+
.subscribe((data: { clientAddressData: any; clientAddressFieldConfig: any; clientAddressTemplateData: any }) => {
8790
this.clientAddressData = data.clientAddressData;
8891
this.clientAddressFieldConfig = data.clientAddressFieldConfig;
8992
this.clientAddressTemplate = data.clientAddressTemplateData;
9093
this.clientId = this.route.parent.snapshot.paramMap.get('clientId');
91-
}
92-
);
94+
});
9395
}
9496

9597
/**
@@ -170,7 +172,7 @@ export class AddressTabComponent {
170172
let postalSub: Subscription;
171173

172174
dialogRef.afterOpened().subscribe(() => {
173-
const form: UntypedFormGroup = dialogRef.componentInstance.form;
175+
const form: FormGroup = dialogRef.componentInstance.form;
174176
const postalCodeControl = form.get('postalCode');
175177
if (!postalCodeControl) return;
176178

@@ -226,7 +228,7 @@ export class AddressTabComponent {
226228
/**
227229
* Gets the ISO country code for the currently selected country in the form.
228230
*/
229-
private getSelectedCountryCode(form: UntypedFormGroup): string | null {
231+
private getSelectedCountryCode(form: FormGroup): string | null {
230232
const countryIdValue = form.get('countryId')?.value;
231233
if (!countryIdValue) return null;
232234

@@ -245,7 +247,7 @@ export class AddressTabComponent {
245247
* Clears form fields that were previously set by auto-fill,
246248
* so stale data doesn't persist when a new lookup fails or returns different results.
247249
*/
248-
private clearAutoFilledFields(form: UntypedFormGroup) {
250+
private clearAutoFilledFields(form: FormGroup) {
249251
for (const fieldName of this.autoFilledFields) {
250252
const control = form.get(fieldName);
251253
if (control) {
@@ -256,7 +258,7 @@ export class AddressTabComponent {
256258
this.autoFilledFields.clear();
257259
}
258260

259-
private applyResolvedAddress(form: UntypedFormGroup, address: ResolvedAddress) {
261+
private applyResolvedAddress(form: FormGroup, address: ResolvedAddress) {
260262
const cityControl = form.get('city');
261263
if (cityControl && address.city) {
262264
cityControl.setValue(address.city);

src/app/clients/clients-view/charges/charges-overview/charges-overview.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*/
88

99
/** Angular Imports */
10-
import { ChangeDetectionStrategy, Component, OnInit, ViewChild, inject } from '@angular/core';
10+
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, ViewChild, inject } from '@angular/core';
11+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1112
import { MatDialog } from '@angular/material/dialog';
1213
import { MatPaginator } from '@angular/material/paginator';
1314
import {
@@ -58,6 +59,7 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
5859
export class ChargesOverviewComponent implements OnInit {
5960
private route = inject(ActivatedRoute);
6061
dialog = inject(MatDialog);
62+
private destroyRef = inject(DestroyRef);
6163

6264
/** Columns to be displayed in charge overview table. */
6365
displayedColumns: string[] = [
@@ -82,7 +84,7 @@ export class ChargesOverviewComponent implements OnInit {
8284
* @param {MatDialog} dialog Dialog reference.
8385
*/
8486
constructor() {
85-
this.route.data.subscribe((data: { clientChargesData: any }) => {
87+
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { clientChargesData: any }) => {
8688
this.chargeOverviewData = data.clientChargesData;
8789
});
8890
}

src/app/clients/clients-view/charges/client-pay-charges/client-pay-charges.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
*/
88

99
/** Angular Imports */
10-
import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
11-
import { UntypedFormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
10+
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
11+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
12+
import { FormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
1213
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
1314

1415
/** Custom Services. */
@@ -31,11 +32,12 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
3132
})
3233
export class ClientPayChargesComponent implements OnInit {
3334
private clientsService = inject(ClientsService);
34-
private formBuilder = inject(UntypedFormBuilder);
35+
private formBuilder = inject(FormBuilder);
3536
private route = inject(ActivatedRoute);
3637
private router = inject(Router);
3738
private dateUtils = inject(Dates);
3839
private settingsService = inject(SettingsService);
40+
private destroyRef = inject(DestroyRef);
3941

4042
/** Transaction Form. */
4143
transactionForm: any;
@@ -53,7 +55,7 @@ export class ClientPayChargesComponent implements OnInit {
5355
* @param {SettingsService} settingsService Setting service
5456
*/
5557
constructor() {
56-
this.route.data.subscribe((data: { transactionData: any }) => {
58+
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { transactionData: any }) => {
5759
this.transactionData = data.transactionData;
5860
});
5961
}

0 commit comments

Comments
 (0)