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

Admin page: Fix pricing/currency displayed on the upgrade page #21594

Merged
merged 3 commits into from
Nov 1, 2021
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 @@ -10,9 +10,9 @@ import { isEmpty } from 'lodash';
/**
* Internal dependencies
*/
import QuerySiteProducts from 'components/data/query-site-products';
import QueryProducts from 'components/data/query-products';
import { JetpackLoadingIcon } from 'components/jetpack-loading-icon';
import { isFetchingSiteProducts } from 'state/site-products';
import { isFetchingProducts as isFetchingProductsSelector } from 'state/products';
import { arePromotionsActive, getProductsForPurchase } from 'state/initial-state';
import { PRODUCT_DESCRIPTION_PRODUCTS as SUPPORTED_PRODUCTS } from './constants';
import ProductDescription from './product-description';
Expand Down Expand Up @@ -49,7 +49,7 @@ const ProductDescriptions = props => {

return (
<>
<QuerySiteProducts />
<QueryProducts />
{ isLoading ? (
<div className="jp-product-descriptions__loading">
<JetpackLoadingIcon />
Expand All @@ -70,6 +70,6 @@ ProductDescriptions.propTypes = {

export default connect( state => ( {
arePromotionsActive: arePromotionsActive( state ),
isFetchingProducts: isFetchingSiteProducts( state ),
isFetchingProducts: isFetchingProductsSelector( state ),
products: getProductsForPurchase( state ),
} ) )( ProductDescriptions );
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function buildInitialState() {
}
}
},
siteProducts: {
products: {
"items": {
"jetpack_security_daily": {
"product_slug": "jetpack_security_daily",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getRedirectUrl } from '@automattic/jetpack-components';
*/
import { JETPACK_SET_INITIAL_STATE, MOCK_SWITCH_USER_PERMISSIONS } from 'state/action-types';
import { getPlanDuration } from 'state/plans/reducer';
import { getSiteProducts } from 'state/site-products';
import { getProducts } from 'state/products';
import { isCurrentUserLinked } from 'state/connection';

export const initialState = ( state = window.Initial_State, action ) => {
Expand Down Expand Up @@ -474,7 +474,7 @@ export const getUpgradeUrl = ( state, source, userId = '', planDuration = false
*/
export function getProductsForPurchase( state ) {
const staticProducts = get( state.jetpack.initialState, 'products', {} );
const siteProducts = getSiteProducts( state );
const jetpackProducts = getProducts( state );
const products = {};

for ( const [ key, product ] of Object.entries( staticProducts ) ) {
Expand All @@ -484,12 +484,12 @@ export function getProductsForPurchase( state ) {
key: key,
description: product.description,
features: product.features,
available: get( siteProducts, [ product.slug, 'available' ], false ),
currencyCode: get( siteProducts, [ product.slug, 'currency_code' ], '' ),
available: get( jetpackProducts, [ product.slug, 'available' ], false ),
currencyCode: get( jetpackProducts, [ product.slug, 'currency_code' ], '' ),
showPromotion: product.show_promotion,
promotionPercentage: product.discount_percent,
includedInPlans: product.included_in_plans,
fullPrice: get( siteProducts, [ product.slug, 'cost' ], '' ),
fullPrice: get( jetpackProducts, [ product.slug, 'cost' ], '' ),
upgradeUrl: getRedirectUrl( 'jetpack-product-description-checkout', {
path: product.slug,
} ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Fixes the prices and currencies to be based on user's preferences on the WPA upgrade page.