diff --git a/src/components/OneToMany.tsx b/src/components/OneToMany.tsx index d5c8d06..972b8bc 100644 --- a/src/components/OneToMany.tsx +++ b/src/components/OneToMany.tsx @@ -11,23 +11,20 @@ interface Props { const OneToMany: FC = ({}) => { const { lines } = useContext(SalesOrderContext); - console.log("Lineas: "+JSON.stringify(lines)) + return ( - + - + <> {item.producto.nombre} } - keyExtractor={(item: SalesOrderLine) => String(item.producto.id)} + /> {lines.map((line: SalesOrderLine) =>({line.producto.id}))} diff --git a/src/screens/salesorder/ProductItem.tsx b/src/screens/salesorder/ProductItem.tsx index 721fc04..2da3dd0 100644 --- a/src/screens/salesorder/ProductItem.tsx +++ b/src/screens/salesorder/ProductItem.tsx @@ -1,5 +1,5 @@ import React, { FC, useContext, useEffect, useState } from 'react' -import { FlatList, RefreshControl, Text, TouchableOpacity, View } from 'react-native' +import { FlatList, Text, TouchableOpacity, View } from 'react-native' import { useNavigation } from '@react-navigation/native'; @@ -32,16 +32,10 @@ export const ProductItem: FC = ({ entities, screenName, columnDisplay }) const newLine: SalesOrderLine = { producto: { id: item['id'], nombre: item["nombre"] }, cantidad: 1, - precio: 0 + precio: item["precio"] } add(newLine) - navigation.navigate( - { - name: screenName, - params: { productId: item['id'] }, - merge: true, - } as never - ); + navigation.pop(); }} > diff --git a/src/screens/salesorder/SalesOrderFormScreen.tsx b/src/screens/salesorder/SalesOrderFormScreen.tsx index fda344c..b3947df 100644 --- a/src/screens/salesorder/SalesOrderFormScreen.tsx +++ b/src/screens/salesorder/SalesOrderFormScreen.tsx @@ -1,9 +1,9 @@ import { useContext, useEffect, useState } from 'react' -import { FlatList, Text, View } from 'react-native' +import { FlatList, Text } from 'react-native' import { Button } from '../../components/Button'; import { Card } from '../../components/Card'; import { Input } from '../../components/Input'; -import { useForm, useFieldArray } from 'react-hook-form'; +import { useForm } from 'react-hook-form'; import { NativeStackScreenProps } from '@react-navigation/native-stack'; import { useFetchWithAuth } from '../../hooks/useFetchWithAuth'; import { saveWithAuth } from '../../hooks/saveWithAuth'; @@ -15,11 +15,10 @@ import { SalesOrderContext } from './SalesOrderContex'; interface Props extends NativeStackScreenProps { }; export const SalesOrderFormScreen = ({ route, navigation }: Props) => { - console.log("Apertura de screem :" + route.params?.productId) const {lines, setLines, add} = useContext(SalesOrderContext); - const { control, handleSubmit, setValue, getValues, formState: { errors } } = useForm({ + const { control, handleSubmit, setValue, formState: { errors } } = useForm({ defaultValues: { id: 0, numero: '', @@ -32,29 +31,6 @@ export const SalesOrderFormScreen = ({ route, navigation }: Props) => { id = String(route.params.id); } - useEffect(() => { - if (route.params?.productId != undefined && route.params?.productId > 0) { - const newId = route.params?.productId; - const exits = lines.filter(line => line.producto.id == newId) - if (exits.length == 0) { - const newLine: SalesOrderLine = { - producto: { id: newId, nombre: "test" }, - cantidad: 1, - precio: 0 - } - console.log("Nueva linea :" + route.params?.productId) - //append(newLine); - add(newLine); - //setValue("detalle", lines); - //console.table(fields) - }else{ - console.log("Linea repetida"); - console.log(exits) - } - - } - }, [route.params?.productId]); - const getInitData = async () => { if (!id || id == "0") return; @@ -67,7 +43,6 @@ export const SalesOrderFormScreen = ({ route, navigation }: Props) => { setValue("numero", data['numero']) setValue("cliente", data['cliente']) const lines: SalesOrderLine[] = data['detalle']; - console.log("Agregando lineas:") setLines(lines); } @@ -85,6 +60,7 @@ export const SalesOrderFormScreen = ({ route, navigation }: Props) => { try { let endpoint = "pedido"; entity['cliente'] = { id: entity['cliente'].id } + entity['detalle'] = lines; const { data, error } = await saveWithAuth(endpoint, id, entity); if (error) { console.log(error);