Skip to content

Commit

Permalink
Fix premium remix settings regression
Browse files Browse the repository at this point in the history
  • Loading branch information
Saliou Diallo committed Oct 20, 2023
1 parent b02e6b5 commit 5d3b092
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
SHOW_REMIXES,
SHOW_REMIXES_BASE
} from './types'
import { IS_PREMIUM, PREMIUM_CONDITIONS } from '../AccessAndSaleField'

const messages = {
title: 'Remix Settings',
Expand All @@ -51,6 +52,10 @@ export const RemixSettingsField = () => {
useTrackField<FieldVisibility[typeof SHOW_REMIXES_BASE]>(SHOW_REMIXES)
const [{ value: remixOf }, , { setValue: setRemixOf }] =
useTrackField<SingleTrackEditValues[typeof REMIX_OF]>(REMIX_OF)
const [{ value: isPremium }] =
useTrackField<SingleTrackEditValues[typeof IS_PREMIUM]>(IS_PREMIUM)
const [{ value: premiumConditions }] =
useTrackField<SingleTrackEditValues[typeof PREMIUM_CONDITIONS]>(PREMIUM_CONDITIONS)

const parentTrackId = remixOf?.tracks[0].parent_track_id
const { data: remixOfTrack } = useGetTrackById(
Expand All @@ -72,8 +77,10 @@ export const RemixSettingsField = () => {
set(initialValues, SHOW_REMIXES, showRemixes)
set(initialValues, IS_REMIX, isRemix)
set(initialValues, REMIX_LINK, remixLink)
set(initialValues, IS_PREMIUM, isPremium)
set(initialValues, PREMIUM_CONDITIONS, premiumConditions)
return initialValues as unknown as RemixSettingsFormValues
}, [showRemixes, isRemix, remixLink, parentTrackId])
}, [showRemixes, isRemix, remixLink, parentTrackId, isPremium, premiumConditions])

const handleSubmit = useCallback(
(values: RemixSettingsFormValues) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
getPathFromTrackUrl,
useGetTrackByPermalink,
accountSelectors,
usePremiumContentAccess
usePremiumContentAccess,
isPremiumContentUSDCPurchaseGated,
isPremiumContentCollectibleGated
} from '@audius/common'
import { useField } from 'formik'
import { useSelector } from 'react-redux'
Expand All @@ -18,6 +20,8 @@ import { SwitchRowField } from '../SwitchRowField'
import styles from './RemixSettingsField.module.css'
import { TrackInfo } from './TrackInfo'
import { CAN_REMIX_PARENT, IS_REMIX, REMIX_LINK, SHOW_REMIXES } from './types'
import { HelpCallout } from 'components/help-callout/HelpCallout'
import { IS_PREMIUM, PREMIUM_CONDITIONS } from '../AccessAndSaleField'
const { getUserId } = accountSelectors

const messages = {
Expand All @@ -31,10 +35,18 @@ const messages = {
description:
"Paste the original Audius track link if yours is a remix. Your remix will typically appear on the original track's page.",
linkLabel: 'Link to Remix'
}
},
changeAvailabilityPrefix: 'Availablity is set to ',
changeAvailabilitySuffix:
'. To enable these options, change availability to Public.',
premium: 'Premium (Pay-to-Unlock)',
collectibleGated: 'Collectible Gated',
specialAccess: 'Special Access'
}

export const RemixSettingsMenuFields = () => {
const [{ value: isPremium }] = useField(IS_PREMIUM)
const [{ value: premiumConditions }] = useField(PREMIUM_CONDITIONS)
const [{ value: trackUrl }] = useField(REMIX_LINK)
const [, , { setValue: setCanRemixParent }] = useField(CAN_REMIX_PARENT)
const permalink = useThrottle(getPathFromTrackUrl(trackUrl), 1000)
Expand All @@ -59,17 +71,31 @@ export const RemixSettingsMenuFields = () => {

return (
<div className={styles.fields}>
{isPremium ? (
<HelpCallout
content={`${messages.changeAvailabilityPrefix} ${
isPremiumContentUSDCPurchaseGated(premiumConditions)
? messages.premium
: isPremiumContentCollectibleGated(premiumConditions)
? messages.collectibleGated
: messages.specialAccess
}${messages.changeAvailabilitySuffix}`}
/>
) : null}
<SwitchRowField
name={SHOW_REMIXES}
header={messages.hideRemix.header}
description={messages.hideRemix.description}
inverted
disabled={isPremium}
checked={isPremium}
inverted={!isPremium}
/>
<Divider />
<SwitchRowField
name={IS_REMIX}
header={messages.remixOf.header}
description={messages.remixOf.description}
disabled={isPremium}
>
<TextField name={REMIX_LINK} label={messages.remixOf.linkLabel} />
{track ? <TrackInfo trackId={track.track_id} /> : null}
Expand Down

0 comments on commit 5d3b092

Please sign in to comment.