Skip to content
Snippets Groups Projects
ModalConfirmarCuradoria.js 7.89 KiB
Newer Older
/*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 from 'react';
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 CloseModalButton from './CloseModalButton'
lfr20's avatar
lfr20 committed
import { postRequest } from './HelperFunctions/getAxiosConfig'
lfr20's avatar
lfr20 committed
export default function ModalConfirmarCuradoriaOpen(props) {

    const handleCancel = () => {
        props.handleClose()
        props.cancel()
    }

    const transformReportCriteria = (criteria) => {
        let newArr = []
        criteria.map((criterium) =>
lfr20's avatar
lfr20 committed
            newArr.push({ "question_id": criterium.id, "accepted": criterium.accepted })
lfr20's avatar
lfr20 committed
    function handleSuccess(data) {
    const handleConfirmation = () => {
        const url = `/submissions/${props.recursoId}/answer`
lfr20's avatar
lfr20 committed
            "submission": {
                "justification": props.justificativa,
                "answers": transformReportCriteria(props.reportCriteria)
lfr20's avatar
lfr20 committed
        postRequest(
            url,
            payload,
            handleSuccess,
            (error) => {
                props.handleErrorAprove()
            }
        )
    }

    return (
        <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's avatar
vgm18 committed
                <Container contrast={props.contrast} recusado={!props.aceito}>
lfr20's avatar
lfr20 committed
                        <span style={{ width: "32px" }} />
                        <h2>Recurso a ser {props.aceito ? 'aprovado' : 'recusado'}</h2>
lfr20's avatar
lfr20 committed
                        <CloseModalButton handleClose={props.handleClose} />
                    </Header>
                    <Content>
                        {
                            props.aceito ?
lfr20's avatar
lfr20 committed
                                (
                                    <p>Este recurso será publicado na plataforma. Você confirma essa avaliação?
                                    </p>
                                )
                                :
                                (
                                    <>
                                        <p>Agradecemos a sua contribuição. Você avaliou que o recurso não está em conformidade com o(s) seguinte(s) critério(s):
lfr20's avatar
lfr20 committed
                                        {
                                            props.reportCriteria.filter((criterium) => criterium.accepted === false).map((criterium) =>
                                                <p key={criterium.id} className="reason-offensive">{criterium.text}</p>
                                            )
                                        }
                                        <p>Você confirma essa avaliação? Ao confirmar, o recurso não será publicado na plataforma.</p>
                                    </>
                                )
lfr20's avatar
lfr20 committed
                        <ButtonsDiv>
vgm18's avatar
vgm18 committed
                            <ButtonEnviarAvaliar contrast={props.contrast} onClick={() => { handleConfirmation() }}>SIM, CONFIRMAR</ButtonEnviarAvaliar>
                            <GreyButton contrast={props.contrast} onClick={handleCancel}>NÃO, ALTERAR AVALIAÇÃO</GreyButton>
lfr20's avatar
lfr20 committed
                        </ButtonsDiv>
                    </Content>
                </Container>
            </Fade>
        </StyledModal>
    )
}


const Content = styled.div`
    padding : 30px;
    overflow : visible;
    max-width : 100%;
vgm18's avatar
vgm18 committed
    color : inherit;
    font-size : 16px;
    text-align : start;
    .reason-offensive {
        font-weight : 700;
    }

    p {
        margin : 0 0 10px;
    }
`

const Header = styled.div`
    display : flex;
    flex-direction : row;
    align-items : center;
    max-height : none;
    justify-content : space-between;
vgm18's avatar
vgm18 committed
    color : inherit;

    h2 {
        font-size : 30px;
        margin-top : 20px;
        margin-bottom : 10px;
        font-weight : lighter;
    }
`

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 Container = styled.div`
    box-sizing : border-box;
    box-shadow : 0 7px 8px -4px rgba(0,0,0,.2),0 13px 19px 2px rgba(0,0,0,.14),0 5px 24px 4px rgba(0,0,0,.12);
vgm18's avatar
vgm18 committed
    background-color : ${props => props.contrast === "" ? "white" : "black"} !important;
    color : ${props => props.contrast === "" ? "#666" : "white"} !important;
    align : center;
    display : flex;
    flex-direction : column;
    min-width : 240px;
    position : relative;
    border-radius : 4px;
    max-width : 100%;
vgm18's avatar
vgm18 committed
    border: ${props => props.contrast === "" ? "" : "1px solid white"} !important;
    max-height : ${props => props.recusado ? 'none' : '370px'};

    @media screen and (max-width : 699px) {
        overflow : ${props => props.recusado ? 'scroll' : 'visible'};
        width : 100%;
        height : 100%;
    }

    p {
        margin : 0 0 10px;
    }
`
const ButtonsDiv = styled.div`
    display : flex;
    max-width : 100%;
    text-align : center;
    align-items : center;
    justify-content : center;
    padding-top : 20px;

    @media screen and (min-width : 990px) {
        flex-direction : row;
    }
    @media screen and (max-width : 989px) {
        flex-direction : column;
    }
`
const GreyButton = styled(Button)`
    &:hover {
vgm18's avatar
vgm18 committed
        background-color : ${props => props.contrast === "" ? "rgba(158,158,158,0.2)" : ""} !important;
    }
    max-height : 36px !important;

    background-color : transparent !important;
vgm18's avatar
vgm18 committed
    color: ${props => props.contrast === "" ? "#666" : "yellow"} !important;
    text-decoration : ${props => props.contrast === "" ? "none" : "underline"} !important;
    outline : none !important;
    text-align : center !important;
    font-weight : 600 !important;
    .MuiButton-label {
        padding-left : 16px !important;
        padding-right : 16px !important;
    }
    @media screen and (max-width : 989px) {
        margin-top : 10px !important;
    }
`

const ButtonEnviarAvaliar = styled(Button)`
vgm18's avatar
vgm18 committed
    color : ${props => props.contrast === "" ? `rgba(255,255,255,0.87)` : `yellow`} !important;
    font-weight : 600 !important;
vgm18's avatar
vgm18 committed
    background-color : ${props => props.contrast === "" ? "#ff7f00" : "black"} !important;
    text-decoration: ${props => props.contrast === "" ? "none" : "underline"} !important;
    border: ${props => props.contrast === "" ? "" : "1px solid white"} !important;
    margin-left : 8px !important;
    margin-right : 8px !important;

    .MuiButton-label {
        padding-left : 16px !important;
        padding-right : 16px !important;
    }
`