-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include added price/cost in upgraded storage label
- Loading branch information
1 parent
6d0efd7
commit 04c291d
Showing
3 changed files
with
115 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 50 additions & 3 deletions
53
packages/plans-grid-next/src/components/storage/components/plan-storage-label.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters