-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat: 상품 썸네일 및 판매시작 api 연동
- Loading branch information
Showing
21 changed files
with
289 additions
and
134 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,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.text.primary}; | ||
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"> | ||
상품이 등록된 이후부터 계속해서 | ||
</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.