Skip to content

Commit

Permalink
removed logging and reorganised fetching countries
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcaprice committed Jun 12, 2024
1 parent 38dcdb3 commit 4b59766
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions ui/src/app/home/member-info/member-info-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,43 +65,36 @@ export class MemberInfoEditComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
console.log('getting countries')

this.memberService
.getCountries()
.pipe(take(1))
.subscribe((countries) => {
this.countries = countries
combineLatest([this.activatedRoute.params, this.accountService.getAccountData()])
.pipe(
switchMap(([params, account]) => {
if (params['id']) {
this.managedMember = params['id']
}
if (account) {
this.account = account
if (this.managedMember) {
this.memberService.setManagedMember(params['id'])
return this.memberService.getMemberData(this.managedMember)
} else {
return this.memberService.getMemberData(account?.salesforceId)
}
} else {
return EMPTY
}
}),
takeUntil(this.destroy$)
)
.subscribe((data) => {
this.memberData = data
this.orgIdsTransformed = Object.entries(this.memberData?.orgIds || {}).flatMap(([name, ids]) =>
ids.map((id: string) => ({ id, name }))
)
this.validateUrl()
if (data) {
this.updateForm(data)
combineLatest([this.activatedRoute.params, this.accountService.getAccountData(), this.memberService.getCountries()])
.pipe(
switchMap(([params, account, countries]) => {
this.countries = countries
if (params['id']) {
this.managedMember = params['id']
}
if (account) {
this.account = account
if (this.managedMember) {
this.memberService.setManagedMember(params['id'])
return this.memberService.getMemberData(this.managedMember)
} else {
return this.memberService.getMemberData(account?.salesforceId)
}
})
} else {
return EMPTY
}
}),
takeUntil(this.destroy$)
)
.subscribe((data) => {
this.memberData = data
this.orgIdsTransformed = Object.entries(this.memberData?.orgIds || {}).flatMap(([name, ids]) =>
ids.map((id: string) => ({ id, name }))
)
this.validateUrl()
if (data) {
this.updateForm(data)
}
})

this.editForm.valueChanges.subscribe(() => {
Expand All @@ -118,8 +111,6 @@ export class MemberInfoEditComponent implements OnInit, OnDestroy {
}

updateForm(data: ISFMemberData) {
console.log('updating form: billing address is ', data.billingAddress)

if (data && data.id) {
this.editForm.patchValue({
orgName: data.name || null,
Expand All @@ -130,14 +121,9 @@ export class MemberInfoEditComponent implements OnInit, OnDestroy {
email: data.publicDisplayEmail,
})
if (data.billingAddress) {
console.log('this.countries is ', this.countries)

if (this.countries) {
this.country = this.countries.find((country) => country.name === data.billingAddress?.country)
console.log('chosen as currently selected country', this.country)
if (this.country) {
console.log('setting states to ', this.country.states)

this.states = this.country.states
} else {
console.error('Unable to find country: ', data.billingAddress.country)
Expand Down

0 comments on commit 4b59766

Please sign in to comment.