-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4018a98
commit 4741173
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* | ||
* ReviewItem | ||
* | ||
*/ | ||
import React, { memo } from 'react'; | ||
import styled from 'styled-components/macro'; | ||
import { Review } from '../../../api/types/review'; | ||
import { | ||
Avatar, | ||
ListItem, | ||
ListItemAvatar, | ||
ListItemText, | ||
Typography, | ||
} from '@material-ui/core'; | ||
import { Images } from '../../../images'; | ||
import { Rating } from '@material-ui/lab'; | ||
|
||
interface Props { | ||
review: Review; | ||
} | ||
|
||
const OwnerAvatar = styled(Avatar)` | ||
height: 30px; | ||
width: 30px; | ||
`; | ||
|
||
const RatingWrapper = styled.div` | ||
flex-direction: column; | ||
`; | ||
|
||
export const ReviewItem = memo( | ||
({ review: { createDate, owner, rating, title } }: Props) => { | ||
return ( | ||
<ListItem> | ||
<ListItemAvatar> | ||
<OwnerAvatar src={owner.image ?? Images.userPlaceHolder} /> | ||
</ListItemAvatar> | ||
<ListItemText primary={owner.fullName} /> | ||
<RatingWrapper> | ||
<Typography variant={'caption'}>{createDate}</Typography> | ||
<Rating value={rating} size="large" readOnly={true} /> | ||
<Typography variant={'body1'}>{title}</Typography> | ||
</RatingWrapper> | ||
</ListItem> | ||
); | ||
}, | ||
({ review: oldReview }, { review: newReview }) => | ||
oldReview.id === newReview.id, | ||
); |
32 changes: 32 additions & 0 deletions
32
src/app/pages/Products/ProductDetails/ProductReviews/index.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* | ||
* ProductReviews | ||
* | ||
*/ | ||
import * as React from 'react'; | ||
import styled from 'styled-components/macro'; | ||
import { useProductReviews } from '../../hooks'; | ||
import { ReviewItem } from '../../../../components/ReviewItem'; | ||
|
||
interface Props { | ||
productId: string; | ||
} | ||
|
||
const List = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
export const ProductReviews = ({ productId }: Props) => { | ||
const { data: reviews, isLoading } = useProductReviews(productId, 1); | ||
if (isLoading) { | ||
return null; | ||
} | ||
return ( | ||
<List> | ||
{reviews.results.map(review => ( | ||
<ReviewItem review={review} /> | ||
))} | ||
</List> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="react-scripts" /> |