-
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 #73 from UnbFeelings/support
Feature/Support
- Loading branch information
Showing
12 changed files
with
531 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import React from 'react'; | ||
import Snackbar from '@material-ui/core/Snackbar'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
|
||
import axios from '../../../configs/axios'; | ||
import Endpoints from '../../../configs/endpoints'; | ||
import SupportItem from '../../shared/SupportItem'; | ||
import SimpleModalWrapped from '../../shared/ConfirmDeletionModal'; | ||
|
||
class SupportTimeline extends React.Component { | ||
state = { | ||
supports: { results: [] }, | ||
// gettingData: false, | ||
showModal: false, | ||
snackbar: { | ||
display: false, | ||
message: '', | ||
}, | ||
}; | ||
|
||
async componentDidMount() { | ||
this.fetchSupports(); | ||
} | ||
|
||
fetchSupports = async () => { | ||
let endpoint; | ||
if (this.props.match.url === '/supports-sent') { | ||
endpoint = Endpoints.SUPPORT_FROM_STUDENT; | ||
} else { | ||
endpoint = Endpoints.SUPPORT_TO_STUDENT; | ||
} | ||
|
||
// this.setState({ gettingData: true }); | ||
|
||
try { | ||
const response = await axios.get(`${endpoint}/`); | ||
this.setState({ supports: response.data }); | ||
} catch (err) { | ||
// console.log('fetchReceivedSupports - err', err); | ||
this.setState({ snackbar: { display: true, message: 'Ocorreu um erro, tente novamente.' } }); | ||
} finally { | ||
// this.setState({ gettingData: false }); | ||
} | ||
}; | ||
|
||
removeSupport = async id => { | ||
this.setState({ showModal: true, supportToRemove: id }); | ||
}; | ||
|
||
confirmRemoval = async id => { | ||
try { | ||
await axios.delete(`${Endpoints.SUPPORT}/${id}/`); | ||
this.setState({ snackbar: { display: true, message: 'Apoio removido com sucesso' } }); | ||
this.fetchSupports(); | ||
} catch (err) { | ||
// console.log('removeSupport - err', err); | ||
this.setState({ snackbar: { display: true, message: 'Ocorreu um erro, tente novamente.' } }); | ||
} finally { | ||
this.setState({ showModal: false, supportToRemove: '' }); | ||
} | ||
} | ||
|
||
renderSupport = (item) => ( | ||
<SupportItem | ||
item={item} | ||
removeItem={id => this.removeSupport(id)} | ||
/> | ||
); | ||
|
||
handleCloseSnackbar = () => { | ||
// Hide the successful post creation message | ||
this.setState({ snackbar: { display: false, message: '' } }); | ||
}; | ||
|
||
createSupportList = () => { | ||
if (this.state.supports.results.length === 0) { | ||
return null; | ||
} | ||
|
||
return this.state.supports.results.map(item => this.renderSupport(item)); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<React.Fragment> | ||
{this.createSupportList()} | ||
|
||
<SimpleModalWrapped | ||
visible={this.state.showModal} | ||
title="Deseja excluir este apoio?" | ||
description="Tem certeza que deseja excluir este apoio? Essa ação não poderá ser desfeita" | ||
action="Excluir" | ||
onConfirm={() => this.confirmRemoval(this.state.supportToRemove)} | ||
onCancel={() => this.setState({ showModal: !this.state.showModal })} | ||
/> | ||
|
||
<Snackbar | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'left', | ||
}} | ||
open={this.state.snackbar.display} | ||
autoHideDuration={6000} | ||
onClose={this.handleCloseSnackbar} | ||
ContentProps={{ | ||
'aria-describedby': 'message-id', | ||
}} | ||
message={<span id="message-id">{this.state.snackbar.message}</span>} | ||
action={[ | ||
<IconButton | ||
key="close" | ||
aria-label="Close" | ||
color="inherit" | ||
onClick={this.handleCloseSnackbar} | ||
> | ||
<CloseIcon /> | ||
</IconButton>, | ||
]} | ||
/> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default SupportTimeline; |
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,70 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { withStyles } from '@material-ui/core/styles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import Modal from '@material-ui/core/Modal'; | ||
import Button from '@material-ui/core/Button'; | ||
|
||
function getModalStyle() { | ||
const top = 50; | ||
const left = 50; | ||
|
||
return { | ||
top: `${top}%`, | ||
left: `${left}%`, | ||
transform: `translate(-${top}%, -${left}%)`, | ||
}; | ||
} | ||
|
||
const styles = theme => ({ | ||
paper: { | ||
position: 'absolute', | ||
width: theme.spacing.unit * 50, | ||
backgroundColor: theme.palette.background.paper, | ||
boxShadow: theme.shadows[5], | ||
padding: theme.spacing.unit * 4, | ||
}, | ||
}); | ||
|
||
class SimpleModal extends React.Component { | ||
render() { | ||
const { classes } = this.props; | ||
|
||
return ( | ||
<div> | ||
<Modal | ||
aria-labelledby="simple-modal-title" | ||
aria-describedby="simple-modal-description" | ||
open={this.props.visible} | ||
onClose={this.onCancel} | ||
> | ||
<div style={getModalStyle()} className={classes.paper}> | ||
<Typography variant="title" id="modal-title"> | ||
{this.props.title} | ||
</Typography> | ||
<Typography variant="subheading" id="simple-modal-description"> | ||
{this.props.description} | ||
</Typography> | ||
<Button color="secondary" onClick={this.props.onConfirm}>{this.props.action}</Button> | ||
<Button onClick={this.props.onCancel}>Cancelar</Button> | ||
</div> | ||
</Modal> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
SimpleModal.propTypes = { | ||
visible: PropTypes.bool.isRequired, | ||
title: PropTypes.string.isRequired, | ||
description: PropTypes.string.isRequired, | ||
action: PropTypes.string.isRequired, | ||
onConfirm: PropTypes.func.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
}; | ||
|
||
// We need an intermediary variable for handling the recursive nesting. | ||
const SimpleModalWrapped = withStyles(styles)(SimpleModal); | ||
|
||
export default SimpleModalWrapped; |
Oops, something went wrong.