summaryrefslogtreecommitdiffstats
path: root/src/app/(protected)/reservations/create.tsx
blob: 65a16f5b34130ffa139b4e1386322f914990327f (plain)
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
import { useLocalSearchParams } from 'expo-router';
import {
  KeyboardAvoidingView,
  Platform,
  Pressable,
  ScrollView,
  StyleSheet,
  Text,
  TextInput,
  View,
} from 'react-native';
import { useCreateReservation } from '@/features/reservations/hooks/useCreateReservation';
import { StatusMessage } from '@/shared/ui/StatusMessage';

export default function CreateReservationScreen() {
  const params = useLocalSearchParams<{
    officeId?: string;
    officeName?: string;
  }>();

  const officeId =
    typeof params.officeId === 'string' ? params.officeId : undefined;
  const officeName =
    typeof params.officeName === 'string' ? params.officeName : undefined;

  const {
    date,
    startTime,
    endTime,
    isFormComplete,
    isSubmitting,
    error,
    successMessage,
    setDate,
    setStartTime,
    setEndTime,
    submit,
  } = useCreateReservation({ officeId, officeName });

  return (
    <KeyboardAvoidingView
      style={styles.container}
      behavior={Platform.OS === 'ios' ? 'padding' : undefined}
    >
      <ScrollView contentContainerStyle={styles.content}>
        <Text style={styles.title}>Crear reserva</Text>
        <Text style={styles.subtitle}>
          Completa la fecha y el horario en formato 24h.
        </Text>

        <View style={styles.infoBox}>
          <Text style={styles.label}>Espacio</Text>
          <Text style={styles.value}>{officeName ?? 'No indicado'}</Text>
        </View>

        <View style={styles.rulesBox}>
          <Text style={styles.rulesTitle}>Condiciones de reserva</Text>
          <Text style={styles.rulesText}>Horario permitido: de 08:00 a 20:00</Text>
          <Text style={styles.rulesText}>Duración mínima: 30 minutos</Text>
          <Text style={styles.rulesText}>Duración máxima: 8 horas</Text>
        </View>

        <View style={styles.field}>
          <Text style={styles.label}>Fecha</Text>
          <TextInput
            style={styles.input}
            placeholder="2026-04-01"
            value={date}
            onChangeText={setDate}
            keyboardType="number-pad"
            maxLength={10}
          />
          <Text style={styles.helper}>Formato: YYYY-MM-DD</Text>
        </View>

        <View style={styles.row}>
          <View style={[styles.field, styles.rowField]}>
            <Text style={styles.label}>Hora de inicio</Text>
            <TextInput
              style={styles.input}
              placeholder="09:00"
              value={startTime}
              onChangeText={setStartTime}
              keyboardType="number-pad"
              maxLength={5}
            />
            <Text style={styles.helper}>Formato 24h</Text>
          </View>

          <View style={[styles.field, styles.rowField]}>
            <Text style={styles.label}>Hora de fin</Text>
            <TextInput
              style={styles.input}
              placeholder="10:00"
              value={endTime}
              onChangeText={setEndTime}
              keyboardType="number-pad"
              maxLength={5}
            />
            <Text style={styles.helper}>Debe ser posterior</Text>
          </View>
        </View>

        {error ? <StatusMessage message={error} /> : null}
        {successMessage ? <StatusMessage message={successMessage} tone="success" /> : null}

        <Pressable
          style={[styles.button, (!isFormComplete || isSubmitting) && styles.buttonDisabled]}
          onPress={submit}
          disabled={!isFormComplete || isSubmitting}
        >
          <Text style={styles.buttonText}>
            {isSubmitting ? 'Guardando...' : 'Guardar reserva'}
          </Text>
        </Pressable>
      </ScrollView>
    </KeyboardAvoidingView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  content: {
    padding: 16,
    gap: 14,
  },
  title: {
    fontSize: 28,
    fontWeight: '700',
  },
  subtitle: {
    color: '#555',
    marginBottom: 4,
  },
  infoBox: {
    borderWidth: 1,
    borderColor: '#ddd',
    borderRadius: 12,
    padding: 12,
    gap: 6,
    marginBottom: 8,
  },
  rulesBox: {
    borderWidth: 1,
    borderColor: '#d7e3f7',
    backgroundColor: '#f4f8ff',
    borderRadius: 12,
    padding: 12,
    gap: 4,
  },
  rulesTitle: {
    fontSize: 14,
    fontWeight: '700',
    color: '#1d4f91',
    marginBottom: 2,
  },
  rulesText: {
    color: '#365b86',
    fontSize: 13,
  },
  field: {
    gap: 6,
  },
  row: {
    flexDirection: 'row',
    gap: 12,
  },
  rowField: {
    flex: 1,
  },
  label: {
    fontSize: 14,
    fontWeight: '700',
    color: '#444',
  },
  value: {
    fontSize: 16,
    color: '#111',
  },
  input: {
    borderWidth: 1,
    borderColor: '#ccc',
    borderRadius: 10,
    paddingHorizontal: 14,
    paddingVertical: 12,
  },
  helper: {
    color: '#666',
    fontSize: 12,
  },
  button: {
    backgroundColor: '#1f6feb',
    paddingVertical: 14,
    borderRadius: 10,
    alignItems: 'center',
    marginTop: 8,
  },
  buttonDisabled: {
    backgroundColor: '#8fb5ec',
  },
  buttonText: {
    color: '#fff',
    fontWeight: '600',
  },
});