Skip to content

Commit

Permalink
Merge pull request #166 from amolsontakke3576/feature/2351_clearbit_i…
Browse files Browse the repository at this point in the history
…ntegration

Clearbit Organization Name Validation
  • Loading branch information
dealako authored Dec 29, 2020
2 parents 5116c06 + a28cb38 commit 0e7730d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
9 changes: 9 additions & 0 deletions src/app/core/models/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ export class CompanyModel {
companyName: string;
companyWebsite: string;
logoURL: string;
}
export class ClearBitModel {
Employees: string;
ID: string;
Industry: string;
Link: string;
Name: string;
Sector: string;
Source: string;
}
7 changes: 6 additions & 1 deletion src/app/core/services/cla-contributor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { UpdateUserModel, UserModel } from '../models/user';
import { AlertService } from 'src/app/shared/services/alert.service';
import { ActiveSignatureModel } from '../models/active-signature';
import { IndividualRequestSignatureModel } from '../models/individual-request-signature';
import { CompanyModel, OrganizationListModel, OrganizationModel } from '../models/organization';
import { ClearBitModel, CompanyModel, OrganizationListModel, OrganizationModel } from '../models/organization';
import { EmployeeSignatureModel } from '../models/employee-signature';
import { InviteCompanyModel } from '../models/invite-company';
import { CLAManagersModel } from '../models/cla-manager';
Expand Down Expand Up @@ -72,6 +72,11 @@ export class ClaContributorService {
return this.httpClient.get<OrganizationListModel>(url);
}

getClearBitData(organizationWebsite: string): Observable<ClearBitModel> {
const url = this.v4BaseUrl + 'v4/company/lookup?websiteName=' + organizationWebsite;
return this.httpClient.get<ClearBitModel>(url);
}

hasOrganizationExist(organizationName: string, organizationWebsite: string): Observable<OrganizationListModel> {
let url = this.baseURL + 'v3/organization/search?';
if (organizationName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
</div>

<div class="col-10 element">
<input #organizationName type="text" name="companyName" placeholder="Enter Organization Name"
(input)="onNameKeypress()" (focusout)="onFocusOut()" formControlName="companyName" tabindex="2"
<input #organizationName type="text" name="companyName" placeholder="Organization Name"
(input)="onNameKeypress()" [readonly]="hasReadonly" formControlName="companyName" tabindex="2"
class="form-control" />
<ng-container *ngIf="searchType === 'ORGANIZATION_NAME'; then dropdownList;">
</ng-container>
Expand Down Expand Up @@ -159,4 +159,4 @@
</form>
</div>
</div>
</ng-template>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ClaContributorService } from 'src/app/core/services/cla-contributor.ser
import { StorageService } from 'src/app/shared/services/storage.service';
import { AppSettings } from 'src/app/config/app-settings';
import { UserModel } from 'src/app/core/models/user';
import { OrganizationListModel, Organization } from 'src/app/core/models/organization';
import { OrganizationListModel, Organization, ClearBitModel } from 'src/app/core/models/organization';

@Component({
selector: 'app-add-company-modal',
Expand All @@ -33,6 +33,7 @@ export class AddCompanyModalComponent implements OnInit {
searchType: string;
hasShowDropdown: boolean;
selectedOrganization: Organization;
hasReadonly: boolean;

constructor(
private formBuilder: FormBuilder,
Expand All @@ -49,6 +50,7 @@ export class AddCompanyModalComponent implements OnInit {
}

ngOnInit(): void {
this.hasReadonly = true;
this.form = this.formBuilder.group({
companyName: ['', Validators.compose([
Validators.required,
Expand Down Expand Up @@ -84,6 +86,7 @@ export class AddCompanyModalComponent implements OnInit {
}

onWebsiteKeypress() {
this.hasReadonly = true;
this.hasOrganizationExist = false;
this.searchType = 'ORGANIZATION_WEBSITE';
if (this.form.controls.companyWebsite.valid) {
Expand All @@ -94,7 +97,6 @@ export class AddCompanyModalComponent implements OnInit {
}

onNameKeypress() {
this.hasOrganizationExist = false;
this.searchType = 'ORGANIZATION_NAME';
if (this.form.controls.companyName.valid) {
this.checkOrganization();
Expand Down Expand Up @@ -125,6 +127,7 @@ export class AddCompanyModalComponent implements OnInit {
this.organizationList = response;
this.hasShowDropdown = true;
if (this.organizationList.list.length === 0) {
this.hasReadonly = false;
this.resetOrganizationList();
}
if (this.searchType === 'ORGANIZATION_NAME') {
Expand All @@ -149,7 +152,32 @@ export class AddCompanyModalComponent implements OnInit {
}

onFocusOut() {
this.hasShowDropdown = false;
setTimeout(() => {
this.hasShowDropdown = false;
this.getOrganizationNameByDomain();
}, 100);
}

getOrganizationNameByDomain() {
const domain = this.form.controls.companyWebsite.value;
this.claContributorService.getClearBitData(domain).subscribe(
(response: ClearBitModel) => {
this.hasOrganizationExist = false;
this.form.controls.companyName.setValue(response.Name);
this.selectedOrganization = new Organization;
if (response.ID) {
this.hasOrganizationExist = true;
}
this.selectedOrganization.organization_id = response.ID;
this.selectedOrganization.organization_name = response.Name;
this.selectedOrganization.organization_website = response.Link;
},
(exception) => {
this.hasReadonly = false;
this.form.controls.companyName.setValue('');
this.claContributorService.handleError(exception);
}
);
}

addOrganization() {
Expand Down Expand Up @@ -199,46 +227,12 @@ export class AddCompanyModalComponent implements OnInit {
// Skip success dialog and show CLA not sign dialog.

this.onClickDialogBtn();
// this.claContributorService.addCompany(userModel.user_id, data).subscribe(
// (response: CompanyModel) => {
// this.hasError = false;

// // change company model to organization model.
// this.selectedOrganization = {
// organization_id: response.companyID,
// organization_name: response.companyName,
// organization_website: response.companyWebsite
// };

// // Store newly added org in local storage for assiging company owner role.
// const newOrgData = {
// organizationId: response.companyID,
// createdBy: userModel.user_id,
// data: data
// };
// let newOrganizations: any[] = JSON.parse(this.storageService.getItem(AppSettings.NEW_ORGANIZATIONS));
// newOrganizations = newOrganizations === null ? [] : newOrganizations;
// newOrganizations.push(newOrgData);
// this.storageService.setItem(AppSettings.NEW_ORGANIZATIONS, newOrganizations);

// this.title = 'Successfully Added';
// this.message = 'Your organization has been successfully added to our data. Please proceed further to continue the process to add a CLA Manager.';
// this.openDialog(this.successModal);
// },
// (exception) => {
// this.hasError = true;
// this.title = 'Request Failed';
// this.message = exception.error.Message;
// this.openDialog(this.successModal);
// }
// );
}

onSelectOrganization(organization) {
this.hasOrganizationExist = true;
this.selectedOrganization = organization;
this.form.controls.companyName.setValue(organization.organization_name);
this.form.controls.companyWebsite.setValue(organization.organization_website);
this.form.controls.companyName.setValue(organization.organization_name);
this.organizationList = new OrganizationListModel;
}

Expand Down

0 comments on commit 0e7730d

Please sign in to comment.