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-1962] Disable selectable pills during purchase #6435

Merged
merged 5 commits into from
Oct 24, 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 @@ -40,11 +40,24 @@
border: 1px solid var(--harmony-s-400);
}

.pill.disabled {
pointer-events: none;
}

.large:active,
.large.selected {
box-shadow: none;
}

.disabled {
opacity: 0.45;
}

.disabled:hover {
dharit-tan marked this conversation as resolved.
Show resolved Hide resolved
background-color: var(--harmony-white);
border: 1px solid var(--harmony-border-strong);
}

.icon path {
fill: currentColor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const SelectablePill = forwardRef<
size = 'default',
isSelected,
label,
disabled,
icon: IconComponent,
className,
...restProps
Expand All @@ -28,7 +29,8 @@ export const SelectablePill = forwardRef<
styles.pill,
{
[styles.large]: size === 'large',
[styles.selected]: isSelected
[styles.selected]: isSelected,
[styles.disabled]: disabled
},
className
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export type SelectablePillProps = {
size?: 'default' | 'large'
isSelected: boolean
label: string
disabled?: boolean
icon?: IconComponent
} & Omit<ComponentPropsWithoutRef<'button'>, 'children'>
7 changes: 5 additions & 2 deletions packages/mobile/src/components/core/HarmonySelectablePill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const HarmonySelectablePill = (props: HarmonySelectablePillProps) => {
onPressIn,
onPressOut,
size,
disabled,
style,
...other
} = props
Expand Down Expand Up @@ -110,14 +111,16 @@ export const HarmonySelectablePill = (props: HarmonySelectablePillProps) => {
styles.pill,
size === 'large' ? styles.pillLarge : undefined,
isSelected ? styles.pressed : undefined,
disabled ? { opacity: 0.45 } : undefined,
{ transform: [{ scale }] },
style
]}
>
<Pressable
accessibilityRole='button'
onPressIn={handlePressIn}
onPressOut={handlePressOut}
onPressIn={disabled ? undefined : handlePressIn}
onPressOut={disabled ? undefined : handlePressOut}
disabled={disabled}
style={[
styles.pressable,
size === 'large' ? styles.pressableLarge : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ const formatPillAmount = (val: number) => `$${Math.floor(val / 100)}`

export type PayExtraFormSectionProps = {
amountPresets: PayExtraAmountPresetValues
disabled?: boolean
}

export const PayExtraFormSection = ({
amountPresets
amountPresets,
disabled
}: PayExtraFormSectionProps) => {
const [{ value: preset }, , { setValue: setPreset }] = useField(AMOUNT_PRESET)
const [{ value: customAmount }, { error: customAmountError }] =
Expand All @@ -69,20 +71,23 @@ export const PayExtraFormSection = ({
style={styles.pill}
isSelected={preset === PayExtraPreset.LOW}
label={formatPillAmount(amountPresets[PayExtraPreset.LOW])}
disabled={disabled}
onPress={() => handleClickPreset(PayExtraPreset.LOW)}
/>
<HarmonySelectablePill
size='large'
style={styles.pill}
isSelected={preset === PayExtraPreset.MEDIUM}
label={formatPillAmount(amountPresets[PayExtraPreset.MEDIUM])}
disabled={disabled}
onPress={() => handleClickPreset(PayExtraPreset.MEDIUM)}
/>
<HarmonySelectablePill
size='large'
style={styles.pill}
isSelected={preset === PayExtraPreset.HIGH}
label={formatPillAmount(amountPresets[PayExtraPreset.HIGH])}
disabled={disabled}
onPress={() => handleClickPreset(PayExtraPreset.HIGH)}
/>
</View>
Expand All @@ -91,6 +96,7 @@ export const PayExtraFormSection = ({
style={styles.pill}
isSelected={preset === PayExtraPreset.CUSTOM}
label={messages.customAmount}
disabled={disabled}
onPress={() => handleClickPreset(PayExtraPreset.CUSTOM)}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const RenderForm = ({ track }: { track: PurchasableTrackMetadata }) => {
const { amountDue } = purchaseSummaryValues

const isPurchaseSuccessful = stage === PurchaseContentStage.FINISH
const isInProgress = isContentPurchaseInProgress(stage)

// Navigate to track screen in the background if purchase is successful
useEffect(() => {
Expand All @@ -240,7 +241,10 @@ const RenderForm = ({ track }: { track: PurchasableTrackMetadata }) => {
) : null}
<View style={styles.formContentSection}>
{isPurchaseSuccessful ? null : (
<PayExtraFormSection amountPresets={presetValues} />
<PayExtraFormSection
amountPresets={presetValues}
disabled={isInProgress}
/>
)}
<PurchaseSummaryTable
{...purchaseSummaryValues}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const formatPillAmount = (val: number) => `$${Math.floor(val / 100)}`

export type PayExtraFormSectionProps = {
amountPresets: PayExtraAmountPresetValues
disabled?: boolean
}

export const PayExtraFormSection = ({
amountPresets
amountPresets,
disabled
}: PayExtraFormSectionProps) => {
const [{ value: preset }, , { setValue: setPreset }] = useField(AMOUNT_PRESET)

Expand All @@ -47,6 +49,7 @@ export const PayExtraFormSection = ({
size='large'
type='button'
onClick={() => handleClickPreset(PayExtraPreset.LOW)}
disabled={disabled}
/>
<SelectablePill
className={styles.presetPill}
Expand All @@ -55,6 +58,7 @@ export const PayExtraFormSection = ({
size='large'
type='button'
onClick={() => handleClickPreset(PayExtraPreset.MEDIUM)}
disabled={disabled}
/>
<SelectablePill
className={styles.presetPill}
Expand All @@ -63,6 +67,7 @@ export const PayExtraFormSection = ({
size='large'
type='button'
onClick={() => handleClickPreset(PayExtraPreset.HIGH)}
disabled={disabled}
/>
</div>
<SelectablePill
Expand All @@ -72,13 +77,15 @@ export const PayExtraFormSection = ({
size='large'
type='button'
onClick={() => handleClickPreset(PayExtraPreset.CUSTOM)}
disabled={disabled}
/>
</div>
{preset === PayExtraPreset.CUSTOM ? (
<PriceField
placeholder={messages.placeholder}
label={messages.customAmount}
name={CUSTOM_AMOUNT}
disabled={disabled}
/>
) : null}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PurchaseContentStage, usePayExtraPresets } from '@audius/common'
import {
PurchaseContentStage,
isContentPurchaseInProgress,
usePayExtraPresets
} from '@audius/common'
import { IconCheck } from '@audius/stems'

import { Icon } from 'components/Icon'
Expand Down Expand Up @@ -27,6 +31,7 @@ export const PurchaseContentFormFields = ({
}: PurchaseContentFormFieldsProps) => {
const payExtraAmountPresetValues = usePayExtraPresets(useRemoteVar)
const isPurchased = stage === PurchaseContentStage.FINISH
const isInProgress = isContentPurchaseInProgress(stage)

if (isPurchased) {
return (
Expand All @@ -48,7 +53,10 @@ export const PurchaseContentFormFields = ({
}
return (
<>
<PayExtraFormSection amountPresets={payExtraAmountPresetValues} />
<PayExtraFormSection
amountPresets={payExtraAmountPresetValues}
disabled={isInProgress}
/>
<PurchaseSummaryTable
{...purchaseSummaryValues}
isPurchased={isPurchased}
Expand Down