From ea315d576a83d0d902f5accc1751f9caffd4a336 Mon Sep 17 00:00:00 2001 From: Vinicius Gabriel Machado <vgm18@inf.ufpr.br> Date: Mon, 12 Apr 2021 13:40:41 -0300 Subject: [PATCH] Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments section) when not logged in, now they will call handleLogin & fixed button for Esqueceu a senha, now he will redirect properly --- src/Components/ContactButtons/FollowButton.js | 2 +- src/Components/ContactCardOptions.js | 154 ++++++++---- src/Components/LoginContainerFunction.js | 2 +- .../ResourcePageComponents/CommentsArea.js | 193 +++++++++------ .../ResourcePageComponents/Sobre.js | 229 +++++++++++------- 5 files changed, 363 insertions(+), 217 deletions(-) diff --git a/src/Components/ContactButtons/FollowButton.js b/src/Components/ContactButtons/FollowButton.js index 9666eeae..f2a42e33 100644 --- a/src/Components/ContactButtons/FollowButton.js +++ b/src/Components/ContactButtons/FollowButton.js @@ -60,7 +60,7 @@ export function NoIcon (props) { ) } -const NoIconButton = styled(Button)` +export const NoIconButton = styled(Button)` .MuiButton-label { color : #00bcd4 !important; } diff --git a/src/Components/ContactCardOptions.js b/src/Components/ContactCardOptions.js index deb12ba4..4a1340e4 100644 --- a/src/Components/ContactCardOptions.js +++ b/src/Components/ContactCardOptions.js @@ -16,7 +16,8 @@ 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, {useState} from 'react'; +import React, {useContext, useState} from 'react'; +import {Store} from '../Store' import styled from 'styled-components' import Button from '@material-ui/core/Button'; import Menu from '@material-ui/core/Menu'; @@ -29,10 +30,37 @@ import PersonAddIcon from '@material-ui/icons/PersonAdd'; import {putRequest} from './HelperFunctions/getAxiosConfig' import ReportModal from './ReportModal.js' import {Link} from 'react-router-dom' +import LoginModal from './LoginModal.js' +import Snackbar from '@material-ui/core/Snackbar'; +import SignUpModal from './SignUpModal' +import MuiAlert from '@material-ui/lab/Alert'; + +function Alert(props) { + return <MuiAlert elevation={6} variant="filled" {...props} />; +} export default function SimpleMenu(props) { - // const {state} = useContext(Store) + const {state} = useContext(Store) const [anchorEl, setAnchorEl] = React.useState(null); + const [loginOpen, setLogin] = useState(false) + const [successfulLoginOpen, handleSuccessfulLogin] = useState(false) + const [signUpOpen, setSignUp] = useState(false) + + const handleSignUp = () => { + setSignUp(!signUpOpen) + } + + const handleLogin = () => { + setLogin(!loginOpen) + } + + const toggleSnackbar = (event, reason) => { + if (reason === 'clickaway') { + return; + } + + handleSuccessfulLogin(false); + } function handleClick(event) { setAnchorEl(event.currentTarget); @@ -58,53 +86,83 @@ export default function SimpleMenu(props) { } return ( - <> - { - reportModal && - <ReportModal open={reportModal} handleClose={() => handleModal(false)} - form="user" complainableId={props.followableID} - complainableType={"User"} - {...props}/> - } - <div style={{fontSize: "12px", display : "flex", flexDirection : "column", justifyContent : "center"}}> - <ButtonNoWidth aria-controls="simple-menu" aria-haspopup="true" onClick={handleClick} style={{color : "#666"}}> - <MoreVertIcon style={{color : "#666"}}/> - </ButtonNoWidth> - <Menu - id="simple-menu" - anchorEl={anchorEl} - keepMounted - open={Boolean(anchorEl)} - onClose={handleClose} - > - <StyledMenuItem onClick={handleClose}> - <Link to={"/usuario-publico/" + props.followableID}> - <ListItemIcon><OpenIcon /></ListItemIcon>Abrir - </Link> - </StyledMenuItem> - - { - props.followed ? - ( - <StyledMenuItem onClick={() => {handleFollow(props.followableID)}}> - <ListItemIcon><ReportIcon /></ListItemIcon>Deixar de Seguir - </StyledMenuItem> - ) - : - ( - <StyledMenuItem onClick={() => {handleFollow(props.followableID)}}> - <ListItemIcon><PersonAddIcon /></ListItemIcon>Seguir - </StyledMenuItem> - ) - } - - - <StyledMenuItem onClick={() => {handleModal(true); handleClose()}}> - <ListItemIcon><ReportIcon /></ListItemIcon>Reportar - </StyledMenuItem> - </Menu> + <React.Fragment> + <Snackbar open={successfulLoginOpen} autoHideDuration={1000} onClose={toggleSnackbar} + anchorOrigin={{ vertical: 'top', horizontal: 'center' }} + > + <Alert severity="success" style={{ backgroundColor: "#00acc1" }}>Você está conectado(a)!</Alert> + </Snackbar> + {/*-------------------------------MODALS---------------------------------------*/} + <LoginModal open={loginOpen} handleClose={() => setLogin(false)} openSignUp={handleSignUp} + openSnackbar={() => { handleSuccessfulLogin(true) }} + /> + <SignUpModal open={signUpOpen} handleClose={handleSignUp} openLogin={handleLogin} /> + {/*----------------------------------------------------------------------------*/} + <> + { + reportModal && + <ReportModal open={reportModal} handleClose={() => handleModal(false)} + form="user" complainableId={props.followableID} + complainableType={"User"} + {...props}/> + } + <div style={{fontSize: "12px", display : "flex", flexDirection : "column", justifyContent : "center"}}> + <ButtonNoWidth aria-controls="simple-menu" aria-haspopup="true" onClick={handleClick} style={{color : "#666"}}> + <MoreVertIcon style={{color : "#666"}}/> + </ButtonNoWidth> + <Menu + id="simple-menu" + anchorEl={anchorEl} + keepMounted + open={Boolean(anchorEl)} + onClose={handleClose} + > + <StyledMenuItem onClick={handleClose}> + <Link to={"/usuario-publico/" + props.followableID}> + <ListItemIcon><OpenIcon /></ListItemIcon>Abrir + </Link> + </StyledMenuItem> + + { + props.followed ? + ( + <StyledMenuItem onClick={() => {handleFollow(props.followableID)}}> + <ListItemIcon><ReportIcon /></ListItemIcon>Deixar de Seguir + </StyledMenuItem> + ) + : + ( + state.currentUser.id !== '' ? ( + <StyledMenuItem onClick={() => {handleFollow(props.followableID)}}> + <ListItemIcon><PersonAddIcon /></ListItemIcon>Seguir + </StyledMenuItem> + ) + : + ( + <StyledMenuItem onClick={() => {handleLogin(props.followableID)}}> + <ListItemIcon><PersonAddIcon /></ListItemIcon>Seguir + </StyledMenuItem> + ) + ) + } + + { + state.currentUser.id !== '' ? ( + <StyledMenuItem onClick={() => {handleModal(true); handleClose()}}> + <ListItemIcon><ReportIcon /></ListItemIcon>Reportar + </StyledMenuItem> + ) + : + ( + <StyledMenuItem onClick={() => {handleLogin(true)}}> + <ListItemIcon><ReportIcon /></ListItemIcon>Reportar + </StyledMenuItem> + ) + } + </Menu> </div> - </> + </> + </React.Fragment> ); } diff --git a/src/Components/LoginContainerFunction.js b/src/Components/LoginContainerFunction.js index 8534da0a..0e79abf1 100644 --- a/src/Components/LoginContainerFunction.js +++ b/src/Components/LoginContainerFunction.js @@ -157,7 +157,7 @@ export default function LoginContainer (props) { <RememberRecover> <LabeledCheckbox label={<StyledLabel><StyledSpan>Lembrar-me</StyledSpan></StyledLabel>} handleChange={() => setCheckbox(!checkboxControl)}/> - <UserForgotTheirPasswordSpan>Esqueceu a senha? <Link to={"recuperar-senha"} style={{textAlign: "right", color:"#4cd0e1"}} onClick={props.handleClose}>Clique aqui!</Link></UserForgotTheirPasswordSpan> + <UserForgotTheirPasswordSpan>Esqueceu a senha? <Link to={"/recuperar-senha"} style={{textAlign: "right", color:"#4cd0e1"}} onClick={props.handleClose}>Clique aqui!</Link></UserForgotTheirPasswordSpan> </RememberRecover> <ConfirmContainerStyled> diff --git a/src/Components/ResourcePageComponents/CommentsArea.js b/src/Components/ResourcePageComponents/CommentsArea.js index 10a9482f..946ce4d4 100644 --- a/src/Components/ResourcePageComponents/CommentsArea.js +++ b/src/Components/ResourcePageComponents/CommentsArea.js @@ -27,12 +27,39 @@ import {apiDomain} from '../../env'; import CommentForm from './CommentForm.js' import Comment from '../Comment.js' import {getRequest} from '../HelperFunctions/getAxiosConfig' +import LoginModal from './../LoginModal.js' +import Snackbar from '@material-ui/core/Snackbar'; +import SignUpModal from './../SignUpModal' +import MuiAlert from '@material-ui/lab/Alert'; + +function Alert(props) { + return <MuiAlert elevation={6} variant="filled" {...props} />; +} export default function CommentsArea (props) { const {state} = useContext(Store) const [comentarios, setComentarios] = useState([]) const [gambiarra, setState] = useState(0) const forceUpdate = () => {setState(gambiarra + 1)} + const [loginOpen, setLogin] = useState(false) + const [successfulLoginOpen, handleSuccessfulLogin] = useState(false) + const [signUpOpen, setSignUp] = useState(false) + + const handleSignUp = () => { + setSignUp(!signUpOpen) + } + + const handleLogin = () => { + setLogin(!loginOpen) + } + + const toggleSnackbar = (event, reason) => { + if (reason === 'clickaway') { + return; + } + + handleSuccessfulLogin(false); + } function handleSuccess (data) { setComentarios(data.sort((a, b) => a.updated_at > b.updated_at ? -1 : 1)) @@ -45,84 +72,96 @@ export default function CommentsArea (props) { }, [gambiarra]) return ( - <Grid container spacing={2} style={{padding : "10px"}}> - { - (state.currentUser.id !== '') ? - ( - <Grid item xs={12} > - <GrayContainer> - <h3>Conte sua experiência com o Recurso</h3> - <Grid container style={{paddingTop : "20px"}}> - <Grid item xs={2} style={{paddingLeft : "15px", paddingRight : "15px"}}> - <img src={apiDomain + state.currentUser.avatar} className="minha-imagem" alt="user avatar"/> - </Grid> - <Grid item xs={10}> - <CommentForm - recursoId={props.recursoId} - handleSnackbar={props.handleSnackbar} - rerenderCallback={forceUpdate} - recurso={props.recurso} - /> + <React.Fragment> + <Snackbar open={successfulLoginOpen} autoHideDuration={1000} onClose={toggleSnackbar} + anchorOrigin={{ vertical: 'top', horizontal: 'center' }} + > + <Alert severity="success" style={{ backgroundColor: "#00acc1" }}>Você está conectado(a)!</Alert> + </Snackbar> + {/*-------------------------------MODALS---------------------------------------*/} + <LoginModal open={loginOpen} handleClose={() => setLogin(false)} openSignUp={handleSignUp} + openSnackbar={() => { handleSuccessfulLogin(true) }} + /> + <SignUpModal open={signUpOpen} handleClose={handleSignUp} openLogin={handleLogin} /> + {/*----------------------------------------------------------------------------*/} + <Grid container spacing={2} style={{padding : "10px"}}> + { + (state.currentUser.id !== '') ? + ( + <Grid item xs={12} > + <GrayContainer> + <h3>Conte sua experiência com o Recurso</h3> + <Grid container style={{paddingTop : "20px"}}> + <Grid item xs={2} style={{paddingLeft : "15px", paddingRight : "15px"}}> + <img src={apiDomain + state.currentUser.avatar} className="minha-imagem" alt="user avatar"/> + </Grid> + <Grid item xs={10}> + <CommentForm + recursoId={props.recursoId} + handleSnackbar={props.handleSnackbar} + rerenderCallback={forceUpdate} + recurso={props.recurso} + /> + </Grid> </Grid> - </Grid> - </GrayContainer> - </Grid> - ) - : - ( - <Grid item xs={12}> - <LogInToComment> - <span className="span-laranja">Você precisa entrar para comentar</span> - {/*adicionar funcionalidade ao botao de entrar*/} - <Button style={{textTransform : "uppercase", color : "#666", fontWeight : "700"}}> - <ExitToAppIcon/>ENTRAR - </Button> - </LogInToComment> - </Grid> - ) - } - { - comentarios.length !== 0 ? - ( - <ComentariosBox> - <h3>{comentarios.length} {comentarios.length !== 1 ? 'Relatos' : 'Relato'} sobre o uso do Recurso</h3> - { - comentarios.map( comentario => - <div className="comentario-template" key={comentario.id}> - <Comment - authorID={comentario.user ? comentario.user.id : null} - authorAvatar={comentario.user ? comentario.user.avatar : null} - authorName={comentario.user ? comentario.user.name : null} - name={comentario.name} - rating={comentario.rating_average} - reviewRatings = {comentario.review_ratings} - description={comentario.description} - createdAt={comentario.created_at} - recurso={true} - reviewID={comentario.id} - objectID={props.recursoId} - rerenderCallback={forceUpdate} - handleSnackbar={props.handleSnackbar} - /> - </div> - ) - } - </ComentariosBox> - ) - : - ( - <Grid item xs={12}> - <LogInToComment> - <img alt="" src={Comentarios} /> - <span className="span-laranja">Compartilhe sua experiência com a Rede!</span> - <AoRelatar> - Ao relatar sua experiência de uso do Recurso você estará auxiliando professores de todo país. - </AoRelatar> - </LogInToComment> - </Grid> - ) - } - </Grid> + </GrayContainer> + </Grid> + ) + : + ( + <Grid item xs={12}> + <LogInToComment> + <span className="span-laranja">Você precisa entrar para comentar</span> + <Button onClick={() => handleLogin(true)} style={{textTransform : "uppercase", color : "#666", fontWeight : "700"}}> + <ExitToAppIcon/>ENTRAR + </Button> + </LogInToComment> + </Grid> + ) + } + { + comentarios.length !== 0 ? + ( + <ComentariosBox> + <h3>{comentarios.length} {comentarios.length !== 1 ? 'Relatos' : 'Relato'} sobre o uso do Recurso</h3> + { + comentarios.map( comentario => + <div className="comentario-template" key={comentario.id}> + <Comment + authorID={comentario.user ? comentario.user.id : null} + authorAvatar={comentario.user ? comentario.user.avatar : null} + authorName={comentario.user ? comentario.user.name : null} + name={comentario.name} + rating={comentario.rating_average} + reviewRatings = {comentario.review_ratings} + description={comentario.description} + createdAt={comentario.created_at} + recurso={true} + reviewID={comentario.id} + objectID={props.recursoId} + rerenderCallback={forceUpdate} + handleSnackbar={props.handleSnackbar} + /> + </div> + ) + } + </ComentariosBox> + ) + : + ( + <Grid item xs={12}> + <LogInToComment> + <img alt="" src={Comentarios} /> + <span className="span-laranja">Compartilhe sua experiência com a Rede!</span> + <AoRelatar> + Ao relatar sua experiência de uso do Recurso você estará auxiliando professores de todo país. + </AoRelatar> + </LogInToComment> + </Grid> + ) + } + </Grid> + </React.Fragment> ) } diff --git a/src/Components/ResourcePageComponents/Sobre.js b/src/Components/ResourcePageComponents/Sobre.js index 0d262187..576799ed 100644 --- a/src/Components/ResourcePageComponents/Sobre.js +++ b/src/Components/ResourcePageComponents/Sobre.js @@ -21,7 +21,7 @@ import {Store} from '../../Store' import styled from 'styled-components' import Grid from '@material-ui/core/Grid'; import {Link} from 'react-router-dom' -import {NoIcon} from '../ContactButtons/FollowButton.js' +import {NoIcon, NoIconButton} from '../ContactButtons/FollowButton.js' import {NoIconFollowing} from '../ContactButtons/FollowingButton.js' import Collapse from '@material-ui/core/Collapse'; import SdCardIcon from '@material-ui/icons/SdCard'; @@ -34,6 +34,14 @@ import UpdateIcon from '@material-ui/icons/Update'; import AssignmentIcon from '@material-ui/icons/Assignment'; import License from '../../img/cc_license.png' import ContactCardOptions from '../ContactCardOptions.js' +import LoginModal from './../LoginModal.js' +import Snackbar from '@material-ui/core/Snackbar'; +import SignUpModal from './../SignUpModal' +import MuiAlert from '@material-ui/lab/Alert'; + +function Alert(props) { + return <MuiAlert elevation={6} variant="filled" {...props} />; +} function AdditionalInfoItem (props) { return ( @@ -50,6 +58,25 @@ export default function Sobre (props) { const [collapsed, setCollapsed] = useState(false) const toggleCollapsed = () => {setCollapsed(!collapsed)}; + const [loginOpen, setLogin] = useState(false) + const [successfulLoginOpen, handleSuccessfulLogin] = useState(false) + const [signUpOpen, setSignUp] = useState(false) + + const handleSignUp = () => { + setSignUp(!signUpOpen) + } + + const handleLogin = () => { + setLogin(!loginOpen) + } + + const toggleSnackbar = (event, reason) => { + if (reason === 'clickaway') { + return; + } + + handleSuccessfulLogin(false); + } var moment = require('moment') @@ -141,106 +168,128 @@ export default function Sobre (props) { const toggleFollowed = () => {setFollowed(!followed)} return ( - <Grid container style={{paddingRight : "15px", paddingLeft : "15px"}}> - - <Grid item xs={windowWidth > 990 ? 9 : 12} style={{paddingRight : "15px"}}> - <Collapse in={collapsed} collapsedHeight={338}> - <SobreDiv> - <div className="titulo"> - Sobre o Recurso - </div> - - <div className="sobre-conteudo"> - <div className="tags-container"> - { - props.tags && - props.tags.map( (tag) => - <span key={tag.name}>{tag.name}</span> - ) - } - </div> - <div className="conteudo"> - <p className="descricao-objeto">{props.description}</p> - { - props.author && - <p className="autoria"> - <b>Autoria: </b>{props.author} - </p> - } + <React.Fragment> + <Snackbar open={successfulLoginOpen} autoHideDuration={1000} onClose={toggleSnackbar} + anchorOrigin={{ vertical: 'top', horizontal: 'center' }} + > + <Alert severity="success" style={{ backgroundColor: "#00acc1" }}>Você está conectado(a)!</Alert> + </Snackbar> + {/*-------------------------------MODALS---------------------------------------*/} + <LoginModal open={loginOpen} handleClose={() => setLogin(false)} openSignUp={handleSignUp} + openSnackbar={() => { handleSuccessfulLogin(true) }} + /> + <SignUpModal open={signUpOpen} handleClose={handleSignUp} openLogin={handleLogin} /> + {/*----------------------------------------------------------------------------*/} + <Grid container style={{paddingRight : "15px", paddingLeft : "15px"}}> + + <Grid item xs={windowWidth > 990 ? 9 : 12} style={{paddingRight : "15px"}}> + <Collapse in={collapsed} collapsedHeight={338}> + <SobreDiv> + <div className="titulo"> + Sobre o Recurso </div> - </div> - <div className="titulo"> - Informações Adicionais - </div> + <div className="sobre-conteudo"> + <div className="tags-container"> + { + props.tags && + props.tags.map( (tag) => + <span key={tag.name}>{tag.name}</span> + ) + } + </div> + <div className="conteudo"> + <p className="descricao-objeto">{props.description}</p> + { + props.author && + <p className="autoria"> + <b>Autoria: </b>{props.author} + </p> + } + </div> + </div> - {additionalInfo} + <div className="titulo"> + Informações Adicionais + </div> - </SobreDiv> - </Collapse> - </Grid> + {additionalInfo} - <Grid item xs={windowWidth > 990 ? 3 : 12}> - <MetasObjeto> - <div className="enviado-por"> - Enviado por: - </div> + </SobreDiv> + </Collapse> + </Grid> + <Grid item xs={windowWidth > 990 ? 3 : 12}> + <MetasObjeto> + <div className="enviado-por"> + Enviado por: + </div> - <div className="foto-autor"> - <Link to={"/usuario-publico/" + props.id}> - <img src={props.avatar} alt="user avatar"/> - </Link> - </div> - <div className="nome-autor"> - <Link to={"/usuario-publico/" + props.id} style={{textDecoration : "none"}}> - <span className="span-st">{props.publisher}</span> - </Link> - </div> + <div className="foto-autor"> + <Link to={"/usuario-publico/" + props.id}> + <img src={props.avatar} alt="user avatar"/> + </Link> + </div> - <div style={{paddingTop : "0.75em", display : "flex", justifyContent : "center"}}> - { - (props.id !== state.currentUser.id) && - followed ? ( - <> - <NoIconFollowing followableID={props.id} toggleFollowed={toggleFollowed}/> - <ContactCardOptions followableID={props.id}/> - </> - ) - : - ( - <> - <NoIcon followableID={props.id} toggleFollowed={toggleFollowed}/> - <ContactCardOptions followableID={props.id}/> - </> - ) - } - </div> - </MetasObjeto> - </Grid> + <div className="nome-autor"> + <Link to={"/usuario-publico/" + props.id} style={{textDecoration : "none"}}> + <span className="span-st">{props.publisher}</span> + </Link> + </div> - <Grid item xs={12} style={{paddingTop : "15px"}}> - <CollapseControl onClick={() => {toggleCollapsed()}}> - { - collapsed ? - ( - <React.Fragment> - <span>VER MENOS</span> - <ExpandLessIcon/> - </React.Fragment> - ) - : - ( - <React.Fragment> - <span>VER MAIS</span> - <ExpandMoreIcon/> - </React.Fragment> - ) - } - </CollapseControl> + <div style={{paddingTop : "0.75em", display : "flex", justifyContent : "center"}}> + { + (props.id !== state.currentUser.id) && + followed ? ( + <> + <NoIconFollowing followableID={props.id} toggleFollowed={toggleFollowed}/> + <ContactCardOptions followableID={props.id}/> + </> + ) + : + ( + state.currentUser.id !== '' ? ( + <> + <NoIcon followableID={props.id} toggleFollowed={toggleFollowed}/> + <ContactCardOptions followableID={props.id}/> + </> + ) + : + ( + <> + <NoIconButton onClick={() => handleLogin(true)}>seguir</NoIconButton> + <ContactCardOptions followableID={props.id}/> + </> + ) + ) + } + </div> + </MetasObjeto> + </Grid> + + <Grid item xs={12} style={{paddingTop : "15px"}}> + <CollapseControl onClick={() => {toggleCollapsed()}}> + { + collapsed ? + ( + <React.Fragment> + <span>VER MENOS</span> + <ExpandLessIcon/> + </React.Fragment> + ) + : + ( + <React.Fragment> + <span>VER MAIS</span> + <ExpandMoreIcon/> + </React.Fragment> + ) + } + </CollapseControl> + </Grid> </Grid> - </Grid> + </React.Fragment> ) } -- GitLab