Newer
Older

Lucas Eduardo Schoenfelder
committed
/*Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana
This file is part of Plataforma Integrada MEC.
Plataforma Integrada MEC is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Plataforma Integrada MEC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/
import React, {useContext, useState} from 'react';

Lucas Eduardo Schoenfelder
committed
import { Button } from '@material-ui/core';
import Modal from '@material-ui/core/Modal';
import Backdrop from '@material-ui/core/Backdrop';
import Fade from '@material-ui/core/Fade';
import styled from 'styled-components'
import {Store} from '../Store.js'
import CloseIcon from '@material-ui/icons/Close';

Lucas Eduardo Schoenfelder
committed
import ReportUserForm from './ReportUserForm.js'
import ReportRecursoForm from './ReportRecursoForm.js'
import ReportColecaoForm from './ReportColecaoForm.js'

Lucas Eduardo Schoenfelder
committed
import {postRequest} from './HelperFunctions/getAxiosConfig'
import SnackbarComponent from './SnackbarComponent.js'

Lucas Eduardo Schoenfelder
committed
function CloseModalButton (props) {
return (
<StyledCloseModalButton onClick={props.handleClose}>
<CloseIcon style={props.contrast === "" ? { color: "#666" } : { color: "white" }}/>

Lucas Eduardo Schoenfelder
committed
</StyledCloseModalButton>
)
}
export default function ReportModal (props) {
const {state} = useContext(Store)
const [snackbarOpen, handleSnackbar] = useState(false)

Lucas Eduardo Schoenfelder
committed
const handleSubmit = (complaint_reason_id, description) => {
const url = `/complaints/`

Lucas Eduardo Schoenfelder
committed
const payload = {
"complaint" : {
"user_id" : state.currentUser.id,
"description" : description,
"complainable_id" : props.complainableId,
"complainable_type" : props.complainableType,
"complaint_reason_id" : complaint_reason_id
}
}
postRequest(url, payload, (data) => {
console.log(data)
props.handleClose();
handleSnackbar(true);
}, (error) => {console.log(error)})

Lucas Eduardo Schoenfelder
committed
}

Lucas Eduardo Schoenfelder
committed
const renderForm = (formType) => {
switch (formType) {

vgm18
committed
<ReportColecaoForm contrast={props.contrast} handleClose={props.handleClose} handleSubmit={handleSubmit}/>

Lucas Eduardo Schoenfelder
committed
case 'recurso':

vgm18
committed
return (
<ReportRecursoForm contrast={props.contrast} handleClose={props.handleClose} handleSubmit={handleSubmit}/>

Lucas Eduardo Schoenfelder
committed
)
default:
return (

vgm18
committed
<ReportUserForm contrast={props.contrast} handleClose={props.handleClose} handleSubmit={handleSubmit}/>

Lucas Eduardo Schoenfelder
committed
)
}
}

Lucas Eduardo Schoenfelder
committed
return (
<SnackbarComponent snackbarOpen={snackbarOpen} severity={"success"} handleClose={() => {handleSnackbar(false)}} text={"Sua reclamação foi recebida."}/>
<StyledModal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
open={props.open}
centered="true"
onClose={props.handleClose}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
>
<Fade in={props.open}>

vgm18
committed
<ReportContainer className={`${props.contrast}BackColor ${props.contrast}Text ${props.contrast}Border`}>
<Header>
<span style={{width:"32px"}}/>
<h2>O que está acontecendo?</h2>
<CloseModalButton contrast={props.contrast} handleClose={props.handleClose}/>
</Header>
<Content>
{
renderForm(props.form)
}
</Content>
</ReportContainer>
</Fade>
</StyledModal>
</React.Fragment>

Lucas Eduardo Schoenfelder
committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
)
}
const Content = styled.div`
padding : 20px 30px;
overflow : visible;
max-width : 470px;
`
const Header = styled.div`
display : flex;
flex-direction : row;
padding : 10px 26px 0 26px;
align-items : center;
justify-content : space-between;
height : 64px;
h2 {
font-size : 26px;
font-weight : lighter;
}
`
const StyledCloseModalButton = styled(Button)`
display : inline-block;
position : relative;
float : right !important;
margin-right : -8px !important;
background : transparent !important;
min-width: 0 !important;
width : 40px;
`
const StyledModal = styled(Modal)`
.djXaxP{
margin : 0 !important;
}
display : flex;
align-items: center;
justify-content : center;
text-align : center;
padding : 10px !important;
max-width : none;
max-height : none;
`
const ReportContainer = styled.div`
box-sizing : border-box;
max-width : none;
align : center;
display : flex;
flex-direction : column;
min-width : 240px;
max-height : none;
position : relative;
padding : 10px;
border-radius : 4px;
@media screen and (max-width : 899px) {
width : 100%;
height : 100%;
}
`