-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopendex-implementation.tsx
More file actions
440 lines (395 loc) · 11.4 KB
/
opendex-implementation.tsx
File metadata and controls
440 lines (395 loc) · 11.4 KB
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/**
* Implementación principal de Opendex Identity Employee para Opendex Corporation
* Integra todos los componentes corporativos personalizados
*/
import { StackApp, StackProvider } from '@opendex/stack';
import React from 'react';
import {
OpendexAuthPage,
opendexAuthStyles,
OpendexFullAuthPage
} from './opendex-auth-components';
import {
OpendexDashboardHeader,
opendexDashboardMetadata,
opendexDashboardStyles
} from './opendex-dashboard-config';
import { OpendexLayout } from './opendex-layout';
import { opendexTheme } from './opendex-theme';
// Configuración de la aplicación Opendex Identity Employee para Opendex
const opendexStackConfig = {
projectId: process.env.NEXT_PUBLIC_STACK_PROJECT_ID || 'opendex-corporate',
publishableClientKey: process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || 'opendex-publishable-key',
secretServerKey: process.env.STACK_SECRET_SERVER_KEY || 'opendex-secret-key',
apiUrl: process.env.NEXT_PUBLIC_STACK_API_URL || 'https://api.opendex.com',
urls: {
signIn: '/auth/signin',
signUp: '/auth/signup',
accountSettings: '/auth/account',
afterSignIn: '/dashboard',
afterSignUp: '/dashboard/onboarding',
},
theme: opendexTheme,
};
// Componente principal de la aplicación Opendex
export function OpendexApp({ children }: { children: React.ReactNode }) {
return (
<StackProvider config={opendexStackConfig}>
<OpendexLayout>
<style jsx global>{opendexAuthStyles}</style>
<style jsx global>{opendexDashboardStyles}</style>
{children}
</OpendexLayout>
</StackProvider>
);
}
// Páginas de autenticación específicas para Opendex
export function OpendexSignInPage() {
return (
<OpendexApp>
<OpendexFullAuthPage type="sign-in" />
</OpendexApp>
);
}
export function OpendexSignUpPage() {
return (
<OpendexApp>
<OpendexFullAuthPage type="sign-up" />
</OpendexApp>
);
}
// Dashboard corporativo de Opendex
export function OpendexDashboard({ children }: { children: React.ReactNode }) {
return (
<OpendexApp>
<div className="opendex-dashboard">
<OpendexDashboardHeader />
<main className="opendex-dashboard-main">
{children}
</main>
</div>
</OpendexApp>
);
}
// Componente de configuración de proyecto Opendex
export function OpendexProjectConfig() {
return {
// Configuración del proyecto
displayName: 'Opendex Corporation',
description: 'Sistema de autenticación corporativo de Opendex Corporation',
isProductionMode: process.env.NODE_ENV === 'production',
// Configuración de autenticación
auth: {
credentialEnabled: true,
magicLinkEnabled: true,
passkeyEnabled: true,
signUpEnabled: true,
emailVerificationRequired: true,
passwordResetEnabled: true,
},
// Proveedores OAuth corporativos
oauthProviders: [
{
id: 'google',
enabled: true,
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
scopes: ['openid', 'email', 'profile'],
},
{
id: 'microsoft',
enabled: true,
clientId: process.env.MICROSOFT_CLIENT_ID,
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
scopes: ['openid', 'email', 'profile'],
},
{
id: 'github',
enabled: true,
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
scopes: ['user:email'],
},
],
// Configuración de equipos
teams: {
enabled: true,
allowMultipleTeams: true,
requireTeamApproval: true,
defaultTeamRole: 'member',
},
// Configuración de permisos
permissions: {
enabled: true,
defaultPermissions: ['profile:read', 'profile:write'],
},
// Configuración de emails
emails: {
enabled: true,
from: 'noreply@opendex.com',
replyTo: 'support@opendex.com',
templates: {
welcome: 'opendex-welcome',
verification: 'opendex-verification',
passwordReset: 'opendex-password-reset',
teamInvitation: 'opendex-team-invitation',
},
},
// Configuración de webhooks
webhooks: {
enabled: true,
events: [
'user.created',
'user.updated',
'user.deleted',
'team.created',
'team.updated',
'team.deleted',
'auth.login',
'auth.logout',
],
},
// Configuración de seguridad
security: {
mfaRequired: true,
sessionTimeout: 8, // horas
maxLoginAttempts: 5,
lockoutDuration: 30, // minutos
passwordPolicy: {
minLength: 12,
requireUppercase: true,
requireLowercase: true,
requireNumbers: true,
requireSymbols: true,
preventReuse: 5,
maxAge: 90, // días
},
},
};
}
// Hook personalizado para usar Opendex Identity Employee en Opendex
export function useOpendexStack() {
const stackApp = StackApp.use();
return {
...stackApp,
// Métodos personalizados para Opendex
opendex: {
// Crear usuario corporativo
createCorporateUser: async (userData: {
email: string;
displayName: string;
teamId?: string;
role?: string;
}) => {
return await stackApp.admin.createUser({
...userData,
emailVerified: true,
projectId: 'opendex-corporate',
});
},
// Crear equipo corporativo
createCorporateTeam: async (teamData: {
displayName: string;
description: string;
ownerId: string;
}) => {
return await stackApp.admin.createTeam({
...teamData,
projectId: 'opendex-corporate',
});
},
// Enviar invitación corporativa
sendCorporateInvitation: async (invitationData: {
email: string;
teamId: string;
role: string;
inviterId: string;
}) => {
return await stackApp.admin.sendTeamInvitation({
...invitationData,
projectId: 'opendex-corporate',
});
},
// Obtener estadísticas corporativas
getCorporateStats: async () => {
const users = await stackApp.admin.listUsers();
const teams = await stackApp.admin.listTeams();
return {
totalUsers: users.length,
totalTeams: teams.length,
activeUsers: users.filter(u => u.lastSignInAt).length,
newUsersThisMonth: users.filter(u => {
const monthAgo = new Date();
monthAgo.setMonth(monthAgo.getMonth() - 1);
return new Date(u.createdAt) > monthAgo;
}).length,
};
},
},
};
}
// Componente de página de inicio corporativa
export function OpendexHomePage() {
const { opendex } = useOpendexStack();
const [stats, setStats] = React.useState(null);
React.useEffect(() => {
opendex.getCorporateStats().then(setStats);
}, []);
return (
<OpendexDashboard>
<div className="opendex-home-page">
<div className="opendex-welcome-section">
<h1>Bienvenido a Opendex Corporation</h1>
<p>Opendex Identity Employee - Sistema de gestión de identidad de empleados</p>
</div>
{stats && (
<div className="opendex-stats-grid">
<div className="opendex-stat-card">
<h3>Usuarios Totales</h3>
<p className="opendex-stat-number">{stats.totalUsers}</p>
</div>
<div className="opendex-stat-card">
<h3>Equipos</h3>
<p className="opendex-stat-number">{stats.totalTeams}</p>
</div>
<div className="opendex-stat-card">
<h3>Usuarios Activos</h3>
<p className="opendex-stat-number">{stats.activeUsers}</p>
</div>
<div className="opendex-stat-card">
<h3>Nuevos este Mes</h3>
<p className="opendex-stat-number">{stats.newUsersThisMonth}</p>
</div>
</div>
)}
<div className="opendex-quick-actions">
<h2>Acciones Rápidas</h2>
<div className="opendex-action-buttons">
<button className="opendex-action-button">
<span>👥</span>
Gestionar Usuarios
</button>
<button className="opendex-action-button">
<span>🏢</span>
Gestionar Equipos
</button>
<button className="opendex-action-button">
<span>🔐</span>
Configurar Opendex Identity Employee
</button>
<button className="opendex-action-button">
<span>📊</span>
Ver Reportes
</button>
</div>
</div>
</div>
</OpendexDashboard>
);
}
// Estilos adicionales para la página de inicio
export const opendexHomeStyles = `
.opendex-home-page {
padding: 2rem;
max-width: 1200px;
margin: 0 auto;
}
.opendex-welcome-section {
text-align: center;
margin-bottom: 3rem;
}
.opendex-welcome-section h1 {
color: #0066CC;
font-size: 2.5rem;
font-weight: 600;
margin-bottom: 1rem;
}
.opendex-welcome-section p {
color: #5F6368;
font-size: 1.125rem;
}
.opendex-stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin-bottom: 3rem;
}
.opendex-stat-card {
background: white;
padding: 1.5rem;
border-radius: 0.75rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
border: 1px solid #E8EAED;
}
.opendex-stat-card h3 {
color: #3C4043;
font-size: 1rem;
font-weight: 500;
margin-bottom: 0.5rem;
}
.opendex-stat-number {
color: #0066CC;
font-size: 2rem;
font-weight: 700;
margin: 0;
}
.opendex-quick-actions {
background: white;
padding: 2rem;
border-radius: 0.75rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border: 1px solid #E8EAED;
}
.opendex-quick-actions h2 {
color: #3C4043;
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 1.5rem;
}
.opendex-action-buttons {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
.opendex-action-button {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 1rem;
background: #F8F9FA;
border: 1px solid #E8EAED;
border-radius: 0.5rem;
cursor: pointer;
transition: all 0.2s ease;
font-size: 0.875rem;
font-weight: 500;
color: #3C4043;
}
.opendex-action-button:hover {
background: #E6F2FF;
border-color: #0066CC;
color: #0066CC;
}
.opendex-action-button span {
font-size: 1.25rem;
}
@media (max-width: 768px) {
.opendex-home-page {
padding: 1rem;
}
.opendex-welcome-section h1 {
font-size: 2rem;
}
.opendex-stats-grid {
grid-template-columns: 1fr;
}
.opendex-action-buttons {
grid-template-columns: 1fr;
}
}
`;
// Exportar todos los componentes y configuraciones
export {
OpendexAuthPage, opendexAuthStyles, OpendexDashboard, opendexDashboardMetadata, opendexDashboardStyles, OpendexFullAuthPage, OpendexHomePage, opendexHomeStyles, OpendexLayout, OpendexProjectConfig, opendexTheme, useOpendexStack
};