Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 7d989a5

Browse files
Respect core settings for showing the Checkout block (#7883)
* Respect core settings for showing the Checkout block * Add account creation option from core to checkout context provider * Fix TS errors * Adjust display logic of <LoginPrompt /> * Update assets/js/blocks/checkout/block.tsx Co-authored-by: Mike Jolley <[email protected]> * Rename <LoginPrompt> to <MustLoginPrompt> * Show space between login text and login link * Fix TS error Co-authored-by: Mike Jolley <[email protected]>
1 parent 924c823 commit 7d989a5

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

assets/js/base/components/block-error-boundary/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface BlockErrorBoundaryProps extends BlockErrorBase {
4747
* Override the default error with a function that takes the error message and returns a React component
4848
*/
4949
renderError?: ( props: RenderErrorProps ) => React.ReactNode;
50-
showErrorMessage?: boolean;
50+
showErrorMessage?: boolean | undefined;
5151
}
5252

5353
export interface DerivedStateReturn {

assets/js/base/components/sidebar-layout/style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
margin: 0 auto $gap;
55
position: relative;
66

7+
.wc-block-must-login-prompt {
8+
display: block;
9+
}
10+
711
.wc-block-components-main {
812
box-sizing: border-box;
913
margin: 0;

assets/js/blocks/checkout/block.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ import type { Attributes } from './types';
3535
import { CheckoutBlockContext } from './context';
3636
import { hasNoticesOfType } from '../../utils/notices';
3737

38-
const LoginPrompt = () => {
38+
const MustLoginPrompt = () => {
3939
return (
40-
<>
40+
<div className="wc-block-must-login-prompt">
4141
{ __(
42-
'You must be logged in to checkout. ',
42+
'You must be logged in to checkout.',
4343
'woo-gutenberg-products-block'
44-
) }
44+
) }{ ' ' }
4545
<a href={ LOGIN_TO_CHECKOUT_URL }>
4646
{ __(
4747
'Click here to log in.',
4848
'woo-gutenberg-products-block'
4949
) }
5050
</a>
51-
</>
51+
</div>
5252
);
5353
};
5454

@@ -84,22 +84,29 @@ const Checkout = ( {
8484
return <CheckoutOrderError />;
8585
}
8686

87+
/**
88+
* If checkout requires an account (guest checkout is turned off), render
89+
* a notice and prevent access to the checkout, unless we explicitly allow
90+
* account creation during the checkout flow.
91+
*/
8792
if (
8893
isLoginRequired( customerId ) &&
89-
getSetting( 'checkoutAllowsSignup', false )
94+
! getSetting( 'checkoutAllowsSignup', false )
9095
) {
91-
<LoginPrompt />;
96+
return <MustLoginPrompt />;
9297
}
9398

9499
return (
95100
<CheckoutBlockContext.Provider
96-
value={ {
97-
showCompanyField,
98-
requireCompanyField,
99-
showApartmentField,
100-
showPhoneField,
101-
requirePhoneField,
102-
} }
101+
value={
102+
{
103+
showCompanyField,
104+
requireCompanyField,
105+
showApartmentField,
106+
showPhoneField,
107+
requirePhoneField,
108+
} as Attributes
109+
}
103110
>
104111
{ children }
105112
</CheckoutBlockContext.Provider>

assets/js/settings/shared/default-constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { allSettings } from './settings-init';
99
export const ADMIN_URL = allSettings.adminUrl;
1010
export const COUNTRIES = allSettings.countries;
1111
export const CURRENCY = allSettings.currency;
12-
export const CURRENT_USER_IS_ADMIN = allSettings.currentUserIsAdmin;
12+
export const CURRENT_USER_IS_ADMIN = allSettings.currentUserIsAdmin as boolean;
1313
export const HOME_URL = allSettings.homeUrl;
1414
export const LOCALE = allSettings.locale;
1515
export const ORDER_STATUSES = allSettings.orderStatuses;

0 commit comments

Comments
 (0)