From 5acf018a22364bd76aa9bdc198cd6fa0e7dba8e5 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 30 Sep 2025 19:03:20 +0200 Subject: [PATCH] Clientes --- .../customer-empty-card.tsx | 5 +- .../customer-modal-selector.tsx | 15 +- .../customer-search-dialog.tsx | 155 ++++++++++-------- .../src/web/schemas/customer.api.schema.ts | 2 +- 4 files changed, 100 insertions(+), 77 deletions(-) diff --git a/modules/customers/src/web/components/customer-modal-selector/customer-empty-card.tsx b/modules/customers/src/web/components/customer-modal-selector/customer-empty-card.tsx index fcfb39f7..44824592 100644 --- a/modules/customers/src/web/components/customer-modal-selector/customer-empty-card.tsx +++ b/modules/customers/src/web/components/customer-modal-selector/customer-empty-card.tsx @@ -1,10 +1,10 @@ -import { SearchIcon, UserPlusIcon } from "lucide-react"; +import { UserSearchIcon } from "lucide-react"; export const CustomerEmptyCard = () => { return (
- +

@@ -14,7 +14,6 @@ export const CustomerEmptyCard = () => { Haz clic para buscar un cliente existente o crear uno nuevo

-
); }; diff --git a/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx b/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx index ba8dec2a..e28b859f 100644 --- a/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx +++ b/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx @@ -1,6 +1,6 @@ import { useEffect, useMemo, useState } from "react"; import { useCustomersSearchQuery } from "../../hooks"; -import { CustomerSummary } from "../../schemas"; +import { CustomerSummary, defaultCustomerFormData } from "../../schemas"; import { CustomerCard } from "./customer-card"; import { CustomerEmptyCard } from "./customer-empty-card"; import { CreateCustomerFormDialog } from "./customer-form-dialog"; @@ -30,7 +30,8 @@ export const CustomerModalSelector = ({ value, onValueChange }: CustomerModalSel // Cliente seleccionado y creación local optimista const [selected, setSelected] = useState(null); - const [newClient, setNewClient] = useState>({ name: "", email: "" }); + const [newClient, setNewClient] = + useState>(defaultCustomerFormData); const [localCreated, setLocalCreated] = useState([]); const { @@ -61,19 +62,17 @@ export const CustomerModalSelector = ({ value, onValueChange }: CustomerModalSel const handleCreate = () => { if (!newClient.name || !newClient.email) return; - const client: CustomerSummary = { + const newCustomer: CustomerSummary = { id: crypto.randomUUID?.() ?? Date.now().toString(), ...newClient, }; - setLocalCreated((prev) => [client, ...prev]); - setSelected(client); - onValueChange?.(client.id); + setLocalCreated((prev) => [newCustomer, ...prev]); + setSelected(newCustomer); + onValueChange?.(newCustomer.id); setShowForm(false); setShowSearch(false); }; - console.log(customers); - return ( <> + + {isLoading &&

Cargando…

} + {isError &&

{errorMessage}

} + {!isLoading && !isError && ( + <> +

No se encontraron clientes

+ {searchQuery && ( + + )} + )} + - {customers.map((customer) => ( - onSelectClient(customer)} - className='flex items-center gap-x-4 py-5 cursor-pointer' - > -
- -
-
-
- {customer.name} - {customer.trade_name && ( - - {customer.trade_name} - - )} + {customers.map((customer) => { + return ( + onSelectClient(customer)} + className='flex items-center gap-x-4 py-5 cursor-pointer' + > +
+
-
- {customer.tin && ( - - {customer.tin} - - )} - {customer.email_primary && ( - - {customer.email_primary} - - )} - {customer.mobile_primary && ( - - {customer.mobile_primary} - - )} +
+
+ {customer.name} + {customer.trade_name && ( + + {customer.trade_name} + + )} +
+
+ {customer.tin && ( + + {customer.tin} + + )} + {customer.email_primary && ( + + {customer.email_primary} + + )} + {customer.mobile_primary && ( + + {customer.mobile_primary} + + )} +
-
- -
- ))} - - - onCreateClient()} - className='flex items-center gap-3 p-3 border-t' - > -
- -
- Agregar nuevo cliente -
+ + + ); + })}
+ + + ); diff --git a/modules/customers/src/web/schemas/customer.api.schema.ts b/modules/customers/src/web/schemas/customer.api.schema.ts index bcb7b34d..cdc2dd6a 100644 --- a/modules/customers/src/web/schemas/customer.api.schema.ts +++ b/modules/customers/src/web/schemas/customer.api.schema.ts @@ -22,4 +22,4 @@ export type CustomerUpdateInput = z.infer; // Cuerp export type CustomersPage = ListCustomersResponseDTO; // Ítem simplificado dentro del listado (no toda la entidad) -export type CustomerSummary = ArrayElement; +export type CustomerSummary = Omit, "metadata">;