Skip to content

Commit

Permalink
fix: redirect properly after complete onboarding (#17724)
Browse files Browse the repository at this point in the history
fix redirecting after complete onboarding
  • Loading branch information
raquelmsmith authored Oct 2, 2023
1 parent f70777f commit 36bc0fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -39,10 +38,7 @@ export const OnboardingOtherProductsStep = (): JSX.Element => {
</div>
</div>
<div className="justify-self-end min-w-30 flex justify-end">
<LemonButton
type="primary"
onClick={() => completeOnboarding(urls.onboarding(suggestedProduct.type))}
>
<LemonButton type="primary" onClick={() => completeOnboarding(suggestedProduct.type)}>
Get started
</LemonButton>
</div>
Expand Down
28 changes: 19 additions & 9 deletions frontend/src/scenes/onboarding/onboardingLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -50,13 +51,13 @@ export const onboardingLogic = kea<onboardingLogicType>({
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 }),
Expand Down Expand Up @@ -158,17 +159,21 @@ export const onboardingLogic = kea<onboardingLogicType>({
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,
Expand Down Expand Up @@ -235,6 +240,11 @@ export const onboardingLogic = kea<onboardingLogicType>({
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 }) => {
Expand Down

0 comments on commit 36bc0fe

Please sign in to comment.