Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ramzitannous committed Mar 8, 2021
1 parent 4018a98 commit 4741173
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/app/components/ReviewItem/index.tsx
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 src/app/pages/Products/ProductDetails/ProductReviews/index.tsx
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>
);
};
1 change: 1 addition & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />

0 comments on commit 4741173

Please sign in to comment.