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:
parent
652e7648f8
commit
40a410ae1f
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Remove empty values from the shipping class request so slug can be generated server side
|
|
@ -86,7 +86,7 @@ export function Edit( {
|
|||
|
||||
const [ categories ] = useEntityProp< PartialProduct[ 'categories' ] >(
|
||||
'postType',
|
||||
'product',
|
||||
context.postType,
|
||||
'categories'
|
||||
);
|
||||
const [ shippingClass, setShippingClass ] = useEntityProp< string >(
|
||||
|
|
|
@ -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 >;
|
||||
|
|
Loading…
Reference in New Issue