Last active
August 27, 2022 10:38
-
-
Save susimsek/a0a64d624bc72807f91f565b116fcf64 to your computer and use it in GitHub Desktop.
Graphql Product Overview Page
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
const ProductOverview = () => { | |
const { id } = useParams(); | |
const { loading, data, error } = useProductAndReviewsQuery({ | |
variables: { | |
id | |
}, | |
}) | |
if (loading) { | |
return <div className="d-flex justify-content-center"> | |
<Spinner animation="border" role="status"> | |
<span className="visually-hidden">Loading...</span> | |
</Spinner> | |
</div> | |
} | |
if (error) { | |
return <Container>Error...</Container> | |
} | |
return ( | |
<Container> | |
<Row> | |
<Card> | |
<Card.Header className="text-center text-primary">Reviews</Card.Header> | |
<ListGroup variant="flush"> | |
{data.product.reviews.length === 0 && <ListGroup.Item>There are no reviews</ListGroup.Item>} | |
{data.product.reviews.map(review => ( | |
<ListGroup.Item key={review.id}> | |
<> | |
{review.text} | |
<StarRating rating={review.starRating}/> | |
</> | |
</ListGroup.Item> | |
))} | |
</ListGroup> | |
</Card> | |
</Row> | |
</Container> | |
) | |
} | |
export default ProductOverview; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment