Skip to content

Instantly share code, notes, and snippets.

@nutterbrand
Created January 3, 2021 04:12
Show Gist options
  • Save nutterbrand/cd52d4348a8c59bd900c1ca426d619ce to your computer and use it in GitHub Desktop.
Save nutterbrand/cd52d4348a8c59bd900c1ca426d619ce to your computer and use it in GitHub Desktop.
pages/index.js Contains resource picker with action to update state
import { EmptyState, Layout, Page } from '@shopify/polaris';
import { ResourcePicker, TitleBar } from '@shopify/app-bridge-react';
const img = 'https://cdn.shopify.com/s/files/1/0757/9955/files/empty-state.svg';
class Index extends React.Component {
state = { open: false };
render() {
return (
<Page>
<TitleBar
title="Sample App"
primaryAction={{
content: 'Select products',
}}
/>
<ResourcePicker
resourceType="Product"
showVariants={false}
open={this.state.open}
onSelection={(resources) => this.handleSelection(resources)}
onCancel={() => this.setState({ open: false })}
/>
<Layout>
<EmptyState
heading="Select products to start"
action={{
content: 'Select products',
onAction: () => this.setState({ open: true }),
}}
image={img}
>
<p>Select products and change their price temporarily</p>
</EmptyState>
</Layout>
</Page >
);
}
handleSelection = (resources) => {
this.setState({ open: false })
console.log(resources)
};
}
export default Index;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment