Implement a feature where users who identify as e-commerce sellers ("Yes" to the relevant question) are immediately redirected to https://app.onrampfunds.com/smb-signup with specific form values appended as URL parameters. Users selecting "No" should proceed with the standard form flow.
-
Code Organization:
- Create a new directory
src/for source JavaScript files if it doesn't exist. - Create a new file
src/ecommerce-redirect.jsto contain the logic specifically for handling the e-commerce seller redirect. - Keep existing form logic (HubSpot integration, general validation, multi-step handling) in
ms-form-route.js(potentially move it tosrc/ms-form-route.jsfor consistency). - Update the
esbuildcommand inpackage.jsonto bundle the necessary files (e.g.,src/ecommerce-redirect.jsandsrc/ms-form-route.jsor a main entry point that imports them) into the single output filedist/ms-form-route.js.
- Create a new directory
-
Identify Key HTML Elements:
- Locate the form (
id="wf-form-SMB"inindex.html). - Identify the input/select elements for:
- E-commerce seller question (
id="Are-you-an-ecommerce-seller") - Funding amount (
id="Funding-Amount") - Average monthly sales (
id="Revenue-per-month") - Funding reason (
id="Use-of-funds")
- E-commerce seller question (
- Locate the form (
-
Implement Redirect Logic (in
src/ecommerce-redirect.js):- Add a
DOMContentLoadedevent listener (or export an initialization function). - Get references to the identified HTML elements.
- Add helper functions:
cleanDollarValue(inputElement): To parse and validate dollar amount inputs, removing '$' and ',', ensuring the value is a positive integer. Returns the number ornull.getMappedFundingReason(selectElement): To map the selected funding reason ("Inventory", "Marketing", "Other Business Expense") to the required lowercase parameter values ("inventory", "marketing", "other"). Returns the mapped value ornull.
- Attach a
changeevent listener to theAre-you-an-ecommerce-sellerselect element. - Inside the
changelistener:- Check if the selected value is "Yes".
- If "Yes":
- Call helper functions to get cleaned/validated
fundingAmount,avgMonthlySales, andfundingReason. - Create a
URLSearchParamsobject. - Append
marketing_survey_upsert_survey_form[online_merchant]=true. - Conditionally append
marketing_survey_upsert_survey_form[funding_amount],marketing_survey_upsert_survey_form[average_monthly_sales], andmarketing_survey_upsert_survey_form[funding_reason]only if their corresponding cleaned/mapped values are notnull. - Construct the final redirect URL:
https://app.onrampfunds.com/smb-signup?${params.toString()}. - Trigger the redirect using
window.location.href.
- Call helper functions to get cleaned/validated
- If "No": Allow the form to proceed with its default multi-step/submission behavior (handled by
ms-form-route.js).
- Add a
-
Refactor
ms-form-route.js(Optional but Recommended):- Ensure the existing code in
ms-form-route.jsdoesn't conflict with the redirect logic (e.g., prevent HubSpot submission if a redirect occurs). - Consider moving this file to
src/ms-form-route.js.
- Ensure the existing code in
-
Update Build Process (
package.json):- Modify the
scripts.buildandscripts.build:prodcommands to correctly bundle the JavaScript files from thesrc/directory intodist/ms-form-route.js.
- Modify the
-
Testing:
- Test the "Yes" path: Fill relevant fields, select "Yes", verify redirect URL and parameters.
- Test the "No" path: Select "No", verify the form proceeds through its steps and submits normally.
- Test edge cases: Select "Yes" with invalid/missing amounts, empty funding reason, etc.
The redirect URL should follow this structure:
https://app.onrampfunds.com/smb-signup?marketing_survey_upsert_survey_form[parameter_name]=value&...
online_merchant:true(required for redirect)funding_amount: Integer > 0 (optional, appended if valid)average_monthly_sales: Integer > 0 (optional, appended if valid)funding_reason: "inventory", "marketing", or "other" (optional, appended if validly selected and mapped)