Skip to content

Commit

Permalink
include added price/cost in upgraded storage label
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskmnds committed May 30, 2024
1 parent 6d0efd7 commit 04c291d
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,25 +299,6 @@ const PlanSelector = styled.header`
}
`;

const StorageButton = styled.div`
background: #f2f2f2;
border-radius: 5px;
padding: 4px 0;
width: -moz-fit-content;
width: fit-content;
text-align: center;
font-size: 0.75rem;
font-weight: 400;
line-height: 20px;
color: var( --studio-gray-90 );
min-width: 64px;
margin-top: 10px;
${ plansGridMediumLarge( css`
margin-top: 0;
` ) }
`;

const FeatureFootnotes = styled.div`
ol {
margin: 2em 0 0 1em;
Expand Down Expand Up @@ -611,11 +592,7 @@ const ComparisonGridFeatureGroupRowCell: React.FunctionComponent< {
) : (
gridPlan.features.storageOptions.map( ( storageOption ) => {
if ( ! storageOption?.isAddOn ) {
return (
<StorageButton>
<PlanStorageLabel storageOption={ storageOption } planSlug={ planSlug } />
</StorageButton>
);
return <PlanStorageLabel storageOption={ storageOption } planSlug={ planSlug } />;
}
} )
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,72 @@
import { PlanSlug, StorageOption } from '@automattic/calypso-products';
import {
PLAN_BUSINESS,
PLAN_ECOMMERCE,
PlanSlug,
StorageOption,
} from '@automattic/calypso-products';
import { AddOns } from '@automattic/data-stores';
import { formatCurrency } from '@automattic/format-currency';
import classNames from 'classnames';
import { useTranslate } from 'i18n-calypso';
import { usePlansGridContext } from '../../../grid-context';
import useIsLargeCurrency from '../../../hooks/use-is-large-currency';
import useStorageStringFromFeature from '../hooks/use-storage-string-from-feature';

interface Props {
storageOption: StorageOption;
planSlug: PlanSlug;
}

const ELIGIBLE_PLANS_FOR_STORAGE_UPGRADE = [ PLAN_BUSINESS, PLAN_ECOMMERCE ];

const PlanStorageLabel = ( { storageOption, planSlug }: Props ) => {
const { siteId } = usePlansGridContext();
const translate = useTranslate();
const { siteId, gridPlansIndex } = usePlansGridContext();
const currencyCode = gridPlansIndex[ planSlug ].pricing.currencyCode;
const storageStringFromFeature = useStorageStringFromFeature( {
siteId,
storageFeature: storageOption.slug,
planSlug,
} );
const storageAddOns = AddOns.useStorageAddOns( { siteId } );
const storageAddOnsPurchased = storageAddOns.filter( ( addOn ) => addOn?.purchased );
const monthlyAddedCost = storageAddOnsPurchased
? Object.values( storageAddOnsPurchased ).reduce( ( total, addOn ) => {
return total + ( addOn?.prices?.monthlyPrice ?? 0 );
}, 0 )
: 0;
const formattedMonthlyAddedCost =
monthlyAddedCost &&
currencyCode &&
formatCurrency( monthlyAddedCost, currencyCode, { isSmallestUnit: true } );
const isLargeCurrency = useIsLargeCurrency( {
prices: [ monthlyAddedCost ],
isAddOn: true,
currencyCode: currencyCode ?? 'USD',
} );

const containerClasses = classNames( 'plans-grid-next-plan-storage-label__container', {
'is-row': ! isLargeCurrency,
} );

return (
const volumeJSX = (
<div className="plan-features-2023-grid__storage-buttons" key={ storageOption.slug }>
{ storageStringFromFeature }
</div>
);

return formattedMonthlyAddedCost && ELIGIBLE_PLANS_FOR_STORAGE_UPGRADE.includes( planSlug ) ? (
<div className={ containerClasses }>
{ volumeJSX }
<div className="plans-grid-next-plan-storage-label__offset-price">
{ translate( '+ %(formattedMonthlyAddedCost)s/month', {
args: { formattedMonthlyAddedCost },
} ) }
</div>
</div>
) : (
volumeJSX
);
};

export default PlanStorageLabel;
91 changes: 64 additions & 27 deletions packages/plans-grid-next/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -468,19 +468,6 @@ $mobile-card-max-width: 440px;
}
}

.storage-add-on-dropdown__offset-price-container {
width: 100%;
margin-top: 8px;
text-align: left;

.storage-add-on-dropdown__offset-price {
color: var(--studio-green-50);

font-size: 0.75rem;
font-weight: 500;
}
}

.plan-features-2023-grid__content {
.plan-features-2023-grid__table-bottom {
margin-top: 54px;
Expand Down Expand Up @@ -640,20 +627,6 @@ $mobile-card-max-width: 440px;
.plan-features-2023-grid__storage-title {
margin-bottom: 10px;
}

.plan-features-2023-grid__storage-buttons {
background: #f2f2f2;
/* stylelint-disable-next-line */
border-radius: 5px;
padding: 4px 0;
width: fit-content;
text-align: center;
font-size: $font-body-extra-small;
font-weight: 400;
line-height: 20px;
color: var(--studio-gray-90);
min-width: 64px;
}
}

.plan-features-2023-grid__common-title {
Expand Down Expand Up @@ -1069,3 +1042,67 @@ $mobile-card-max-width: 440px;
}
}
}

/**
* Storage Add-On Dropdown parts
*/

.plans-grid-next-plan-storage-label__container {
display: flex;
gap: 5px;
flex-direction: column;
align-items: baseline;

&.is-row {
flex-direction: row;
}

/**
* Comparison grid overrides
* - always render as column/wrapped
*/
.plans-grid-next-comparison-grid & {
flex-direction: column;
align-items: center;
}
}

.plans-grid-next-plan-storage-label__offset-price {
color: var(--studio-green-50);
font-size: $font-body-extra-small;
font-weight: 500;
}

.storage-add-on-dropdown__offset-price-container {
width: 100%;
margin-top: 8px;
text-align: left;

.storage-add-on-dropdown__offset-price {
color: var(--studio-green-50);
font-size: $font-body-extra-small;
font-weight: 500;
}
}

.plan-features-2023-grid__storage-buttons {
background: #f2f2f2;
color: var(--studio-gray-90);
/* stylelint-disable-next-line */
border-radius: 5px;
padding: 4px 0;
text-align: center;
font-size: $font-body-extra-small;
font-weight: 400;
line-height: 20px;
width: fit-content;
min-width: 64px;

.plans-grid-next-comparison-grid & {
margin-top: 10px;

@include plans-grid-medium-large {
margin-top: 0;
}
}
}

0 comments on commit 04c291d

Please sign in to comment.