Skip to content

Commit

Permalink
Set product status after publishing (#45436)
Browse files Browse the repository at this point in the history
* Set product status after publishing

* Refactor save

* Add changelog

* Remove comment

* Rename select alias
  • Loading branch information
octaedro authored and Konamiman committed Mar 13, 2024
1 parent 1683c84 commit 622eb7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Set product status after publishing #45436
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { dispatch, useSelect } from '@wordpress/data';
import { dispatch, useSelect, select as wpSelect } from '@wordpress/data';
import { useState } from '@wordpress/element';
import type { Product, ProductStatus } from '@woocommerce/data';

Expand Down Expand Up @@ -70,17 +70,21 @@ export function useProductManager< T = Product >( postType: string ) {
setIsSaving( true );

await validate( extraProps );
const { saveEntityRecord } = dispatch( 'core' );

// @ts-expect-error There are no types for this.
const { editEntityRecord, saveEditedEntityRecord } =
dispatch( 'core' );

await editEntityRecord< T >( 'postType', postType, id, extraProps );
const { blocks, content, selection, ...editedProduct } = wpSelect(
'core'
// @ts-expect-error There are no types for this.
).getEditedEntityRecord( 'postType', postType, id );

const savedProduct = await saveEditedEntityRecord< T >(
const savedProduct = await saveEntityRecord(
'postType',
postType,
id,
{
...editedProduct,
...extraProps,
},
// @ts-expect-error There are no types for this.
{
throwOnError: true,
}
Expand Down

0 comments on commit 622eb7c

Please sign in to comment.