Created
July 15, 2020 16:06
-
-
Save fsgreco/38227d2d43d2d8714cc7e49431ddcc77 to your computer and use it in GitHub Desktop.
products.js component with the new Stripe API v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { graphql, StaticQuery } from 'gatsby' | |
import Product from './product.js' | |
const PRODUCTS_QUERY = graphql` | |
query allProducts { | |
allStripePrice(filter: {active: {eq: true}}) { | |
edges { | |
node { | |
nickname | |
unit_amount | |
id | |
product { | |
id | |
} | |
} | |
} | |
} | |
allStripeProduct(filter: {active: {eq: true}}) { | |
edges { | |
node { | |
id | |
name | |
images | |
} | |
} | |
} | |
} | |
` | |
const Products = () => ( | |
<StaticQuery query={PRODUCTS_QUERY} render={ | |
data => { | |
const { allStripePrice, allStripeProduct } = data | |
return allStripeProduct.edges.map( ({node}) => { | |
const productId = node.id | |
const priceVariation = allStripePrice.edges.filter(({ node }) => productId === node.product.id ) | |
return ( | |
<Product key={node.id} | |
item={node} | |
prices={priceVariation} | |
/> | |
) | |
}) | |
} | |
} | |
/> | |
) | |
export default Products |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment