Introduce handleConfirm. Export handlePrompt & handleConfirm from product-editor (#44226)
* Introduce handleConfirm. Export handlePrompt, and handleConfirm from product-editor * Change as requested * Add changelog * Fix onCancel behaviour * Fix lint error --------- Co-authored-by: Lee Willis <lee@ademti-software.co.uk> Co-authored-by: Matt Sherman <matt@jam123.com>
This commit is contained in:
parent
b0ea77326f
commit
b88821f685
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: dev
|
||||
|
||||
Exports handlePrompt from @woocommerce/product-editor for use by extensions expanding the variation quick update menu. Also introduces handleConfirm and exposes it also
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
export type HandleConfirmProps = {
|
||||
message?: string;
|
||||
onOk(): void;
|
||||
onCancel?(): void;
|
||||
};
|
||||
|
||||
export async function handleConfirm( {
|
||||
message = __( 'Are you sure?', 'woocommerce' ),
|
||||
onOk,
|
||||
onCancel,
|
||||
}: HandleConfirmProps ) {
|
||||
// eslint-disable-next-line no-alert
|
||||
if ( window.confirm( message ) ) {
|
||||
onOk?.();
|
||||
return;
|
||||
}
|
||||
|
||||
onCancel?.();
|
||||
}
|
|
@ -20,9 +20,7 @@ export async function handlePrompt( {
|
|||
const value = window.prompt( message, defaultValue );
|
||||
|
||||
if ( value === null ) {
|
||||
if ( onCancel ) {
|
||||
onCancel();
|
||||
}
|
||||
onCancel?.();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ import {
|
|||
import { preventLeavingProductForm } from './prevent-leaving-product-form';
|
||||
import { hasAttributesUsedForVariations } from './has-attributes-used-for-variations';
|
||||
import { isValidEmail } from './validate-email';
|
||||
import { handlePrompt } from './handle-prompt';
|
||||
import { handleConfirm } from './handle-confirm';
|
||||
|
||||
export * from './create-ordered-children';
|
||||
export * from './date';
|
||||
|
@ -45,6 +47,8 @@ export {
|
|||
getProductTitle,
|
||||
getProductVariationTitle,
|
||||
getTruncatedProductVariationTitle,
|
||||
handleConfirm,
|
||||
handlePrompt,
|
||||
hasAttributesUsedForVariations,
|
||||
isValidEmail,
|
||||
preventLeavingProductForm,
|
||||
|
|
Loading…
Reference in New Issue