Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAY-1923] Navigate to track screen in the background on successful purchase #6272

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Button, LockedStatusBadge, Text } from 'app/components/core'
import { NativeDrawer } from 'app/components/drawer'
import { useDrawer } from 'app/hooks/useDrawer'
import { useIsUSDCEnabled } from 'app/hooks/useIsUSDCEnabled'
import { useNavigation } from 'app/hooks/useNavigation'
import { flexRowCentered, makeStyles } from 'app/styles'
import { spacing } from 'app/styles/spacing'
import { useThemeColors } from 'app/utils/theme'
Expand Down Expand Up @@ -167,6 +168,7 @@ const PremiumTrackPurchaseDrawerHeader = ({
// to the FormikContext, which can only be used in a component which is a descendant
// of the `<Formik />` component
const RenderForm = ({ track }: { track: PurchasableTrackMetadata }) => {
const navigation = useNavigation()
const styles = useStyles()
const { specialLightGreen, accentRed, secondary } = useThemeColors()

Expand All @@ -186,6 +188,13 @@ const RenderForm = ({ track }: { track: PurchasableTrackMetadata }) => {

const isPurchaseSuccessful = stage === PurchaseContentStage.FINISH

// Navigate to track screen in the background if purchase is successful
useEffect(() => {
if (isPurchaseSuccessful) {
navigation.navigate('Track', { id: track.track_id })
sddioulde marked this conversation as resolved.
Show resolved Hide resolved
}
}, [isPurchaseSuccessful, navigation, track.track_id])

const handleTermsPress = useCallback(() => {
Linking.openURL('https://audius.co/legal/terms-of-use')
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { useCallback } from 'react'
import type { UserTrackMetadata } from '@audius/common'
import { View } from 'react-native'

import IconCaretRight from 'app/assets/images/iconCaretRight.svg'
import IconVerified from 'app/assets/images/iconVerified.svg'
import { Text } from 'app/components/core'
import { Button, Text } from 'app/components/core'
import { useDrawer } from 'app/hooks/useDrawer'
import { flexRowCentered, makeStyles } from 'app/styles'
import { spacing } from 'app/styles/spacing'
import { EventNames } from 'app/types/analytics'
Expand All @@ -16,10 +18,11 @@ import { TwitterButton } from '../twitter-button'
const messages = {
success: 'Your purchase was successful!',
shareTwitterText: (trackTitle: string, handle: string) =>
`I bought the track ${trackTitle} by ${handle} on Audius! #AudiusPremium`
`I bought the track ${trackTitle} by ${handle} on Audius! #AudiusPremium`,
viewTrack: 'View Track'
}

const useStyles = makeStyles(({ spacing, typography, palette }) => ({
const useStyles = makeStyles(({ spacing, palette }) => ({
root: {
paddingTop: spacing(2),
gap: spacing(9),
Expand All @@ -29,12 +32,19 @@ const useStyles = makeStyles(({ spacing, typography, palette }) => ({
...flexRowCentered(),
alignSelf: 'center',
gap: spacing(2)
},
viewTrack: {
sddioulde marked this conversation as resolved.
Show resolved Hide resolved
borderWidth: 0
},
viewTrackText: {
color: palette.neutralLight4
}
}))

export const PurchaseSuccess = ({ track }: { track: UserTrackMetadata }) => {
const styles = useStyles()
const { specialGreen, staticWhite } = useThemeColors()
const { specialGreen, staticWhite, neutralLight4 } = useThemeColors()
const { onClose } = useDrawer('PremiumTrackPurchase')
const { handle } = track.user
const { title } = track
const link = getTrackRoute(track, true)
Expand Down Expand Up @@ -72,6 +82,18 @@ export const PurchaseSuccess = ({ track }: { track: UserTrackMetadata }) => {
handle={handle}
size='large'
/>
<Button
onPress={onClose}
title={messages.viewTrack}
variant='commonAlt'
styles={{
root: styles.viewTrack,
text: styles.viewTrackText
}}
IconProps={{ width: 20, height: 20, fill: neutralLight4 }}
size='large'
icon={IconCaretRight}
/>
</View>
)
}