Skip to content
Snippets Groups Projects
PartThree.js 21.8 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/>.*/

lfr20's avatar
lfr20 committed
import React, { useState, useEffect, useContext } from 'react'
import { Store } from '../../Store.js'
import Grid from '@material-ui/core/Grid';
import styled from 'styled-components'
lfr20's avatar
lfr20 committed
import { apiDomain } from '../../env';
import Stepper from './Stepper.js'
import LoadingSpinner from '../LoadingSpinner.js'
import MoreIcon from '@material-ui/icons/More';
import SdCardIcon from '@material-ui/icons/SdCard';
import DateRangeIcon from '@material-ui/icons/DateRange';
import UpdateIcon from '@material-ui/icons/Update';
import TranslateIcon from '@material-ui/icons/Translate';
import AssignmentIcon from '@material-ui/icons/Assignment';
lfr20's avatar
lfr20 committed
import { GrayButton, OrangeButton } from './StyledComponents';
import ModalCancelar from './ModalCancelar.js'
lfr20's avatar
lfr20 committed
import { getDefaultThumbnail } from '../HelperFunctions/getDefaultThumbnail'
import { getRequest } from '../HelperFunctions/getAxiosConfig.js'
import ReCaptcha from 'react-recaptcha'
lfr20's avatar
lfr20 committed
export default function PartThree(props) {
    var moment = require('moment')
lfr20's avatar
lfr20 committed
    const { state } = useContext(Store)
    const [loading, setLoading] = useState(false)
    const [unavailableButton, setButtonAvailability] = useState(true);

    const [draft, setDraft] = useState({})
    const [subjects, setSubjects] = useState('')
    const [description, setDescription] = useState('')
    const [author, setAuthor] = useState('')

lfr20's avatar
lfr20 committed
    function handleSuccess(data) {
        console.log(data.tags)
        console.log(data.language)
        console.log(data.subjects)
        // console.log(data.tags)

lfr20's avatar
lfr20 committed
        setSubjects(data.subjects.map((subject) => (subject.name)).join(', '))
lfr20's avatar
lfr20 committed
        // setTags(data.tags.map(tag => tag.name))
        setDescription(data.description)
        setAuthor(data.author)
        setLoading(false)
    }

    useEffect(() => {
lfr20's avatar
lfr20 committed
        setLoading(true)
        if (state.currentUser.id !== "") {
            const url = `/learning_objects/${props.draftID}`

lfr20's avatar
lfr20 committed
            getRequest(url, handleSuccess, (error) => { console.log(error) })

        }
    }, [state.currentUser.id])

    let windowWidth = window.innerWidth
    const [modalCancelar, toggleModalCancelar] = useState(false)

    const checkAccessLevel = (levelToCheck) => {
        if (state.currentUser.id !== '') {
lfr20's avatar
lfr20 committed
            return (checkUserRole(levelToCheck))
        }
    }

    const checkUserRole = (userRole) => {
lfr20's avatar
lfr20 committed
        return (state.currentUser.roles.filter((role) => role.name === userRole).length > 0)
lfr20's avatar
lfr20 committed
    function captchaVerified(response) {
        <React.Fragment>
lfr20's avatar
lfr20 committed
            {
                !loading ?
                    (
                        <React.Fragment>
                            <ModalCancelar
vgm18's avatar
vgm18 committed
                                contrast={props.contrast}
lfr20's avatar
lfr20 committed
                                open={modalCancelar}
                                handleClose={() => { toggleModalCancelar(false) }}
                                draftID={draft.id}
                            />
lfr20's avatar
lfr20 committed
                            <Grid container style={props.contrast === "" ? { backgroundColor: "#f4f4f4" } : { backgroundColor: "black" }}>
lfr20's avatar
lfr20 committed
                                <Grid item xs={12}>
lfr20's avatar
lfr20 committed
                                    <StyledSessao1 contrast={props.contrast} className="page-content-preview">
lfr20's avatar
lfr20 committed
                                        <div className="cabecalho">
                                            <div className="feedback-upload">
vgm18's avatar
vgm18 committed
                                                <Stepper contrast={props.contrast} activeStep={props.activeStep} />
lfr20's avatar
lfr20 committed
                                                <h2>Quase , agora  falta publicar!</h2>
                                                <span className="subtitle">Veja abaixo como o seu Recurso vai aparecer na Plataforma:</span>
                                            </div>
lfr20's avatar
lfr20 committed
                                    </StyledSessao1>

lfr20's avatar
lfr20 committed
                                    <CaixaContainer contrast={props.contrast}>
lfr20's avatar
lfr20 committed
                                        <div>
                                            <div className="cabecalho-objeto">
                                                <img alt="" className="img-objeto"
                                                    src={draft.thumbnail === null ? getDefaultThumbnail(draft.object_type) : apiDomain + draft.thumbnail} />
                                                <div className="texto-objeto">
                                                    <h3>{draft.name}</h3>
                                                    <div className="relacionado">
                                                        Relacionado com: {subjects}
                                                    </div>

                                                    {
                                                        draft.tags &&
                                                        <div className="tags-objeto">
vgm18's avatar
vgm18 committed
                                                            Palavras chave: <br/>
lfr20's avatar
lfr20 committed
                                                            {draft.tags.map((tag) => {
                                                                return (
                                                                    <div className="tag" key={tag.name}>{tag.name}</div>
                                                                )
                                                            })}
                                                        </div>
                                                    }

                                                </div>
                                            </div>
lfr20's avatar
lfr20 committed
                                            <div className="sobre-objeto">
                                                <Grid container>
                                                    <Grid item xs={windowWidth > 990 ? 7 : 12} className="left">
                                                        <div className="titulo">
                                                            Sobre o Recurso
vgm18's avatar
vgm18 committed
                                                        </div>
lfr20's avatar
lfr20 committed
                                                        <div className="sobre-conteudo">
                                                            <p className="descricao">{description}</p>
                                                            {
                                                                author !== '' &&
                                                                <p className="autor">
                                                                    <b>Autoria:</b>
                                                                    <br />
                                                                    {author}
                                                                </p>
                                                            }
                                                        </div>
                                                    </Grid>

                                                    <Grid item xs={windowWidth > 990 ? 4 : 12} className="right">
                                                        <span className="meta-objeto">
                                                            <MoreIcon /> <b>Tipo de mídia: </b>{draft.object_type}
                                                        </span>

                                                        <span className="meta-objeto">
                                                            <SdCardIcon /> <b>Tamanho: </b>
                                                        </span>

                                                        <span className="meta-objeto">
                                                            <DateRangeIcon /> <b>Enviado: </b>
                                                            {moment(draft.created_at).format("DD/MM/YYYY")}
                                                        </span>

                                                        <span className="meta-objeto">
                                                            <UpdateIcon /><b>Atualização: </b>
                                                            {moment(draft.updated_at).format("DD/MM/YYYY")}
                                                        </span>

lfr20's avatar
lfr20 committed
                                                        {draft.language &&
lfr20's avatar
lfr20 committed
                                                            draft.language.map((language =>
                                                                <span className="meta-objeto" key={language.id}>
                                                                    <TranslateIcon /><b>Idioma: </b>{language.name}
                                                                </span>
                                                            ))
                                                        }

                                                        <span className="meta-objeto">
                                                            <AssignmentIcon /><b>Licença: </b>{draft.license ? draft.license.name : ""}
                                                        </span>
                                                    </Grid>
                                                </Grid>
lfr20's avatar
lfr20 committed
                                        </div>
                                    </CaixaContainer>
vgm18's avatar
vgm18 committed
                                    <Sessao3 contrast={props.contrast}>
lfr20's avatar
lfr20 committed
                                        <form>
                                            <Grid container>
                                                <Grid item xs={windowWidth > 990 ? 6 : 12} style={{ paddingRight: "15px", paddingLeft: "15px", textAlign: windowWidth > 990 ? 'right' : 'center' }}>
                                                    <span style={{ fontSize: "14px" }}>
                                                        Para segurança da plataforma <br /> marque que você não é um robô
vgm18's avatar
vgm18 committed
                                                    </span>
lfr20's avatar
lfr20 committed
                                                </Grid>

lfr20's avatar
lfr20 committed
                                                <Grid item xs={windowWidth > 990 ? 6 : 12} style={{ paddingRight: "15px", paddingLeft: "15px" }}>
                                                    <div style={{ margin: "0 auto", width: "304px" }}>
                                                        {
                                                            //<ReCaptcha sitekey={process.env.REACT_APP_SITE_KEY} verifyCallback={captchaVerified} /> //when key set in env
vgm18's avatar
vgm18 committed
                                                            <ReCaptcha sitekey="6LfxuKUUAAAAAIzYpCzEtJyeE8QRjBYa44dvHlTX" verifyCallback={captchaVerified} /> //use this one on production
                                                            //<ReCaptcha sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI" verifyCallback={captchaVerified} /> //test key, from google, do not use this one on production
lfr20's avatar
lfr20 committed
                                                        }
lfr20's avatar
lfr20 committed
                                                </Grid>
                                                <Grid item xs={12} style={{ paddingRight: "15px", paddingLeft: "15px", marginTop: "30px", textAlign: 'center' }}>
vgm18's avatar
vgm18 committed
                                                    <GrayButton contrast={props.contrast} onClick={() => { props.stepperControl(-1) }}>VOLTAR</GrayButton>
                                                    <GrayButton contrast={props.contrast} onClick={() => { toggleModalCancelar(true) }}>CANCELAR</GrayButton>
lfr20's avatar
lfr20 committed
                                                    {
                                                        checkAccessLevel("partner") ?
                                                            (
                                                                unavailableButton ? (
vgm18's avatar
vgm18 committed
                                                                    <GrayButton contrast={props.contrast} disabled={unavailableButton}>PUBLICAR RECURSO</GrayButton>
vgm18's avatar
vgm18 committed
                                                                    <OrangeButton contrast={props.contrast} onClick={props.handlePost}>PUBLICAR RECURSO</OrangeButton>
lfr20's avatar
lfr20 committed
                                                            )
                                                            :
                                                            (
                                                                unavailableButton ? (
vgm18's avatar
vgm18 committed
                                                                    <GrayButton contrast={props.contrast} disabled={unavailableButton}>SUBMETER RECURSO</GrayButton>
vgm18's avatar
vgm18 committed
                                                                    <OrangeButton contrast={props.contrast} onClick={props.handleSubmit}>SUBMETER RECURSO</OrangeButton>
lfr20's avatar
lfr20 committed
                                                            )

                                                    }
                                                </Grid>
                                            </Grid>
                                        </form>
                                    </Sessao3>
lfr20's avatar
lfr20 committed
                        </React.Fragment>
                    )
                    :
                    (
vgm18's avatar
vgm18 committed
                        <LoadingSpinner contrast={props.contrast} text="CARREGANDO" />
lfr20's avatar
lfr20 committed
                    )
            }
        </React.Fragment>
const Sessao3 = styled.div`
    position : relative;
    top : -120px;
    padding-right :15px;
    padding-left :15px;
    margin-right : auto;
    margin-left : auto;
    @media screen and (min-width: 768px) {
        width : 750px;
    }
    @media screen and (min-width: 992px) {
        width : 970px;
    }
    @media screen and (min-width: 1200px) {
        width : 970px;
vgm18's avatar
vgm18 committed

    color: ${props => props.contrast === "" ? "#666" : "white"};
    background-color: ${props => props.contrast === "" ? "#f4f4f4" : "black"};

`

const CaixaContainer = styled.div`
lfr20's avatar
lfr20 committed
    background: ${props => props.contrast === "" ? "rgba(238,238,238,.5)" : "black"};
    color: ${props => props.contrast === "" ? "#666" : "white"};
    border-radius : 5px;
    position : relative;
    top : -145px;
    padding : 10px;
lfr20's avatar
lfr20 committed
    

    margin-right : auto;
    margin-left : auto;
    @media screen and (min-width: 768px) {
        width : 750px;
    }
    @media screen and (min-width: 992px) {
        width : 970px;
    }
    @media screen and (min-width: 1200px) {
        width : 970px;
    }


    .cabecalho-objeto {
lfr20's avatar
lfr20 committed
        background: ${props => props.contrast === "" ? "#fff" : "black"};
        border: ${props => props.contrast === "" ? "0" : "1px solid white"};
        box-shadow: 0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);
        padding: 0;
        margin-top: 30px;
        margin-bottom: 30px;
        position: relative;
        min-height: 100px;
        margin-top: 0;
        margin-bottom: 10px;
lfr20's avatar
lfr20 committed
        color: ${props => props.contrast === "" ? "#666" : "white"};
vgm18's avatar
vgm18 committed
        overflow: auto;
lfr20's avatar
lfr20 committed
            background: ${props => props.contrast === "" ? "#e5e5e5" : "black"};
            height: 270px;
            width: 400px;
            float: left;
            padding: 0;
        }

        .texto-objeto {
            padding: 20px 20px 0 20px;
            height: content;
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -ms-flex-direction: column;
            flex-direction: column;
            -ms-flex-wrap: nowrap;
            flex-wrap: nowrap;
            -webkit-box-pack: start;
            -ms-flex-pack: start;
            justify-content: flex-start;
            -ms-flex-line-pack: center;
            align-content: center;
            -webkit-box-align: start;
            -ms-flex-align: start;
            align-items: flex-start;

            h3 {
                font-size: 26px;
                font-weight: 400;
                margin: 0;
                padding-bottom: 15px;
            }

            .rating-objeto {
                margin : 0;
                display : inline-flex;
                padding-bottom : 10px;
            }

            .relacionado {
                font-weight : 500;
                font-size : 13px;
            }

            .tags-objeto {
                max-height: 54px;
                font-size: .8em;
                overflow: hidden;
                clear: both;
                display: -webkit-inline-box;
                display: -ms-inline-flexbox;
                display: inline-flex;
                -ms-flex-wrap: wrap;
                flex-wrap: wrap;

                .tag {
                    display: -webkit-inline-box;
                    display: -ms-inline-flexbox;
                    display: inline-flex;
                    margin-right: 3px;
lfr20's avatar
lfr20 committed
                    background: ${props => props.contrast === "" ? "#e5e5e5" : "black"};
                    border: ${props => props.contrast === "" ? "0" : "1px solid white"};
                    padding: 3px 7px;
                    border-radius: 15px;
                    line-height: 18px;
                    margin-bottom: 3px;
                }
            }
        }
    }

    .sobre-objeto {
        margin-top : 0;
        margin-bottom : 0;
        min-height : 275px;
        display : flex;
lfr20's avatar
lfr20 committed
        background: ${props => props.contrast === "" ? "#fff" : "black"};
vgm18's avatar
vgm18 committed
        border: ${props => props.contrast === "" ? "0" : "1px solid white"};
        box-shadow: 0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);
        padding: 0;
        position: relative;
        min-height: 500px;

        .left {
            @media screen and (min-width : 990px) {
                margin-left : 4% !important;
                margin-top : 4% !important;
            }

            @media screen and (max-width : 989px) {
                margin : 0;
                padding : 20px;
                padding-bottom : 0;
            }

            .titulo {
                margin-top: 2% !important;
                margin-bottom: 10px;
                font-family: 'Roboto Light','Roboto Regular',Roboto;
                font-weight: 300;
                font-style: normal;
                font-size: 1.857em;
            }

            .sobre-conteudo {
                flex : 1;
                font-size : 14px !important;

                .descricao {
                    text-align: justify;
                    margin-bottom: 20px;
                    margin-top: 20px;
                }

                .autor {
                    margin : 0 0 10px !important;
                }
            }
        }

        .right {
            margin-top : 4% !important;
            border-left: 1px solid #e5e5e5;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -ms-flex-direction: column;
            flex-direction: column;
            -webkit-box-pack: start;
            -ms-flex-pack: start;
            justify-content: flex-start;
            padding: 20px;
            position : relative;
            margin-bottom : 20px;

            .meta-objeto {
                position: relative;
                width: 100%;
                font-size: 14px;
                margin-bottom: 20px;
                display : inline-block;
            }

            .MuiSvgIcon-root {
                vertical-align : middle !important;
                margin-right : 15px !important;
            }
        }
    }
}
`

const StyledSessao1 = styled.div`
    color : #fff;
lfr20's avatar
lfr20 committed
    background: ${props => props.contrast === "" ? "#00bcd4" : "black"};
    float : none;
    height : 300px;
    text-align : center;
    padding-top : 48px;
    padding-bottom : 48px;
    margin-bottom : 30px;

    .cabecalho {
        display : flex;
        flex-direction : column;
        align-items : center;
        margin-bottom : 30px;

        .feedback-upload {
            display : flex;
            flex-direction : column;
            justify-content : center;
lfr20's avatar
lfr20 committed
            text-align : center;
            margin-top : 20px;
lfr20's avatar
lfr20 committed
            margin-top : 0;
            font-size : 26px;
            font-weight : lighter;
            margin-bottom : 10px;
        }

        .subtitle {
            font-size : 16px;