Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added contact lookup to group e transaction screen #585

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,28 @@ export class ContactLookupComponent {
@Input() contactTypeInputId = 'entity_type';
@Input() contactTypeFormControl: FormControl = new FormControl();
@Input() contactTypeReadOnly = false;
@Input() contactTypeStyleClass = "";
@Input() contactTypeStyleClass = '';

@Input() maxFecCommitteeResults = 5;
@Input() maxFecfileCommitteeResults = 5;
@Input() maxFecfileIndividualResults = 10;
@Input() maxFecfileOrganizationResults = 10;

@Output() fecfileContactSelect =
new EventEmitter<SelectItem<Contact>>();
@Output() fecApiLookupSelect = new EventEmitter<
SelectItem<FecApiLookupData>>();
@Output() fecfileContactSelect = new EventEmitter<SelectItem<Contact>>();
@Output() fecApiLookupSelect = new EventEmitter<SelectItem<FecApiLookupData>>();

selectedContact: FormControl<SelectItem> | null = null;

contactLookupForm: FormGroup = this.formBuilder.group({
selectedContactType: this.contactTypeFormControl,
selectedContact: this.selectedContact
})
selectedContact: this.selectedContact,
});

contactLookupList: SelectItemGroup[] = [];

searchTerm = '';

constructor(
private formBuilder: FormBuilder,
private contactService: ContactService
) { }
constructor(private formBuilder: FormBuilder, private contactService: ContactService) {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
onDropdownSearch(event: any) {
Expand All @@ -50,25 +45,22 @@ export class ContactLookupComponent {
this.searchTerm = searchTerm;
switch (this.contactTypeFormControl.value) {
case ContactTypes.COMMITTEE:
this.contactService.committeeLookup(
searchTerm, this.maxFecCommitteeResults,
this.maxFecfileCommitteeResults).subscribe((response) => {
this.contactLookupList = response &&
response.toSelectItemGroups();
this.contactService
.committeeLookup(searchTerm, this.maxFecCommitteeResults, this.maxFecfileCommitteeResults)
.subscribe((response) => {
this.contactLookupList = response && response.toSelectItemGroups();
});
break;
case ContactTypes.INDIVIDUAL:
this.contactService.individualLookup(searchTerm,
this.maxFecfileIndividualResults).subscribe((response) => {
this.contactLookupList = response &&
response.toSelectItemGroups();
});
this.contactService.individualLookup(searchTerm, this.maxFecfileIndividualResults).subscribe((response) => {
this.contactLookupList = response && response.toSelectItemGroups();
});
break;
case ContactTypes.ORGANIZATION:
this.contactService.organizationLookup(searchTerm,
this.maxFecfileOrganizationResults).subscribe((response) => {
this.contactLookupList = response &&
response.toSelectItemGroups();
this.contactService
.organizationLookup(searchTerm, this.maxFecfileOrganizationResults)
.subscribe((response) => {
this.contactLookupList = response && response.toSelectItemGroups();
});
break;
}
Expand All @@ -85,11 +77,11 @@ export class ContactLookupComponent {
} else if (event.value instanceof FecApiLookupData) {
this.fecApiLookupSelect.emit(event);
}
this.contactLookupForm.patchValue({ selectedContact: '' });
}
}

isContact(value: Contact | FecApiLookupData) {
return value instanceof Contact;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export abstract class TransactionTypeBaseComponent implements OnInit, OnDestroy
protected validateService: ValidateService,
protected fb: FormBuilder,
protected router: Router
) { }
) {}

ngOnInit(): void {
// Intialize FormGroup, this must be done here. Not working when initialized only above the constructor().
Expand Down Expand Up @@ -174,6 +174,9 @@ export abstract class TransactionTypeBaseComponent implements OnInit, OnDestroy
this.form.get('contributor_occupation')?.setValue(value.occupation);
break;
case ContactTypes.COMMITTEE:
this.form.get('donor_committee_fec_id')?.setValue(value.committee_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

this.form.get('contributor_organization_name')?.setValue(value.name);
break;
case ContactTypes.ORGANIZATION:
this.form.get('contributor_organization_name')?.setValue(value.name);
break;
Expand All @@ -186,5 +189,4 @@ export abstract class TransactionTypeBaseComponent implements OnInit, OnDestroy
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ <h3>Contributor</h3>
<div class="col-6">
<div class="field">
<label for="entity_type">CONTRIBUTOR TYPE</label>
<p-dropdown
inputId="entity_type"
formControlName="entity_type"
[options]="contactTypeOptions"
optionLabel="name"
optionValue="code"
[readonly]="true"
styleClass="readonly"
></p-dropdown>
<app-contact-lookup
[contactTypeFormControl]="$any(form).controls['entity_type']"
[contactTypeOptions]="contactTypeOptions"
[contactTypeReadOnly]="true"
contactTypeStyleClass="readonly"
(fecfileContactSelect)="onContactLookupSelect($event)"
>
</app-contact-lookup>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ <h3>Contributor</h3>
<div class="col-6">
<div class="field">
<label for="entity_type">CONTRIBUTOR TYPE</label>
<app-contact-lookup
<app-contact-lookup
[contactTypeFormControl]="$any(form).controls['entity_type']"
[contactTypeOptions]="contactTypeOptions"
[contactTypeReadOnly]="true"
contactTypeStyleClass="readonly"
(fecfileContactSelect)="onContactLookupSelect($event)">
(fecfileContactSelect)="onContactLookupSelect($event)"
>
</app-contact-lookup>
</div>
</div>
Expand Down