| | import { EXAMPLE_FLOW, NEW_HOSTED_SITE_FLOW } from '@automattic/onboarding'; |
| | import validUrl from 'valid-url'; |
| |
|
| | |
| | |
| | export const backUrlExternalSourceStepsOverrides = [ 'use-your-domain' ]; |
| |
|
| | |
| | export const backUrlSourceOverrides = { |
| | 'business-name-generator': '/business-name-generator', |
| | domains: '/domains', |
| | }; |
| |
|
| | export function getExternalBackUrl( source, sectionName = null ) { |
| | if ( ! source ) { |
| | return false; |
| | } |
| |
|
| | if ( backUrlSourceOverrides[ source ] ) { |
| | return backUrlSourceOverrides[ source ]; |
| | } |
| |
|
| | if ( |
| | backUrlExternalSourceStepsOverrides.includes( sectionName ) && |
| | validUrl.isWebUri( source ) |
| | ) { |
| | return source; |
| | } |
| |
|
| | return false; |
| | } |
| |
|
| | |
| | |
| | |
| | export function shouldUseMultipleDomainsInCart( flowName ) { |
| | const enabledFlows = [ |
| | 'domain', |
| | 'onboarding', |
| | 'domains', |
| | 'domains/add', |
| | EXAMPLE_FLOW, |
| | NEW_HOSTED_SITE_FLOW, |
| | ]; |
| |
|
| | return enabledFlows.includes( flowName ); |
| | } |
| |
|
| | export function sortProductsByPriceDescending( productsInCart ) { |
| | |
| | const getSortingValue = ( product ) => { |
| | if ( product.item_subtotal_integer !== 0 ) { |
| | return product.item_subtotal_integer; |
| | } |
| |
|
| | |
| | const nonZeroPrices = |
| | product.cost_overrides |
| | ?.map( ( override ) => override.new_price * 100 ) |
| | .filter( ( price ) => price > 0 ) || []; |
| |
|
| | return nonZeroPrices.length ? Math.min( ...nonZeroPrices ) : product.item_original_cost_integer; |
| | }; |
| |
|
| | return productsInCart.sort( ( a, b ) => { |
| | return getSortingValue( b ) - getSortingValue( a ); |
| | } ); |
| | } |
| |
|