Product Shipping: New class should automatically create a slug (#40847)

* Remove empty values from the shipping class request so slug can be generated server side

* Add changelog file
This commit is contained in:
Maikel David Pérez Gómez 2023-10-18 13:04:14 -04:00 committed by GitHub
parent 652e7648f8
commit 40a410ae1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Remove empty values from the shipping class request so slug can be generated server side

View File

@ -86,7 +86,7 @@ export function Edit( {
const [ categories ] = useEntityProp< PartialProduct[ 'categories' ] >(
'postType',
'product',
context.postType,
'categories'
);
const [ shippingClass, setShippingClass ] = useEntityProp< string >(

View File

@ -111,6 +111,21 @@ export function AddNewShippingClassModal( {
onAdd,
onCancel,
}: AddNewShippingClassModalProps ) {
function handleSubmit( values: Partial< ProductShippingClass > ) {
return onAdd(
Object.entries( values ).reduce( function removeEmptyValue(
current,
[ name, value ]
) {
return {
...current,
[ name ]: value === '' ? undefined : value,
};
},
{} )
);
}
return (
<Modal
title={ __( 'New shipping class', 'woocommerce' ) }
@ -121,7 +136,7 @@ export function AddNewShippingClassModal( {
initialValues={ shippingClass ?? INITIAL_VALUES }
validate={ validateForm }
errors={ {} }
onSubmit={ onAdd }
onSubmit={ handleSubmit }
>
{ ( childrenProps: {
handleSubmit: () => Promise< ProductShippingClass >;