Created
April 17, 2023 03:36
-
-
Save RAAbbott/24f10ebaf90c76c571501af3a820328a to your computer and use it in GitHub Desktop.
Code for `index.jsx` file for your Checkout UI Extension used in my video here: https://youtu.be/FDLoz__VKVk
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 { | |
render, | |
BlockStack, | |
InlineStack, | |
Text, | |
View, | |
Image, | |
Heading, | |
useAppMetafields, | |
} from "@shopify/checkout-ui-extensions-react"; | |
render("Checkout::Dynamic::Render", () => <App />); | |
function App() { | |
const metafields = useAppMetafields({ | |
type: "shop", | |
key: "review", | |
namespace: "featured-review", | |
}); | |
const featuredReview = metafields.length | |
? JSON.parse(metafields[0]?.metafield?.value) | |
: null; | |
if (featuredReview) { | |
return ( | |
<BlockStack> | |
<Heading>What customers are saying</Heading> | |
<BlockStack | |
border="base" | |
padding="loose" | |
spacing="tight" | |
borderRadius="large" | |
> | |
<InlineStack blockAlignment="center" spacing="tight"> | |
<Heading level="3">{featuredReview.customerName}</Heading> | |
<View maxInlineSize="15%" padding="extraTight"> | |
<Image | |
fit="contain" | |
source="https://res.cloudinary.com/dci7ukl75/image/upload/v1680446609/istockphoto-1140391316-612x612_vlgprt.png" | |
/> | |
</View> | |
</InlineStack> | |
<Text>{featuredReview.reviewText}</Text> | |
</BlockStack> | |
</BlockStack> | |
); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment