diff --git a/frontend/app/(agenda)/cronograma.tsx b/frontend/app/(agenda)/cronograma.tsx index 96944b04..5774d970 100644 --- a/frontend/app/(agenda)/cronograma.tsx +++ b/frontend/app/(agenda)/cronograma.tsx @@ -1,14 +1,16 @@ import React, { useState } from 'react'; import { View, Text, TextInput, StyleSheet, Button, Alert, Pressable, ScrollView, StatusBar } from 'react-native'; -import { Picker } from '@react-native-picker/picker'; -import { useForm, Controller } from 'react-hook-form'; +import { useForm, Controller, useFieldArray } from 'react-hook-form'; import { Ionicons } from '@expo/vector-icons'; import { SafeAreaView } from 'react-native-safe-area-context'; +import MultiSelect from 'react-native-multiple-select'; type CronogramaForm = { - diasSemana: string[]; - horaInicio: string; - horaFim: string; + cronogramas: { + diasSemana: string[]; + horaInicio: string; + horaFim: string; + }[]; }; const diasSemana = [ @@ -24,32 +26,26 @@ const diasSemana = [ export default function Cronograma() { const { control, handleSubmit, formState: { errors } } = useForm({ defaultValues: { - diasSemana: [], - horaInicio: '', - horaFim: '', + cronogramas: [{ + diasSemana: [], + horaInicio: '', + horaFim: '', + }], }, }); - const [cronogramas, setCronogramas] = useState([]); + const { fields, append, remove } = useFieldArray({ + control, + name: "cronogramas", + }); const onSubmit = (data: CronogramaForm) => { - if (data.diasSemana.length === 0 || !data.horaInicio || !data.horaFim) { + if (data.cronogramas.some(item => item.diasSemana.length === 0 || !item.horaInicio || !item.horaFim)) { Alert.alert('Erro', 'Por favor, preencha todos os campos.'); return; } - setCronogramas([...cronogramas, data]); - Alert.alert('Cronograma adicionado com sucesso!'); - }; - - const handleDelete = (index: number) => { - const updatedCronogramas = cronogramas.filter((_, i) => i !== index); - setCronogramas(updatedCronogramas); - }; - - const handleDuplicate = (index: number) => { - const cronograma = cronogramas[index]; - setCronogramas([...cronogramas, cronograma]); + Alert.alert('Cronogramas adicionados com sucesso!'); }; const formatTime = (value: string) => { @@ -65,6 +61,21 @@ export default function Cronograma() { return formattedValue; }; + const validateTime = (time: string): boolean => { + const regex = /^([01]?[0-9]|2[0-3]):([0-5]?[0-9])$/; + + if (!regex.test(time)) { + return false; + } + + const [hours, minutes] = time.split(':').map(Number); + + if (hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59) { + return true; + } + return false; + }; + return (