Skip to content

Commit 18ea16b

Browse files
committed
apply the onboarding result
1 parent f91760f commit 18ea16b

4 files changed

Lines changed: 73 additions & 7 deletions

File tree

src/features/onboarding/components/OnboardingModal.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { useEffect } from 'react'
22
import ReactModal from 'react-modal'
33
import { Steps } from 'src/components/Elements'
4-
import { trackOnboardingFinish, trackOnboardingSkip, trackOnboardingStart } from 'src/lib/analytics'
4+
import { SUPPORTED_CARDS } from 'src/config'
5+
import { Tag, useRemoteConfigStore } from 'src/features/remoteConfig'
6+
import {
7+
identifyUserCards,
8+
identifyUserLanguages,
9+
identifyUserOccupation,
10+
trackOnboardingFinish,
11+
trackOnboardingSkip,
12+
trackOnboardingStart,
13+
} from 'src/lib/analytics'
514
import { useUserPreferences } from 'src/stores/preferences'
615
import { HelloTab } from './steps/HelloTab'
716
import { LanguagesTab } from './steps/LanguagesTab'
@@ -14,7 +23,8 @@ type OnboardingModalProps = {
1423
}
1524

1625
export const OnboardingModal = ({ showOnboarding, setShowOnboarding }: OnboardingModalProps) => {
17-
const { markOnboardingAsCompleted } = useUserPreferences()
26+
const { markOnboardingAsCompleted, setTags, setCards } = useUserPreferences()
27+
const { supportedTags } = useRemoteConfigStore()
1828

1929
useEffect(() => {
2030
trackOnboardingStart()
@@ -52,6 +62,29 @@ export const OnboardingModal = ({ showOnboarding, setShowOnboarding }: Onboardin
5262
if (tabsData) {
5363
const { icon, ...occupation } = tabsData
5464
markOnboardingAsCompleted(occupation)
65+
identifyUserOccupation(occupation.title)
66+
67+
const tags =
68+
(occupation.tags
69+
.map((tag) => supportedTags.find((st) => st.value === tag))
70+
.filter(Boolean) as Tag[]) || []
71+
72+
setTags(tags)
73+
identifyUserLanguages(tags.map((tag) => tag.value))
74+
75+
const cards =
76+
occupation.sources
77+
.map((source) => SUPPORTED_CARDS.find((sc) => sc.value === source))
78+
.filter(Boolean)
79+
.map((source, index) => {
80+
return {
81+
id: index,
82+
name: source?.value || '',
83+
}
84+
}) || []
85+
86+
setCards(cards)
87+
identifyUserCards(cards.map((card) => card.name))
5588
}
5689

5790
setShowOnboarding(false)

src/features/onboarding/components/steps/LanguagesTab.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { ChipsSet, StepProps } from 'src/components/Elements'
22
import { useRemoteConfigStore } from 'src/features/remoteConfig'
33
import { Occupation } from '../../types'
44

5-
export const LanguagesTab = ({ moveToPrevious, moveToNext, tabsData }: StepProps<Occupation>) => {
5+
export const LanguagesTab = ({
6+
moveToPrevious,
7+
moveToNext,
8+
setTabsData,
9+
tabsData,
10+
}: StepProps<Occupation>) => {
611
const { supportedTags } = useRemoteConfigStore()
712

813
const sources = supportedTags
@@ -21,7 +26,14 @@ export const LanguagesTab = ({ moveToPrevious, moveToNext, tabsData }: StepProps
2126
<p className="tabBody">Select the languages you're interested in following.</p>
2227
</div>
2328
<div className="tabContent sources">
24-
<ChipsSet options={sources} defaultValues={tabsData.tags} />
29+
<ChipsSet
30+
canSelectMultiple={true}
31+
options={sources}
32+
defaultValues={tabsData.tags}
33+
onChange={(_, selectedChips) => {
34+
setTabsData({ ...tabsData, tags: selectedChips.map((chip) => chip.value) })
35+
}}
36+
/>
2537
</div>
2638
<div className="tabFooter">
2739
<button onClick={() => moveToPrevious && moveToPrevious()}>Back</button>

src/features/onboarding/components/steps/SourcesTab.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { ChipsSet, StepProps } from 'src/components/Elements'
33
import { SUPPORTED_CARDS } from '../../../../config'
44
import { Occupation } from '../../types'
55

6-
export const SourcesTab = ({ moveToPrevious, moveToNext, tabsData }: StepProps<Occupation>) => {
6+
export const SourcesTab = ({
7+
moveToPrevious,
8+
moveToNext,
9+
setTabsData,
10+
tabsData,
11+
}: StepProps<Occupation>) => {
712
const sources = SUPPORTED_CARDS.map((source) => {
813
return {
914
label: source.label,
@@ -19,7 +24,19 @@ export const SourcesTab = ({ moveToPrevious, moveToNext, tabsData }: StepProps<O
1924
<p className="tabBody">Select the sources you're interested in following.</p>
2025
</div>
2126
<div className="tabContent sources">
22-
<ChipsSet options={sources} defaultValues={tabsData.sources} />
27+
<ChipsSet
28+
canSelectMultiple={true}
29+
options={sources}
30+
defaultValues={tabsData.sources}
31+
onChange={(_, selectedChips) => {
32+
console.log(
33+
'sources',
34+
selectedChips.map((chip) => chip.value)
35+
)
36+
37+
setTabsData({ ...tabsData, sources: selectedChips.map((chip) => chip.value) })
38+
}}
39+
/>
2340
</div>
2441
<div className="tabFooter">
2542
<button onClick={() => moveToPrevious && moveToPrevious()}>Back</button>

src/lib/analytics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const setupIdentification = () => {
9090
identifyUserSearchEngine(searchEngine)
9191
identifyUserLinksInNewTab(openLinksNewTab)
9292
if (onboardingResult?.title) {
93-
identifyUserProperty(Attributes.OCCUPATION, onboardingResult.title)
93+
identifyUserOccupation(onboardingResult.title)
9494
}
9595
}
9696

@@ -297,6 +297,10 @@ export const identifyUserSearchEngine = (searchEngineName: string) => {
297297
export const identifyUserLinksInNewTab = (enabled: boolean) => {
298298
identifyUserProperty(Attributes.TARGET, enabled ? 'New Tab' : 'Same Tab')
299299
}
300+
export const identifyUserOccupation = (occupation: string) => {
301+
identifyUserProperty(Attributes.OCCUPATION, occupation)
302+
}
303+
300304
// Private functions
301305
type trackEventProps = {
302306
object: Exclude<Objects, null | undefined>

0 commit comments

Comments
 (0)