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

[EP-2362] Save contact info after sign up #1130

Merged
merged 3 commits into from
Jan 14, 2025
Merged

Conversation

canac
Copy link
Contributor

@canac canac commented Jan 8, 2025

Changes

  • Replace the onStateChange binding with dedicated onSignUp and onSignIn bindings
  • After sign up, use the order service to save the donor details to the user's account. If saving fails, show the contact info form with the fields from sign up pre-populated.

I made this a PR instead of committing directly so it's easier for you to see what changed and see if I'm going in the right direction with this.

@canac canac requested a review from dr-bizz January 8, 2025 20:40
@canac canac self-assigned this Jan 8, 2025
Copy link
Contributor

@dr-bizz dr-bizz left a comment

Choose a reason for hiding this comment

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

It looks great! I have a few questions, but I don't want to block you so I will approve the PR.

@@ -1,4 +1,4 @@
<contact-info submitted="$ctrl.submitted" on-submit="$ctrl.onSubmit(success)"></contact-info>
<contact-info submitted="$ctrl.submitted" on-submit="$ctrl.onSubmit(success)" donor-details="$ctrl.signUpDonorDetails"></contact-info>
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is signUpDonorDetails defined? Were you also meant to commit changes to the contactInfoModal.component.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is set in checkDonorDetails if there was an error saving the donor details

src/common/components/signUpModal/signUpModal.component.js Outdated Show resolved Hide resolved
src/common/components/signUpModal/signUpModal.component.js Outdated Show resolved Hide resolved
@canac canac force-pushed the 2362-okta-save-contact-info branch from e146d50 to 5efb9d2 Compare January 9, 2025 19:31
@canac canac force-pushed the 2362-okta-save-contact-info branch from 5efb9d2 to 1227c65 Compare January 13, 2025 22:41
@canac
Copy link
Contributor Author

canac commented Jan 13, 2025

@dr-bizz Sorry for the force-push. I rebased on top of #1132, combined several fixup commits, and added the organization fields you added. I'll go through it myself more in tomorrow morning to see if I missed anything, but I'm pushing for you to take a look at too when you get a chance.

@canac canac requested a review from dr-bizz January 13, 2025 22:44
Copy link
Contributor

@dr-bizz dr-bizz left a comment

Choose a reason for hiding this comment

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

Great work with this! I only had comments, nothing bad, just some of my thoughts.

I've approved this to not delay you.

Comment on lines 137 to 158
this.getDonorDetailsSubscription = this.orderService.getDonorDetails().flatMap((donorDetails) => {
if (signUpDonorDetails && donorDetails['registration-state'] === 'NEW') {
// Save the contact info from signup
merge(donorDetails, signUpDonorDetails)

const requests = [this.orderService.updateDonorDetails(donorDetails)]
if (donorDetails.email) {
requests.push(this.orderService.addEmail(donorDetails.email, donorDetails.emailFormUri))
}

// Send each of the requests and pass donorDetails to the next step after the requests complete
return Observable.forkJoin(requests).map(() => donorDetails).do({
error: () => {
// If there was an error, save the donor details from sign up so that they will be added
// to the contact info form. The error handler below will change the step to contact-info.
this.signUpDonorDetails = signUpDonorDetails
}
})
}

// Pass donorDetails to the next step
return Observable.of(donorDetails)
}).subscribe({
Copy link
Contributor

Choose a reason for hiding this comment

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

Researching flatMap I came across switchMap which could bet better for us to use as it ensures the latest request is processed.

I haven't tried this so it might not work.

Suggested change
this.getDonorDetailsSubscription = this.orderService.getDonorDetails().flatMap((donorDetails) => {
if (signUpDonorDetails && donorDetails['registration-state'] === 'NEW') {
// Save the contact info from signup
merge(donorDetails, signUpDonorDetails)
const requests = [this.orderService.updateDonorDetails(donorDetails)]
if (donorDetails.email) {
requests.push(this.orderService.addEmail(donorDetails.email, donorDetails.emailFormUri))
}
// Send each of the requests and pass donorDetails to the next step after the requests complete
return Observable.forkJoin(requests).map(() => donorDetails).do({
error: () => {
// If there was an error, save the donor details from sign up so that they will be added
// to the contact info form. The error handler below will change the step to contact-info.
this.signUpDonorDetails = signUpDonorDetails
}
})
}
// Pass donorDetails to the next step
return Observable.of(donorDetails)
}).subscribe({
this.getDonorDetailsSubscription = this.orderService.getDonorDetails().switchMap((donorDetails) => {
if (signUpDonorDetails && donorDetails['registration-state'] === 'NEW') {
// Save the contact info from signup
merge(donorDetails, signUpDonorDetails)
const requests = [this.orderService.updateDonorDetails(donorDetails)]
if (donorDetails.email) {
requests.push(this.orderService.addEmail(donorDetails.email, donorDetails.emailFormUri))
}
// Send each of the requests and pass donorDetails to the next step after the requests complete
return Observable.forkJoin(requests).map(() => donorDetails).catch((error) => {
// If there was an error, save the donor details from sign up so that they will be added
// to the contact info form. The error handler below will change the step to contact-info.
this.signUpDonorDetails = signUpDonorDetails
return Observable.throw(error);
})
}
// Pass donorDetails to the next step
return Observable.of(donorDetails)
}).subscribe({

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None of the observables emit more than one item, so I don't think it matters, but I can switch it.

Why does your suggestion switch from do to catch? I was thinking that do was nice because you can pass through the same error without having to do return Observable.throw(error).

Copy link
Contributor

Choose a reason for hiding this comment

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

I switched do to catch as it was easier to read, but these changes are just suggestions based on preference.

You are correct, you don't need to write Observable.throw(error) if you write do

@canac canac force-pushed the 2362-okta-save-contact-info branch 3 times, most recently from e59b733 to db3f0d3 Compare January 14, 2025 19:57
@canac canac force-pushed the 2362-okta-save-contact-info branch from db3f0d3 to 2097ab2 Compare January 14, 2025 20:00
@canac canac merged commit 4475d67 into 2362-okta Jan 14, 2025
1 check passed
@canac canac deleted the 2362-okta-save-contact-info branch January 14, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants