Skip to content

Commit f7cbe6b

Browse files
committed
refactor: simplify onboarding process by removing unused components and props
1 parent 46512af commit f7cbe6b

5 files changed

Lines changed: 93 additions & 128 deletions

File tree

src/App.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import clsx from 'clsx'
2-
import { useEffect, useLayoutEffect, useState } from 'react'
2+
import { useEffect, useLayoutEffect } from 'react'
33
import { DNDLayout } from 'src/components/Layout'
44
import {
55
identifyAdvBlocked,
@@ -10,7 +10,6 @@ import {
1010
import { useUserPreferences } from 'src/stores/preferences'
1111
import { AppContentLayout } from './components/Layout'
1212
import { verifyAdvStatus } from './features/adv/utils/status'
13-
import { isWebOrExtensionVersion } from './utils/Environment'
1413
import { lazyImport } from './utils/lazyImport'
1514
const { OnboardingModal } = lazyImport(() => import('src/features/onboarding'), 'OnboardingModal')
1615

@@ -25,16 +24,8 @@ const intersectionCallback = (entries: IntersectionObserverEntry[]) => {
2524
}
2625

2726
export const App = () => {
28-
const [showOnboarding, setShowOnboarding] = useState(true)
29-
const {
30-
onboardingCompleted,
31-
maxVisibleCards,
32-
setAdvStatus,
33-
isDNDModeActive,
34-
layout,
35-
DNDDuration,
36-
setDNDDuration,
37-
} = useUserPreferences()
27+
const { maxVisibleCards, setAdvStatus, isDNDModeActive, layout, DNDDuration, setDNDDuration } =
28+
useUserPreferences()
3829

3930
useLayoutEffect(() => {
4031
document.documentElement.style.setProperty('--max-visible-cards', maxVisibleCards.toString())
@@ -78,10 +69,7 @@ export const App = () => {
7869

7970
return (
8071
<>
81-
{!onboardingCompleted && isWebOrExtensionVersion() === 'extension' && (
82-
<OnboardingModal showOnboarding={showOnboarding} setShowOnboarding={setShowOnboarding} />
83-
)}
84-
72+
<OnboardingModal />
8573
<div
8674
className={clsx(
8775
'layoutLayers hideScrollBar',

src/features/onboarding/components/OnboardingModal.tsx

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,23 @@
11
import { useEffect } from 'react'
22
import ReactModal from 'react-modal'
3-
import { Steps } from 'src/components/Elements'
4-
import { SUPPORTED_CARDS } from 'src/config/supportedCards'
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'
3+
import { trackOnboardingStart } from 'src/lib/analytics'
144
import { useUserPreferences } from 'src/stores/preferences'
15-
import { SelectedCard } from 'src/types'
165
import { HelloTab } from './steps/HelloTab'
17-
import { LanguagesTab } from './steps/LanguagesTab'
18-
import { SourcesTab } from './steps/SourcesTab'
196
import './steps/tabs.css'
207

21-
type OnboardingModalProps = {
22-
showOnboarding: boolean
23-
setShowOnboarding: (show: boolean) => void
24-
}
25-
26-
export const OnboardingModal = ({ showOnboarding, setShowOnboarding }: OnboardingModalProps) => {
27-
const { markOnboardingAsCompleted, setTags, setCards } = useUserPreferences()
28-
const { supportedTags } = useRemoteConfigStore()
8+
export const OnboardingModal = () => {
9+
const { onboardingCompleted } = useUserPreferences()
2910

3011
useEffect(() => {
3112
trackOnboardingStart()
3213
}, [])
3314
return (
3415
<ReactModal
35-
isOpen={showOnboarding}
16+
isOpen={!onboardingCompleted}
3617
ariaHideApp={false}
3718
shouldCloseOnEsc={false}
3819
shouldCloseOnOverlayClick={false}
3920
shouldFocusAfterRender={false}
40-
onRequestClose={() => setShowOnboarding(false)}
4121
contentLabel="Onboarding"
4222
className="Modal scrollable"
4323
style={{
@@ -47,50 +27,7 @@ export const OnboardingModal = ({ showOnboarding, setShowOnboarding }: Onboardin
4727
}}
4828
overlayClassName="Overlay">
4929
<div className="onboardingModal">
50-
<Steps
51-
steps={[
52-
{ title: 'Hello', element: HelloTab },
53-
{ title: 'Sources', element: SourcesTab },
54-
{ title: 'Languages', element: LanguagesTab },
55-
]}
56-
onSkip={() => {
57-
trackOnboardingSkip()
58-
markOnboardingAsCompleted(null)
59-
setShowOnboarding(false)
60-
}}
61-
onFinish={(tabsData) => {
62-
trackOnboardingFinish()
63-
if (tabsData) {
64-
const { icon, ...occupation } = tabsData
65-
markOnboardingAsCompleted(occupation)
66-
identifyUserOccupation(occupation.title)
67-
68-
const tags =
69-
(occupation.tags
70-
.map((tag) => supportedTags.find((st) => st.value === tag))
71-
.filter(Boolean) as Tag[]) || []
72-
73-
setTags(tags)
74-
identifyUserLanguages(tags.map((tag) => tag.value))
75-
76-
const cards = (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-
type: 'supported',
84-
}
85-
}) || []) as SelectedCard[]
86-
87-
setCards(cards)
88-
identifyUserCards(cards.map((card) => card.name))
89-
}
90-
91-
setShowOnboarding(false)
92-
}}
93-
/>
30+
<HelloTab />
9431
</div>
9532
</ReactModal>
9633
)

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

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import clsx from 'clsx'
2-
import { useState } from 'react'
32
import { AiFillMobile, AiFillSecurityScan } from 'react-icons/ai'
43
import { BsArrowRight, BsFillGearFill } from 'react-icons/bs'
54
import { FaDatabase, FaPaintBrush, FaRobot, FaServer } from 'react-icons/fa'
65
import { RiDeviceFill } from 'react-icons/ri'
76
import { TbDots } from 'react-icons/tb'
8-
import { StepProps } from 'src/components/Elements'
7+
import { Tag, useRemoteConfigStore } from 'src/features/remoteConfig'
8+
import { useUserPreferences } from 'src/stores/preferences'
99
import { Occupation } from '../../types'
1010

1111
const OCCUPATIONS: Occupation[] = [
1212
{
1313
title: 'Front-End Engineer',
1414
icon: FaPaintBrush,
1515
sources: ['devto', 'github', 'medium', 'hashnode'],
16-
tags: ['javascript', 'typescript'],
16+
tags: ['frontend', 'javascript', 'typescript', 'css', 'react', 'vue', 'angular'],
1717
},
1818
{
1919
title: 'Back-End Engineer',
2020
icon: BsFillGearFill,
2121
sources: ['devto', 'github', 'medium', 'hashnode'],
22-
tags: ['go', 'php', 'ruby', 'rust', 'r'],
22+
tags: ['backend', 'go', 'php', 'ruby', 'rust', 'r'],
2323
},
2424
{
2525
title: 'Full Stack Engineer',
@@ -31,74 +31,92 @@ const OCCUPATIONS: Occupation[] = [
3131
title: 'Mobile',
3232
icon: AiFillMobile,
3333
sources: ['reddit', 'github', 'medium', 'hashnode'],
34-
tags: ['android', 'kotlin', 'java', 'swift', 'objective-c'],
34+
tags: [
35+
'android',
36+
'mobile',
37+
'kotlin',
38+
'java',
39+
'ios',
40+
'swift',
41+
'objectivec',
42+
'react native',
43+
'flutter',
44+
],
3545
},
3646
{
3747
title: 'Devops Engineer',
3848
icon: FaServer,
3949
sources: ['freecodecamp', 'github', 'reddit', 'devto'],
40-
tags: ['devops', 'bash'],
50+
tags: ['devops', 'kubernetes', 'docker', 'bash'],
4151
},
4252
{
4353
title: 'Data Engineer',
4454
icon: FaDatabase,
4555
sources: ['freecodecamp', 'github', 'reddit', 'devto'],
46-
tags: ['data-science', 'python', 'artificial-intelligence', 'machine-learning'],
56+
tags: ['data science', 'python', 'artificial intelligence', 'machine learning'],
4757
},
4858
{
4959
title: 'Security Engineer',
5060
icon: AiFillSecurityScan,
5161
sources: ['freecodecamp', 'github', 'reddit', 'devto'],
52-
tags: ['c++', 'bash', 'python'],
62+
tags: ['security', 'cpp', 'bash', 'python'],
5363
},
5464
{
5565
title: 'ML Engineer',
5666
icon: FaRobot,
5767
sources: ['github', 'freecodecamp', 'hackernews', 'devto'],
58-
tags: ['machine-learning', 'artificial-intelligence', 'python'],
68+
tags: ['machine learning', 'artificial intelligence', 'python'],
5969
},
6070
{
6171
title: 'Other',
6272
icon: TbDots,
6373
sources: ['hackernews', 'github', 'producthunt', 'devto'],
64-
tags: [],
74+
tags: ['webdev', 'mobile'],
6575
},
6676
]
6777

68-
export const HelloTab = ({
69-
moveToNext,
70-
moveToPrevious,
71-
setTabsData,
72-
tabsData,
73-
}: StepProps<Occupation>) => {
74-
const [selectedOccupation, setSelectedOccupation] = useState<Occupation | undefined>(
75-
tabsData || OCCUPATIONS[0]
76-
)
77-
const onOccupationClicked = (occupation: Occupation) => {
78-
setSelectedOccupation(occupation)
79-
}
78+
export const HelloTab = () => {
79+
const { markOnboardingAsCompleted, setCards, setTags, setOccupation, occupation } =
80+
useUserPreferences()
81+
82+
const { tags } = useRemoteConfigStore()
8083

81-
const onClickNext = () => {
82-
if (selectedOccupation === undefined) {
83-
return
84+
const onStartClicked = () => {
85+
const selectedOccupation = OCCUPATIONS.find((occ) => occ.title === occupation)
86+
if (selectedOccupation) {
87+
setOccupation(selectedOccupation.title)
88+
setCards(
89+
selectedOccupation.sources.map((source, index) => ({
90+
id: index,
91+
name: source,
92+
type: 'supported',
93+
}))
94+
)
95+
const userTags = selectedOccupation.tags
96+
.map((tag) => {
97+
return tags.find((t) => t.value === tag)
98+
})
99+
.filter(Boolean) as Array<Tag>
100+
101+
setTags(userTags)
84102
}
85103

86-
setTabsData(selectedOccupation)
87-
moveToNext && moveToNext()
104+
markOnboardingAsCompleted()
88105
}
106+
89107
return (
90108
<div>
91109
<div className="tabHeader">
92-
<h1 className="tabTitle">Hi, 👋 Welcome to Hackertab</h1>
93-
<p className="tabBody">Let's customize your Hackertab experience!</p>
110+
<h1 className="tabTitle">👋 Let’s set up your Hackertab</h1>
111+
<p className="tabBody">Select your developer role 👨🏻‍💻 to personalize your Hackertab.</p>
94112
</div>
95113
<div className="occupations">
96114
{OCCUPATIONS.map((occ) => {
97115
return (
98116
<button
99117
key={occ.title}
100-
onClick={() => onOccupationClicked(occ)}
101-
className={clsx('occupation', selectedOccupation?.title === occ.title && 'active')}>
118+
onClick={() => setOccupation(occ.title)}
119+
className={clsx('occupation', occupation === occ.title && 'active')}>
102120
<span>
103121
<occ.icon className="occupationIcon" />
104122
</span>
@@ -108,10 +126,11 @@ export const HelloTab = ({
108126
})}
109127
</div>
110128
<div className="tabFooter">
111-
<button onClick={() => moveToPrevious && moveToPrevious()}>Skip</button>
112-
<button className="positiveButton" onClick={() => onClickNext()}>
113-
<BsArrowRight /> Next
114-
</button>
129+
{occupation && (
130+
<button className="positiveButton" onClick={onStartClicked}>
131+
<BsArrowRight /> Start now
132+
</button>
133+
)}
115134
</div>
116135
</div>
117136
)

src/lib/analytics.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ export const setupAnalytics = () => {
9999
export const setupIdentification = () => {
100100
const {
101101
userSelectedTags,
102-
onboardingResult,
103102
theme,
104103
cards,
105104
listingMode,
106105
openLinksNewTab,
106+
occupation,
107107
promptEngine,
108108
maxVisibleCards,
109109
layout,
@@ -118,8 +118,8 @@ export const setupIdentification = () => {
118118
identifyUserLinksInNewTab(openLinksNewTab)
119119
identifyUserMaxVisibleCards(maxVisibleCards)
120120
identifyDisplayLayout(layout)
121-
if (onboardingResult?.title) {
122-
identifyUserOccupation(onboardingResult.title)
121+
if (occupation) {
122+
identifyUserOccupation(occupation)
123123
}
124124
identifySentryUser({
125125
[Attributes.LANGUAGES]: userSelectedTags.map((tag: any) => tag.value),

0 commit comments

Comments
 (0)