Modificaciones
This commit is contained in:
@@ -146,7 +146,7 @@ export default function Home() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{ data?.status.idStatus !== undefined && data?.status.idStatus >= 4 && (
|
||||
{ data?.status.idStatus !== undefined && data?.status.idStatus >= 4 && data?.status.idStatus !== 8 && data?.status.idStatus !== 9 && (
|
||||
<PreTermino
|
||||
alumno={{tokenAlumno: localStorage.getItem('token') || ""}}
|
||||
servicio={data}
|
||||
|
||||
@@ -8,6 +8,10 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function BarraProgreso({ idStatus }: Props) {
|
||||
// Si el status es 7, mostrar como si fuera 1 (Pre Registro)
|
||||
// Si el status es 8 o 9, mostrar como 5 (Termino)
|
||||
const statusMapeado = idStatus === 7 ? 1 : (idStatus === 8 || idStatus === 9 ? 5 : idStatus);
|
||||
|
||||
const steps = [
|
||||
{ label: "Pre Registro", icon: <FaUserPlus />, id: 1 },
|
||||
{ label: "Pre Registro Validado", icon: <FaUserCheck />, id: 2 },
|
||||
@@ -21,8 +25,8 @@ export default function BarraProgreso({ idStatus }: Props) {
|
||||
<div className="container mt-5">
|
||||
<div className="d-flex justify-content-center align-items-center position-relative">
|
||||
{steps.map((step, index) => {
|
||||
const isActive = idStatus >= step.id;
|
||||
const isCurrent = idStatus === step.id;
|
||||
const isActive = statusMapeado >= step.id;
|
||||
const isCurrent = statusMapeado === step.id;
|
||||
|
||||
return (
|
||||
<div key={index} className="text-center position-relative flex-fill">
|
||||
|
||||
@@ -29,6 +29,7 @@ type Formulario = { titulo?: string; descripcion?: string; preguntas: Pregunta[]
|
||||
export default function FullCuestionario() {
|
||||
const [respuestas, setRespuestas] = useState<Record<string, string | string[] | Record<number, string | null> | null>>({});
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isFormDisabled, setIsFormDisabled] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
@@ -100,6 +101,29 @@ export default function FullCuestionario() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
// Verificar si el cuestionario ya fue contestado
|
||||
useEffect(() => {
|
||||
const checkIfFormAlreadyCompleted = async () => {
|
||||
try {
|
||||
const idServicio = typeof window !== 'undefined' ? localStorage.getItem('idServicio') : null;
|
||||
if (!idServicio) return;
|
||||
|
||||
const response = await axiosInstance.get(`/servicio/admin?idServicio=${idServicio}`);
|
||||
const idCuestionarioAlumno2 = response.data?.idCuestionarioAlumno2;
|
||||
|
||||
// Si ya existe un cuestionario contestado, deshabilitar el formulario
|
||||
if (idCuestionarioAlumno2 && idCuestionarioAlumno2 > 0) {
|
||||
setIsFormDisabled(true);
|
||||
window.alert('Este cuestionario ya ha sido contestado. No puedes modificar tus respuestas.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error al verificar cuestionario:', error);
|
||||
}
|
||||
};
|
||||
|
||||
checkIfFormAlreadyCompleted();
|
||||
}, []);
|
||||
|
||||
const isMobile = () => typeof window !== 'undefined' && window.innerWidth < 576;
|
||||
|
||||
const sortedItems = useMemo(() => {
|
||||
@@ -304,7 +328,7 @@ export default function FullCuestionario() {
|
||||
{p.opciones?.map((op) => (
|
||||
<div key={p.id + '-' + op} className="SINO">
|
||||
<label>
|
||||
<input type="radio" name={p.id} checked={respuestas[p.id] === op} onChange={() => updateRespuestas(p.id, op)} /> {op}
|
||||
<input type="radio" name={p.id} checked={respuestas[p.id] === op} onChange={() => updateRespuestas(p.id, op)} disabled={isFormDisabled} /> {op}
|
||||
</label>
|
||||
</div>
|
||||
))}
|
||||
@@ -315,7 +339,7 @@ export default function FullCuestionario() {
|
||||
{p.opciones?.map((op) => (
|
||||
<div key={op} className="SINO">
|
||||
<label className="mt-2">
|
||||
<input className="checkb" type="checkbox" value={op} checked={Array.isArray(respuestas[p.id]) && (respuestas[p.id] as string[]).includes(op)} onChange={(e) => toggleSelection(p.id, op, e)} /> {op}
|
||||
<input className="checkb" type="checkbox" value={op} checked={Array.isArray(respuestas[p.id]) && (respuestas[p.id] as string[]).includes(op)} onChange={(e) => toggleSelection(p.id, op, e)} disabled={isFormDisabled} /> {op}
|
||||
</label>
|
||||
</div>
|
||||
))}
|
||||
@@ -323,7 +347,7 @@ export default function FullCuestionario() {
|
||||
)}
|
||||
{p.tipo === 'texto' && (
|
||||
<div>
|
||||
<input id={p.id} className="form-control bg-transparent" type="text" value={(respuestas[p.id] as string) || ''} onChange={(e) => updateRespuestas(p.id, e.target.value)} maxLength={p.limite || 200} placeholder="Escribe tu respuesta aquí" />
|
||||
<input id={p.id} className="form-control bg-transparent" type="text" value={(respuestas[p.id] as string) || ''} onChange={(e) => updateRespuestas(p.id, e.target.value)} maxLength={p.limite || 200} placeholder="Escribe tu respuesta aquí" disabled={isFormDisabled} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -353,7 +377,7 @@ export default function FullCuestionario() {
|
||||
<td className="bg-transparent">{r.textoRenglon}</td>
|
||||
{r.opciones.map((op) => (
|
||||
<td className="bg-transparent" key={op}>
|
||||
<input type="radio" name={`tabla-${t.idTabla}-renglon-${r.idRenglon}`} value={op} checked={Boolean(tablaResp && tablaResp[r.idRenglon] === op)} onChange={() => handleTableResponse(t.idTabla, r.idRenglon, op)} />
|
||||
<input type="radio" name={`tabla-${t.idTabla}-renglon-${r.idRenglon}`} value={op} checked={Boolean(tablaResp && tablaResp[r.idRenglon] === op)} onChange={() => handleTableResponse(t.idTabla, r.idRenglon, op)} disabled={isFormDisabled} />
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
@@ -366,9 +390,14 @@ export default function FullCuestionario() {
|
||||
})}
|
||||
|
||||
<div className="my-6 mb-6 text-center mb-5">
|
||||
<button className="btn btn-success is-medium" onClick={submitForm} disabled={!isFormComplete}>
|
||||
<button className="btn btn-success is-medium" onClick={submitForm} disabled={!isFormComplete || isFormDisabled || isLoading}>
|
||||
{isLoading ? 'Enviando...' : 'Enviar'}
|
||||
</button>
|
||||
{isFormDisabled && (
|
||||
<div className="alert alert-info mt-3" role="alert">
|
||||
Este cuestionario ya ha sido contestado y no puede ser modificado.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ export default function PreTermino({
|
||||
|
||||
{/* !servicio.idCuestionarioAlumno && !servicio.idCuestionarioAlumno2 ? */}
|
||||
|
||||
{!servicio.idCuestionarioAlumno ? (
|
||||
{servicio.idCuestionarioAlumno2 ? (
|
||||
<div className="mb-5">
|
||||
<a
|
||||
href="/alumno/cuestionario"
|
||||
|
||||
Reference in New Issue
Block a user