-
Notifications
You must be signed in to change notification settings - Fork 45
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
feat(reader-revenue): make NYP and Stripe Gateway optional #1645
Changes from 4 commits
79c2612
db8797e
c7c5b5c
bb3b2e1
9f528b8
a991eb8
a985f00
308181d
3701068
42e145b
3a15ae5
5f9479a
977db4b
2b65371
c388896
5b8470c
9f041db
8c01e69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) = | |
}, [ attributes.defaultFrequency ] ); | ||
|
||
const [ selectedFrequency, setSelectedFrequency ] = useState( attributes.defaultFrequency ); | ||
|
||
const canUseNameYourPrice = window.newspack_blocks_data?.can_use_name_your_price; | ||
const renderFrequencySelect = ( frequencySlug: DonationFrequencySlug ) => ( | ||
<> | ||
<input | ||
|
@@ -89,38 +89,75 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) = | |
</button> | ||
); | ||
|
||
const getFrequencyLabel = ( frequencySlug: DonationFrequencySlug ) => { | ||
switch ( frequencySlug ) { | ||
case 'once': | ||
return ''; | ||
case 'month': | ||
return __( ' per month', 'newspack-blocks' ); | ||
case 'year': | ||
return __( ' per year', 'newspack-blocks' ); | ||
} | ||
}; | ||
|
||
// This code is fired on tab select and updates aria elements, tabindex states, and radio buttons | ||
const displayAmount = ( amount: number ) => amount.toFixed( 2 ).replace( /\.?0*$/, '' ); | ||
|
||
const renderUntieredForm = () => ( | ||
<div className="wp-block-newspack-blocks-donate__options"> | ||
<div className="wp-block-newspack-blocks-donate__frequencies frequencies"> | ||
<div className="tab-container">{ availableFrequencies.map( renderTab ) }</div> | ||
{ availableFrequencies.map( frequencySlug => ( | ||
<div | ||
className="wp-block-newspack-blocks-donate__frequency frequency" | ||
key={ frequencySlug } | ||
> | ||
{ renderFrequencySelect( frequencySlug ) } | ||
<div className="input-container"> | ||
<label | ||
className="donate-label" | ||
htmlFor={ 'newspack-' + frequencySlug + '-' + uid + '-untiered-input' } | ||
> | ||
{ __( 'Donation amount', 'newspack-blocks' ) } | ||
</label> | ||
<div className="wp-block-newspack-blocks-donate__money-input money-input"> | ||
<span className="currency">{ settings.currencySymbol }</span> | ||
<AmountValueInput | ||
{ ...props } | ||
frequencySlug={ frequencySlug } | ||
tierIndex={ 3 } | ||
id={ `newspack-${ frequencySlug }-${ uid }-untiered-input` } | ||
/> | ||
{ availableFrequencies.map( frequencySlug => { | ||
const untieredAmount = amounts[ frequencySlug ][ 3 ]; | ||
return ( | ||
<div | ||
className="wp-block-newspack-blocks-donate__frequency frequency" | ||
key={ frequencySlug } | ||
> | ||
{ renderFrequencySelect( frequencySlug ) } | ||
<div className="input-container"> | ||
{ canUseNameYourPrice ? ( | ||
<> | ||
<label | ||
className="donate-label" | ||
htmlFor={ 'newspack-' + frequencySlug + '-' + uid + '-untiered-input' } | ||
> | ||
{ __( 'Donation amount', 'newspack-blocks' ) } | ||
</label> | ||
<div className="wp-block-newspack-blocks-donate__money-input money-input"> | ||
<span className="currency">{ settings.currencySymbol }</span> | ||
<AmountValueInput | ||
{ ...props } | ||
frequencySlug={ frequencySlug } | ||
tierIndex={ 3 } | ||
id={ `newspack-${ frequencySlug }-${ uid }-untiered-input` } | ||
/> | ||
</div> | ||
</> | ||
) : ( | ||
<> | ||
<input | ||
type="radio" | ||
value={ untieredAmount } | ||
className={ 'frequency-input' } | ||
id={ `newspack-${ frequencySlug }-${ uid }-untiered-input` } | ||
name={ `donation_value_${ frequencySlug }` } | ||
defaultChecked={ true } | ||
/> | ||
<label | ||
className="tier-select-label tier-label" | ||
htmlFor={ `newspack-${ frequencySlug }-${ uid }-untiered-input` } | ||
> | ||
{ settings.currencySymbol + | ||
untieredAmount.toFixed( 2 ).replace( /\.?0*$/, '' ) + | ||
getFrequencyLabel( frequencySlug ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this might cause an issue for languages where the amount should not precede the per month/year text? Might be a better idea to have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, although I had some trouble conceptualizing how we'd translate such a string when it has to include HTML tags for styling, too. 3701068 is my best attempt—how's it look? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @dkoo! I left some additional review comments for this 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great suggestions here! Thank you for the guidance on this part—admittedly our work around making sure things are translatable has been lacking. 😅 |
||
</label> | ||
</> | ||
) } | ||
</div> | ||
</div> | ||
</div> | ||
) ) } | ||
); | ||
} ) } | ||
</div> | ||
</div> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: is it necessary to create a variable here considering this is only used in one place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, not necessary—updated in 42e145b.