-
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.
Merge pull request #14 from coconut-thisABLE/refactor/detail/add-review
Refactor/detail/add review
- Loading branch information
Showing
8 changed files
with
359 additions
and
6 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,60 @@ | ||
import styled from '@emotion/styled' | ||
import { useState } from 'react' | ||
import { reviewAverageCount } from '../../data' | ||
import { ReviewSortType } from '../../types/state' | ||
import Text from '../common/Text' | ||
import ReviewInput from './ReviewInput' | ||
import ReviewList from './ReviewList' | ||
|
||
// TODO: set location id | ||
const ReviewContainer = () => { | ||
const [sort, setSort] = useState<ReviewSortType>('recommended') | ||
|
||
return ( | ||
<> | ||
<ReviewContainerHeader> | ||
<Text size={1.2} bold> | ||
{reviewAverageCount.count} 개의 리뷰 | ||
</Text> | ||
<ReviewSortContainer> | ||
<SelectSort | ||
sort={sort} | ||
name={'recommended'} | ||
onClick={() => setSort('recommended')} | ||
> | ||
추천순 | ||
</SelectSort> | ||
<SelectSort | ||
sort={sort} | ||
name={'createdAt'} | ||
onClick={() => setSort('createdAt')} | ||
> | ||
최신순 | ||
</SelectSort> | ||
</ReviewSortContainer> | ||
</ReviewContainerHeader> | ||
<ReviewInput /> | ||
<ReviewList /> | ||
</> | ||
) | ||
} | ||
|
||
const ReviewContainerHeader = styled.header` | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: flex-end; | ||
flex-direction: row; | ||
` | ||
const SelectSort = styled.div<{ sort: string; name: string }>` | ||
font-weight: ${({ sort, name }) => (sort === name ? 'bold' : 'normal')}; | ||
padding: 0 0.5rem; | ||
cursor: pointer; | ||
` | ||
const ReviewSortContainer = styled.div` | ||
display: flex; | ||
${SelectSort}:first-of-type { | ||
border-right: 1px solid black; | ||
} | ||
` | ||
|
||
export default ReviewContainer |
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,113 @@ | ||
import styled from '@emotion/styled' | ||
import React, { useState, useEffect } from 'react' | ||
import Text, { StyledText } from '../common/Text' | ||
|
||
import Radio from '@mui/material/Radio' | ||
import RadioGroup from '@mui/material/RadioGroup' | ||
import FormControlLabel from '@mui/material/FormControlLabel' | ||
import FormControl from '@mui/material/FormControl' | ||
import Rating from '@mui/material/Rating' | ||
import { ReviewUserType } from '../../types/state' | ||
|
||
const ReviewInput = () => { | ||
const [userType, setUserType] = useState<ReviewUserType>('anonymous') | ||
const [inputValue, setInputValue] = useState<string>('') | ||
const [rate, setRate] = useState<number | null>(0) | ||
|
||
return ( | ||
<ReviewInputContainer> | ||
<ReviewInputHeader> | ||
<UserInfo> | ||
<Text>평점</Text> | ||
<Rating | ||
value={rate} | ||
precision={0.5} | ||
onChange={(_, newRate) => { | ||
setRate(newRate) | ||
}} | ||
/> | ||
</UserInfo> | ||
<FormControl> | ||
<RadioGroup | ||
row | ||
value={userType} | ||
onChange={(e) => setUserType(e.target.value as ReviewUserType)} | ||
> | ||
<FormControlLabel | ||
value="disabled" | ||
control={<Radio size="small" />} | ||
label="장애인" | ||
/> | ||
<FormControlLabel | ||
value="able" | ||
control={<Radio size="small" />} | ||
label="비장애인" | ||
/> | ||
<FormControlLabel | ||
value="anonymous" | ||
control={<Radio size="small" />} | ||
label="익명" | ||
/> | ||
</RadioGroup> | ||
</FormControl> | ||
</ReviewInputHeader> | ||
|
||
<ReviewInputArea | ||
onChange={(e) => setInputValue(e.target.value)} | ||
placeholder="리뷰는 익명으로 등록됩니다." | ||
value={inputValue} | ||
/> | ||
<ReviewInputButton | ||
onClick={() => { | ||
// postReview(userType, locationId, inputValue, rating) | ||
setInputValue('') | ||
setRate(0) | ||
}} | ||
> | ||
등록 | ||
</ReviewInputButton> | ||
</ReviewInputContainer> | ||
) | ||
} | ||
|
||
const ReviewInputContainer = styled.section` | ||
display: flex; | ||
flex-direction: column; | ||
margin-top: 1rem; | ||
` | ||
const ReviewInputHeader = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-around; | ||
align-items: center; | ||
` | ||
const UserInfo = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
${StyledText} { | ||
margin-right: 0.2rem; | ||
} | ||
` | ||
const ReviewInputArea = styled.textarea` | ||
border: 2px solid #9d9d9d; | ||
border-radius: 10px; | ||
font-size: 1rem; | ||
min-height: 5rem; | ||
padding: 0.3rem; | ||
margin-top: 0.4rem; | ||
resize: none; | ||
` | ||
const ReviewInputButton = styled.button` | ||
display: flex; | ||
background-color: #e599b3; | ||
color: white; | ||
font-size: 0.9rem; | ||
margin-top: 0.6rem; | ||
padding: 0.4rem; | ||
justify-content: center; | ||
align-items: center; | ||
border-radius: 5px; | ||
` | ||
|
||
export default ReviewInput |
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,112 @@ | ||
import styled from '@emotion/styled' | ||
import Image from 'next/image' | ||
import { reviews } from '../../data' | ||
import Text, { StyledText } from '../common/Text' | ||
|
||
import Rating from '@mui/material/Rating' | ||
|
||
const ReviewList = () => { | ||
return ( | ||
<ReviewListContainer> | ||
{reviews?.data?.map((review) => ( | ||
<ReviewContainer key={review._id}> | ||
<ReviewInfoWrapper> | ||
<ReviewStarUserTypeWrapper> | ||
<Rating | ||
value={review.star} | ||
precision={0.5} | ||
size="small" | ||
readOnly | ||
/> | ||
<Text color="#f0a044" size={0.9}> | ||
{review.userType} | ||
</Text> | ||
</ReviewStarUserTypeWrapper> | ||
<Text color="#9d9d9d" size={0.7}> | ||
{review.createdAt.substring(0, 10)} | ||
</Text> | ||
</ReviewInfoWrapper> | ||
<ReviewText>{review.detail}</ReviewText> | ||
<HelpButtonWrapper> | ||
<HelpButton | ||
// onClick={() => { | ||
// postReviewRecommend(review._id) | ||
// }} | ||
> | ||
<Image | ||
src={'/images/thumbs_up.svg'} | ||
width={15} | ||
height={15} | ||
></Image> | ||
<ButtonDescriptionText>도움이 돼요</ButtonDescriptionText> | ||
<Text color="#cb3267" size={1} bold> | ||
{review.good} | ||
</Text> | ||
</HelpButton> | ||
<HelpButton | ||
// onClick={() => postReviewDiscourage(review._id)} | ||
> | ||
<Image | ||
src={'/images/thumbs_down.svg'} | ||
width={15} | ||
height={15} | ||
></Image> | ||
<ButtonDescriptionText>도움이 안 돼요</ButtonDescriptionText> | ||
<Text color="#cb3267" size={1} bold> | ||
{review.bad} | ||
</Text> | ||
</HelpButton> | ||
</HelpButtonWrapper> | ||
</ReviewContainer> | ||
))} | ||
</ReviewListContainer> | ||
) | ||
} | ||
|
||
const ReviewListContainer = styled.section`` | ||
const ReviewContainer = styled.div` | ||
margin-top: 1rem; | ||
padding-bottom: 1rem; | ||
border-bottom: #9d9d9d; | ||
border-bottom-width: 0.08rem; | ||
border-bottom-style: solid; | ||
` | ||
const ReviewInfoWrapper = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
` | ||
const ReviewStarUserTypeWrapper = styled.div` | ||
display: flex; | ||
align-items: center; | ||
${StyledText} { | ||
margin-left: 0.4rem; | ||
} | ||
` | ||
const ReviewText = styled.p` | ||
font-size: 1rem; | ||
align-items: center; | ||
margin-left: 0.5rem; | ||
margin-top: 0.5rem; | ||
` | ||
const HelpButtonWrapper = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
` | ||
const HelpButton = styled.button` | ||
display: flex; | ||
font-weight: bold; | ||
font-size: 0.8rem; | ||
height: 1.7rem; | ||
align-items: center; | ||
border: 1px solid #f0a044; | ||
border-radius: 10px; | ||
background-color: #ffffff; | ||
padding-left: 1rem; | ||
padding-right: 1rem; | ||
` | ||
const ButtonDescriptionText = styled.p` | ||
margin: 0 0.5rem 0 0.2rem; | ||
` | ||
|
||
export default ReviewList |
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
Oops, something went wrong.