Skip to content

Commit

Permalink
Send full form values to email signup endpoint (#191)
Browse files Browse the repository at this point in the history
## Test Plan

Submit the form with an email filled out; look at network inspector to
make sure the new param is included and reflects the form value.
  • Loading branch information
oyamauchi authored Oct 29, 2024
1 parent 5fddf51 commit 570e63f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/email-signup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { safeLocalStorage } from './safe-local-storage';
import { FormValues } from './state-calculator-form';

const LOCAL_STORAGE_KEY = 'RA-calc-email-submitted';

Expand All @@ -15,8 +16,7 @@ export function wasEmailSubmitted(): boolean {
export async function submitEmailSignup(
apiHost: string,
apiKey: string,
email: string,
zip: string,
formValues: FormValues,
emailRequired: boolean,
): Promise<boolean> {
safeLocalStorage.setItem(LOCAL_STORAGE_KEY, true);
Expand All @@ -27,7 +27,7 @@ export async function submitEmailSignup(

const response = await fetch(url, {
method: 'POST',
body: JSON.stringify({ email, zip, emailRequired }),
body: JSON.stringify({ ...formValues, emailRequired }),
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
Expand Down
5 changes: 2 additions & 3 deletions src/state-calculator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ const StateCalculator: FC<{
const submit = (formValues: FormValues) => {
safeLocalStorage.setItem(FORM_VALUES_LOCAL_STORAGE_KEY, formValues);

const email = formValues.email;
if (email && !emailSubmitted) {
submitEmailSignup(apiHost, apiKey, email, formValues.zip, emailRequired);
if (formValues.email && !emailSubmitted) {
submitEmailSignup(apiHost, apiKey, formValues, emailRequired);
// This hides the email field
setEmailSubmitted(true);
}
Expand Down

0 comments on commit 570e63f

Please sign in to comment.