File size: 9,189 Bytes
5d31219
 
 
 
 
 
 
728f73b
5d31219
 
 
728f73b
5d31219
 
 
 
 
 
19a6616
5d31219
 
 
 
 
 
 
 
 
728f73b
5d31219
 
 
 
7518068
5d31219
 
 
c5e758a
5d31219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3b8db8
5d31219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import Toggler from './components/Toggler';
import Dashboard from './screens/Dashboard';
import Login from './screens/Login';
import Reportes from './screens/Reportes';
import MonitoreoGnosis from './screens/MonitoreoGnosis';

function HectronApp() {
  const [logged, setLogged] = useState(false);
  const [sintonizado, setSintonizado] = useState(false);

  useEffect(() => {
    const token = localStorage.getItem('token');
    if (token) {
      setLogged(true);
    }
  }, []);

  const handleLogin = async (email, password) => {
    try {
      const response = await axios.post('/login', { email, password });
      localStorage.setItem('token', response.data.token);
      setLogged(true);
    } catch (error) {
      console.error(error);
    }
  };

  const handleLogout = () => {
    localStorage.removeItem('token');
    setLogged(false);
  };

  const handleSintonizar = () => {
    setSintonizado(!sintonizado);
  };

  return (
    <div className="flex h-screen justify-center items-center overflow-hidden">
      {logged ? (
        <div className="relative flex w-full items-center justify-between py-4">
          <div className="hidden lg:block">
            <img src="/hectron-logo.png" alt="Hectron logo" className="w-32" />
          </div>
          <div className="lg:hidden">
            <Toggler
              checked={sintonizado}
              onChange={handleSintonizar}
              label="Sintonizar"
            />
          </div>
          <div className="hidden lg:flex">
            <Toggler
              checked={sintonizado}
              onChange={handleSintonizar}
              label="Sintonizar"
              className="ml-auto"
            />
          </div>
          <div className="lg:hidden">
            <button
              onClick={handleLogout}
              className="bg-red-500 hover:bg-red-700 text-white py-2 px-4 rounded"
            >
              Desconectar
            </button>
          </div>
        </div>
      ) : (
        <Login onLogin={handleLogin} />
      )}
      {logged && (
        <main className="flex-1 max-w-7xl mx-auto p-4">
          <div className="flex w-full lg:h-screen">
            <div className="w-24 lg:w-64 fixed top-24 hidden lg:block left-4 bg-white shadow-md rounded p-4">
              <ul>
                <li>
                  <a
                    href="#"
                    className="flex justify-between items-center py-2 text-gray-600 hover:text-gray-900"
                  >
                    <span>Monitoreo de Gnosis</span>
                    <span className="ml-2">
                      <i className="fas fa-tachometer-alt" />
                    </span>
                  </a>
                </li>
                <li>
                  <a
                    href="#"
                    className="flex justify-between items-center py-2 text-gray-600 hover:text-gray-900"
                  >
                    <span>Configuración de alertas</span>
                    <span className="ml-2">
                      <i className="fas fa-bell" />
                    </span>
                  </a>
                </li>
                <li>
                  <a
                    href="#"
                    className="flex justify-between items-center py-2 text-gray-600 hover:text-gray-900"
                  >
                    <span>Acceso a reportes</span>
                    <span className="ml-2">
                      <i className="fas fa-file" />
                    </span>
                  </a>
                </li>
                <li>
                  <a
                    href="#"
                    className="flex justify-between items-center py-2 text-gray-600 hover:text-gray-900"
                  >
                    <span>Desplegar agentes y ejecutar tareas</span>
                    <span className="ml-2">
                      <i className="fas fa-robot" />
                    </span>
                  </a>
                </li>
              </ul>
            </div>
            <div className="w-full lg:w-7xl mx-auto p-4">
              {sintonizado && <Dashboard />}
              {!sintonizado && (
                <div className="text-center">
                  <h2 className="text-2xl font-bold mb-4">Dashboard</h2>
                  <p>Pulse el botón para sintonizar</p>
                  <button
                    onClick={handleSintonizar}
                    className="bg-blue-500 hover:bg-blue-700 text-white py-2 px-4 rounded"
                  >
                    Sintonizar
                  </button>
                </div>
              )}
              {!logged && <Reportes />}
              {logged && !sintonizado && (
                <MonitoreoGnosis />
              )}
            </div>
          </div>
        </main>
      )}
    </div>
  );
}

