summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/app/(protected)/(tabs)/_layout.tsx24
-rw-r--r--src/app/(protected)/(tabs)/_layout.tsx~ (renamed from src/app/(protected)/offices/index.tsx)0
-rw-r--r--src/app/(protected)/(tabs)/home.tsx (renamed from src/app/(protected)/home.tsx)0
-rw-r--r--src/app/(protected)/(tabs)/offices/index.tsx107
-rw-r--r--src/app/(protected)/(tabs)/profile/index.tsx28
-rw-r--r--src/app/(protected)/(tabs)/reservations/index.tsx28
-rw-r--r--src/app/(protected)/offices/[officeId].tsx119
-rw-r--r--src/app/(protected)/reservations/create.tsx28
-rw-r--r--src/features/offices/hooks/useOffice.ts47
-rw-r--r--src/features/offices/hooks/useOffice.ts~ (renamed from src/app/(protected)/profile/index.tsx)0
-rw-r--r--src/features/offices/hooks/useOffices.ts34
-rw-r--r--src/features/offices/hooks/useOffices.ts~ (renamed from src/app/(protected)/reservations/index.tsx)0
-rw-r--r--src/features/offices/services/officesService.ts30
-rw-r--r--src/features/offices/services/officesService.ts~0
-rw-r--r--src/features/offices/types.ts7
-rw-r--r--src/features/offices/types.ts~0
16 files changed, 452 insertions, 0 deletions
diff --git a/src/app/(protected)/(tabs)/_layout.tsx b/src/app/(protected)/(tabs)/_layout.tsx
new file mode 100644
index 0000000..0b71c6d
--- /dev/null
+++ b/src/app/(protected)/(tabs)/_layout.tsx
@@ -0,0 +1,24 @@
+import { Tabs } from 'expo-router';
+
+export default function TabsLayout() {
+ return (
+ <Tabs screenOptions={{ headerShown: false }}>
+ <Tabs.Screen
+ name="home"
+ options={{ title: 'Inicio' }}
+ />
+ <Tabs.Screen
+ name="offices"
+ options={{ title: 'Espacios' }}
+ />
+ <Tabs.Screen
+ name="reservations"
+ options={{ title: 'Reservas' }}
+ />
+ <Tabs.Screen
+ name="profile"
+ options={{ title: 'Perfil' }}
+ />
+ </Tabs>
+ );
+}
diff --git a/src/app/(protected)/offices/index.tsx b/src/app/(protected)/(tabs)/_layout.tsx~
index e69de29..e69de29 100644
--- a/src/app/(protected)/offices/index.tsx
+++ b/src/app/(protected)/(tabs)/_layout.tsx~
diff --git a/src/app/(protected)/home.tsx b/src/app/(protected)/(tabs)/home.tsx
index 76a5bda..76a5bda 100644
--- a/src/app/(protected)/home.tsx
+++ b/src/app/(protected)/(tabs)/home.tsx
diff --git a/src/app/(protected)/(tabs)/offices/index.tsx b/src/app/(protected)/(tabs)/offices/index.tsx
new file mode 100644
index 0000000..23445ee
--- /dev/null
+++ b/src/app/(protected)/(tabs)/offices/index.tsx
@@ -0,0 +1,107 @@
+import { Link } from 'expo-router';
+import {
+ ActivityIndicator,
+ FlatList,
+ Pressable,
+ StyleSheet,
+ Text,
+ View,
+} from 'react-native';
+import { useOffices } from '@/features/offices/hooks/useOffices';
+
+export default function OfficesScreen() {
+ const { offices, loading, error, reload } = useOffices();
+
+ if (loading) {
+ return (
+ <View style={styles.center}>
+ <ActivityIndicator size="large" />
+ </View>
+ );
+ }
+
+ if (error) {
+ return (
+ <View style={styles.center}>
+ <Text style={styles.error}>{error}</Text>
+ <Pressable style={styles.button} onPress={reload}>
+ <Text style={styles.buttonText}>Reintentar</Text>
+ </Pressable>
+ </View>
+ );
+ }
+
+ return (
+ <View style={styles.container}>
+ <Text style={styles.title}>Espacios</Text>
+
+ <FlatList
+ data={offices}
+ keyExtractor={(item) => item.id}
+ contentContainerStyle={styles.list}
+ ListEmptyComponent={
+ <Text style={styles.empty}>No hay espacios disponibles</Text>
+ }
+ renderItem={({ item }) => (
+ <Link href={`/(protected)/offices/${item.id}`} asChild>
+ <Pressable style={styles.card}>
+ <Text style={styles.cardTitle}>{item.name}</Text>
+ <Text>{item.location}</Text>
+ <Text>Capacidad: {item.capacity}</Text>
+ {item.description ? <Text>{item.description}</Text> : null}
+ </Pressable>
+ </Link>
+ )}
+ />
+ </View>
+ );
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ padding: 16,
+ },
+ center: {
+ flex: 1,
+ alignItems: 'center',
+ justifyContent: 'center',
+ padding: 24,
+ },
+ title: {
+ fontSize: 28,
+ fontWeight: '700',
+ marginBottom: 16,
+ },
+ list: {
+ gap: 12,
+ },
+ card: {
+ borderWidth: 1,
+ borderColor: '#ddd',
+ borderRadius: 12,
+ padding: 16,
+ gap: 6,
+ },
+ cardTitle: {
+ fontSize: 18,
+ fontWeight: '600',
+ },
+ error: {
+ color: 'red',
+ marginBottom: 12,
+ },
+ button: {
+ backgroundColor: '#1f6feb',
+ paddingHorizontal: 16,
+ paddingVertical: 12,
+ borderRadius: 10,
+ },
+ buttonText: {
+ color: '#fff',
+ fontWeight: '600',
+ },
+ empty: {
+ color: '#666',
+ },
+});
diff --git a/src/app/(protected)/(tabs)/profile/index.tsx b/src/app/(protected)/(tabs)/profile/index.tsx
new file mode 100644
index 0000000..a59d568
--- /dev/null
+++ b/src/app/(protected)/(tabs)/profile/index.tsx
@@ -0,0 +1,28 @@
+import { StyleSheet, Text, View } from 'react-native';
+
+export default function ProfileScreen() {
+ return (
+ <View style={styles.container}>
+ <Text style={styles.title}>Perfil</Text>
+ <Text style={styles.text}>Pantalla en construcción.</Text>
+ </View>
+ );
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ padding: 16,
+ justifyContent: 'center',
+ alignItems: 'center',
+ gap: 12,
+ },
+ title: {
+ fontSize: 28,
+ fontWeight: '700',
+ },
+ text: {
+ fontSize: 16,
+ color: '#555',
+ },
+});
diff --git a/src/app/(protected)/(tabs)/reservations/index.tsx b/src/app/(protected)/(tabs)/reservations/index.tsx
new file mode 100644
index 0000000..817ec6e
--- /dev/null
+++ b/src/app/(protected)/(tabs)/reservations/index.tsx
@@ -0,0 +1,28 @@
+import { StyleSheet, Text, View } from 'react-native';
+
+export default function ReservationsScreen() {
+ return (
+ <View style={styles.container}>
+ <Text style={styles.title}>Reservas</Text>
+ <Text style={styles.text}>Pantalla en construcción.</Text>
+ </View>
+ );
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ padding: 16,
+ justifyContent: 'center',
+ alignItems: 'center',
+ gap: 12,
+ },
+ title: {
+ fontSize: 28,
+ fontWeight: '700',
+ },
+ text: {
+ fontSize: 16,
+ color: '#555',
+ },
+});
diff --git a/src/app/(protected)/offices/[officeId].tsx b/src/app/(protected)/offices/[officeId].tsx
index e69de29..77fd610 100644
--- a/src/app/(protected)/offices/[officeId].tsx
+++ b/src/app/(protected)/offices/[officeId].tsx
@@ -0,0 +1,119 @@
+import { Link, useLocalSearchParams } from 'expo-router';
+import { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native';
+import { useOffice } from '@/features/offices/hooks/useOffice';
+
+export default function OfficeDetailScreen() {
+ const params = useLocalSearchParams<{ officeId: string }>();
+ const officeId = typeof params.officeId === 'string' ? params.officeId : undefined;
+
+ const { office, loading, error, reload } = useOffice(officeId);
+
+ if (loading) {
+ return (
+ <View style={styles.center}>
+ <ActivityIndicator size="large" />
+ </View>
+ );
+ }
+
+ if (error || !office) {
+ return (
+ <View style={styles.center}>
+ <Text style={styles.error}>{error ?? 'No se pudo cargar la oficina'}</Text>
+
+ <Pressable style={styles.button} onPress={reload}>
+ <Text style={styles.buttonText}>Reintentar</Text>
+ </Pressable>
+
+ <Link href="/(protected)/offices" asChild>
+ <Pressable style={styles.secondaryButton}>
+ <Text style={styles.buttonText}>Volver a espacios</Text>
+ </Pressable>
+ </Link>
+ </View>
+ );
+ }
+
+ return (
+ <View style={styles.container}>
+ <Text style={styles.title}>{office.name}</Text>
+
+ <View style={styles.card}>
+ <Text style={styles.label}>Ubicación</Text>
+ <Text style={styles.value}>{office.location}</Text>
+
+ <Text style={styles.label}>Capacidad</Text>
+ <Text style={styles.value}>{office.capacity} personas</Text>
+
+ {office.description ? (
+ <>
+ <Text style={styles.label}>Descripción</Text>
+ <Text style={styles.value}>{office.description}</Text>
+ </>
+ ) : null}
+ </View>
+
+ <Link href="/(protected)/reservations/create" asChild>
+ <Pressable style={styles.button}>
+ <Text style={styles.buttonText}>Reservar este espacio</Text>
+ </Pressable>
+ </Link>
+ </View>
+ );
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ padding: 16,
+ gap: 16,
+ },
+ center: {
+ flex: 1,
+ alignItems: 'center',
+ justifyContent: 'center',
+ padding: 24,
+ gap: 12,
+ },
+ title: {
+ fontSize: 28,
+ fontWeight: '700',
+ },
+ card: {
+ borderWidth: 1,
+ borderColor: '#ddd',
+ borderRadius: 12,
+ padding: 16,
+ gap: 10,
+ },
+ label: {
+ fontSize: 14,
+ fontWeight: '700',
+ color: '#444',
+ },
+ value: {
+ fontSize: 16,
+ color: '#111',
+ },
+ button: {
+ backgroundColor: '#1f6feb',
+ paddingVertical: 14,
+ borderRadius: 10,
+ alignItems: 'center',
+ },
+ secondaryButton: {
+ backgroundColor: '#555',
+ paddingVertical: 14,
+ paddingHorizontal: 16,
+ borderRadius: 10,
+ alignItems: 'center',
+ },
+ buttonText: {
+ color: '#fff',
+ fontWeight: '600',
+ },
+ error: {
+ color: 'red',
+ textAlign: 'center',
+ },
+});
diff --git a/src/app/(protected)/reservations/create.tsx b/src/app/(protected)/reservations/create.tsx
index e69de29..c1c88b3 100644
--- a/src/app/(protected)/reservations/create.tsx
+++ b/src/app/(protected)/reservations/create.tsx
@@ -0,0 +1,28 @@
+import { StyleSheet, Text, View } from 'react-native';
+
+export default function CreateReservationScreen() {
+ return (
+ <View style={styles.container}>
+ <Text style={styles.title}>Crear reserva</Text>
+ <Text style={styles.text}>Pantalla en construcción.</Text>
+ </View>
+ );
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ padding: 16,
+ justifyContent: 'center',
+ alignItems: 'center',
+ gap: 12,
+ },
+ title: {
+ fontSize: 28,
+ fontWeight: '700',
+ },
+ text: {
+ fontSize: 16,
+ color: '#555',
+ },
+});
diff --git a/src/features/offices/hooks/useOffice.ts b/src/features/offices/hooks/useOffice.ts
new file mode 100644
index 0000000..87d47b5
--- /dev/null
+++ b/src/features/offices/hooks/useOffice.ts
@@ -0,0 +1,47 @@
+import { useEffect, useState } from 'react';
+import { officesService } from '@/features/offices/services/officesService';
+import { Office } from '@/features/offices/types';
+
+export function useOffice(officeId?: string) {
+ const [office, setOffice] = useState<Office | null>(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState<string | null>(null);
+
+ const loadOffice = async () => {
+ if (!officeId) {
+ setError('No se indicó una oficina válida');
+ setLoading(false);
+ return;
+ }
+
+ try {
+ setError(null);
+ setLoading(true);
+
+ const data = await officesService.getById(officeId);
+
+ if (!data) {
+ setOffice(null);
+ setError('La oficina no existe');
+ return;
+ }
+
+ setOffice(data);
+ } catch (err: any) {
+ setError(err?.message ?? 'No se pudo cargar la oficina');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ loadOffice();
+ }, [officeId]);
+
+ return {
+ office,
+ loading,
+ error,
+ reload: loadOffice,
+ };
+}
diff --git a/src/app/(protected)/profile/index.tsx b/src/features/offices/hooks/useOffice.ts~
index e69de29..e69de29 100644
--- a/src/app/(protected)/profile/index.tsx
+++ b/src/features/offices/hooks/useOffice.ts~
diff --git a/src/features/offices/hooks/useOffices.ts b/src/features/offices/hooks/useOffices.ts
new file mode 100644
index 0000000..ff08f6c
--- /dev/null
+++ b/src/features/offices/hooks/useOffices.ts
@@ -0,0 +1,34 @@
+import { useEffect, useState } from 'react';
+import { officesService } from '@/features/offices/services/officesService';
+import { Office } from '@/features/offices/types';
+
+export function useOffices() {
+ const [offices, setOffices] = useState<Office[]>([]);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState<string | null>(null);
+
+ const loadOffices = async () => {
+ try {
+ setError(null);
+ setLoading(true);
+
+ const data = await officesService.getAll();
+ setOffices(data);
+ } catch (err: any) {
+ setError(err?.message ?? 'No se pudieron cargar los espacios');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ loadOffices();
+ }, []);
+
+ return {
+ offices,
+ loading,
+ error,
+ reload: loadOffices,
+ };
+}
diff --git a/src/app/(protected)/reservations/index.tsx b/src/features/offices/hooks/useOffices.ts~
index e69de29..e69de29 100644
--- a/src/app/(protected)/reservations/index.tsx
+++ b/src/features/offices/hooks/useOffices.ts~
diff --git a/src/features/offices/services/officesService.ts b/src/features/offices/services/officesService.ts
new file mode 100644
index 0000000..72cf081
--- /dev/null
+++ b/src/features/offices/services/officesService.ts
@@ -0,0 +1,30 @@
+import { collection, doc, getDoc, getDocs } from 'firebase/firestore';
+import { db } from '@/shared/lib/firebase/config';
+import { Office } from '@/features/offices/types';
+
+function mapOffice(id: string, data: any): Office {
+ return {
+ id,
+ name: data.name ?? '',
+ location: data.location ?? '',
+ capacity: data.capacity ?? 0,
+ description: data.description ?? '',
+ };
+}
+
+export const officesService = {
+ async getAll(): Promise<Office[]> {
+ const snapshot = await getDocs(collection(db, 'offices'));
+ return snapshot.docs.map((item) => mapOffice(item.id, item.data()));
+ },
+
+ async getById(id: string): Promise<Office | null> {
+ const snapshot = await getDoc(doc(db, 'offices', id));
+
+ if (!snapshot.exists()) {
+ return null;
+ }
+
+ return mapOffice(snapshot.id, snapshot.data());
+ },
+};
diff --git a/src/features/offices/services/officesService.ts~ b/src/features/offices/services/officesService.ts~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/features/offices/services/officesService.ts~
diff --git a/src/features/offices/types.ts b/src/features/offices/types.ts
new file mode 100644
index 0000000..9f9d039
--- /dev/null
+++ b/src/features/offices/types.ts
@@ -0,0 +1,7 @@
+export type Office = {
+ id: string;
+ name: string;
+ location: string;
+ capacity: number;
+ description?: string;
+};
diff --git a/src/features/offices/types.ts~ b/src/features/offices/types.ts~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/features/offices/types.ts~