From 36bc0fe946d061ff8d50dcd5a24676f97929fe5e Mon Sep 17 00:00:00 2001 From: Raquel Smith Date: Mon, 2 Oct 2023 14:33:15 -0700 Subject: [PATCH] fix: redirect properly after complete onboarding (#17724) fix redirecting after complete onboarding --- .../OnboardingOtherProductsStep.tsx | 6 +--- .../src/scenes/onboarding/onboardingLogic.tsx | 28 +++++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/frontend/src/scenes/onboarding/OnboardingOtherProductsStep.tsx b/frontend/src/scenes/onboarding/OnboardingOtherProductsStep.tsx index 56102c51a7646..49e7c1fdde7c3 100644 --- a/frontend/src/scenes/onboarding/OnboardingOtherProductsStep.tsx +++ b/frontend/src/scenes/onboarding/OnboardingOtherProductsStep.tsx @@ -2,7 +2,6 @@ import { LemonButton, LemonCard } from '@posthog/lemon-ui' import { OnboardingStep } from './OnboardingStep' import { onboardingLogic } from './onboardingLogic' import { useActions, useValues } from 'kea' -import { urls } from 'scenes/urls' export const OnboardingOtherProductsStep = (): JSX.Element => { const { product, suggestedProducts } = useValues(onboardingLogic) @@ -39,10 +38,7 @@ export const OnboardingOtherProductsStep = (): JSX.Element => {
- completeOnboarding(urls.onboarding(suggestedProduct.type))} - > + completeOnboarding(suggestedProduct.type)}> Get started
diff --git a/frontend/src/scenes/onboarding/onboardingLogic.tsx b/frontend/src/scenes/onboarding/onboardingLogic.tsx index 5899e10ac4308..2e980cf9f3574 100644 --- a/frontend/src/scenes/onboarding/onboardingLogic.tsx +++ b/frontend/src/scenes/onboarding/onboardingLogic.tsx @@ -2,12 +2,13 @@ import { kea } from 'kea' import { BillingProductV2Type, ProductKey } from '~/types' import { urls } from 'scenes/urls' -import type { onboardingLogicType } from './onboardingLogicType' import { billingLogic } from 'scenes/billing/billingLogic' import { teamLogic } from 'scenes/teamLogic' -import { combineUrl } from 'kea-router' +import { combineUrl, router } from 'kea-router' import { eventUsageLogic } from 'lib/utils/eventUsageLogic' +import type { onboardingLogicType } from './onboardingLogicType' + export interface OnboardingLogicProps { productKey: ProductKey | null } @@ -50,13 +51,13 @@ export const onboardingLogic = kea({ path: ['scenes', 'onboarding', 'onboardingLogic'], connect: { values: [billingLogic, ['billing'], teamLogic, ['currentTeam']], - actions: [billingLogic, ['loadBillingSuccess'], teamLogic, ['updateCurrentTeam']], + actions: [billingLogic, ['loadBillingSuccess'], teamLogic, ['updateCurrentTeamSuccess']], }, actions: { setProduct: (product: BillingProductV2Type | null) => ({ product }), setProductKey: (productKey: string | null) => ({ productKey }), setCurrentOnboardingStepNumber: (currentOnboardingStepNumber: number) => ({ currentOnboardingStepNumber }), - completeOnboarding: (redirectUri?: string) => ({ redirectUri }), + completeOnboarding: (nextProductKey?: string) => ({ nextProductKey }), setAllOnboardingSteps: (allOnboardingSteps: AllOnboardingSteps) => ({ allOnboardingSteps }), setStepKey: (stepKey: string) => ({ stepKey }), setSubscribedDuringOnboarding: (subscribedDuringOnboarding: boolean) => ({ subscribedDuringOnboarding }), @@ -158,17 +159,21 @@ export const onboardingLogic = kea({ eventUsageLogic.actions.reportSubscribedDuringOnboarding(productKey) } }, - completeOnboarding: ({ redirectUri }) => { + completeOnboarding: ({ nextProductKey }) => { if (values.productKey) { - eventUsageLogic.actions.reportOnboardingCompleted(values.productKey) - actions.updateCurrentTeam({ + const product = values.productKey + eventUsageLogic.actions.reportOnboardingCompleted(product) + if (nextProductKey) { + actions.setProductKey(nextProductKey) + router.actions.push(urls.onboarding(nextProductKey)) + } + teamLogic.actions.updateCurrentTeam({ has_completed_onboarding_for: { ...values.currentTeam?.has_completed_onboarding_for, - [values.productKey]: true, + [product]: true, }, }) } - window.location.href = redirectUri || values.onCompleteOnbardingRedirectUrl }, setAllOnboardingSteps: ({ allOnboardingSteps }) => { // once we have the onboarding steps we need to make sure the step key is valid, @@ -235,6 +240,11 @@ export const onboardingLogic = kea({ return [`/onboarding/${values.productKey}`] } }, + updateCurrentTeamSuccess(val) { + if (values.productKey && val.payload?.has_completed_onboarding_for?.[values.productKey]) { + return [values.onCompleteOnbardingRedirectUrl] + } + }, }), urlToAction: ({ actions, values }) => ({ '/onboarding/:productKey': ({ productKey }, { success, upgraded, step }) => {