export default HectronApp;
```
**Login.js**
```jsx
import React, { useState } from 'react';
import axios from 'axios';

const Login = ({ onLogin }) => {
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');
  const [error, setError] = useState(null);

  const handleLogin = async () => {
    if (!email || !password) {
      return setError('Correo electrónico y contraseña son obligatorios');
    }
    try {
      const response = await axios.post('/login', { email, password });
      onLogin(email, password);
    } catch (error) {
      console.error(error);
      setError('Error de autenticación');
    }
  };

  return (
    <div className="flex h-screen justify-center items-center overflow-hidden bg-gray-100">
      <div className="max-w-md p-8 bg-white rounded-lg shadow-lg">
        <h2 className="text-2xl font-bold mb-4">Inicio de sesión</h2>
        {error && <p className="text-red-500 mb-4">{error}</p>}
        <form>
          <div className="mb-4">
            <label className="block text-gray-700 text-sm font-bold mb-2" htmlFor="email">
              Correo electrónico
            </label>
            <input
              className="shadow appearance-none border rounded py-2 px-3 w-full justify-center items-center"
              id="email"
              type="email"
              value={email}
              onChange={(e) => setEmail(e.target.value)}
            />
          </div>
          <div className="mb-4">
            <label className="block text-gray-700 text-sm font-bold mb-2" htmlFor="password">
              Contraseña
            </label>
            <input
              className="shadow appearance-none border rounded py-2 px-3 w-full justify-center items-center"
              id="password"
              type="password"
              value={password}
              onChange={(e) => setPassword(e.target.value)}
            />
          </div>
          <button
            className="bg-blue-500 hover:bg-blue-700 text-white py-2 px-4 rounded"
            onClick={handleLogin}
          >
            Iniciar sesión
          </button>
        </form>
      </div>
    </div>
  );
};

export default Login;
```
**Dashboard.js**
```jsx
import React from 'react';
import axios from 'axios';

const Dashboard = () => {
  const [data, setData] = React.useState({});

  React.useEffect(() => {
    const fetchDashboardData = async () => {
      try {
        const response = await axios.get('/dashboard');
        setData(response.data);
      } catch (error) {
        console.error(error);
      }
    };
    fetchDashboardData();
  }, []);

  return (
    <div className="max-w-md p-8 bg-white rounded-lg shadow-lg">
      <h2 className="text-2xl font-bold mb-4">Dashboard</h2>
      <ul>
        <li>
          <span className="text-gray-700 text-sm font-bold mb-2">Monitoreo de Gnosis</span>
          <span className="ml-2">{data.monitoreoGnosis}</span>
        </li>
        <li>
          <span className="text-gray-700 text-sm font-bold mb-2">Configuración de alertas</span>
          <span className="ml-2">{data.configuracionAlertas}</span>
        </li>
        <li>
          <span className="text-gray-700 text-sm font-bold mb-2">Acceso a reportes</span>
          <span className="ml-2">{data.accesoReportes}</span>
        </li>
      </ul>
    </div>
  );
};

export default Dashboard;
```
**Reportes.js**
```jsx
import React from 'react';

const Reportes = () => {
  return (
    <div className="max-w-md p-8 bg-white rounded-lg shadow-lg">
      <h2 className="text-2xl font-bold mb-4">Reportes</h2>
      <p>Este es un lugar donde se podrán ver reportes de la aplicación.</p>
    </div>
  );
};

export default Reportes;
```
**MonitoreoGnosis.js**
```jsx
import React from 'react';

const MonitoreoGnosis = () => {
  return (
    <div className="max-w-md p-8 bg-white rounded-lg shadow-lg">
      <h2 className="text-2xl font-bold mb-4">Monitoreo de Gnosis</h2>
      <p>Este es un lugar donde se puede monitorear la salud y el estado del sistema.</p>
    </div>
  );
};

export default MonitoreoGnosis;
```
Estos componentes principales están implementados con Tailwind y se pueden personalizar de acuerdo a las necesidades específicas de HECTRON.