Antigravity AI commited on
Commit
9d7bd77
·
1 Parent(s): 4e002a8

Add expanded seedData function

Browse files
Files changed (3) hide show
  1. data.json +0 -25
  2. seed.js +0 -72
  3. src/components/admin/DashboardOverview.jsx +52 -39
data.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "menu": {
3
- "item1": { "name": "Hamburgesa Clásica", "price": 12.50, "category": "Fuertes", "image": "/images/burger.png", "active": true },
4
- "item2": { "name": "Pasta Pomodoro", "price": 10.00, "category": "Pasta", "image": "/images/pasta.png", "active": true },
5
- "item3": { "name": "Tacos de Pollo", "price": 9.00, "category": "Entradas", "image": "/images/tacos.png", "active": true },
6
- "item4": { "name": "Pizza Margherita", "price": 14.00, "category": "Pizzas", "image": "/images/pizza.png", "active": true },
7
- "item5": { "name": "Ensalada César", "price": 8.50, "category": "Entradas", "image": "https://images.unsplash.com/photo-1550304943-4f24f54ddde9?auto=format&fit=crop&q=80&w=1000", "active": true },
8
- "item6": { "name": "Sopa de Tomate", "price": 7.00, "category": "Entradas", "image": "https://images.unsplash.com/photo-1547592166-23ac45744acd?auto=format&fit=crop&q=80&w=1000", "active": true },
9
- "item7": { "name": "Sandwich Gourmet", "price": 11.00, "category": "Fuertes", "image": "https://images.unsplash.com/photo-1528735602780-2552fd46c7af?auto=format&fit=crop&q=80&w=1000", "active": true },
10
- "item8": { "name": "Chocolate Muffin", "price": 4.50, "category": "Postres", "image": "https://images.unsplash.com/photo-1582231222779-1adb0b322f84?auto=format&fit=crop&q=80&w=1000", "active": true },
11
- "spec1": { "name": "Ribeye Premium", "price": 35.00, "category": "Especialidades", "image": "/images/steak.png", "active": true },
12
- "spec2": { "name": "Risotto de Trufa", "price": 28.00, "category": "Especialidades", "image": "/images/risotto.png", "active": true },
13
- "spec3": { "name": "Salmón Glaseado", "price": 26.00, "category": "Especialidades", "image": "https://images.unsplash.com/photo-1467003909585-2f8a72700288?auto=format&fit=crop&q=80&w=1000", "active": true },
14
- "spec4": { "name": "Pato a la Naranja", "price": 32.00, "category": "Especialidades", "image": "https://images.unsplash.com/photo-1626082927389-6cd097cdc6ec?auto=format&fit=crop&q=80&w=1000", "active": true },
15
- "spec5": { "name": "Langosta Thermidor", "price": 45.00, "category": "Especialidades", "image": "https://images.unsplash.com/photo-1553243599-c052f82958d2?auto=format&fit=crop&q=80&w=1000", "active": true }
16
- },
17
- "inventory": {
18
- "inv1": { "name": "Pan de Burger", "quantity": 50, "unit": "Und", "minStock": 10 },
19
- "inv2": { "name": "Carne Res", "quantity": 20, "unit": "Kg", "minStock": 5 },
20
- "inv3": { "name": "Tomate", "quantity": 15, "unit": "Kg", "minStock": 3 }
21
- },
22
- "config": {
23
- "menuTheme": "light"
24
- }
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
seed.js DELETED
@@ -1,72 +0,0 @@
1
- import { initializeApp } from "firebase/app";
2
- import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword } from "firebase/auth";
3
- import { getDatabase, ref, set, push } from "firebase/database";
4
-
5
- const firebaseConfig = {
6
- apiKey: "AIzaSyBm2Tvsz7SHtWEWO-97p3gvqC76iqt05VM",
7
- authDomain: "rest-fc379.firebaseapp.com",
8
- databaseURL: "https://rest-fc379-default-rtdb.firebaseio.com",
9
- projectId: "rest-fc379",
10
- storageBucket: "rest-fc379.firebasestorage.app",
11
- messagingSenderId: "119970678093",
12
- appId: "1:119970678093:web:16fb097882249fdce0e304"
13
- };
14
-
15
- const app = initializeApp(firebaseConfig);
16
- const auth = getAuth(app);
17
- const db = getDatabase(app);
18
-
19
- const run = async () => {
20
- const email = "admin@rest-os.com";
21
- const password = "admin-password123";
22
-
23
- console.log("Intentando crear/autenticar usuario...");
24
-
25
- let user;
26
- try {
27
- const res = await createUserWithEmailAndPassword(auth, email, password);
28
- user = res.user;
29
- console.log("Usuario creado con éxito.");
30
- } catch (e) {
31
- if (e.code === 'auth/email-already-in-use') {
32
- console.log("El usuario ya existe, intentando login...");
33
- const res = await signInWithEmailAndPassword(auth, email, password);
34
- user = res.user;
35
- console.log("Login exitoso.");
36
- } else {
37
- throw e;
38
- }
39
- }
40
-
41
- if (user) {
42
- console.log("Autenticado. Iniciando sembrado...");
43
- const menuRef = ref(db, 'menu');
44
-
45
- const menuExamples = [
46
- { name: 'Hamburgesa Clásica', price: 12.50, category: 'Fuertes', image: '/images/burger.png', active: true },
47
- { name: 'Pasta Pomodoro', price: 10.00, category: 'Pasta', image: '/images/pasta.png', active: true },
48
- { name: 'Tacos de Pollo', price: 9.00, category: 'Entradas', image: '/images/tacos.png', active: true },
49
- { name: 'Pizza Margherita', price: 14.00, category: 'Pizzas', image: '/images/pizza.png', active: true },
50
- { name: 'Ensalada César', price: 8.50, category: 'Entradas', image: 'https://images.unsplash.com/photo-1550304943-4f24f54ddde9?auto=format&fit=crop&q=80&w=1000', active: true },
51
- { name: 'Sopa de Tomate', price: 7.00, category: 'Entradas', image: 'https://images.unsplash.com/photo-1547592166-23ac45744acd?auto=format&fit=crop&q=80&w=1000', active: true },
52
- { name: 'Sandwich Gourmet', price: 11.00, category: 'Fuertes', image: 'https://images.unsplash.com/photo-1528735602780-2552fd46c7af?auto=format&fit=crop&q=80&w=1000', active: true },
53
- { name: 'Chocolate Muffin', price: 4.50, category: 'Postres', image: 'https://images.unsplash.com/photo-1582231222779-1adb0b322f84?auto=format&fit=crop&q=80&w=1000', active: true },
54
- { name: 'Ribeye Premium', price: 35.00, category: 'Especialidades', image: '/images/steak.png', active: true },
55
- { name: 'Risotto de Trufa', price: 28.00, category: 'Especialidades', image: '/images/risotto.png', active: true },
56
- { name: 'Salmón Glaseado', price: 26.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1467003909585-2f8a72700288?auto=format&fit=crop&q=80&w=1000', active: true },
57
- { name: 'Pato a la Naranja', price: 32.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1626082927389-6cd097cdc6ec?auto=format&fit=crop&q=80&w=1000', active: true },
58
- { name: 'Langosta Thermidor', price: 45.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1553243599-c052f82958d2?auto=format&fit=crop&q=80&w=1000', active: true }
59
- ];
60
-
61
- for (const item of menuExamples) {
62
- await set(push(menuRef), item);
63
- console.log(`Agregado: ${item.name}`);
64
- }
65
-
66
- await set(ref(db, 'config/menuTheme'), 'light');
67
- console.log("Sembrado finalizado.");
68
- }
69
- process.exit(0);
70
- };
71
-
72
- run().catch(console.error);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/components/admin/DashboardOverview.jsx CHANGED
@@ -1,6 +1,6 @@
1
  import React, { useState, useEffect } from 'react';
2
  import { db } from '../../firebase/config';
3
- import { ref, onValue } from 'firebase/database';
4
  import { TrendingUp, Users, ShoppingBag, AlertCircle } from 'lucide-react';
5
 
6
  export default function DashboardOverview() {
@@ -23,48 +23,61 @@ export default function DashboardOverview() {
23
  ];
24
 
25
  const seedData = async () => {
26
- if (!window.confirm('¿Deseas cargar toda la información de ejemplo en el sistema? Esto agregará productos, insumos y mesas.')) return;
27
 
28
- // 1. Sembrar Menú (8 Productos + 5 Especialidades)
29
- const menuRef = ref(db, 'menu');
30
- const menuExamples = [
31
- // Productos (8)
32
- { name: 'Hamburgesa Clásica', price: 12.50, category: 'Fuertes', image: '/images/burger.png', active: true },
33
- { name: 'Pasta Pomodoro', price: 10.00, category: 'Pasta', image: '/images/pasta.png', active: true },
34
- { name: 'Tacos de Pollo', price: 9.00, category: 'Entradas', image: '/images/tacos.png', active: true },
35
- { name: 'Pizza Margherita', price: 14.00, category: 'Pizzas', image: '/images/pizza.png', active: true },
36
- { name: 'Ensalada César', price: 8.50, category: 'Entradas', image: 'https://images.unsplash.com/photo-1550304943-4f24f54ddde9?auto=format&fit=crop&q=80&w=1000', active: true },
37
- { name: 'Sopa de Tomate', price: 7.00, category: 'Entradas', image: 'https://images.unsplash.com/photo-1547592166-23ac45744acd?auto=format&fit=crop&q=80&w=1000', active: true },
38
- { name: 'Sandwich Gourmet', price: 11.00, category: 'Fuertes', image: 'https://images.unsplash.com/photo-1528735602780-2552fd46c7af?auto=format&fit=crop&q=80&w=1000', active: true },
39
- { name: 'Chocolate Muffin', price: 4.50, category: 'Postres', image: 'https://images.unsplash.com/photo-1582231222779-1adb0b322f84?auto=format&fit=crop&q=80&w=1000', active: true },
40
-
41
- // Especialidades (5)
42
- { name: 'Ribeye Premium', price: 35.00, category: 'Especialidades', image: '/images/steak.png', active: true },
43
- { name: 'Risotto de Trufa', price: 28.00, category: 'Especialidades', image: '/images/risotto.png', active: true },
44
- { name: 'Salmón Glaseado', price: 26.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1467003909585-2f8a72700288?auto=format&fit=crop&q=80&w=1000', active: true },
45
- { name: 'Pato a la Naranja', price: 32.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1626082927389-6cd097cdc6ec?auto=format&fit=crop&q=80&w=1000', active: true },
46
- { name: 'Langosta Thermidor', price: 45.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1553243599-c052f82958d2?auto=format&fit=crop&q=80&w=1000', active: true }
47
- ];
48
- for (const item of menuExamples) { await set(push(menuRef), item); }
49
 
50
- // 2. Sembrar Inventario
51
- const invRef = ref(db, 'inventory');
52
- const invExamples = [
53
- { name: 'Harina de Trigo', quantity: 100, unit: 'Kg', minStock: 20 },
54
- { name: 'Tomate Cherry', quantity: 15, unit: 'Kg', minStock: 5 },
55
- { name: 'Queso Mozzarella', quantity: 40, unit: 'Kg', minStock: 10 },
56
- { name: 'Carne de Res Premium', quantity: 25, unit: 'Kg', minStock: 8 },
57
- { name: 'Limones', quantity: 200, unit: 'Und', minStock: 50 }
58
- ];
59
- for (const item of invExamples) { await set(push(invRef), item); }
 
 
60
 
61
- // 3. Sembrar Mesas
62
- const tableRef = ref(db, 'config/tables');
63
- for (let i = 1; i <= 8; i++) {
64
- await set(push(tableRef), { number: i, capacity: i > 4 ? 6 : 4, status: 'available', x: 0, y: 0 });
65
- }
66
 
67
- alert('Sistema poblado con datos de ejemplo con éxito.');
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  };
69
 
70
  return (
 
1
  import React, { useState, useEffect } from 'react';
2
  import { db } from '../../firebase/config';
3
+ import { ref, onValue, push, set } from 'firebase/database';
4
  import { TrendingUp, Users, ShoppingBag, AlertCircle } from 'lucide-react';
5
 
6
  export default function DashboardOverview() {
 
23
  ];
24
 
25
  const seedData = async () => {
26
+ if (!window.confirm('¿Deseas cargar toda la información de ejemplo en el sistema? Esto agregará productos, insumos, usuarios y mesas.')) return;
27
 
28
+ try {
29
+ // 1. Sembrar Menú (8 Productos + 5 Especialidades)
30
+ const menuRef = ref(db, 'menu');
31
+ const menuExamples = [
32
+ { name: 'Hamburgesa Clásica', price: 12.50, category: 'Fuertes', image: '/images/burger.png', active: true },
33
+ { name: 'Pasta Pomodoro', price: 10.00, category: 'Pasta', image: '/images/pasta.png', active: true },
34
+ { name: 'Tacos de Pollo', price: 9.00, category: 'Entradas', image: '/images/tacos.png', active: true },
35
+ { name: 'Pizza Margherita', price: 14.00, category: 'Pizzas', image: '/images/pizza.png', active: true },
36
+ { name: 'Ensalada César', price: 8.50, category: 'Entradas', image: 'https://images.unsplash.com/photo-1550304943-4f24f54ddde9?auto=format&fit=crop&q=80&w=1000', active: true },
37
+ { name: 'Sopa de Tomate', price: 7.00, category: 'Entradas', image: 'https://images.unsplash.com/photo-1547592166-23ac45744acd?auto=format&fit=crop&q=80&w=1000', active: true },
38
+ { name: 'Sandwich Gourmet', price: 11.00, category: 'Fuertes', image: 'https://images.unsplash.com/photo-1528735602780-2552fd46c7af?auto=format&fit=crop&q=80&w=1000', active: true },
39
+ { name: 'Chocolate Muffin', price: 4.50, category: 'Postres', image: 'https://images.unsplash.com/photo-1582231222779-1adb0b322f84?auto=format&fit=crop&q=80&w=1000', active: true },
40
+ { name: 'Ribeye Premium', price: 35.00, category: 'Especialidades', image: '/images/steak.png', active: true },
41
+ { name: 'Risotto de Trufa', price: 28.00, category: 'Especialidades', image: '/images/risotto.png', active: true },
42
+ { name: 'Salmón Glaseado', price: 26.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1467003909585-2f8a72700288?auto=format&fit=crop&q=80&w=1000', active: true },
43
+ { name: 'Pato a la Naranja', price: 32.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1626082927389-6cd097cdc6ec?auto=format&fit=crop&q=80&w=1000', active: true },
44
+ { name: 'Langosta Thermidor', price: 45.00, category: 'Especialidades', image: 'https://images.unsplash.com/photo-1553243599-c052f82958d2?auto=format&fit=crop&q=80&w=1000', active: true }
45
+ ];
46
+ for (const item of menuExamples) { await set(push(menuRef), item); }
 
 
47
 
48
+ // 2. Sembrar Inventario
49
+ const invRef = ref(db, 'inventory');
50
+ const invExamples = [
51
+ { name: 'Harina de Trigo', quantity: 100, unit: 'Kg', minStock: 20 },
52
+ { name: 'Tomate Cherry', quantity: 15, unit: 'Kg', minStock: 5 },
53
+ { name: 'Queso Mozzarella', quantity: 40, unit: 'Kg', minStock: 10 },
54
+ { name: 'Carne de Res Premium', quantity: 25, unit: 'Kg', minStock: 8 },
55
+ { name: 'Limones', quantity: 200, unit: 'Und', minStock: 50 },
56
+ { name: 'Papas', quantity: 120, unit: 'Kg', minStock: 30 },
57
+ { name: 'Cebolla', quantity: 30, unit: 'Kg', minStock: 10 }
58
+ ];
59
+ for (const item of invExamples) { await set(push(invRef), item); }
60
 
61
+ // 3. Sembrar Mesas
62
+ const tableRef = ref(db, 'config/tables');
63
+ for (let i = 1; i <= 12; i++) {
64
+ await set(push(tableRef), { number: i, capacity: i > 6 ? 6 : 4, status: 'available', x: 0, y: 0 });
65
+ }
66
 
67
+ // 4. Sembrar Usuarios
68
+ const usersRef = ref(db, 'users');
69
+ const users = [
70
+ { name: 'Juan Pérez', role: 'Mesero', shift: 'Mañana', pin: '1234' },
71
+ { name: 'Ana García', role: 'Cocinero', shift: 'Tarde', pin: '5678' },
72
+ { name: 'Carlos López', role: 'Cajero', shift: 'Completo', pin: '9999' }
73
+ ];
74
+ for (const u of users) { await set(push(usersRef), u); }
75
+
76
+ alert('¡Sistema poblado con datos de ejemplo con éxito! Ya puedes ver los insumos y los platillos. Ve al menú correspondiente para confirmarlo.');
77
+ } catch (err) {
78
+ console.error(err);
79
+ alert('Hubo un error al intentar subir los datos. Verifica la conexión de red o la consola.');
80
+ }
81
  };
82
 
83
  return (