-
Notifications
You must be signed in to change notification settings - Fork 2
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
상품 등록페이지 구현 #60
Merged
Merged
상품 등록페이지 구현 #60
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
474744c
feat: build enroll product UI
Johnie-Yeo 506d285
feat: image process in client
Johnie-Yeo 9dc3fa1
refactor: refactoring overally
Johnie-Yeo 5dc20c2
feat: add alert dialog for image upload error
Johnie-Yeo 54c8804
feat: make carousel to show uploaded images
Johnie-Yeo 27e4012
fix: fix image carousel to list
Johnie-Yeo dfcde1f
feat: add picture remove
Johnie-Yeo a185b3f
chore: fix useFetch
Johnie-Yeo 853869c
feat: post send form data to product-api server
Johnie-Yeo c4688dd
refactor: according to codereview refactor overally
Johnie-Yeo 28af4a3
chore: change directory name common to assets
Johnie-Yeo 89aefd9
fix: fix submit
Johnie-Yeo 5138b48
fix: fix warnings
Johnie-Yeo 8eab806
fix: fix image upload process
Johnie-Yeo 86407f8
chore: fix error modal message
Johnie-Yeo 84729b4
fix: fix css style
Johnie-Yeo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const imageHandleURI = 'http://localhost:5000/products/picture'; | ||
const productHandleURI = 'http://localhost:5000/products'; | ||
const loginStatusHandleURI = 'http://localhost:5001/myInfo'; | ||
export {imageHandleURI, productHandleURI, loginStatusHandleURI}; |
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 React, {useState, useContext, useRef} from 'react'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import PhotoCamera from '@material-ui/icons/PhotoCamera'; | ||
import {makeStyles} from '@material-ui/core/styles'; | ||
|
||
import {ProductContext} from '../contexts/productStore'; | ||
|
||
import useImageUpload from '../hooks/useImageUpload'; | ||
|
||
const useStyles = makeStyles(() => ({ | ||
input: {display: 'none'}, | ||
})); | ||
const AddPicture = () => { | ||
const classes = useStyles(); | ||
const fileMaximumUploadErrorMessage = '사진은 10장까지만 입력 가능합니다.'; | ||
const [file, setFile] = useState([]); | ||
const inputRef = useRef(false); | ||
const {images, setImages, setAlertMessage} = useContext(ProductContext); | ||
|
||
useImageUpload(images, file, inputRef, setImages, setAlertMessage); | ||
|
||
const imageUploadListener = async (evt) => { | ||
const selectedFiles = Array.from(evt.target.files); | ||
|
||
const numberOfCurrentUploadedImage = images.length; | ||
const allowToUpload = 10 - numberOfCurrentUploadedImage; | ||
const numberOfSelectedFile = selectedFiles.length; | ||
|
||
if (numberOfSelectedFile > allowToUpload) { | ||
const allowed = selectedFiles.filter((file, index) => { | ||
if (index < allowToUpload) { | ||
return file; | ||
} | ||
}); | ||
setFile(allowed); | ||
setAlertMessage(fileMaximumUploadErrorMessage); | ||
return; | ||
} | ||
setFile(selectedFiles); | ||
}; | ||
|
||
return ( | ||
<> | ||
<input | ||
accept='image/*' | ||
className={classes.input} | ||
id='icon-button-file' | ||
type='file' | ||
onChange={imageUploadListener} | ||
multiple | ||
ref={inputRef} | ||
/> | ||
<label htmlFor='icon-button-file'> | ||
<IconButton aria-label='upload picture' component='span'> | ||
<PhotoCamera /> | ||
</IconButton> | ||
</label> | ||
</> | ||
); | ||
}; | ||
|
||
export default AddPicture; |
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,48 @@ | ||
import React, {useState, useEffect, useContext} from 'react'; | ||
import Dialog from '@material-ui/core/Dialog'; | ||
import DialogActions from '@material-ui/core/DialogActions'; | ||
import DialogContent from '@material-ui/core/DialogContent'; | ||
import DialogContentText from '@material-ui/core/DialogContentText'; | ||
import Button from '@material-ui/core/Button'; | ||
import {ProductContext} from '../contexts/productStore'; | ||
|
||
const AlertDialog = () => { | ||
const {alertMessage} = useContext(ProductContext); | ||
const [open, setOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
if (alertMessage.length > 0) { | ||
setOpen(true); | ||
} else { | ||
setOpen(false); | ||
} | ||
}, [alertMessage]); | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Dialog | ||
open={open} | ||
onClose={handleClose} | ||
aria-labelledby='alert-dialog-title' | ||
aria-describedby='alert-dialog-description' | ||
> | ||
<DialogContent> | ||
<DialogContentText id='alert-dialog-description'> | ||
{alertMessage} | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={handleClose} color='primary' autoFocus> | ||
확인 | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AlertDialog; |
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,45 @@ | ||
import React from 'react'; | ||
import {makeStyles} from '@material-ui/core/styles'; | ||
import RadioGroup from '@material-ui/core/RadioGroup'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import RadioButton from './radioButton'; | ||
|
||
const useStyles = makeStyles(() => ({ | ||
radioGroup: { | ||
marginTop: '0.3rem', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
}, | ||
})); | ||
|
||
const DealType = ({onDealTypeChange}) => { | ||
const classes = useStyles(); | ||
|
||
const onRadioButtonChange = (e) => { | ||
onDealTypeChange(e.target.value); | ||
}; | ||
|
||
return ( | ||
<RadioGroup | ||
defaultValue='직거래' | ||
aria-label='거래유형' | ||
name='customized-radios' | ||
className={classes.radioGroup} | ||
onChange={onRadioButtonChange} | ||
> | ||
<FormControlLabel | ||
value='택배거래' | ||
control={<RadioButton />} | ||
label='택배거래' | ||
/> | ||
<FormControlLabel | ||
value='직거래' | ||
control={<RadioButton />} | ||
label='직거래' | ||
/> | ||
</RadioGroup> | ||
); | ||
}; | ||
|
||
export default DealType; |
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,67 @@ | ||
import React, {useState} from 'react'; | ||
import {makeStyles} from '@material-ui/core/styles'; | ||
import SwipeableDrawer from '@material-ui/core/SwipeableDrawer'; | ||
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; | ||
|
||
import DrawerList from './drawerList'; | ||
|
||
const useStyles = makeStyles(() => ({ | ||
field: { | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
borderBottom: '1px solid black', | ||
marginTop: '1rem', | ||
}, | ||
})); | ||
|
||
const Drawer = ({name, data, loading, onDrawerSelected}) => { | ||
const classes = useStyles(); | ||
const [state, setState] = useState({ | ||
bottom: false, | ||
}); | ||
|
||
const toggleDrawer = (side, open) => (event) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Closure 잘 활용하신 것같습니다. |
||
const isTabOrShift = (evt) => { | ||
if ( | ||
evt && | ||
evt.type === 'keydown' && | ||
(evt.key === 'Tab' || evt.key === 'Shift') | ||
) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
if (isTabOrShift(event)) { | ||
return; | ||
} | ||
|
||
setState({...state, [side]: open}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div onClick={toggleDrawer('bottom', true)} className={classes.field}> | ||
<div>{name}</div> | ||
<ExpandMoreIcon /> | ||
</div> | ||
<SwipeableDrawer | ||
anchor='bottom' | ||
open={state.bottom} | ||
onClose={toggleDrawer('bottom', false)} | ||
onOpen={toggleDrawer('bottom', true)} | ||
> | ||
<DrawerList | ||
loading={loading} | ||
side='bottom' | ||
data={data} | ||
onDrawerSelected={onDrawerSelected} | ||
toggleDrawer={toggleDrawer} | ||
/> | ||
</SwipeableDrawer> | ||
</> | ||
); | ||
}; | ||
|
||
export default Drawer; |
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,43 @@ | ||
import React from 'react'; | ||
import List from '@material-ui/core/List'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import {makeStyles} from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles(() => ({ | ||
fullList: { | ||
width: 'auto', | ||
height: '15rem', | ||
}, | ||
})); | ||
|
||
const DrawerList = ({loading, side, data, onDrawerSelected, toggleDrawer}) => { | ||
const classes = useStyles(); | ||
|
||
const onListClick = (e) => { | ||
const name = e.target.textContent; | ||
onDrawerSelected(name); | ||
}; | ||
|
||
if (loading) { | ||
return 'loading'; | ||
} | ||
return ( | ||
<div | ||
className={classes.fullList} | ||
role='presentation' | ||
onClick={toggleDrawer(side, false)} | ||
onKeyDown={toggleDrawer(side, false)} | ||
> | ||
<List> | ||
{data.map((text) => ( | ||
<ListItem button key={text} onClick={onListClick}> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DrawerList; |
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,38 @@ | ||
import React from 'react'; | ||
import {makeStyles} from '@material-ui/core/styles'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import ExitToAppIcon from '@material-ui/icons/ExitToApp'; | ||
import AddPicture from './addPicture'; | ||
|
||
const useStyles = makeStyles(() => ({ | ||
root: { | ||
height: '2.5rem', | ||
}, | ||
headerButtons: { | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
background: 'white', | ||
color: '#555', | ||
}, | ||
exit: { | ||
color: '#555', | ||
}, | ||
})); | ||
|
||
const Header = () => { | ||
const classes = useStyles(); | ||
return ( | ||
<div className={classes.root}> | ||
<AppBar position='static'> | ||
<Toolbar variant='dense' className={classes.headerButtons}> | ||
<ExitToAppIcon className={classes.exit} /> | ||
중고거래 글쓰기 | ||
<AddPicture /> | ||
</Toolbar> | ||
</AppBar> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Header; |
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 React, {useState, useEffect, useContext} from 'react'; | ||
import {ProductContext} from '../contexts/productStore'; | ||
import Loading from './loading'; | ||
import ProductImage from './productImage'; | ||
import {makeStyles} from '@material-ui/core'; | ||
|
||
const useStyle = makeStyles(() => ({ | ||
container: { | ||
width: '13rem', | ||
height: '4.2rem', | ||
display: 'flex', | ||
alignItems: 'center', | ||
overflowX: 'auto', | ||
overflowY: 'hidden', | ||
marginTop: '0.3rem', | ||
color: '#555', | ||
}, | ||
})); | ||
|
||
const ImageList = () => { | ||
const classes = useStyle(); | ||
const {images} = useContext(ProductContext); | ||
const [imageList, setImageList] = useState(''); | ||
|
||
const buildImageList = (images) => { | ||
let result = ''; | ||
|
||
if (images.length) { | ||
result = images.map((image, index) => { | ||
if (!image.loading) { | ||
return ( | ||
<ProductImage | ||
key={index} | ||
mobile={image.mobile} | ||
name={image.name} | ||
deskTop={image.deskTop} | ||
/> | ||
); | ||
} else { | ||
return <Loading key={index} />; | ||
} | ||
}); | ||
} else if (images.length === 0) { | ||
result = '사진을 등록해 주세요'; | ||
} else { | ||
throw new Error('image context is not an array!!!'); | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
useEffect(() => { | ||
const newImageList = buildImageList(images); | ||
setImageList(newImageList); | ||
}, [images]); | ||
|
||
return <div className={classes.container}>{imageList}</div>; | ||
}; | ||
|
||
export default ImageList; |
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.
별도의 상수로 해당 hook 함수의 최상단에 사용해보는 것은 어떨까요?
지금 value, label각각 값이 중복되어 사용해 있는데 해당 값을 나중에 수정시 바로 찾아갈 수 있을 것 같고, 동일한 element를 반복문으로 생성하여 활용할 수 있을 것 같습니다.
ex: const TYPENAME = ['택배거래', '직거래'];
하지만 여러 요소도 아니라서 단순히 두개의 값만 출력하는 경우에는 이 경우도 적절하다 생각이 듭니다.