diff --git a/src/dtos/prova/prova.ts b/src/dtos/prova/prova.ts index f53ece05..b7b51df0 100644 --- a/src/dtos/prova/prova.ts +++ b/src/dtos/prova/prova.ts @@ -1,6 +1,17 @@ import { DateTime } from "luxon"; +import { ICategoria } from "../categoria/categoria"; import { Edicao } from "../../enums/prova/edicao"; +export interface SimuladoResumo { + _id: string; + nome: string; + categoria: ICategoria; + questoes: { _id: string }[]; + bloqueado: boolean; + aproveitamento?: number; + vezesRespondido?: number; +} + export interface Prova { _id: string; edicao: Edicao; @@ -16,6 +27,7 @@ export interface Prova { filename: string; gabarito: string; enemAreas: string[]; + simulados?: SimuladoResumo[]; } export interface CreateProva { diff --git a/src/pages/dash/data.ts b/src/pages/dash/data.ts index db9389dd..bd57f137 100644 --- a/src/pages/dash/data.ts +++ b/src/pages/dash/data.ts @@ -14,7 +14,6 @@ import { DASH_PROVAS, DASH_QUESTION, DASH_ROLES, - DASH_SIMULADO, DASH_SUPPORT, DASH_PARTNER_SUPPORT, ESSAY_REVIEW_CURSINHO, @@ -197,13 +196,6 @@ export const adminMenuItems: DashCardMenu[] = [ link: `/dashboard/${ESSAY_REVIEW_LIST}`, permissions: [Roles.revisarTodasRedacoes], }, - { - icon: Matematica, - alt: "dash_simulado", - text: "Simulados", - link: `/dashboard/${DASH_SIMULADO}`, - permissions: [Roles.criarQuestao], - }, { icon: Historia, alt: "localiza cursinho", diff --git a/src/pages/dashSimulado/index.tsx b/src/pages/dashSimulado/index.tsx deleted file mode 100644 index 87f1d032..00000000 --- a/src/pages/dashSimulado/index.tsx +++ /dev/null @@ -1,171 +0,0 @@ -import { useEffect, useMemo, useState } from "react"; -import { FilterProps } from "../../components/atoms/filter"; -import { SelectProps } from "../../components/atoms/select"; -import { OptionProps } from "../../components/atoms/selectOption"; -import { ButtonProps } from "../../components/molecules/button"; -import { CardDash } from "../../components/molecules/cardDash"; -import DashCardTemplate from "../../components/templates/dashCardTemplate"; -import { DashCardContext } from "../../context/dashCardContext"; -import { ISimuladoDTO } from "../../dtos/simulado/simuladoDto"; -import { StatusEnum } from "../../enums/generic/statusEnum"; -import { useToastAsync } from "../../hooks/useToastAsync"; -import { getSimulados } from "../../services/simulado/getSimulados"; -import { useAuthStore } from "../../store/auth"; -import { formatDate } from "../../utils/date"; -import { Paginate } from "../../utils/paginate"; - -const BLOQUEADO_ALL = "all"; -const BLOQUEADO_BLOCKED = "blocked"; -const BLOQUEADO_UNBLOCKED = "unblocked"; - -const bloqueadoOptions: OptionProps[] = [ - { id: BLOQUEADO_ALL, name: "Todos" }, - { id: BLOQUEADO_BLOCKED, name: "Bloqueados" }, - { id: BLOQUEADO_UNBLOCKED, name: "Liberados" }, -]; - -function DashSimulado() { - const [simulados, setSimulados] = useState([]); - const [nameFilter, setNameFilter] = useState(""); - const [categoriaFilter, setCategoriaFilter] = useState(""); - const [bloqueadoFilter, setBloqueadoFilter] = - useState(BLOQUEADO_ALL); - const [resetKey, setResetKey] = useState(0); - const { - data: { token }, - } = useAuthStore(); - const executeAsync = useToastAsync(); - const limitCards = 500; - - const cardTransformation = (simulado: ISimuladoDTO): CardDash => ({ - id: simulado._id, - title: simulado.nome, - status: simulado.bloqueado ? StatusEnum.Rejected : StatusEnum.Approved, - infos: [ - { field: "Categoria", value: simulado.categoria.nome }, - { - field: "Duracao", - value: simulado.categoria.duracao.toString() + " minutos", - }, - { - field: "Questoes", - value: `${simulado.questoes.length.toString()}/${(simulado.categoria.quantidadeTotalQuestao ?? 0).toString()}`, - }, - { - field: "Descrição", - value: - simulado.descricao && simulado.descricao.length > 20 - ? simulado.descricao.substring(0, 20) + "..." - : simulado.descricao, - }, - { - field: "Atualizado em ", - value: simulado.updatedAt - ? formatDate(simulado.updatedAt.toString()) - : "", - }, - ], - }); - - useEffect(() => { - executeAsync({ - action: () => getSimulados(token, 1, limitCards), - loadingMessage: "Buscando Simulados...", - successMessage: "Simulados carregados com sucesso!", - errorMessage: (error) => error.message, - onSuccess: (res) => setSimulados(res.data), - onError: () => setSimulados([]), - }); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [token]); - - const getMoreCards = async ( - page: number - ): Promise> => { - return await getSimulados(token, page, limitCards); - }; - - const categoriaOptions: OptionProps[] = useMemo(() => { - const names = new Set(); - simulados.forEach((s) => { - if (s.categoria?.nome) names.add(s.categoria.nome); - }); - return [ - { id: "", name: "Todos os tipos" }, - ...Array.from(names) - .sort((a, b) => a.localeCompare(b)) - .map((n) => ({ id: n, name: n })), - ]; - }, [simulados]); - - const filteredSimulados = useMemo(() => { - const term = nameFilter.trim().toLowerCase(); - return simulados.filter((s) => { - if (term && !s.nome.toLowerCase().includes(term)) return false; - if (categoriaFilter && s.categoria?.nome !== categoriaFilter) return false; - if (bloqueadoFilter === BLOQUEADO_BLOCKED && !s.bloqueado) return false; - if (bloqueadoFilter === BLOQUEADO_UNBLOCKED && s.bloqueado) return false; - return true; - }); - }, [simulados, nameFilter, categoriaFilter, bloqueadoFilter]); - - const filterProps: FilterProps = { - placeholder: "Buscar por nome", - filtrar: (e: React.ChangeEvent) => - setNameFilter(e.target.value), - defaultValue: nameFilter, - }; - - const selectFiltes: SelectProps[] = [ - { - options: categoriaOptions, - defaultValue: categoriaFilter, - setState: (value: string) => setCategoriaFilter(value), - }, - { - options: bloqueadoOptions, - defaultValue: bloqueadoFilter, - setState: (value: string) => setBloqueadoFilter(value), - }, - ]; - - const hasActiveFilters = - nameFilter !== "" || categoriaFilter !== "" || bloqueadoFilter !== BLOQUEADO_ALL; - - const buttons: ButtonProps[] = [ - { - onClick: () => { - setNameFilter(""); - setCategoriaFilter(""); - setBloqueadoFilter(BLOQUEADO_ALL); - setResetKey((k) => k + 1); - }, - typeStyle: "quaternary", - size: "small", - disabled: !hasActiveFilters, - children: "Limpar filtros", - }, - ]; - - return ( - {}, - getMoreCards, - cardTransformation, - limitCards, - filterProps, - selectFiltes, - buttons, - totalItems: filteredSimulados.length, - }} - > - - - ); -} - -export default DashSimulado; diff --git a/src/routes/PlatformRoutes.tsx b/src/routes/PlatformRoutes.tsx index 5579dd09..b9f9a4a2 100644 --- a/src/routes/PlatformRoutes.tsx +++ b/src/routes/PlatformRoutes.tsx @@ -39,7 +39,6 @@ import DashNews from "../pages/dashNews"; import DashProva from "../pages/dashProvas"; import DashQuestionNew from "../pages/dashQuestionNew"; import DashRoles from "../pages/dashRoles"; -import DashSimulado from "../pages/dashSimulado"; import Forgot from "../pages/forgot"; import Login from "../pages/login"; import Logout from "../pages/logout"; @@ -72,7 +71,6 @@ import { DASH_PROVAS, DASH_QUESTION, DASH_ROLES, - DASH_SIMULADO, DASH_SUPPORT, DASH_PARTNER_SUPPORT, DECLARED_INTEREST, @@ -343,16 +341,6 @@ export function PlatformRoutes() { } /> - - - - } - /> { + const response = await fetchWrapper(provaById(id), { + method: "GET", + headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }, + }); + const res = await response.json(); + if (response.status !== 200) { + throw new Error(`Erro ao buscar Prova ${res.message}`); + } + return res; +} diff --git a/src/services/urls.ts b/src/services/urls.ts index 789deedd..646e6be8 100644 --- a/src/services/urls.ts +++ b/src/services/urls.ts @@ -54,6 +54,7 @@ export const answer = `${simulado}/answer`; export const report = `${simulado}/report`; export const prova = `${mssimulado}/prova`; +export const provaById = (id: string) => `${prova}/${id}`; export const missing = `${prova}/missing`; export const questoes = `${mssimulado}/questoes`; export const historico = `${mssimulado}/historico`;