Add manual stock management section to product management experience (#35047)
* Add manual stock management section to product management experience * Add changelog entry * Add default value for stock status * Fix up lint issues * Handle PR feedback
This commit is contained in:
parent
114be56f63
commit
3a2a22905b
|
@ -28,7 +28,7 @@ const AddProductPage: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<div className="woocommerce-add-product">
|
<div className="woocommerce-add-product">
|
||||||
<Form< Partial< Product > >
|
<Form< Partial< Product > >
|
||||||
initialValues={ { stock_quantity: 0 } }
|
initialValues={ { stock_quantity: 0, stock_status: 'instock' } }
|
||||||
errors={ {} }
|
errors={ {} }
|
||||||
validate={ validate }
|
validate={ validate }
|
||||||
>
|
>
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
max-width: 1032px;
|
max-width: 1032px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
||||||
h4 {
|
h4,
|
||||||
|
.components-radio-control .components-base-control__label {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin-bottom: 18px;
|
margin-bottom: 18px;
|
||||||
margin-top: 26px;
|
margin-top: 26px;
|
||||||
|
text-transform: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.components-card__body h4:first-child {
|
.components-card__body h4:first-child {
|
||||||
|
|
|
@ -15,11 +15,15 @@
|
||||||
|
|
||||||
.components-base-control,
|
.components-base-control,
|
||||||
.woocommerce-rich-text-editor {
|
.woocommerce-rich-text-editor {
|
||||||
&:not(:first-child) {
|
&:not(:first-child):not(.components-radio-control) {
|
||||||
margin-top: $gap-large - $gap-smaller;
|
margin-top: $gap-large - $gap-smaller;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.components-radio-control .components-v-stack {
|
||||||
|
gap: $gap-small;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__header {
|
&__header {
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { RadioControl } from '@wordpress/components';
|
||||||
|
import { useFormContext } from '@woocommerce/components';
|
||||||
|
import { Product } from '@woocommerce/data';
|
||||||
|
|
||||||
|
export const ManualStockSection: React.FC = () => {
|
||||||
|
const { getInputProps } = useFormContext< Product >();
|
||||||
|
const inputProps = getInputProps( 'stock_status' );
|
||||||
|
// These properties cause issues with the RadioControl component.
|
||||||
|
// A fix to form upstream would help if we can identify what type of input is used.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
delete inputProps.checked;
|
||||||
|
delete inputProps.value;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<RadioControl
|
||||||
|
label={ __( 'Stock status', 'woocommerce' ) }
|
||||||
|
options={ [
|
||||||
|
{
|
||||||
|
label: __( 'In stock', 'woocommerce' ),
|
||||||
|
value: 'instock',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: __( 'Out of stock', 'woocommerce' ),
|
||||||
|
value: 'outofstock',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: __( 'On backorder', 'woocommerce' ),
|
||||||
|
value: 'onbackorder',
|
||||||
|
},
|
||||||
|
] }
|
||||||
|
{ ...inputProps }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
|
@ -20,6 +20,7 @@ import { getCheckboxProps, getTextControlProps } from '../utils';
|
||||||
import { getAdminSetting } from '~/utils/admin-settings';
|
import { getAdminSetting } from '~/utils/admin-settings';
|
||||||
import { ProductSectionLayout } from '../../layout/product-section-layout';
|
import { ProductSectionLayout } from '../../layout/product-section-layout';
|
||||||
import { ManageStockSection } from './manage-stock-section';
|
import { ManageStockSection } from './manage-stock-section';
|
||||||
|
import { ManualStockSection } from './manual-stock-section';
|
||||||
|
|
||||||
export const ProductInventorySection: React.FC = () => {
|
export const ProductInventorySection: React.FC = () => {
|
||||||
const { getInputProps, values } = useFormContext< Product >();
|
const { getInputProps, values } = useFormContext< Product >();
|
||||||
|
@ -82,6 +83,7 @@ export const ProductInventorySection: React.FC = () => {
|
||||||
{ values.manage_stock && <ManageStockSection /> }
|
{ values.manage_stock && <ManageStockSection /> }
|
||||||
</>
|
</>
|
||||||
) }
|
) }
|
||||||
|
{ ! values.manage_stock && <ManualStockSection /> }
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
</ProductSectionLayout>
|
</ProductSectionLayout>
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add manual stock management section to product management experience
|
Loading…
Reference in New Issue