This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include a notice to redirect user to template editor (#9508)
- Loading branch information
1 parent
db5f228
commit 7539964
Showing
5 changed files
with
88 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.wc-default-template-notice.is-dismissible { | ||
margin: 0; | ||
padding-right: 16px; | ||
.components-notice__dismiss { | ||
min-width: 24px; | ||
} | ||
.components-notice__content { | ||
margin: 4px 0; | ||
} | ||
svg { | ||
width: 16px; | ||
height: 16px; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Notice, Button } from '@wordpress/components'; | ||
import { useState } from '@wordpress/element'; | ||
import { isSiteEditorPage } from '@woocommerce/utils'; | ||
import { select } from '@wordpress/data'; | ||
import { getSetting } from '@woocommerce/settings'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './editor.scss'; | ||
|
||
export function TemplateNotice( { block }: { block: string } ) { | ||
const [ settingStatus, setStatus ] = useState( 'pristine' ); | ||
const store = select( 'core/edit-site' ); | ||
|
||
if ( settingStatus === 'dismissed' || isSiteEditorPage( store ) ) { | ||
return null; | ||
} | ||
|
||
const editUrl = `${ getSetting( | ||
'adminUrl' | ||
) }site-editor.php?postType=wp_template&postId=woocommerce%2Fwoocommerce%2F%2F${ block }`; | ||
|
||
const noticeContent = sprintf( | ||
// translators: %s: cart or checkout page name. | ||
__( | ||
'The default %s can be customized in the Site Editor', | ||
'woo-gutenberg-products-block' | ||
), | ||
block === 'checkout' | ||
? __( 'checkout', 'woo-gutenberg-products-block' ) | ||
: __( 'cart', 'woo-gutenberg-products-block' ) | ||
); | ||
|
||
return ( | ||
<Notice | ||
className="wc-default-template-notice" | ||
status={ 'warning' } | ||
onRemove={ () => setStatus( 'dismissed' ) } | ||
spokenMessage={ noticeContent } | ||
> | ||
<> | ||
<p>{ noticeContent }</p> | ||
<Button href={ editUrl } variant="secondary" isSmall={ true }> | ||
{ __( 'Edit template', 'woo-gutenberg-products-block' ) } | ||
</Button> | ||
</> | ||
</Notice> | ||
); | ||
} |
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
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