jgest-react-vite 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -0
- package/index.js +21 -0
- package/package.json +17 -0
- package/template/.env +1 -0
- package/template/README.md +116 -0
- package/template/eslint.config.js +26 -0
- package/template/index.html +13 -0
- package/template/package.json +40 -0
- package/template/pnpm-lock.yaml +3339 -0
- package/template/public/vite.svg +1 -0
- package/template/src/App.tsx +30 -0
- package/template/src/Router.tsx +17 -0
- package/template/src/components/main/ThemeSwitch.tsx +80 -0
- package/template/src/components/shared/MyModal.tsx +51 -0
- package/template/src/components/shared/MyPopover.tsx +44 -0
- package/template/src/hooks/shared/useNotification.ts +25 -0
- package/template/src/hooks/shared/useSetTimezone.ts +20 -0
- package/template/src/index.css +9 -0
- package/template/src/layouts/MainLayout.tsx +23 -0
- package/template/src/main.tsx +10 -0
- package/template/src/modules/MainPage/MainPageContent.tsx +100 -0
- package/template/src/pages/MainPage/MainPage.tsx +12 -0
- package/template/src/providers/NotificationProvider/NotificationProvider.tsx +61 -0
- package/template/src/providers/NotificationProvider/context/NotificationContext.tsx +20 -0
- package/template/src/services/ApiService.ts +54 -0
- package/template/src/services/ToBeTested/ApiService-New.ts +94 -0
- package/template/src/store/ThemeStore/Themes/themes.ts +28 -0
- package/template/src/store/ThemeStore/themeStore.ts +28 -0
- package/template/tsconfig.app.json +28 -0
- package/template/tsconfig.json +7 -0
- package/template/tsconfig.node.json +26 -0
- package/template/vite.config.ts +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# React + TypeScript + Vite Template (JGest)
|
|
2
|
+
|
|
3
|
+
Este es un template personalizado de React optimizado para el desarrollo rápido con Material UI, gestión de estado y servicios de API preconfigurados.
|
|
4
|
+
|
|
5
|
+
## 🚀 Configuración del Proyecto
|
|
6
|
+
|
|
7
|
+
### 1. Configurar la API
|
|
8
|
+
Para que el proyecto se comunique con tu backend, debes configurar la URL base en el archivo `.env`.
|
|
9
|
+
|
|
10
|
+
Crea o edita el archivo `.env` en la raíz del proyecto:
|
|
11
|
+
```env
|
|
12
|
+
VITE_APP_API_URL='https://tu-api.com/api'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### 2. Instalación y Ejecución
|
|
16
|
+
```bash
|
|
17
|
+
npm install
|
|
18
|
+
npm run dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🛠️ Servicios y Utilidades
|
|
24
|
+
|
|
25
|
+
### `ApiService`
|
|
26
|
+
Ubicación: `src/services/ApiService.ts`
|
|
27
|
+
|
|
28
|
+
Un servicio basado en **Axios** para realizar peticiones HTTP de forma sencilla. Ya maneja la captura de errores y los devuelve en un formato consistente.
|
|
29
|
+
|
|
30
|
+
**Uso:**
|
|
31
|
+
```typescript
|
|
32
|
+
import { api } from './services/ApiService';
|
|
33
|
+
|
|
34
|
+
// Ejemplo GET
|
|
35
|
+
const data = await api.get<MiTipo>('/endpoint');
|
|
36
|
+
|
|
37
|
+
// Ejemplo POST
|
|
38
|
+
const result = await api.post('/endpoint', { nombre: 'Ejemplo' });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### `useNotification` (Hook)
|
|
42
|
+
Ubicación: `src/hooks/shared/useNotification.ts`
|
|
43
|
+
|
|
44
|
+
Permite mostrar alertas (notificaciones) en la interfaz de usuario. Debe usarse dentro del `NotificationProvider`.
|
|
45
|
+
|
|
46
|
+
**Uso:**
|
|
47
|
+
```typescript
|
|
48
|
+
import { useNotification } from './hooks/shared/useNotification';
|
|
49
|
+
|
|
50
|
+
const { showNotification } = useNotification();
|
|
51
|
+
|
|
52
|
+
// Mostrar mensaje de éxito
|
|
53
|
+
showNotification('Operación exitosa', 'success');
|
|
54
|
+
|
|
55
|
+
// Manejar errores de la API automáticamente
|
|
56
|
+
try {
|
|
57
|
+
await api.post(...);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
showNotification(error); // Muestra el error formateado por el ApiService
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `useSetTimezone` (Hook)
|
|
64
|
+
Ubicación: `src/hooks/shared/useSetTimezone.ts`
|
|
65
|
+
|
|
66
|
+
Utilidad para formatear fechas recibidas de la API a la zona horaria local (`Europe/Madrid`).
|
|
67
|
+
|
|
68
|
+
**Uso:**
|
|
69
|
+
```typescript
|
|
70
|
+
import useSetTimezone from './hooks/shared/useSetTimezone';
|
|
71
|
+
|
|
72
|
+
const { setTimezone } = useSetTimezone();
|
|
73
|
+
const fechaFormateada = setTimezone('2024-03-12T10:00:00Z');
|
|
74
|
+
// Salida: "12/3/2024, 11:00:00" (ajustado a Madrid)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🧩 Componentes Destacados
|
|
80
|
+
|
|
81
|
+
### `ThemeToggle`
|
|
82
|
+
Ubicación: `src/components/main/ThemeSwitch.tsx`
|
|
83
|
+
|
|
84
|
+
Un componente de interruptor (Switch) estilizado para alternar entre el modo claro y oscuro. Utiliza un store global para persistir la preferencia.
|
|
85
|
+
|
|
86
|
+
**Uso:**
|
|
87
|
+
Simplemente importa y coloca el componente en tu barra de navegación o sidebar:
|
|
88
|
+
```tsx
|
|
89
|
+
import ThemeToggle from './components/main/ThemeSwitch';
|
|
90
|
+
|
|
91
|
+
<ThemeToggle />
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `MyModal`
|
|
95
|
+
Ubicación: `src/components/shared/MyModal.tsx`
|
|
96
|
+
|
|
97
|
+
Un componente base para crear modales consistentes, con fondo desenfocado y scroll interno.
|
|
98
|
+
|
|
99
|
+
**Propiedades:**
|
|
100
|
+
- `children`: Contenido del modal.
|
|
101
|
+
- `minWidth`: Ancho mínimo (por defecto 800px).
|
|
102
|
+
- `onClose`: Función que se ejecuta al cerrar o hacer clic fuera.
|
|
103
|
+
|
|
104
|
+
### `MyPopover`
|
|
105
|
+
Ubicación: `src/components/shared/MyPopover.tsx`
|
|
106
|
+
|
|
107
|
+
Componente para mostrar menús contextuales o popovers flexibles con posicionamiento automático.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 🏗️ Estructura de Carpetas
|
|
112
|
+
- `src/components`: Componentes visuales (shared/main).
|
|
113
|
+
- `src/hooks`: Lógica reutilizable y hooks personalizados.
|
|
114
|
+
- `src/providers`: Proveedores de contexto (Notificaciones, Auth, etc.).
|
|
115
|
+
- `src/services`: Llamadas a APIs y servicios externos.
|
|
116
|
+
- `src/store`: Gestión de estado global (Zustand/Context).
|
package/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
const targetDir = process.argv[2] || "mi-app";
|
|
11
|
+
|
|
12
|
+
// Ruta correcta a la carpeta template
|
|
13
|
+
const templateDir = path.join(__dirname, "template");
|
|
14
|
+
|
|
15
|
+
// Copiar plantilla
|
|
16
|
+
fs.cpSync(templateDir, path.join(cwd, targetDir), { recursive: true });
|
|
17
|
+
|
|
18
|
+
console.log(`\nProyecto creado en ./${targetDir}`);
|
|
19
|
+
console.log("Ejecuta:");
|
|
20
|
+
console.log(` cd ${targetDir}`);
|
|
21
|
+
console.log(" pnpm install\n");
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"name": "jgest-react-vite",
|
|
4
|
+
"version": "1.1.2",
|
|
5
|
+
"description": "Una template de React con Vite",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"react",
|
|
9
|
+
"vite",
|
|
10
|
+
"template"
|
|
11
|
+
],
|
|
12
|
+
"author": "Jaime Gómez-Estrada",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"files": [
|
|
15
|
+
"template"
|
|
16
|
+
]
|
|
17
|
+
}
|
package/template/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VITE_APP_API_URL=''
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# React + TypeScript + Vite Template (JGest)
|
|
2
|
+
|
|
3
|
+
Este es un template personalizado de React optimizado para el desarrollo rápido con Material UI, gestión de estado y servicios de API preconfigurados.
|
|
4
|
+
|
|
5
|
+
## 🚀 Configuración del Proyecto
|
|
6
|
+
|
|
7
|
+
### 1. Configurar la API
|
|
8
|
+
Para que el proyecto se comunique con tu backend, debes configurar la URL base en el archivo `.env`.
|
|
9
|
+
|
|
10
|
+
Crea o edita el archivo `.env` en la raíz del proyecto:
|
|
11
|
+
```env
|
|
12
|
+
VITE_APP_API_URL='https://tu-api.com/api'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### 2. Instalación y Ejecución
|
|
16
|
+
```bash
|
|
17
|
+
npm install
|
|
18
|
+
npm run dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🛠️ Servicios y Utilidades
|
|
24
|
+
|
|
25
|
+
### `ApiService`
|
|
26
|
+
Ubicación: `src/services/ApiService.ts`
|
|
27
|
+
|
|
28
|
+
Un servicio basado en **Axios** para realizar peticiones HTTP de forma sencilla. Ya maneja la captura de errores y los devuelve en un formato consistente.
|
|
29
|
+
|
|
30
|
+
**Uso:**
|
|
31
|
+
```typescript
|
|
32
|
+
import { api } from './services/ApiService';
|
|
33
|
+
|
|
34
|
+
// Ejemplo GET
|
|
35
|
+
const data = await api.get<MiTipo>('/endpoint');
|
|
36
|
+
|
|
37
|
+
// Ejemplo POST
|
|
38
|
+
const result = await api.post('/endpoint', { nombre: 'Ejemplo' });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### `useNotification` (Hook)
|
|
42
|
+
Ubicación: `src/hooks/shared/useNotification.ts`
|
|
43
|
+
|
|
44
|
+
Permite mostrar alertas (notificaciones) en la interfaz de usuario. Debe usarse dentro del `NotificationProvider`.
|
|
45
|
+
|
|
46
|
+
**Uso:**
|
|
47
|
+
```typescript
|
|
48
|
+
import { useNotification } from './hooks/shared/useNotification';
|
|
49
|
+
|
|
50
|
+
const { showNotification } = useNotification();
|
|
51
|
+
|
|
52
|
+
// Mostrar mensaje de éxito
|
|
53
|
+
showNotification('Operación exitosa', 'success');
|
|
54
|
+
|
|
55
|
+
// Manejar errores de la API automáticamente
|
|
56
|
+
try {
|
|
57
|
+
await api.post(...);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
showNotification(error); // Muestra el error formateado por el ApiService
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `useSetTimezone` (Hook)
|
|
64
|
+
Ubicación: `src/hooks/shared/useSetTimezone.ts`
|
|
65
|
+
|
|
66
|
+
Utilidad para formatear fechas recibidas de la API a la zona horaria local (`Europe/Madrid`).
|
|
67
|
+
|
|
68
|
+
**Uso:**
|
|
69
|
+
```typescript
|
|
70
|
+
import useSetTimezone from './hooks/shared/useSetTimezone';
|
|
71
|
+
|
|
72
|
+
const { setTimezone } = useSetTimezone();
|
|
73
|
+
const fechaFormateada = setTimezone('2024-03-12T10:00:00Z');
|
|
74
|
+
// Salida: "12/3/2024, 11:00:00" (ajustado a Madrid)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🧩 Componentes Destacados
|
|
80
|
+
|
|
81
|
+
### `ThemeToggle`
|
|
82
|
+
Ubicación: `src/components/main/ThemeSwitch.tsx`
|
|
83
|
+
|
|
84
|
+
Un componente de interruptor (Switch) estilizado para alternar entre el modo claro y oscuro. Utiliza un store global para persistir la preferencia.
|
|
85
|
+
|
|
86
|
+
**Uso:**
|
|
87
|
+
Simplemente importa y coloca el componente en tu barra de navegación o sidebar:
|
|
88
|
+
```tsx
|
|
89
|
+
import ThemeToggle from './components/main/ThemeSwitch';
|
|
90
|
+
|
|
91
|
+
<ThemeToggle />
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `MyModal`
|
|
95
|
+
Ubicación: `src/components/shared/MyModal.tsx`
|
|
96
|
+
|
|
97
|
+
Un componente base para crear modales consistentes, con fondo desenfocado y scroll interno.
|
|
98
|
+
|
|
99
|
+
**Propiedades:**
|
|
100
|
+
- `children`: Contenido del modal.
|
|
101
|
+
- `minWidth`: Ancho mínimo (por defecto 800px).
|
|
102
|
+
- `onClose`: Función que se ejecuta al cerrar o hacer clic fuera.
|
|
103
|
+
|
|
104
|
+
### `MyPopover`
|
|
105
|
+
Ubicación: `src/components/shared/MyPopover.tsx`
|
|
106
|
+
|
|
107
|
+
Componente para mostrar menús contextuales o popovers flexibles con posicionamiento automático.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 🏗️ Estructura de Carpetas
|
|
112
|
+
- `src/components`: Componentes visuales (shared/main).
|
|
113
|
+
- `src/hooks`: Lógica reutilizable y hooks personalizados.
|
|
114
|
+
- `src/providers`: Proveedores de contexto (Notificaciones, Auth, etc.).
|
|
115
|
+
- `src/services`: Llamadas a APIs y servicios externos.
|
|
116
|
+
- `src/store`: Gestión de estado global (Zustand/Context).
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(['dist']),
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
extends: [
|
|
13
|
+
js.configs.recommended,
|
|
14
|
+
tseslint.configs.recommended,
|
|
15
|
+
reactHooks.configs.flat.recommended,
|
|
16
|
+
reactRefresh.configs.vite,
|
|
17
|
+
],
|
|
18
|
+
languageOptions: {
|
|
19
|
+
ecmaVersion: 2020,
|
|
20
|
+
globals: globals.browser,
|
|
21
|
+
},
|
|
22
|
+
// rules: {
|
|
23
|
+
// "@typescript-eslint/no-explicit-any": ["off"]
|
|
24
|
+
// },
|
|
25
|
+
},
|
|
26
|
+
])
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>JGEST-Template</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "prueba-lis-remake",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc -b && vite build",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@emotion/react": "^11.14.0",
|
|
14
|
+
"@emotion/styled": "^11.14.1",
|
|
15
|
+
"@mui/material": "^7.3.9",
|
|
16
|
+
"@tailwindcss/vite": "^4.2.1",
|
|
17
|
+
"@tanstack/react-query": "^5.90.21",
|
|
18
|
+
"axios": "^1.13.6",
|
|
19
|
+
"formik": "^2.4.9",
|
|
20
|
+
"react": "^19.2.0",
|
|
21
|
+
"react-dom": "^19.2.0",
|
|
22
|
+
"react-router-dom": "^7.13.1",
|
|
23
|
+
"tailwindcss": "^4.2.1",
|
|
24
|
+
"zustand": "^5.0.11"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@eslint/js": "^9.39.1",
|
|
28
|
+
"@types/node": "^24.10.1",
|
|
29
|
+
"@types/react": "^19.2.7",
|
|
30
|
+
"@types/react-dom": "^19.2.3",
|
|
31
|
+
"@vitejs/plugin-react-swc": "^4.2.3",
|
|
32
|
+
"eslint": "^9.39.1",
|
|
33
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
34
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
35
|
+
"globals": "^16.5.0",
|
|
36
|
+
"typescript": "~5.9.3",
|
|
37
|
+
"typescript-eslint": "^8.48.0",
|
|
38
|
+
"vite": "^7.3.1"
|
|
39
|
+
}
|
|
40
|
+
}
|