-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: 상품 썸네일 및 판매시작 api 연동 #124
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
19948f4
style: 헤더와 컨텐츠 사이 margin 추가
f21dc0f
feat: 상품 확인 페이지
a63f392
feat: 판매 시작 api 연동
dea6508
refactor: 판매 시작 api react-query로 호출
741b3c1
refactor: 상품 썸네일 마크업 리팩터링
bfb545d
refactor: palette 컬러코드 추가
e4c709c
refactor: splitText 공통 함수 분리
8950c1b
refactor: onError 발생 시 openErrorSnackbar 변경
5448c46
feat: 상품 등록 단계별 api 호출로직 훅으로 분리
c268cc3
refactor: 리턴 데이터 타입 제네릭 타입으로 수정
jiyaaany 33789a3
remove: common black 컬러 제거
52ec7e6
chore: yarn.lock 파일 수정된 거 복구
jiyaaany 76ed7ea
remove: usePost에서 error 스낵바 처리를 하고 있어 useSaveProduct 훅에서 제거
jiyaaany eb76c79
refactor: palette text 컬러로 수정
jiyaaany File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@ | ||
import { Typography } from '@material-ui/core'; | ||
import { Link } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
import { theme } from 'themes'; | ||
|
||
export const ProductCard = styled(Link)` | ||
color: ${theme.palette.common.black}; | ||
text-decoration: none; | ||
width: ${theme.spacing(55)}; | ||
border: 5px solid ${theme.palette.grey[200]}; | ||
border-radius: ${theme.spacing(6)}; | ||
`; | ||
|
||
export const RepresentativeImage = styled.img` | ||
width: ${theme.spacing(55)}; | ||
height: ${theme.spacing(46)}; | ||
border-radius: ${theme.spacing(6)}; | ||
`; | ||
|
||
export const Tag = styled.div` | ||
display: inline-block; | ||
background: ${theme.palette.grey[300]}; | ||
padding: ${theme.spacing(1)}; | ||
margin: ${theme.spacing(0.4)}; | ||
border-radius: ${theme.spacing(2)}; | ||
font-size: ${theme.spacing(1.5)}; | ||
`; | ||
|
||
export const Price = styled(Typography)` | ||
margin-left: ${theme.spacing(1)}; | ||
`; | ||
|
||
export const InfoMessage = styled.li` | ||
margin-top: ${theme.spacing(1)}; | ||
`; |
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,78 @@ | ||
import { Box, Grid, Typography } from '@material-ui/core'; | ||
import React from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { splitText } from 'utils/splitText'; | ||
|
||
import { currentProductIdAtom, currentProductInputAtom } from '../recoils'; | ||
|
||
import { | ||
ProductCard, | ||
RepresentativeImage, | ||
InfoMessage, | ||
Price, | ||
Tag, | ||
} from './Confirm.css'; | ||
|
||
const Confirm = (): React.ReactElement => { | ||
const { name, fullPrice, discountPrice, representativeImageUrl, tags } = | ||
useRecoilValue(currentProductInputAtom); | ||
const currentProductId = useRecoilValue(currentProductIdAtom); | ||
|
||
const getRate = (): string => { | ||
const rate = Math.round((discountPrice / fullPrice) * 100); | ||
|
||
return isNaN(rate) ? '' : rate.toString(); | ||
}; | ||
|
||
const getPrice = (): string => { | ||
const price = fullPrice - discountPrice; | ||
|
||
return isNaN(price) && Math.sign(price) ? '' : price.toLocaleString(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Grid container> | ||
<ProductCard to={`/product/${currentProductId}`}> | ||
{representativeImageUrl && ( | ||
<RepresentativeImage | ||
src="//via.placeholder.com/500x300" | ||
alt="상품 대표 이미지" | ||
/> | ||
)} | ||
<Box px={4} py={2}> | ||
<Typography variant="h4">{name}</Typography> | ||
<Box display="flex" justifyContent="space-between" mt={4}> | ||
<div> | ||
{splitText(tags, '#').map((tag: string) => ( | ||
<Tag>#{tag}</Tag> | ||
))} | ||
</div> | ||
<Box display="flex"> | ||
<Typography color="primary"> | ||
<b>{getRate()}%</b> | ||
</Typography> | ||
<Price variant="h4">{getPrice()}원</Price> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</ProductCard> | ||
</Grid> | ||
<ul> | ||
<InfoMessage> | ||
상품은 위와 같이 다른 니터들에게 노출될 예정이에요! | ||
</InfoMessage> | ||
<InfoMessage>클릭하면 상세도 확인해볼 수 있어요!</InfoMessage> | ||
<InfoMessage> | ||
노출되는 기간은 " | ||
<Typography display="inline" color="primary"> | ||
jiyaaany marked this conversation as resolved.
Show resolved
Hide resolved
|
||
상품이 등록된 이후부터 계속해서 | ||
</Typography> | ||
" 노출됩니다. | ||
</InfoMessage> | ||
</ul> | ||
</> | ||
); | ||
}; | ||
|
||
export default Confirm; |
62 changes: 62 additions & 0 deletions
62
src/pages/CreateProduct/components/Footer/hooks/useSaveProduct.ts
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,62 @@ | ||
import { FAILED_TO_SAVE_PRODUCT } from 'constants/errors'; | ||
|
||
import { usePost } from 'hooks/usePost'; | ||
import { | ||
currentProductIdAtom, | ||
currentProductInputAtom, | ||
currentStepAtom, | ||
} from 'pages/CreateProduct/recoils'; | ||
import { PAGE } from 'pages/CreateProduct/types'; | ||
import { useRecoilValue, useSetRecoilState } from 'recoil'; | ||
import { splitText } from 'utils/splitText'; | ||
|
||
type SaveProduct = { | ||
saveProduct: () => void; | ||
}; | ||
|
||
export const useSaveProduct = (): SaveProduct => { | ||
const setCurrentStep = useSetRecoilState(currentStepAtom); | ||
const setCurrentProductId = useSetRecoilState(currentProductIdAtom); | ||
|
||
const { | ||
name, | ||
fullPrice, | ||
discountPrice, | ||
representativeImageUrl, | ||
specifiedSalesStartDate, | ||
specifiedSalesEndDate, | ||
tags, | ||
designIds, | ||
} = useRecoilValue(currentProductInputAtom); | ||
|
||
const onSuccess = () => { | ||
if (data) { | ||
setCurrentProductId(data.payload.id); | ||
} | ||
setCurrentStep(PAGE.INTRODUCTION); | ||
}; | ||
|
||
const { data, mutate } = usePost({ | ||
pathname: '/product/package', | ||
errorMessage: FAILED_TO_SAVE_PRODUCT, | ||
onSuccess, | ||
}); | ||
|
||
const saveProduct = (): void => { | ||
const postProductData = { | ||
id: null, | ||
name, | ||
full_price: fullPrice, | ||
discount_price: discountPrice, | ||
representative_image_url: representativeImageUrl, | ||
specified_sales_start_date: specifiedSalesStartDate, | ||
specified_sales_end_date: specifiedSalesEndDate, | ||
tags: splitText(tags, '#'), | ||
design_ids: designIds, | ||
}; | ||
|
||
mutate(postProductData); | ||
}; | ||
|
||
return { saveProduct }; | ||
}; |
26 changes: 26 additions & 0 deletions
26
src/pages/CreateProduct/components/Footer/hooks/useStartSale.ts
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,26 @@ | ||
import { MY_INFORMATION_ROUTER_ROOT } from 'constants/path'; | ||
|
||
import { usePost } from 'hooks/usePost'; | ||
import { currentProductIdAtom } from 'pages/CreateProduct/recoils'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
type StartSale = { | ||
startSale: () => void; | ||
}; | ||
|
||
export const useStartSale = (): StartSale => { | ||
const currentProductId = useRecoilValue(currentProductIdAtom); | ||
const history = useHistory(); | ||
|
||
const { mutate } = usePost({ | ||
pathname: '/product', | ||
}); | ||
|
||
const startSale = () => { | ||
mutate({ id: currentProductId }); | ||
history.push(MY_INFORMATION_ROUTER_ROOT); | ||
}; | ||
|
||
return { startSale }; | ||
}; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: color: ${palette.text.secondary}; 이런거 안써주시고 새로 정의하신 이유가 궁금해욤
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A: 정의한게 아니라
palette
정의된거 보니까 기본으로common
이라는 객체가 있고 그 안에 white, black 있습니당!palette.ts
에 common 정의되어있는거 제가 한 것 같은데 ,, 왜 추가했는지 ,, 기억도 나지 않고 제거해도 동일하게 작동하네요 (33789a3 )${palette.text.secondary}는 회색인 것 같슴다
node_modules/@material-ui/core/styles/createPalette.d.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${palette.text.primary}도 있어용
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eb76c79 수정했어용