Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#22707 integracao tela cadastro servico #56

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE IF EXISTS agenda
DROP COLUMN IF EXISTS data_inicio,
DROP COLUMN IF EXISTS data_fim,
DROP COLUMN IF EXISTS disponivel,
DROP COLUMN IF EXISTS id_prestador;
18 changes: 12 additions & 6 deletions frontend/app/(auth)/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ const login = async (data: LoginForm) => {
}
}
}
const storeToken = async (token: string) => {

const storeToken = async (token) => {
try {
await AsyncStorage.setItem('jwt_token', token);
} catch (error) {
if (error instanceof Error) {
console.error('Erro ao salvar token no AsyncStorage:', error);
if (typeof window !== 'undefined' && window.localStorage) {
// Ambiente navegador
window.localStorage.setItem('jwt_token', token);
console.log('windows')
} else {
// Ambiente móvel
await AsyncStorage.setItem('jwt_token', token);
console.log('movel')
}
throw error;
} catch (error) {
console.error('Erro ao salvar token:', error);
}
};

Expand Down
50 changes: 50 additions & 0 deletions frontend/app/(extra)/ListaServico.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useEffect, useState } from 'react';
import { SafeAreaView, Text, FlatList, View, StyleSheet } from 'react-native';
import servicoService from '../../service/ServicoService'

export default function ListaServico() {
const [servicos, setServicos] = useState([]);

useEffect(() => {
const fetchServicos = async () => {
try {
const response = await servicoService.getAllServicos();
setServicos(response.data);
} catch (error) {
console.error('Erro ao buscar serviços:', error);
}
};
fetchServicos();
}, []);

const renderItem = ({ item }) => (
<View style={styles.itemContainer}>
<Text style={styles.servicoNome}>{item.servico}</Text>
</View>
);

return (
<SafeAreaView style={styles.container}>
<FlatList
data={servicos}
keyExtractor={(item) => item.id.toString()}
renderItem={renderItem}
/>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
},
itemContainer: {
padding: 12,
borderBottomWidth: 1,
borderBottomColor: '#ddd',
},
servicoNome: {
fontSize: 18,
},
});
52 changes: 27 additions & 25 deletions frontend/app/(extra)/criaServico.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { SafeAreaView, Text, View, TextInput, TouchableOpacity, StyleSheet, Scro
import { useForm, Controller } from 'react-hook-form';
import { Ionicons } from '@expo/vector-icons';
import { Picker } from '@react-native-picker/picker';
import ServicoService from '../../service/ServicoService'


const usuarioLogado = {id: 1, nome: 'p'};

type criarServicoForm = {
prestador: string;
//prestador: string;
servico: string;
descricao: string;
tempo: string;
Expand All @@ -19,14 +22,34 @@ export default function criaServico() {
defaultValues: {
descricao: '',
preco: '',
prestador: '',
// prestador: '',
servico: '',
setor: '',
tempo: ''
},
mode: "onChange"
});
const onSubmit = (data: criarServicoForm) => console.log(data);



const onSubmit = async (data: criarServicoForm) => {

try {

const servicoData ={
prestador: {id: usuarioLogado.id},
descricao: data.descricao,
tempoServico: data.tempo,
preco: parseFloat(data.preco.replace(',', '.')), // Converte o preço para número
setor: { id: data.setor }
}

await ServicoService.createServico(servicoData);

} catch (error) {
console.error('Erro ao cadastrar serviço:', error);
}
};

const onlyText = (text: string) => text.replace(/[^a-zA-Z\s]/g, '');

Expand Down Expand Up @@ -55,34 +78,13 @@ export default function criaServico() {
<View style={estilos.header}>
<View style={estilos.userText}>
<Ionicons name="person-circle-outline" size={35} color="white" />
<Text style={estilos.userName}>Usuário</Text>
<Text style={estilos.userName}>{usuarioLogado.nome}</Text>
</View>
</View>

<ScrollView contentContainerStyle={estilos.scrollViewContainer}>
<View style={estilos.formulario}>

<View style={estilos.containerInput}>
<Controller
control={control}
name="prestador"
rules={{
required: 'Nome do prestador é obrigatório.',
pattern: /[a-zA-Z]+$/
}}
render={({ field: { onChange, value } }) => (
<TextInput
style={estilos.input}
value={value}
onChangeText={text => onChange(onlyText(text))}
placeholder="Nome do Prestador"
inputMode='text'
/>
)}
/>
{errors.prestador && <Text style={estilos.erro}>{errors.prestador?.message}</Text>}
</View>

<View style={estilos.containerInput}>
<Controller
control={control}
Expand Down
153 changes: 3 additions & 150 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading