From 355fc25095b94288adb8f87f654a73ee9cabc64b Mon Sep 17 00:00:00 2001 From: David Arranz Date: Tue, 12 Nov 2024 12:28:22 +0100 Subject: [PATCH] =?UTF-8?q?Se=20a=C3=B1ade=20cantidad=20en=20articulos=20a?= =?UTF-8?q?=20a=C3=B1adir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: darranz --- .../components/CatalogPickerDataTable.tsx | 39 +++++++++++++++++-- .../editors/QuoteDetailsCardEditor.tsx | 4 +- client/src/app/quotes/edit.tsx | 4 +- .../CustomButtons/BackHistoryButton.tsx | 2 +- client/src/locales/en.json | 8 +++- client/src/locales/es.json | 10 +++-- 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/client/src/app/quotes/components/CatalogPickerDataTable.tsx b/client/src/app/quotes/components/CatalogPickerDataTable.tsx index 99f8674..e4c3202 100644 --- a/client/src/app/quotes/components/CatalogPickerDataTable.tsx +++ b/client/src/app/quotes/components/CatalogPickerDataTable.tsx @@ -9,13 +9,26 @@ import { IListArticles_Response_DTO, MoneyValue } from "@shared/contexts"; import { ColumnDef, Row } from "@tanstack/react-table"; import { t } from "i18next"; import { PackagePlusIcon } from "lucide-react"; -import { useMemo } from "react"; +import { useMemo, useState } from "react"; import { useNavigate } from "react-router-dom"; -export const CatalogPickerDataTable = ({ onSelect }: { onSelect: (data: unknown) => void }) => { +export const CatalogPickerDataTable = ({ + onSelect, +}: { + onSelect: (data: unknown, quantity: number) => void; +}) => { const navigate = useNavigate(); const { pagination, globalFilter, isFiltered } = useDataTableContext(); + const [quantities, setQuantities] = useState([]); + + const handleQuantity = (index: number, quantity: number) => { + setQuantities((prev) => { + prev[index] = quantity; + return prev; + }); + }; + const { data, isPending, isError, error } = useCatalogList({ pagination: { pageIndex: pagination.pageIndex, @@ -48,6 +61,26 @@ export const CatalogPickerDataTable = ({ onSelect }: { onSelect: (data: unknown) return
{price.toFormat()}
; }, }, + { + id: "quantity" as const, + accessorKey: "quantity", + header: () =>
{t("catalog.list.columns.quantity")}
, + cell: ({ row: { index } }) => { + return ( + { + event.preventDefault(); + handleQuantity(index, +event.target.value); + }} + /> + ); + }, + }, { id: "row-actions", header: () => null, @@ -58,7 +91,7 @@ export const CatalogPickerDataTable = ({ onSelect }: { onSelect: (data: unknown) className='h-8 gap-1' onClick={(event) => { event.preventDefault(); - onSelect && onSelect(row.original); + onSelect && onSelect(row.original, quantities[row.index]); }} > diff --git a/client/src/app/quotes/components/editors/QuoteDetailsCardEditor.tsx b/client/src/app/quotes/components/editors/QuoteDetailsCardEditor.tsx index caa748d..6d27f5a 100644 --- a/client/src/app/quotes/components/editors/QuoteDetailsCardEditor.tsx +++ b/client/src/app/quotes/components/editors/QuoteDetailsCardEditor.tsx @@ -214,12 +214,12 @@ export const QuoteDetailsCardEditor = ({ ); const handleAppendCatalogArticle = useCallback( - (article: any) => { + (article: any, quantity: number = 1) => { console.log(article); fieldActions.append({ ...article, quantity: { - amount: 100, + amount: 100 * quantity, scale: Quantity.DEFAULT_SCALE, }, unit_price: article.retail_price, diff --git a/client/src/app/quotes/edit.tsx b/client/src/app/quotes/edit.tsx index 1a55e44..0212103 100644 --- a/client/src/app/quotes/edit.tsx +++ b/client/src/app/quotes/edit.tsx @@ -318,9 +318,9 @@ export const QuoteEdit = () => {
- +
diff --git a/client/src/components/CustomButtons/BackHistoryButton.tsx b/client/src/components/CustomButtons/BackHistoryButton.tsx index a69d10f..fd4bef9 100644 --- a/client/src/components/CustomButtons/BackHistoryButton.tsx +++ b/client/src/components/CustomButtons/BackHistoryButton.tsx @@ -9,7 +9,7 @@ export const BackHistoryButton = () => { return ( ); }; diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 02f78e0..edb4417 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -119,7 +119,8 @@ "columns": { "description": "Description", "points": "Points", - "retail_price": "Retail price" + "retail_price": "Retail price", + "quantity": "quantity" } } }, @@ -201,7 +202,10 @@ } }, "edit": { - "title": "Quote" + "title": "Quote", + "buttons": { + "save_quote": "Save quote" + } }, "downloading_dialog": { "title": "Downloading quote", diff --git a/client/src/locales/es.json b/client/src/locales/es.json index ca19a08..bb5a609 100644 --- a/client/src/locales/es.json +++ b/client/src/locales/es.json @@ -8,7 +8,7 @@ "save": "Guardar", "save_close": "Guardar y Cerrar", "accept": "Aceptar", - "discard": "Decartar", + "discard": "Descartar", "hide": "Ocultar", "back": "Volver", "upload": "Cargar", @@ -119,7 +119,8 @@ "columns": { "description": "Descripción", "points": "Puntos", - "retail_price": "PVP" + "retail_price": "PVP", + "quantity": "Cantidad" } } }, @@ -201,7 +202,10 @@ } }, "edit": { - "title": "Cotización" + "title": "Cotización", + "buttons": { + "save_quote": "Guardar cotización" + } }, "downloading_dialog": { "title": "Descargando cotización",