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:
Lee Willis 2024-03-19 18:11:14 +00:00 committed by GitHub
parent b0ea77326f
commit b88821f685
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 3 deletions

View File

@ -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

View File

@ -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?.();
}

View File

@ -20,9 +20,7 @@ export async function handlePrompt( {
const value = window.prompt( message, defaultValue );
if ( value === null ) {
if ( onCancel ) {
onCancel();
}
onCancel?.();
return;
}

View File

@ -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,