Skip to content
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
2 changes: 1 addition & 1 deletion packages/contexts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { useThemeContext, ThemeContext, ThemeProvider } from './theme';
export { useThemeContext, ThemeContext, ThemeProvider, isThemeV2Enabled } from './theme';
export {
AnalyticsContext,
AnalyticsProvider,
Expand Down
15 changes: 2 additions & 13 deletions packages/contexts/src/theme/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { type ReactNode } from 'react';

import { useCheckout } from '../checkout';

import { isThemeV2Enabled } from './isThemeV2Enabled';
import ThemeContext from './ThemeContext';

export interface ThemeProviderProps {
Expand All @@ -11,19 +12,7 @@ export interface ThemeProviderProps {
export const ThemeProvider = ({ children }: ThemeProviderProps) => {
const { selectedState: config } = useCheckout((state) => state.data.getConfig());

let themeV2 = false;

if (config?.checkoutSettings) {
const newThemeExperimentEnabled = Boolean(
config.checkoutSettings.features['CHECKOUT-7962.update_font_style_on_checkout_page'] ??
true,
);
const newThemeSettingEnabled = Boolean(
config.checkoutSettings.checkoutUserExperienceSettings.checkoutV2Theme ?? false,
);

themeV2 = newThemeSettingEnabled && newThemeExperimentEnabled;
}
const themeV2 = isThemeV2Enabled(config);

return <ThemeContext.Provider value={{ themeV2 }}>{children}</ThemeContext.Provider>;
};
1 change: 1 addition & 0 deletions packages/contexts/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as ThemeContext, useThemeContext } from './ThemeContext';
export { ThemeProvider } from './ThemeProvider';
export { isThemeV2Enabled } from './isThemeV2Enabled';
17 changes: 17 additions & 0 deletions packages/contexts/src/theme/isThemeV2Enabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type StoreConfig } from '@bigcommerce/checkout-sdk/essential';

export const isThemeV2Enabled = (config?: StoreConfig): boolean => {
if (!config?.checkoutSettings) {
return false;
}

const newThemeExperimentEnabled = Boolean(
config.checkoutSettings.features['CHECKOUT-7962.update_font_style_on_checkout_page'] ??
true,
);
Comment on lines +8 to +11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use isExperimentEnabled()?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest looks good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot actually do that because isExperimentEnabled() is part of core package and using it here will result in circular dependency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. A separate task, isExperimentEnabled() needs to be out of core. 😂

const newThemeSettingEnabled = Boolean(
config.checkoutSettings.checkoutUserExperienceSettings.checkoutV2Theme ?? false,
);

return newThemeSettingEnabled && newThemeExperimentEnabled;
};
4 changes: 2 additions & 2 deletions packages/core/src/app/checkout/CheckoutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,13 @@ const Checkout = ({
(isBillingSameAsShipping: boolean): void => {
setState((prev) => ({ ...prev, isBillingSameAsShipping }));

if (isBillingSameAsShipping) {
if (isBillingSameAsShipping || themeV2) {
navigateToNextIncompleteStep();
} else {
navigateToStep(CheckoutStepType.Billing);
}
},
[navigateToNextIncompleteStep, navigateToStep],
[navigateToNextIncompleteStep, navigateToStep, themeV2],
);

const handleBillingSameAsShippingChange = useCallback(
Expand Down
43 changes: 43 additions & 0 deletions packages/core/src/app/checkout/getCheckoutStepStatuses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,49 @@ describe('getCheckoutStepStatuses()', () => {
]);
});

describe('themeV2 (billing captured on the payment step)', () => {
const getThemeV2Config = () => ({
...getStoreConfig(),
checkoutSettings: {
...getStoreConfig().checkoutSettings,
features: {
...getStoreConfig().checkoutSettings.features,
'CHECKOUT-7962.update_font_style_on_checkout_page': true,
},
checkoutUserExperienceSettings: {
...getStoreConfig().checkoutSettings.checkoutUserExperienceSettings,
checkoutV2Theme: true,
},
},
});

beforeEach(() => {
jest.spyOn(state.data, 'getConfig').mockReturnValue(getThemeV2Config());
});

it('omits the standalone billing step', () => {
expect(
find(getCheckoutStepStatuses(state), { type: CheckoutStepType.Billing }),
).toBeUndefined();
});

it('returns the remaining steps in order without billing', () => {
expect(getCheckoutStepStatuses(state).map((step) => step.type)).toEqual([
CheckoutStepType.Customer,
CheckoutStepType.Shipping,
CheckoutStepType.Payment,
]);
});

it('still omits the billing step when a wallet payment (e.g. Amazon Pay) is present', () => {
jest.spyOn(state.data, 'getCheckout').mockReturnValue(getCheckoutWithPayments());

expect(
find(getCheckoutStepStatuses(state), { type: CheckoutStepType.Billing }),
).toBeUndefined();
});
});

it('marks latter steps as non-editable if earlier steps are incomplete', () => {
jest.spyOn(state.data, 'getShippingAddress').mockReturnValue(undefined);

Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/app/checkout/getCheckoutStepStatuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type CheckoutPayment, type CheckoutSelectors } from '@bigcommerce/check
import { compact } from 'lodash';
import { createSelector } from 'reselect';

import { isThemeV2Enabled } from '@bigcommerce/checkout/contexts';
import { shouldUseStripeLinkByMinimumAmount } from '@bigcommerce/checkout/instrument-utils';

import { isValidAddress } from '../address';
Expand Down Expand Up @@ -96,7 +97,11 @@ const getBillingStepStatus = createSelector(
: EMPTY_ARRAY;
},
({ data }: CheckoutSelectors) => data.getConfig(),
(checkout, billingAddress, billingAddressFields) => {
(checkout, billingAddress, billingAddressFields, config) => {
if (isThemeV2Enabled(config)) {
return undefined;
}

const hasAddress = billingAddress
? isValidAddress(billingAddress, billingAddressFields)
: false;
Expand Down