diff --git a/FrontEnd/src/Components/Clase/Clase.jsx b/FrontEnd/src/Components/Clase/Clase.jsx
index 66fc96cf..15965b4b 100644
--- a/FrontEnd/src/Components/Clase/Clase.jsx
+++ b/FrontEnd/src/Components/Clase/Clase.jsx
@@ -1,66 +1,76 @@
-import { Typography, Button, CardContent} from '@mui/material'
-import React from 'react'
-import Box from '@mui/material/Box'
-import Card from '@mui/material/Card'
-import CardActions from '@mui/material/CardActions'
-import Divider from '@mui/material/Divider';
+import { Typography, Button, CardContent } from '@mui/material';
+import React from 'react';
+import Box from '@mui/material/Box';
+import Card from '@mui/material/Card';
+import CardActions from '@mui/material/CardActions';
+import { nivelDict } from '../../utils/constants';
-
-function Clase({handleClick, handleMoreInfo, clase}) {
-
- const nivelDict = {
- '1' : 'Desde cero',
- '2' : 'Con bases',
- '3' : 'Intermedio',
- '4' : 'Avanzado'
- }
-
- return (
-
-
- {clase.clave}. {clase.nombre_curso}
-
- {
- clase.status === "Inscrito" ?
- Ya estas inscrito
- :
- null
- }
- {
- clase.status === "ListaEspera" ?
- Estas en lista de espera
- :
- null
- }
-
- Periodo: {clase.clavePeriodo}
- Modalidad: {clase.modalidad}
- Nivel: {nivelDict[clase.nivel]}
- = 1 ? "red" : "black" }} variant='body1'>
- { Number(clase.cupo_actual) / Number(clase.cupo_maximo) >=1 ? Lleno
- : ¡Curso {(Number(clase.cupo_actual) / Number(clase.cupo_maximo) * 100).toFixed()}% lleno!
- }
-
-
-
-
-
- { Number(clase.cupo_actual) < Number(clase.cupo_maximo) ?
- :
- }
-
-
- )
+function Clase({ handleClick, handleMoreInfo, clase }) {
+ return (
+
+
+
+ {`${clase.clave}.${clase.nombre_curso}`}
+
+
+ {
+ clase.status === 'Inscrito'
+ ? Ya estas inscrito
+ : null
+ }
+ {
+ clase.status === 'ListaEspera'
+ ? Estas en lista de espera
+ : null
+ }
+
+
+ Periodo:
+ {` ${clase.clavePeriodo}`}
+
+
+ Modalidad:
+ {` ${clase.modalidad}`}
+
+
+ Nivel:
+ {` ${nivelDict[clase.nivel]}`}
+
+ = 1 ? 'red' : 'black' }} variant="body1">
+ { Number(clase.cupo_actual) / Number(clase.cupo_maximo) >= 1 ? Lleno
+ : (
+
+ ¡Curso
+ {(Number(clase.cupo_actual) / Number(clase.cupo_maximo) * 100).toFixed()}
+ % lleno!
+
+ )}
+
+
+
+
+
+ { Number(clase.cupo_actual) < Number(clase.cupo_maximo)
+ ? (
+
+ ) : (
+
+ )}
+
+
+ );
}
-export default Clase
+export default Clase;
diff --git a/FrontEnd/src/Components/Clase/ClaseModal.jsx b/FrontEnd/src/Components/Clase/ClaseModal.jsx
index 335cb552..614f027b 100644
--- a/FrontEnd/src/Components/Clase/ClaseModal.jsx
+++ b/FrontEnd/src/Components/Clase/ClaseModal.jsx
@@ -1,72 +1,79 @@
-import React from 'react'
-import Box from '@mui/material/Box'
-import Typography from '@mui/material/Typography'
+import React from 'react';
+import Box from '@mui/material/Box';
+import Typography from '@mui/material/Typography';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
-import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';
+import { nivelDict } from '../../utils/constants';
+function ClaseModal({ clase }) {
+ const horario = [
+ { dia: 'Lunes', hora: clase.lunes },
+ { dia: 'Martes', hora: clase.martes },
+ { dia: 'Miércoles', hora: clase.miercoles },
+ { dia: 'Jueves', hora: clase.jueves },
+ { dia: 'Viernes', hora: clase.viernes },
+ { dia: 'Sábado', hora: clase.sabado },
+ ];
-const ClaseModal = ({clase}) => {
-
- const nivelDict = {
- '1' : 'Desde cero',
- '2' : 'Con bases',
- '3' : 'Intermedio',
- '4' : 'Avanzado'
- }
-
- return (
- <>
-
- {clase.clave}. {clase.nombre_curso}
- Sobre el curso
- Periodo: {clase.clavePeriodo}
- Area: {clase.area}
- Nivel: {nivelDict[clase.nivel]}
- Modalidad: {clase.modalidad}
- Horario:
-
-
-
-
- Lunes
- {clase.lunes ? clase.lunes : '-'}
-
-
- Martes
- {clase.martes ? clase.martes : '-'}
-
-
- Miércoles
- {clase.miercoles ? clase.miercoles : '-'}
-
-
- Jueves
- {clase.jueves ? clase.jueves : '-'}
-
-
- Viernes
- {clase.viernes ? clase.viernes : '-'}
-
-
- Sábado
- {clase.sabado ? clase.sabado : '-'}
-
-
-
-
- Cupos: ¡Curso {(Number(clase.cupo_actual) / Number(clase.cupo_maximo) * 100).toFixed()}% lleno!
-
- >
- )
+ return (
+
+
+ {`${clase.clave}.${clase.nombre_curso}`}
+
+ Sobre el curso
+
+ Periodo:
+ {` ${clase.clavePeriodo}`}
+
+
+ Area:
+ {` ${clase.area}`}
+
+
+ Nivel:
+ {` ${nivelDict[clase.nivel]}`}
+
+
+ Modalidad:
+ {` ${clase.modalidad}`}
+
+
+ Horario:
+ {` `}
+
+
+
+
+ {horario.map((h, i) => (
+
+ {h.dia}
+ {h.hora ? h.hora : '-'}
+
+ ))}
+
+
+
+
+ Cupos:
+ {` ¡Curso ${(Number(clase.cupo_actual) / Number(clase.cupo_maximo) * 100).toFixed()} % lleno!`}
+
+
+ );
}
-export default ClaseModal
\ No newline at end of file
+export default ClaseModal;
\ No newline at end of file
diff --git a/FrontEnd/src/Components/Clase/EditarInscripcion.jsx b/FrontEnd/src/Components/Clase/EditarInscripcion.jsx
new file mode 100644
index 00000000..f8da5fde
--- /dev/null
+++ b/FrontEnd/src/Components/Clase/EditarInscripcion.jsx
@@ -0,0 +1,131 @@
+import React from 'react';
+import {
+ TextField,
+ Typography,
+} from '@mui/material';
+import MenuItem from '@mui/material/MenuItem';
+import {
+ classAtributes, dayAtributes, niveloptions,
+} from '../../utils/constants';
+
+function EditarInscripcion({
+ clase, currentProfesor, handleChange, profesorList, handleChangeProfesor,
+}) {
+ const textFieldStyle = {
+ paddingBottom: '15px',
+ fontFamily: 'arial',
+ marginRight: 10,
+ width: '40%',
+ };
+
+ const containerStyle = {
+ width: '100%',
+ borderTop: '1px solid gray',
+ paddingTop: '5px',
+ };
+
+ const labelStyle = {
+ textAlign: 'center',
+ marginTop: '10px',
+ };
+
+ return (
+
+ {classAtributes.map((atribute) => (
+
handleChange(e)}
+ name={atribute.key}
+ key={atribute.key}
+ value={clase[atribute.key]}
+ autoFocus
+ />
+ ))}
+ handleChange(e)}
+ select
+ >
+ {['presencial', 'online'].map((e) => (
+
+ ))}
+
+ handleChange(e)}
+ select
+ >
+ {niveloptions.map((e) => (
+
+ ))}
+
+
+ Horarios
+ {dayAtributes.map((atribute) => (
+ handleChange(e)}
+ name={atribute.key}
+ key={atribute.key}
+ value={clase[atribute.key]}
+ />
+ ))}
+
+
+ Datos del profesor
+
+ handleChangeProfesor(e)}
+ select
+ >
+ {profesorList.map((e) => (
+
+ ))}
+
+
+
+
+
+ );
+}
+
+export default EditarInscripcion;
diff --git a/FrontEnd/src/Components/Clase/HeaderInscripcionClase.jsx b/FrontEnd/src/Components/Clase/HeaderInscripcionClase.jsx
index aa07859e..35742381 100644
--- a/FrontEnd/src/Components/Clase/HeaderInscripcionClase.jsx
+++ b/FrontEnd/src/Components/Clase/HeaderInscripcionClase.jsx
@@ -9,87 +9,37 @@ import { InsertDriveFile } from '@mui/icons-material';
import Select from 'react-select';
import { CSVLink } from 'react-csv';
import { subirClases, subirProfes } from '../../api/csv';
+import { parseCSV } from '../../utils/utilFunctions';
function HeaderInscripcionClase({
- data, setOpenModal, dataPeriodo, handleSelectChange, resetClases
+ data, setOpenModal, dataPeriodo, handleSelectChange, resetClases,
}) {
const importFile = () => {
const input = document.createElement('input');
input.type = 'file';
-
input.click();
- input.onchange = (e) => {
+ input.onchange = async (e) => {
const { target } = e;
if (!target.files) {
return;
}
- let file;
- file = target.files[0];
-
+ const file = target.files[0];
const reader = new FileReader();
reader.readAsText(file);
- reader.onload = (e) => {
- if (file.name.includes('.csv')) {
- const result = e.target?.result?.toString();
- result !== undefined ? sendCSV(result) : alert('error');
- } else {
- alert('error: el archivo necesita ser tipo markdown o txt');
- }
+ reader.onload = async (e) => {
+ const result = e.target?.result?.toString();
+ const isCsvFile = file.name.includes('.csv');
+ isCsvFile ? sendCSV(result) : alert('error: el archivo necesita ser tipo markdown o txt');
};
};
};
const sendCSV = async (csv) => {
- const csvArray = csv.split('\n').slice(1);
- const clasesJson = [];
- const profesoresJson = [];
- const profesorHash = {};
-
- csvArray.forEach((iterator, i) => {
- const iteratorArray = iterator.split(',');
- const clavePeriodo = iteratorArray[5];
-
- clasesJson[i] = {
- clave: iteratorArray[0],
- nombre_curso: iteratorArray[1],
- nivel: iteratorArray[2],
- area: iteratorArray[3],
- modalidad: iteratorArray[4],
- clavePeriodo,
- cupo_maximo: iteratorArray[6],
- edad_minima: iteratorArray[7],
- edad_maxima: iteratorArray[8],
- lunes: iteratorArray[9],
- martes: iteratorArray[10],
- miercoles: iteratorArray[11],
- jueves: iteratorArray[12],
- viernes: iteratorArray[13],
- sabado: iteratorArray[14],
- matriculaProfesor: iteratorArray[17],
- cupo_actual: '0',
- nombreProfesor: iteratorArray[15].trim(),
- apellidosProfesor: iteratorArray[16].trim(),
- };
-
- const profesorMatricula = iteratorArray[17];
- if (!profesorHash[profesorMatricula]) {
- profesorHash[profesorMatricula] = true;
- profesoresJson.push({
- nombre: iteratorArray[15].trim(),
- apellidos: iteratorArray[16].trim(),
- matricula: profesorMatricula,
- correo: iteratorArray[18],
- fecha_de_nacimiento: '',
- num_telefono: '',
- num_cursos_impartidos: '0',
- idUser: '',
- });
- }
- });
-
- await subirProfes({ profesoresJson: JSON.stringify(profesoresJson) });
- await subirClases({ clasesJson: JSON.stringify(clasesJson) });
+ const { claseList, profesorList } = parseCSV(csv);
+
+ await subirProfes({ profesoresJson: JSON.stringify(profesorList) });
+ await subirClases({ clasesJson: JSON.stringify(claseList) });
resetClases();
};
diff --git a/FrontEnd/src/Components/Clase/InscripcionClase.jsx b/FrontEnd/src/Components/Clase/InscripcionClase.jsx
new file mode 100644
index 00000000..93b493ba
--- /dev/null
+++ b/FrontEnd/src/Components/Clase/InscripcionClase.jsx
@@ -0,0 +1,84 @@
+import React, { useState } from 'react';
+import {
+ classTemplate,
+} from '../../utils/constants';
+import HeaderInscripcionClase from './HeaderInscripcionClase';
+import BodyInscripcionClase from './BodyInscripcionClase';
+import ModalInscripcionClase from './ModalInscripcionClase';
+import { getWaitList } from '../../api/waitList';
+import { getStudents } from '../../api/students';
+
+function InscripcionClase({
+ data, abrirCerrarModal, resetClases, dataPeriodo, handleSelectChange,
+ profesorList, seleccionarClase, clase, currentProfesor,
+ handleChange, handleChangeProfesor, currentOperation, openModal,
+}) {
+ const [currentClase, setCurrentClase] = useState(null);
+ const [currentWaitList, setCurrentWaitList] = useState(null);
+
+ const getClassWaitList = async (clase) => {
+ try {
+ const studentsList = await getStudents();
+ const students = await studentsList.json();
+ const studentsById = students.reduce((obj, student) => {
+ obj[student._id] = student;
+ return obj;
+ }, {});
+
+ const responseWaitList = await getWaitList();
+ const waitList = await responseWaitList.json();
+ const result = [];
+
+ waitList.forEach((inWaitList) => {
+ if (inWaitList.idClase === clase._id && studentsById[inWaitList.idAlumno]) {
+ const student = studentsById[inWaitList.idAlumno];
+ result.push({
+ _id: inWaitList._id,
+ studentName: `${student.nombre} ${student.apellido_paterno} ${student.apellido_materno}`,
+ time_stamp: inWaitList.time_stamp,
+ });
+ }
+ });
+
+ result.sort((a, b) => (a > b ? 1 : a < b ? -1 : 0));
+ setCurrentWaitList(result);
+ setCurrentClase(clase);
+ seleccionarClase(clase, 'AbrirWaitList');
+ } catch (error) {
+ console.error(error);
+ }
+ };
+
+ return (
+
+ { seleccionarClase(classTemplate, 'Crear'); }}
+ resetClases={resetClases}
+ dataPeriodo={dataPeriodo}
+ handleSelectChange={handleSelectChange}
+ />
+
+
+
+ );
+}
+
+export default InscripcionClase;
diff --git a/FrontEnd/src/Components/Clase/ModalInscripcionClase.jsx b/FrontEnd/src/Components/Clase/ModalInscripcionClase.jsx
index 8e5b5e2a..64ae14b9 100644
--- a/FrontEnd/src/Components/Clase/ModalInscripcionClase.jsx
+++ b/FrontEnd/src/Components/Clase/ModalInscripcionClase.jsx
@@ -2,203 +2,63 @@ import React from 'react';
import {
Button,
Modal,
- TextField,
Typography,
} from '@mui/material';
-import MenuItem from '@mui/material/MenuItem';
import WaitList from './WaitList';
+import EditarInscripcion from './EditarInscripcion';
+import { mapNiveles } from '../../utils/utilFunctions';
import {
- classAtributes, dayAtributes, niveloptions,
-} from '../../utils/constants';
+ createClass, deleteClasses, updateClass,
+} from '../../api/classes.js';
function ModalInscripcionClase({
- clase, currentProfesor, handleChange, profesorList, handleChangeProfesor,
- modalSubmit, currentOperation, openModal, setOpenModal, currentClase, currentWaitList,
+ resetClases, clase, currentProfesor, handleChange, profesorList, handleChangeProfesor,
+ currentOperation, openModal, setOpenModal, currentClase, currentWaitList,
}) {
- const bodyEditar = (
-
- {classAtributes.map((atribute) => (
-
{
- handleChange(e);
- }}
- name={atribute.key}
- key={atribute.key}
- value={clase[atribute.key]}
- autoFocus
- />
- ))}
- {
- handleChange(e);
- }}
- select
- >
- {['presencial', 'online'].map((e) => (
-
- ))}
-
- {
- handleChange(e);
- }}
- select
- >
- {niveloptions.map((e) => (
-
- ))}
-
-
-
- Horarios
-
- {dayAtributes.map((atribute) => (
- {
- handleChange(e);
- }}
- name={atribute.key}
- key={atribute.key}
- value={clase[atribute.key]}
- autoFocus
- />
- ))}
-
-
-
- Datos del profesor
-
-
- {
- handleChangeProfesor(e);
- }}
- select
- >
- {profesorList.map((e) => (
-
- ))}
-
-
-
-
-
- );
+ const modalSubmit = async (e) => {
+ e.preventDefault();
+ try {
+ if (currentOperation === 'Eliminar') {
+ await deleteClasses({
+ _id: clase._id,
+ });
+ } else if (currentOperation === 'Crear') {
+ const claseACrear = mapNiveles(classTemplate, currentProfesor);
+ await createClass(claseACrear);
+ } else if (currentOperation === 'Editar') {
+ const claseAModificar = mapNiveles(clase, currentProfesor);
+ await updateClass(claseAModificar);
+ }
+ } catch (error) {
+ console.log(error);
+ }
+ setOpenModal();
+ resetClases();
+ };
const generateActionModalBody = () => (
- {currentOperation === 'ELiminar' ?
- 'Eliminar una clase' :
- (currentOperation === 'Editar' ?
- 'Actualizar una clase' : 'Añadir nueva clase')}
+ {currentOperation === 'ELiminar'
+ ? 'Eliminar una clase'
+ : (currentOperation === 'Editar'
+ ? 'Actualizar una clase' : 'Añadir nueva clase')}
- {
- currentOperation === 'Eliminar' &&
+ {
+ currentOperation === 'Eliminar'
+ && (
{`Esta clase ${clase.clave} y toda su información relacionada a ella va a ser eliminada`}
-
+
+ )
}
{
- (currentOperation === 'Editar' || currentOperation === 'Crear') && bodyEditar
+ (currentOperation === 'Editar' || currentOperation === 'Crear') &&
}
-
- )
+ );
return (
diff --git a/FrontEnd/src/Components/Dialog/ConfirmationDialog.jsx b/FrontEnd/src/Components/Dialog/ConfirmationDialog.jsx
index d3c60edd..f894fceb 100644
--- a/FrontEnd/src/Components/Dialog/ConfirmationDialog.jsx
+++ b/FrontEnd/src/Components/Dialog/ConfirmationDialog.jsx
@@ -1,16 +1,103 @@
-import React, {useState} from 'react';
+import React from 'react';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
+import { findTerm } from '../../api/term';
+import {
+ getClassStudent,
+ deleteClassStudent,
+} from '../../api/classStudent';
+import {
+ createClassStudent,
+} from '../../api/classStudent';
+import {
+ createWaitList,
+ getWaitList,
+ deleteWaitList,
+} from '../../api/waitList';
+import { dialogTitle, dialogContent } from '../../utils/utilFunctions';
export default function ConfirmationDialog({
- handleClaseRegistrada, handleCancelarClaseRegistrada,
- handleSalirListaEspera, handleClose, open, clase, handleListaEspera, action
+ setError, setErrorMsg, handleClose, open, clase, action
}) {
+ const handleListaEspera = async (clase) => {
+ const waitListResponse = await getWaitList();
+ const lista = (await waitListResponse.json()).filter(
+ (lista) => lista.idAlumno === currentStudent._id,
+ );
+
+ await createWaitList({
+ idAlumno: currentStudent._id,
+ idClase: clase._id,
+ time_stamp: new Date().toISOString(),
+ status: 'Espera',
+ });
+ clase.status = 'ListaEspera';
+ handleCloseDialog();
+ };
+
+ const handleSalirListaEspera = async (clase) => {
+ const periodoResponse = await findTerm({ clave: clase.clavePeriodo });
+ const periodo = await periodoResponse.json();
+
+ const myWaitListResponse = await getWaitList();
+ const myWaitList = (await myWaitListResponse.json()).filter(
+ (aWList) => aWList.idClase === clase._id
+ && aWList.idAlumno === currentStudent._id
+ && aWList.idPeriodo === periodo[0]._id,
+ );
+
+ await deleteWaitList({ _id: myWaitList[0]._id });
+ clase.status = '';
+ handleCloseDialog();
+ };
+
+ const handleClaseRegistrada = async (clase) => {
+ try {
+ const periodoResponse = await findTerm({ clave: clase.clavePeriodo });
+ const periodo = await periodoResponse.json();
+
+ const response = await createClassStudent({
+ idClase: clase._id,
+ idAlumno: currentStudent._id,
+ idPeriodo: periodo[0]._id,
+ });
+
+ const data = await response.json();
+
+ if (data.msg.includes('Un documento fue insertado con el ID')) {
+ clase.status = 'Inscrito';
+ handleCloseDialog();
+ } else {
+ handleCloseDialog();
+ setErrorMsg(data.msg);
+ setError(true);
+ }
+ } catch (error) {
+ alert(error);
+ }
+ };
+
+ const handleCancelarClaseRegistrada = async (clase) => {
+ const periodoResponse = await findTerm({ clave: clase.clavePeriodo });
+ const periodo = await periodoResponse.json();
+
+ const myClassStudentResponse = await getClassStudent();
+ const myClassStudent = (await myClassStudentResponse.json()).filter(
+ (aClass) => aClass.idClase === clase._id
+ && aClass.idAlumno === currentStudent._id
+ && aClass.idPeriodo === periodo[0]._id,
+ );
+
+ await deleteClassStudent({ _id: myClassStudent[0]._id });
+ clase.status = '';
+ handleClose();
+ };
+
const handleClick = () =>{
switch (action) {
case 'ListaEspera':
@@ -28,33 +115,6 @@ export default function ConfirmationDialog({
}
}
- const dialogContent = (clase) => {
- switch (action) {
- case 'ListaEspera':
- return `Estas seguro que quieres entrar a la lista de espera de la clase ${clase.clave} ${clase.nombre_curso} ${clase.nivel}.`
- case 'Registrar':
- return `Estas seguro que quieres inscribir la clase ${clase.clave} ${clase.nombre_curso} ${clase.nivel},
- recuerda que hay inscripciones limitadas.`
- case 'CancelarInscripcion':
- return `Estas seguro que quieres cancelar tu inscripción de la clase ${clase.clave} ${clase.nombre_curso} ${clase.nivel}.`
- case 'SalirLista':
- return `Estas seguro que quieres salir de la lista de espera de la clase ${clase.clave} ${clase.nombre_curso} ${clase.nivel}.`
- }
- }
-
- const dialogTitle = () => {
- switch (action) {
- case 'ListaEspera':
- return '¿Entrar a lista de espera?'
- case 'Registrar':
- return '¿Inscribir esta clase? '
- case 'CancelarInscripcion':
- return '¿Cancelar inscripción?'
- case 'SalirLista':
- return '¿Salir de lista de espera?'
- }
- }
-
return (