feat: add admin management page and types
- Implemented the admin management page with a table displaying admin details. - Created the Administrador type definition for better type safety. - Added SubmitResponse type for handling submission responses. - Included placeholder components for form card previews.
This commit is contained in:
@@ -14,4 +14,46 @@ const axiosInstance = axios.create({
|
||||
},
|
||||
});
|
||||
|
||||
// Request interceptor para agregar el token de autenticación
|
||||
axiosInstance.interceptors.request.use(
|
||||
(config) => {
|
||||
// Obtener el token del sessionStorage
|
||||
const token = sessionStorage.getItem('token');
|
||||
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// Response interceptor para manejar errores de autenticación
|
||||
axiosInstance.interceptors.response.use(
|
||||
(response) => {
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
// Si el token ha expirado o es inválido (401)
|
||||
if (error.response?.status === 401) {
|
||||
// Limpiar el sessionStorage
|
||||
sessionStorage.removeItem('token');
|
||||
sessionStorage.removeItem('user');
|
||||
|
||||
// Redireccionar al login solo si no estamos ya en la página de login
|
||||
if (
|
||||
typeof window !== 'undefined' &&
|
||||
!window.location.pathname.includes('/login')
|
||||
) {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default axiosInstance;
|
||||
|
||||
@@ -268,3 +268,63 @@ export function formatearFechaCard(
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extrae y formatea el horario entre dos fechas.
|
||||
* Retorna el rango de horas en formato "HH:MM a HH:MM Hrs".
|
||||
*
|
||||
* @param {string | Date} fechaInicio - Fecha de inicio en formato ISO 8601 o objeto Date.
|
||||
* @param {string | Date} fechaFin - Fecha de fin en formato ISO 8601 o objeto Date.
|
||||
* @returns {string} Horario formateado en formato "HH:MM a HH:MM Hrs".
|
||||
* @throws {Error} Lanza un error si alguna de las fechas proporcionadas no es válida.
|
||||
*
|
||||
* @example
|
||||
* formatearHorario('2025-08-13T13:00:00.000Z', '2025-08-13T14:00:00.000Z');
|
||||
* // Retorna: "07:00 a 08:00 Hrs" (ajustado a UTC-6)
|
||||
*
|
||||
* @example
|
||||
* formatearHorario(new Date('2025-08-13T19:30:00.000Z'), new Date('2025-08-13T21:45:00.000Z'));
|
||||
* // Retorna: "13:30 a 15:45 Hrs"
|
||||
*
|
||||
* @example
|
||||
* formatearHorario('2025-08-13T13:00:00.000Z', '2025-08-13T13:00:00.000Z');
|
||||
* // Retorna: "07:00 Hrs" (misma hora)
|
||||
*/
|
||||
export function formatearHorario(
|
||||
fechaInicio: string | Date,
|
||||
fechaFin: string | Date
|
||||
): string {
|
||||
// Convertir a Date si son strings
|
||||
const inicio =
|
||||
typeof fechaInicio === 'string' ? new Date(fechaInicio) : fechaInicio;
|
||||
const fin = typeof fechaFin === 'string' ? new Date(fechaFin) : fechaFin;
|
||||
|
||||
if (isNaN(inicio.getTime())) {
|
||||
throw new Error(`Fecha de inicio inválida: ${fechaInicio}`);
|
||||
}
|
||||
|
||||
if (isNaN(fin.getTime())) {
|
||||
throw new Error(`Fecha de fin inválida: ${fechaFin}`);
|
||||
}
|
||||
|
||||
// Ajustar a zona horaria UTC-6 (México)
|
||||
const horaInicio = (inicio.getUTCHours() - 6 + 24) % 24;
|
||||
const minutosInicio = inicio.getUTCMinutes().toString().padStart(2, '0');
|
||||
|
||||
const horaFin = (fin.getUTCHours() - 6 + 24) % 24;
|
||||
const minutosFin = fin.getUTCMinutes().toString().padStart(2, '0');
|
||||
|
||||
const horaInicioFormateada = `${horaInicio
|
||||
.toString()
|
||||
.padStart(2, '0')}:${minutosInicio}`;
|
||||
const horaFinFormateada = `${horaFin
|
||||
.toString()
|
||||
.padStart(2, '0')}:${minutosFin}`;
|
||||
|
||||
// Si es la misma hora, solo mostrar una vez
|
||||
if (horaInicioFormateada === horaFinFormateada) {
|
||||
return `${horaInicioFormateada} Hrs`;
|
||||
}
|
||||
|
||||
return `${horaInicioFormateada} a ${horaFinFormateada}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user