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-3000] Don't open purchase modal for un-authed users #8463

Merged
merged 1 commit into from
May 14, 2024
Merged
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 @@ -8,13 +8,17 @@ import {
SmartCollection,
ID,
User,
isContentUSDCPurchaseGated
isContentUSDCPurchaseGated,
ModalSource,
Track
} from '@audius/common/models'
import { FeatureFlags } from '@audius/common/services'
import {
CollectionTrack,
CollectionsPageType,
CollectionPageTrackRecord
CollectionPageTrackRecord,
usePremiumContentPurchaseModal,
PurchaseableContentType
} from '@audius/common/store'
import { getDogEarType, removeNullable } from '@audius/common/utils'

Expand All @@ -29,6 +33,7 @@ import Page from 'components/page/Page'
import { SuggestedTracks } from 'components/suggested-tracks'
import { Tile } from 'components/tile'
import { TracksTable, TracksTableColumn } from 'components/tracks-table'
import { useAuthenticatedCallback } from 'hooks/useAuthenticatedCallback'
import { useFlag } from 'hooks/useRemoteConfig'
import { smartCollectionIcons } from 'pages/collection-page/smartCollectionIcons'
import { computeCollectionMetadataProps } from 'pages/collection-page/store/utils'
Expand Down Expand Up @@ -209,6 +214,19 @@ const CollectionPage = ({
track.is_stream_gated &&
isContentUSDCPurchaseGated(track.stream_conditions)
)

// Note: This would normally belong in the CollectionPageProvider,
// but it benefits us more to reuse existing hooks and that component cannot use hooks
const { onOpen: openPremiumContentModal } = usePremiumContentPurchaseModal()
const openPurchaseModal = useAuthenticatedCallback(
({ track_id }: Track) => {
openPremiumContentModal(
{ contentId: track_id, contentType: PurchaseableContentType.TRACK },
{ source: ModalSource.TrackListItem }
)
},
[openPremiumContentModal]
)
const isPlayable = !areAllTracksDeleted && numTracks > 0
const dogEarType =
(!collectionLoading &&
Expand Down Expand Up @@ -344,7 +362,7 @@ const CollectionPage = ({
onClickFavorite={onClickSave}
onClickRemove={isOwner ? onClickRemove : undefined}
onClickRepost={onClickRepostTrack}
onClickPurchase={onClickPurchaseTrack}
onClickPurchase={openPurchaseModal}
isPremiumEnabled={isPremiumAlbumsEnabled}
onReorderTracks={onReorderTracks}
onSortTracks={onSortTracks}
Expand Down