Skip to content

Commit de775a3

Browse files
committed
fix(arc-saas): chages in add tenant
GH-64 GH-64
1 parent a0c90d8 commit de775a3

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

projects/arc-lib/src/lib/core/validators.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,11 @@ export function keyValidator(): ValidatorFn {
2222
};
2323
}
2424

25-
export function domainMatchValidator(
26-
emailControl: AbstractControl,
27-
domainControl: AbstractControl,
28-
): ValidatorFn {
29-
return (control: AbstractControl): ValidationErrors | null => {
30-
const emailValue = emailControl.value;
31-
const domainValue = domainControl.value;
3225

33-
if (!emailValue || !domainValue) {
34-
return null;
35-
}
3626

37-
const emailDomain = emailValue.split('@')[1];
38-
if (emailDomain !== domainValue) {
39-
return {domainMismatch: true};
40-
}
41-
42-
return null;
27+
export function domainMatchValidator(emailDomain: string): ValidatorFn {
28+
return (control: AbstractControl): {[key: string]: any} | null => {
29+
const domainValue = control.value;
30+
return domainValue === emailDomain ? null : { 'domainMismatch': true };
4331
};
4432
}

projects/saas-ui/src/app/main/components/tenant-registration/tenant-registration.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {Location} from '@angular/common';
1212
import {BillingPlanService, OnBoardingService} from '../../../shared/services';
1313
import {AnyObject} from '@project-lib/core/api/backend-filter';
1414
import {TenantLead} from '../../../shared/models/tenantLead.model';
15-
import {domainMatchValidator, keyValidator} from '@project-lib/core/validators';
15+
import { keyValidator} from '@project-lib/core/validators';
1616

1717
@Component({
1818
selector: 'app-tenant-registration',

projects/saas-ui/src/app/on-boarding/components/add-tenant/add-tenant.component.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {Location} from '@angular/common';
99
import {BillingPlanService} from '../../../shared/services/billing-plan-service';
1010
import {AnyObject} from '@project-lib/core/api';
1111
import {keyValidator} from '@project-lib/core/validators';
12+
import { Lead } from '../../../shared/models';
1213

1314
@Component({
1415
selector: 'app-add-tenant',
@@ -17,6 +18,7 @@ import {keyValidator} from '@project-lib/core/validators';
1718
})
1819
export class AddTenantComponent implements OnInit {
1920
[x: string]: any;
21+
leadData:Lead;
2022
addTenantForm: FormGroup;
2123
subscriptionPlans: AnyObject[];
2224
leadId = '';
@@ -40,6 +42,9 @@ export class AddTenantComponent implements OnInit {
4042
this.getRadioOptions();
4143
this.route.params.subscribe(params => {
4244
this.leadId = params['leadId'];
45+
if (this.leadId) {
46+
this.getLeadDataById(this.leadId);
47+
}
4348
});
4449
}
4550

@@ -51,6 +56,7 @@ export class AddTenantComponent implements OnInit {
5156
onSubmit() {
5257
if (this.addTenantForm.valid) {
5358
const domainData = this.addTenantForm.value;
59+
console.log(domainData);
5460
if (typeof domainData.domains === 'string') {
5561
domainData.domains = [domainData.domains];
5662
}
@@ -62,4 +68,27 @@ export class AddTenantComponent implements OnInit {
6268
});
6369
}
6470
}
71+
72+
getLeadDataById(leadId: string) {
73+
this.onboardingService.getLeadDetails(leadId).subscribe(
74+
(data:Lead) => {
75+
this.leadData = data;
76+
this.updateDomainFromEmail();
77+
console.log('Lead Data:', this.leadData);
78+
},
79+
error => {
80+
this.toastrService.danger('Failed to fetch lead data', 'Error');
81+
}
82+
);
83+
}
84+
85+
updateDomainFromEmail() {
86+
if (this.leadData && this.leadData.email) {
87+
const emailDomain = this.leadData.email?.substring(this.leadData.email.lastIndexOf('@') + 1);
88+
if (emailDomain) {
89+
this.addTenantForm.get('domains').setValue(emailDomain);
90+
}
91+
}
92+
}
6593
}
94+

0 commit comments

Comments
 (0)