-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into tweak/blocks-e2e-workflow
- Loading branch information
Showing
13 changed files
with
367 additions
and
31 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
4 changes: 4 additions & 0 deletions
4
packages/js/product-editor/changelog/add-44474_post_publishing_message
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,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Add message after publishing a product to pre-publish panel #44864 |
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
2 changes: 2 additions & 0 deletions
2
packages/js/product-editor/src/components/prepublish-panel/post-publish/index.ts
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,2 @@ | ||
export * from './post-publish-section'; | ||
export * from './post-publish-title'; |
98 changes: 98 additions & 0 deletions
98
...s/js/product-editor/src/components/prepublish-panel/post-publish/post-publish-section.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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement, useState, Fragment } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button, PanelBody, TextControl } from '@wordpress/components'; | ||
import { recordEvent } from '@woocommerce/tracks'; | ||
import { useCopyToClipboard } from '@wordpress/compose'; | ||
import { Ref } from 'react'; | ||
import { getNewPath } from '@woocommerce/navigation'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useProductScheduled } from '../../../hooks/use-product-scheduled'; | ||
import { CopyButtonProps, PostPublishSectionProps } from './types'; | ||
import { TRACKS_SOURCE } from '../../../constants'; | ||
import { useProductURL } from '../../../hooks/use-product-url'; | ||
|
||
export function PostPublishSection( { postType }: PostPublishSectionProps ) { | ||
const { getProductURL } = useProductURL( postType ); | ||
const { isScheduled } = useProductScheduled( postType ); | ||
|
||
const [ showCopyConfirmation, setShowCopyConfirmation ] = | ||
useState< boolean >( false ); | ||
|
||
const productURL = getProductURL( isScheduled ); | ||
|
||
const CopyButton = ( { text, onCopy, children }: CopyButtonProps ) => { | ||
const ref = useCopyToClipboard( | ||
text, | ||
onCopy | ||
) as Ref< HTMLButtonElement >; | ||
return ( | ||
<Button variant="secondary" ref={ ref }> | ||
{ children } | ||
</Button> | ||
); | ||
}; | ||
|
||
const onCopyURL = () => { | ||
recordEvent( 'product_prepublish_panel', { | ||
source: TRACKS_SOURCE, | ||
action: 'copy_product_url', | ||
} ); | ||
setShowCopyConfirmation( true ); | ||
setTimeout( () => { | ||
setShowCopyConfirmation( false ); | ||
}, 4000 ); | ||
}; | ||
|
||
const onSelectInput = ( event: React.FocusEvent< HTMLInputElement > ) => { | ||
event.target.select(); | ||
}; | ||
|
||
return ( | ||
<PanelBody> | ||
<p className="post-publish-section__postpublish-subheader"> | ||
<strong>{ __( 'What’s next?', 'woocommerce' ) }</strong> | ||
</p> | ||
<div className="post-publish-section__postpublish-post-address-container"> | ||
{ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ } | ||
{ /* @ts-ignore TextControl requires an 'onChange' but it's not necessary here. */ } | ||
<TextControl | ||
className="post-publish-section__postpublish-post-address" | ||
readOnly | ||
label={ __( 'product address', 'woocommerce' ) } | ||
value={ productURL } | ||
onFocus={ onSelectInput } | ||
/> | ||
|
||
<div className="post-publish-section__copy-button-wrap"> | ||
<CopyButton text={ productURL } onCopy={ onCopyURL }> | ||
<> | ||
{ showCopyConfirmation | ||
? __( 'Copied!', 'woocommerce' ) | ||
: __( 'Copy', 'woocommerce' ) } | ||
</> | ||
</CopyButton> | ||
</div> | ||
</div> | ||
|
||
<div className="post-publish-section__postpublish-buttons"> | ||
{ ! isScheduled && ( | ||
<Button variant="primary" href={ productURL }> | ||
{ __( 'View Product', 'woocommerce' ) } | ||
</Button> | ||
) } | ||
<Button | ||
variant={ isScheduled ? 'primary' : 'secondary' } | ||
href={ getNewPath( {}, '/add-product', {} ) } | ||
> | ||
{ __( 'Add New Product', 'woocommerce' ) } | ||
</Button> | ||
</div> | ||
</PanelBody> | ||
); | ||
} |
74 changes: 74 additions & 0 deletions
74
...ges/js/product-editor/src/components/prepublish-panel/post-publish/post-publish-title.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { createElement, createInterpolateElement } from '@wordpress/element'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PostPublishTitleProps } from './types'; | ||
import { useProductURL } from '../../../hooks/use-product-url'; | ||
import { useProductScheduled } from '../../../hooks/use-product-scheduled'; | ||
|
||
export function PostPublishTitle( { | ||
productType = 'product', | ||
}: PostPublishTitleProps ) { | ||
const { getProductURL } = useProductURL( productType ); | ||
const { isScheduled, formattedDate } = useProductScheduled( productType ); | ||
const [ editedProductName ] = useEntityProp< string >( | ||
'postType', | ||
productType, | ||
'name' | ||
); | ||
|
||
const productURLString = getProductURL( false ); | ||
const getPostPublishedTitle = () => { | ||
if ( isScheduled ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: %s is the date when the product will be published */ | ||
__( | ||
'<productURL /> is now scheduled. It will go live on %s', | ||
'woocommerce' | ||
), | ||
formattedDate | ||
), | ||
{ | ||
productURL: ( | ||
<a | ||
className="woocommerce-product-list__product-name" | ||
href={ productURLString } | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{ editedProductName } | ||
</a> | ||
), | ||
} | ||
); | ||
} | ||
return createInterpolateElement( | ||
__( '<productURL /> is now live.', 'woocommerce' ), | ||
{ | ||
productURL: ( | ||
<a | ||
className="woocommerce-product-list__product-name" | ||
href={ productURLString } | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{ editedProductName } | ||
</a> | ||
), | ||
} | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="woocommerce-product-publish-panel__published"> | ||
{ getPostPublishedTitle() } | ||
</div> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/js/product-editor/src/components/prepublish-panel/post-publish/types.ts
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,13 @@ | ||
export type PostPublishSectionProps = { | ||
postType: string; | ||
}; | ||
|
||
export type PostPublishTitleProps = { | ||
productType: string; | ||
}; | ||
|
||
export type CopyButtonProps = { | ||
text: string; | ||
onCopy: () => void; | ||
children: JSX.Element; | ||
}; |
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
Oops, something went wrong.