diff --git a/src/app/components/Cards.js b/src/app/components/Cards.js index e16c7dff3ab51912a66710fd70d22b6d7e1822f1..ebc4567e212f9ee5847db0c8e50cea42c647b73b 100644 --- a/src/app/components/Cards.js +++ b/src/app/components/Cards.js @@ -164,8 +164,8 @@ export default function Cards(props) { </> : <> - <div className="flex flex-row mt-4 mb-2 justify-start"> - {props?.noAvatar || !props["avatar"] ? <div className={`flex items-center justify-center text-xl font-bold ml-4 text-main rounded-full h-[33px] w-[33px] ${getRandomBg(props["id"])}`} >{props["author"][0]}</div> + <div className="flex flex-row mt-4 mb-2 w-full justify-start "> + {props?.noAvatar || !props["avatar"] ? <div className={`flex items-center shrink-0 justify-center text-xl font-bold ml-1 text-main rounded-full h-[33px] w-[33px] ${getRandomBg(props["id"])}`} >{props["author"][0]}</div> : <img src={mecredURL + props["avatar"]} diff --git a/src/app/publicar/components/InfoForm.js b/src/app/publicar/components/InfoForm.js index b11b0a16a30b337d2b21f636c08937f795c6ab54..23bf44654c7365c7f1d4801f1d3e9bba0bffe5ff 100644 --- a/src/app/publicar/components/InfoForm.js +++ b/src/app/publicar/components/InfoForm.js @@ -186,7 +186,7 @@ export default function InfoForm({ userData, setStep, draft, setDraft, authorTyp /> <FieldLabel name="Palavras-chave Relacionadas ao Conteúdo do seu Recurso*" - description="(Use Enter ou vÃrgula (,) para confirmar a palavra-chave)" + description="(Use Enter ou vÃrgula para confirmar a palavra-chave)" error={(!tags.length && filled)} /> <TextField diff --git a/src/app/recurso/[id]/components/actionButtons.js b/src/app/recurso/[id]/components/actionButtons.js index 0094d45ca4ff81dbc111e99231d9ff058e55ee61..beb57a0527c387c260ab5a04b91d3d8ec41534bb 100644 --- a/src/app/recurso/[id]/components/actionButtons.js +++ b/src/app/recurso/[id]/components/actionButtons.js @@ -30,7 +30,6 @@ function ChangeOnHover({ text, textOnHover }) { export default function ActionButtons({ learningObject, setNeedLoginOpen, state }) { const [liked, setLiked] = useState(learningObject.liked); - const [shareOpen, setShareOpen] = useState(false); const [reportOpen, setReportOpen] = useState(false); const [reported, setReported] = useState(false); @@ -53,33 +52,39 @@ export default function ActionButtons({ learningObject, setNeedLoginOpen, state mecredURLv1 - useEffect(() => { - if (!learningObject?.id) return; - - mecredApi - .get( - mecredURLv1 + "/learning_objects_complaints/" + - learningObject.id, - {}, - { - headers: { - "access-token": token, - "token-type": "Bearer", - client: client, - uid: uid, - Expires: 0, - }, - } - ) - .then((response) => { - setReported(response.data.length !== 0); - }); - }, [client, token, uid, learningObject]); + // useEffect(() => { + // if (!learningObject?.id) return; + + // mecredApi + // .get( + // mecredURLv1 + "/learning_objects_complaints/" + + // learningObject.id, + // {}, + // { + // headers: { + // "access-token": token, + // "token-type": "Bearer", + // client: client, + // uid: uid, + // Expires: 0, + // }, + // } + // ) + // .then((response) => { + // console.log(response.data, "response.data"); + // // setReported(response.data.length !== 0); + // }); + // }, [client, token, uid, learningObject]); useEffect(() => { setLiked(learningObject.liked); }, [learningObject.liked, userData]); + useEffect(() => { + if(!isLoggedIn() || !learningObject?.id) return; + setReported(learningObject.complained); + }, [learningObject]) + let buttonInfo = [ // Botão de curtir { @@ -216,6 +221,7 @@ export default function ActionButtons({ learningObject, setNeedLoginOpen, state <ReportModal learningObject={learningObject} open={reportOpen} + setReported={setReported} onClose={() => setReportOpen(false)} /> {/* Verifica se o usuário está logado antes de abrir o modal de colecionar */} diff --git a/src/app/recurso/[id]/components/reportModal.js b/src/app/recurso/[id]/components/reportModal.js index 9d41bafcbc657c6f58ddd1e13d6f870257dda313..c1eb0b9b93dd36125f96ae01821c7c7f4d7249df 100644 --- a/src/app/recurso/[id]/components/reportModal.js +++ b/src/app/recurso/[id]/components/reportModal.js @@ -13,26 +13,26 @@ import mecredApi from "@/axiosConfig"; import { isLoggedIn } from "@/app/handlers/loginHandler"; -const ModalSucess = ({ open, onClose, modalOnClose }) => { +const ModalSucess = ({ open, onClose, modalOnClose }) => { return ( - <Modal open={open} onClose={onClose} className="grid place-items-center"> - <div className="flex flex-col justify-center bg-main p-5 rounded"> - <p className="text-xl justify-center flex text-main-text mb-2">Agradecemos a sua denúncia</p> - <div className="flex flex-row mt-2"> - <button - className=" text-sm p-2 ml-1 text-main-text border-main rounded-lg normal-case h-9 font-bold bg-main hover:bg-main-hover" - onClick={() => { onClose(); modalOnClose() }} - > - Fechar - </button> - </div> - </div> - </Modal> + <Modal open={open} onClose={onClose} className="grid place-items-center"> + <div className="flex flex-col justify-center bg-main p-5 rounded"> + <p className="text-xl justify-center flex text-main-text mb-2">Agradecemos a sua denúncia</p> + <div className="flex flex-row mt-2"> + <button + className=" text-sm p-2 ml-1 text-main-text border-main rounded-lg normal-case h-9 font-bold bg-main hover:bg-main-hover" + onClick={() => { onClose(); modalOnClose() }} + > + Fechar + </button> + </div> + </div> + </Modal> ) } -export default function ReportModal({ open, onClose, learningObject }) { +export default function ReportModal({ open, onClose, learningObject, setReported }) { const [info, setInfo] = useState(""); const [user, setUser] = useState({}); const [submitOpen, setSubmitOpen] = useState(false); @@ -54,21 +54,21 @@ export default function ReportModal({ open, onClose, learningObject }) { }; const handleSubmit = (e) => { - if (info.length > 150) return; + if (info.length > 150 || info.length === 0) return; e.preventDefault(); const payload = { - complaint: { - user_id: user.id, - description: info, - complainable_id: learningObject.id, - complainable_type: "LearningObject", - complaint_reason_id: e.target["report-radio-group"].value, + "complaint": { + "user_id": user.id, + "description": info, + "complainable_id": learningObject.id, + "complainable_type": "LearningObject", + "complaint_reason_id": Number(e.target["report-radio-group"].value) }, }; try { - const response = mecredApi.post("/complaints", payload, { + const response = mecredApi.post("/complaints/", payload, { headers: { "access-token": token, "token-type": "Bearer", @@ -77,10 +77,11 @@ export default function ReportModal({ open, onClose, learningObject }) { Expires: 0, }, }); - + setSubmitOpen(true); + setReported(true); + - } catch (error) { console.error("Erro na requisição:", error); } @@ -127,14 +128,17 @@ export default function ReportModal({ open, onClose, learningObject }) { helperText={info.length + "/150"} maxRows={5} multiline - label="Escreva mais sobre o problema" + label="Escreva mais sobre o problema*" variant="standard" - error={info.length > 150} + error={info.length > 150 || info.length === 0} /> + <div className="text-sm text-end font-normal text-main-text"> + Os campos preenchidos com * são obrigatórios. + </div> <Button type="submit" variant="contained" - disabled={info.length > 150} + disabled={info.length > 150 || info.length === 0} className="bg-secondary hover:bg-main-hover disabled:bg-red mt-3 text-white hover:text-secondary shadow-none rounded normal-case text-base font-bold" > Enviar