WEB-648 refactor: replace magic numbers with LegalFormId enum (#3068)

This commit is contained in:
Shubham Kumar
2026-01-31 17:35:35 -06:00
committed by GitHub
parent b875408c86
commit cf7ced043c
8 changed files with 53 additions and 20 deletions
@@ -181,7 +181,7 @@
</div>
}
@if (createClientForm.value.legalFormId === 1) {
@if (createClientForm.value.legalFormId === LegalFormId.PERSON) {
<mat-form-field class="flex-48">
<mat-label>{{ 'labels.inputs.Gender' | translate }}</mat-label>
<mat-select formControlName="genderId">
@@ -205,7 +205,7 @@
</mat-select>
</mat-form-field>
@if (createClientForm.value.legalFormId === 1) {
@if (createClientForm.value.legalFormId === LegalFormId.PERSON) {
<mat-checkbox class="flex-48 margin-v" labelPosition="before" formControlName="isStaff">
{{ 'labels.inputs.Is staff' | translate }}?
</mat-checkbox>
@@ -19,6 +19,7 @@ import { Subject } from 'rxjs';
import { filter, switchMap, takeUntil } from 'rxjs/operators';
import { ClientsService } from 'app/clients/clients.service';
import { Dates } from 'app/core/utils/dates';
import { LegalFormId } from 'app/clients/models/legal-form.enum';
/** Custom Services */
import { SettingsService } from 'app/settings/settings.service';
@@ -57,6 +58,9 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
@Output() legalFormChangeEvent = new EventEmitter<{ legalForm: number }>();
/** Expose enum to template */
readonly LegalFormId = LegalFormId;
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
@@ -161,7 +165,7 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
.valueChanges.pipe(takeUntil(this.destroy$))
.subscribe((legalFormId: number) => {
this.legalFormChangeEvent.emit({ legalForm: legalFormId });
if (legalFormId === 1) {
if (legalFormId === LegalFormId.PERSON) {
this.createClientForm.removeControl('fullname');
this.createClientForm.removeControl('clientNonPersonDetails');
this.createClientForm.addControl(
@@ -205,7 +209,7 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
);
}
});
this.createClientForm.get('legalFormId').patchValue(1);
this.createClientForm.get('legalFormId').patchValue(LegalFormId.PERSON);
this.createClientForm
.get('active')
.valueChanges.pipe(takeUntil(this.destroy$))
@@ -244,7 +248,7 @@ export class ClientGeneralStepComponent implements OnInit, OnDestroy {
}
getDateLabel(legalFormId: number, values: string[]): string {
return legalFormId === 1 ? values[0] : values[1];
return legalFormId === LegalFormId.PERSON ? values[0] : values[1];
}
/**
@@ -13,10 +13,10 @@
<div class="flex-fill">
<span class="flex-40">{{ 'labels.inputs.name' | translate }}</span>
@if (client.legalFormId === 2) {
@if (client.legalFormId === LegalFormId.ENTITY) {
<span class="flex-60">{{ client.fullname }}</span>
}
@if (client.legalFormId === 1) {
@if (client.legalFormId === LegalFormId.PERSON) {
<span class="flex-60"
>{{ client.firstname }}
{{ client.middlename ? client.middlename + ' ' + client.lastname : client.lastname }}</span
@@ -43,7 +43,9 @@
@if (client.dateOfBirth) {
<div class="flex-fill">
<span class="flex-40">{{ client.legalFormId === 1 ? 'Date of Birth' : 'Incorporation Date' }}</span>
<span class="flex-40">{{
client.legalFormId === LegalFormId.PERSON ? 'Date of Birth' : 'Incorporation Date'
}}</span>
<span class="flex-60">{{ client.dateOfBirth | dateFormat }}</span>
</div>
}
@@ -115,7 +117,7 @@
</div>
}
@if (client.legalFormId === 1) {
@if (client.legalFormId === LegalFormId.PERSON) {
@if (client.genderId) {
<div class="flex-fill">
<span class="flex-40">{{ 'labels.inputs.Gender' | translate }}</span>
@@ -128,7 +130,7 @@
</div>
}
@if (client.legalFormId === 2) {
@if (client.legalFormId === LegalFormId.ENTITY) {
@if (client.clientNonPersonDetails.incorpValidityTillDate) {
<div class="flex-fill">
<span class="flex-40">{{ 'labels.inputs.Incorporation Validity Till Date' | translate }}</span>
@@ -23,6 +23,7 @@ import { FindPipe } from '../../../pipes/find.pipe';
import { DateFormatPipe } from '../../../pipes/date-format.pipe';
import { YesnoPipe } from '../../../pipes/yesno.pipe';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
import { LegalFormId } from 'app/clients/models/legal-form.enum';
/**
* Client Preview Step Component
@@ -58,6 +59,9 @@ export class ClientPreviewStepComponent {
/** Form submission event */
@Output() submitEvent = new EventEmitter();
/** Expose enum to template */
readonly LegalFormId = LegalFormId;
constructor() {}
/**