Update experimental-products to load sample products
This commit is contained in:
parent
4221c32fa4
commit
570d6dad71
|
@ -7,6 +7,7 @@ import { Text } from '@woocommerce/experimental';
|
||||||
import { registerPlugin } from '@wordpress/plugins';
|
import { registerPlugin } from '@wordpress/plugins';
|
||||||
import { useMemo, useState } from '@wordpress/element';
|
import { useMemo, useState } from '@wordpress/element';
|
||||||
import { Button } from '@wordpress/components';
|
import { Button } from '@wordpress/components';
|
||||||
|
import { getAdminLink } from '@woocommerce/settings';
|
||||||
import { Icon, chevronDown, chevronUp } from '@wordpress/icons';
|
import { Icon, chevronDown, chevronUp } from '@wordpress/icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +21,8 @@ import Stack from './stack';
|
||||||
import Footer from './footer';
|
import Footer from './footer';
|
||||||
import CardLayout from './card-layout';
|
import CardLayout from './card-layout';
|
||||||
import { LoadSampleProductType } from './constants';
|
import { LoadSampleProductType } from './constants';
|
||||||
|
import LoadSampleProductModal from '../components/load-sample-product-modal';
|
||||||
|
import useLoadSampleProducts from '../components/use-load-sample-products';
|
||||||
|
|
||||||
// TODO: Use experiment data from the API, not hardcoded.
|
// TODO: Use experiment data from the API, not hardcoded.
|
||||||
const SHOW_STACK_LAYOUT = true;
|
const SHOW_STACK_LAYOUT = true;
|
||||||
|
@ -54,6 +57,14 @@ export const Products = () => {
|
||||||
const surfacedProductTypeKeys = getSurfacedProductTypeKeys(
|
const surfacedProductTypeKeys = getSurfacedProductTypeKeys(
|
||||||
getOnboardingProductType()
|
getOnboardingProductType()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
loadSampleProduct,
|
||||||
|
isLoadingSampleProducts,
|
||||||
|
} = useLoadSampleProducts( {
|
||||||
|
redirectUrlAfterSuccess: getAdminLink( 'edit.php?post_type=product' ),
|
||||||
|
} );
|
||||||
|
|
||||||
const visibleProductTypes = useMemo( () => {
|
const visibleProductTypes = useMemo( () => {
|
||||||
const surfacedProductTypes = productTypes.filter( ( productType ) =>
|
const surfacedProductTypes = productTypes.filter( ( productType ) =>
|
||||||
surfacedProductTypeKeys.includes( productType.key )
|
surfacedProductTypeKeys.includes( productType.key )
|
||||||
|
@ -69,13 +80,17 @@ export const Products = () => {
|
||||||
if ( ! SHOW_STACK_LAYOUT ) {
|
if ( ! SHOW_STACK_LAYOUT ) {
|
||||||
surfacedProductTypes.push( {
|
surfacedProductTypes.push( {
|
||||||
...LoadSampleProductType,
|
...LoadSampleProductType,
|
||||||
// TODO: Change to load sample product
|
onClick: loadSampleProduct,
|
||||||
onClick: () => new Promise( () => {} ),
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return surfacedProductTypes;
|
return surfacedProductTypes;
|
||||||
}, [ surfacedProductTypeKeys, isExpanded, productTypes ] );
|
}, [
|
||||||
|
surfacedProductTypeKeys,
|
||||||
|
isExpanded,
|
||||||
|
productTypes,
|
||||||
|
loadSampleProduct,
|
||||||
|
] );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="woocommerce-task-products">
|
<div className="woocommerce-task-products">
|
||||||
|
@ -89,7 +104,10 @@ export const Products = () => {
|
||||||
|
|
||||||
<div className="woocommerce-product-content">
|
<div className="woocommerce-product-content">
|
||||||
{ SHOW_STACK_LAYOUT ? (
|
{ SHOW_STACK_LAYOUT ? (
|
||||||
<Stack items={ visibleProductTypes } />
|
<Stack
|
||||||
|
items={ visibleProductTypes }
|
||||||
|
onClickLoadSampleProduct={ loadSampleProduct }
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<CardLayout items={ visibleProductTypes } />
|
<CardLayout items={ visibleProductTypes } />
|
||||||
) }
|
) }
|
||||||
|
@ -99,6 +117,7 @@ export const Products = () => {
|
||||||
/>
|
/>
|
||||||
<Footer />
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
|
{ isLoadingSampleProducts && <LoadSampleProductModal /> }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,9 +17,13 @@ type StackProps = {
|
||||||
items: ( ProductType & {
|
items: ( ProductType & {
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
} )[];
|
} )[];
|
||||||
|
onClickLoadSampleProduct: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Stack: React.FC< StackProps > = ( { items } ) => {
|
const Stack: React.FC< StackProps > = ( {
|
||||||
|
items,
|
||||||
|
onClickLoadSampleProduct,
|
||||||
|
} ) => {
|
||||||
return (
|
return (
|
||||||
<div className="woocommerce-products-stack">
|
<div className="woocommerce-products-stack">
|
||||||
<List items={ items } />
|
<List items={ items } />
|
||||||
|
@ -46,7 +50,14 @@ const Stack: React.FC< StackProps > = ( { items } ) => {
|
||||||
),
|
),
|
||||||
LspLink: (
|
LspLink: (
|
||||||
// TODO: Update this to the load sample product.
|
// TODO: Update this to the load sample product.
|
||||||
<Link href="" type="wc-admin">
|
<Link
|
||||||
|
href=""
|
||||||
|
type="wc-admin"
|
||||||
|
onClick={ () => {
|
||||||
|
onClickLoadSampleProduct();
|
||||||
|
return false;
|
||||||
|
} }
|
||||||
|
>
|
||||||
<></>
|
<></>
|
||||||
</Link>
|
</Link>
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue