-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1901 from breatheco-de/development
Development
- Loading branch information
Showing
8 changed files
with
345 additions
and
3 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
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
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
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
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
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
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,132 @@ | ||
import PropTypes from 'prop-types'; | ||
import { Flex, Text, Box, Avatar, SimpleGrid } from '@chakra-ui/react'; | ||
import useTranslation from 'next-translate/useTranslation'; | ||
import { useRouter } from 'next/router'; | ||
import useStyle from '../hooks/useStyle'; | ||
import Icon from './Icon'; | ||
|
||
function CommentCard({ review, ...rest }) { | ||
const { backgroundColor, fontColor, borderColor, lightColor } = useStyle(); | ||
const roundedRating = Math.round(review.rating) || 0; | ||
|
||
return ( | ||
<Flex | ||
direction="column" | ||
border="1px solid" | ||
borderColor={borderColor} | ||
borderRadius="md" | ||
p="16px" | ||
bg={backgroundColor} | ||
gap="10px" | ||
{...rest} | ||
> | ||
{/* Avatar y Nombre */} | ||
<Flex alignItems="center" gap="10px"> | ||
<Avatar src={review.avatar} name={review.name} size="sm" /> | ||
<Box> | ||
<Text fontWeight="bold" fontColor={fontColor}>{review.name}</Text> | ||
<Flex gap="10px" alignItems="center"> | ||
<Flex gap="4px"> | ||
{Array.from({ length: 5 }).map((_, index) => ( | ||
index + 1 <= roundedRating ? ( | ||
<Icon icon="star" color="#FFB718" width="12px" /> | ||
) : ( | ||
<Icon icon="star" color="#FFFFFF" secondColor="#FFB718" width="12px" /> | ||
) | ||
))} | ||
</Flex> | ||
<Text fontSize="12px" color="gray.500">{review.date}</Text> | ||
</Flex> | ||
</Box> | ||
</Flex> | ||
|
||
<Text fontSize="14px" color={lightColor} mt="8px"> | ||
{review.review} | ||
</Text> | ||
</Flex> | ||
); | ||
} | ||
function Rating({ variant, totalRatings, totalReviews, rating, reviews, link, ...rest }) { | ||
const { t } = useTranslation('common'); | ||
const router = useRouter(); | ||
const roundedRating = Math.round(rating) || 0; | ||
|
||
if (variant === 'inline') { | ||
return ( | ||
<Flex alignItems="center" gap="8px" {...rest}> | ||
{(rating > 0 && roundedRating > 0) && ( | ||
<> | ||
<Text fontSize="14px">{rating}</Text> | ||
<Flex gap="4px"> | ||
{Array.from({ length: 5 }).map((_, index) => { | ||
const isFullStar = index + 1 <= Math.floor(rating); | ||
const isHalfStar = index === Math.floor(rating) && rating % 1 >= 0.5; | ||
|
||
return ( | ||
<Icon | ||
icon="star" | ||
color={isFullStar ? '#FFB718' : '#ffffff'} | ||
secondColor="#FFB718" | ||
width="18px" | ||
fill={isHalfStar ? 'half' : undefined} | ||
/> | ||
); | ||
})} | ||
</Flex> | ||
</> | ||
)} | ||
|
||
{totalRatings > 0 && ( | ||
<Text onClick={() => router.push(link)} color="blue.default" textDecor="underline" fontWeight="bold" fontSize="14px" cursor="pointer"> | ||
{`(${totalRatings} ${t('common:reviews')})`} | ||
</Text> | ||
)} | ||
</Flex> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{reviews?.length > 0 && ( | ||
<Flex direction="column" {...rest}> | ||
<Flex alignItems="center" gap="14px"> | ||
<Icon icon="star" color="#FFB718" width="18px" /> | ||
<Text fontSize="24px">{`${rating > 0 && rating} ${t('course-rating')} ${totalReviews > 0 && `- ${totalReviews} ${t('comments')}`}`}</Text> | ||
</Flex> | ||
<SimpleGrid | ||
columns={{ base: 1, md: 2, lg: 3 }} | ||
spacing="16px" | ||
marginTop="22px" | ||
> | ||
{reviews.map((review) => ( | ||
<CommentCard review={review} /> | ||
))} | ||
</SimpleGrid> | ||
</Flex> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
Rating.propTypes = { | ||
variant: PropTypes.string, | ||
totalRatings: PropTypes.string, | ||
totalReviews: PropTypes.string, | ||
rating: PropTypes.string, | ||
reviews: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object])), | ||
link: PropTypes.string, | ||
}; | ||
|
||
CommentCard.propTypes = { | ||
review: PropTypes.string.isRequired, | ||
}; | ||
|
||
Rating.defaultProps = { | ||
variant: null, | ||
link: null, | ||
totalRatings: 0, | ||
totalReviews: 0, | ||
rating: 0, | ||
reviews: [], | ||
}; | ||
export default Rating; |
Oops, something went wrong.