Test requiring at least one interest in onboarding (#11391)
Co-authored-by: DS Boyce <260543580+ds-boyce@users.noreply.github.com>
This commit is contained in:
@@ -933,17 +933,6 @@
|
|||||||
"count": 1
|
"count": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"src/screens/Onboarding/StepInterests/index.tsx": {
|
|
||||||
"typescript/no-explicit-any": {
|
|
||||||
"count": 1
|
|
||||||
},
|
|
||||||
"typescript/no-misused-promises": {
|
|
||||||
"count": 1
|
|
||||||
},
|
|
||||||
"typescript/require-await": {
|
|
||||||
"count": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"src/screens/Onboarding/StepProfile/index.tsx": {
|
"src/screens/Onboarding/StepProfile/index.tsx": {
|
||||||
"typescript/no-floating-promises": {
|
"typescript/no-floating-promises": {
|
||||||
"count": 2
|
"count": 2
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export enum Features {
|
|||||||
VideoMultipartUploadEnable = 'video:multipart_upload:enable',
|
VideoMultipartUploadEnable = 'video:multipart_upload:enable',
|
||||||
SearchStarterPacksV2Enable = 'search_starter_packs_v2:enable',
|
SearchStarterPacksV2Enable = 'search_starter_packs_v2:enable',
|
||||||
FollowSortEnable = 'follow_sort:enable',
|
FollowSortEnable = 'follow_sort:enable',
|
||||||
|
OnboardingInterestsRequiredEnable = 'onboarding:interests:required:enable',
|
||||||
|
|
||||||
// values
|
// values
|
||||||
TrendingDiscoverValues = 'trending_discover:values',
|
TrendingDiscoverValues = 'trending_discover:values',
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ export type Events = {
|
|||||||
selectedInterests: string[]
|
selectedInterests: string[]
|
||||||
selectedInterestsLength: number
|
selectedInterestsLength: number
|
||||||
}
|
}
|
||||||
|
'onboarding:interests:disabledNextPressed': {}
|
||||||
'onboarding:suggestedAccounts:tabPressed': {
|
'onboarding:suggestedAccounts:tabPressed': {
|
||||||
tab: string
|
tab: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import {useCallback, useState} from 'react'
|
import {useCallback, useState} from 'react'
|
||||||
import {View} from 'react-native'
|
import {Pressable, View} from 'react-native'
|
||||||
import {msg} from '@lingui/core/macro'
|
import {Trans, useLingui} from '@lingui/react/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
|
||||||
import {Trans} from '@lingui/react/macro'
|
|
||||||
|
|
||||||
import {interests, useInterestsDisplayNames} from '#/lib/interests'
|
import {interests, useInterestsDisplayNames} from '#/lib/interests'
|
||||||
import {capitalize} from '#/lib/strings/capitalize'
|
import {capitalize} from '#/lib/strings/capitalize'
|
||||||
@@ -19,20 +17,36 @@ import {atoms as a} from '#/alf'
|
|||||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
import * as Toggle from '#/components/forms/Toggle'
|
import * as Toggle from '#/components/forms/Toggle'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
|
import * as Tooltip from '#/components/Tooltip'
|
||||||
import {useAnalytics} from '#/analytics'
|
import {useAnalytics} from '#/analytics'
|
||||||
|
|
||||||
export function StepInterests() {
|
export function StepInterests() {
|
||||||
const {_} = useLingui()
|
const {t: l} = useLingui()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
const interestsDisplayNames = useInterestsDisplayNames()
|
const interestsDisplayNames = useInterestsDisplayNames()
|
||||||
|
|
||||||
const {state, dispatch} = useOnboardingInternalState()
|
const {state, dispatch} = useOnboardingInternalState()
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [tooltipVisible, setTooltipVisible] = useState(false)
|
||||||
const [selectedInterests, setSelectedInterests] = useState<string[]>(
|
const [selectedInterests, setSelectedInterests] = useState<string[]>(
|
||||||
state.interestsStepResults.selectedInterests.map(i => i),
|
state.interestsStepResults.selectedInterests.map(i => i),
|
||||||
)
|
)
|
||||||
|
/*
|
||||||
|
* Behind this gate, users must choose at least one interest before they can
|
||||||
|
* continue.
|
||||||
|
*/
|
||||||
|
const interestRequired = ax.features.enabled(
|
||||||
|
ax.features.OnboardingInterestsRequiredEnable,
|
||||||
|
)
|
||||||
|
const missingRequiredInterest =
|
||||||
|
interestRequired && selectedInterests.length === 0
|
||||||
|
|
||||||
const saveInterests = useCallback(async () => {
|
const showMissingInterestTooltip = () => {
|
||||||
|
ax.metric('onboarding:interests:disabledNextPressed', {})
|
||||||
|
setTooltipVisible(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveInterests = useCallback(() => {
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -46,12 +60,37 @@ export function StepInterests() {
|
|||||||
selectedInterests,
|
selectedInterests,
|
||||||
selectedInterestsLength: selectedInterests.length,
|
selectedInterestsLength: selectedInterests.length,
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (error) {
|
||||||
logger.info(`onboading: error saving interests`)
|
const e = error as Error
|
||||||
|
logger.info(`onboarding: error saving interests`)
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
}
|
}
|
||||||
}, [ax, selectedInterests, setSaving, dispatch])
|
}, [ax, selectedInterests, setSaving, dispatch])
|
||||||
|
|
||||||
|
const continueButton = (
|
||||||
|
<Button
|
||||||
|
disabled={saving || missingRequiredInterest}
|
||||||
|
testID="onboardingContinue"
|
||||||
|
variant="solid"
|
||||||
|
color="primary"
|
||||||
|
size="large"
|
||||||
|
label={
|
||||||
|
missingRequiredInterest
|
||||||
|
? l`Choose an interest`
|
||||||
|
: l`Continue to next step`
|
||||||
|
}
|
||||||
|
onPress={() => void saveInterests()}>
|
||||||
|
<ButtonText style={{pointerEvents: 'none'}}>
|
||||||
|
{missingRequiredInterest ? (
|
||||||
|
<Trans>Choose an interest</Trans>
|
||||||
|
) : (
|
||||||
|
<Trans>Continue</Trans>
|
||||||
|
)}
|
||||||
|
</ButtonText>
|
||||||
|
{saving && <ButtonIcon icon={Loader} />}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[a.align_start, a.gap_sm]} testID="onboardingInterests">
|
<View style={[a.align_start, a.gap_sm]} testID="onboardingInterests">
|
||||||
<OnboardingPosition />
|
<OnboardingPosition />
|
||||||
@@ -59,14 +98,21 @@ export function StepInterests() {
|
|||||||
<Trans>What are your interests?</Trans>
|
<Trans>What are your interests?</Trans>
|
||||||
</OnboardingTitleText>
|
</OnboardingTitleText>
|
||||||
<OnboardingDescriptionText>
|
<OnboardingDescriptionText>
|
||||||
<Trans>We'll use this to help customize your experience.</Trans>
|
{interestRequired ? (
|
||||||
|
<Trans>
|
||||||
|
Choose at least one. We'll use this to customize your experience.
|
||||||
|
You can change these anytime.
|
||||||
|
</Trans>
|
||||||
|
) : (
|
||||||
|
<Trans>We'll use this to help customize your experience.</Trans>
|
||||||
|
)}
|
||||||
</OnboardingDescriptionText>
|
</OnboardingDescriptionText>
|
||||||
|
|
||||||
<View style={[a.w_full, a.pt_lg]}>
|
<View style={[a.w_full, a.pt_lg]}>
|
||||||
<Toggle.Group
|
<Toggle.Group
|
||||||
values={selectedInterests}
|
values={selectedInterests}
|
||||||
onChange={setSelectedInterests}
|
onChange={setSelectedInterests}
|
||||||
label={_(msg`Select your interests from the options below`)}>
|
label={l`Select your interests from the options below`}>
|
||||||
<View style={[a.flex_row, a.gap_md, a.flex_wrap]}>
|
<View style={[a.flex_row, a.gap_md, a.flex_wrap]}>
|
||||||
{interests.map(interest => (
|
{interests.map(interest => (
|
||||||
<Toggle.Item
|
<Toggle.Item
|
||||||
@@ -81,19 +127,34 @@ export function StepInterests() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
<OnboardingControls.Portal>
|
<OnboardingControls.Portal>
|
||||||
<Button
|
<View style={[a.relative]}>
|
||||||
disabled={saving}
|
{missingRequiredInterest ? (
|
||||||
testID="onboardingContinue"
|
<Tooltip.Outer
|
||||||
variant="solid"
|
position="top"
|
||||||
color="primary"
|
visible={tooltipVisible}
|
||||||
size="large"
|
onVisibleChange={setTooltipVisible}>
|
||||||
label={_(msg`Continue to next step`)}
|
<Tooltip.Target>
|
||||||
onPress={saveInterests}>
|
<Pressable
|
||||||
<ButtonText>
|
accessibilityRole="button"
|
||||||
<Trans>Continue</Trans>
|
accessibilityLabel={l`Choose an interest`}
|
||||||
</ButtonText>
|
accessibilityHint={l`Choose at least one interest to continue`}
|
||||||
{saving && <ButtonIcon icon={Loader} />}
|
onPress={showMissingInterestTooltip}>
|
||||||
</Button>
|
<View
|
||||||
|
pointerEvents="none"
|
||||||
|
accessibilityElementsHidden
|
||||||
|
importantForAccessibility="no-hide-descendants">
|
||||||
|
{continueButton}
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
</Tooltip.Target>
|
||||||
|
<Tooltip.BubbleText label={l`Choose at least one interest.`}>
|
||||||
|
<Trans>Choose at least one interest.</Trans>
|
||||||
|
</Tooltip.BubbleText>
|
||||||
|
</Tooltip.Outer>
|
||||||
|
) : (
|
||||||
|
continueButton
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
</OnboardingControls.Portal>
|
</OnboardingControls.Portal>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user