From bf6604e3d4c050a82f0b479470f6cc0c796babbb Mon Sep 17 00:00:00 2001 From: aswanson-nr Date: Wed, 29 Sep 2021 16:11:06 -0700 Subject: [PATCH] fix: link directly to nr1 instead of login page --- src/components/InstallButton.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/InstallButton.js b/src/components/InstallButton.js index 5c67260d2..aa0942882 100644 --- a/src/components/InstallButton.js +++ b/src/components/InstallButton.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { css } from '@emotion/react'; import { Button, Link, Icon } from '@newrelic/gatsby-theme-newrelic'; @@ -7,7 +7,6 @@ import { getGuidedInstallStackedNr1Url, } from '../utils/get-pack-nr1-url'; import { - NR1_LOGIN_URL, NR1_GUIDED_INSTALL_NERDLET, NR1_PACK_DETAILS_NERDLET, UTM_PARAMETERS, @@ -52,14 +51,16 @@ const createInstallLink = ( ? getGuidedInstallStackedNr1Url(nerdletId) : getPackNr1Url(id, nerdletId); - const installUrl = new URL(hasUtmParameters ? NR1_SIGNUP_URL : NR1_LOGIN_URL); + const installUrl = new URL(hasUtmParameters ? NR1_SIGNUP_URL : platformUrl); if (parameters) { parameters.forEach((value, key) => { installUrl.searchParams.set(key, value); }); } - installUrl.searchParams.set('return_to', platformUrl); + if (hasUtmParameters) { + installUrl.searchParams.set('return_to', platformUrl); + } return installUrl.href; }; @@ -74,7 +75,12 @@ const hasComponent = (quickstart, key) => const InstallButton = ({ quickstart, location, ...props }) => { const hasInstallableComponent = hasComponent(quickstart, 'installPlans'); - const parameters = location.search && new URLSearchParams(location.search); + const [parameters, setParameters] = useState(); + useEffect(() => { + if (location.search) { + setParameters(new URLSearchParams(location.search)); + } + }, [location.search, setParameters]); const hasGuidedInstall = hasInstallableComponent &&