From b4a6ac18f7b88ea81efcbe33d6ab7ef15769be11 Mon Sep 17 00:00:00 2001 From: David Arranz Date: Thu, 8 Oct 2026 12:36:03 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20agregar=20soporte=20para=20selecci?= =?UTF-8?q?=C3=B3n=20de=20idioma=20en=20la=20creaci=C3=B3n=20de=20cotizaci?= =?UTF-8?q?ones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quotes/components/QuotePricesResume.tsx | 2 - client/src/app/quotes/create.tsx | 93 +++++++++++++------ 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/client/src/app/quotes/components/QuotePricesResume.tsx b/client/src/app/quotes/components/QuotePricesResume.tsx index 7df8c7c..14534b5 100644 --- a/client/src/app/quotes/components/QuotePricesResume.tsx +++ b/client/src/app/quotes/components/QuotePricesResume.tsx @@ -7,8 +7,6 @@ import { useMemo } from "react"; import { useFormContext, useWatch } from "react-hook-form"; const calculateQuoteTotals = (prices: any) => { - console.debug("calculateQuoteTotals", prices); - const discountOrError = Percentage.create( prices[1] || { amount: null, diff --git a/client/src/app/quotes/create.tsx b/client/src/app/quotes/create.tsx index ba737f4..968981b 100644 --- a/client/src/app/quotes/create.tsx +++ b/client/src/app/quotes/create.tsx @@ -10,35 +10,53 @@ import { t } from "i18next"; import { SubmitButton } from "@/components"; import { useUnsavedChangesNotifier } from "@/lib/hooks"; -import { Button, Form, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator } from "@/ui"; +import { documentedLanguages } from "@/lib/languages"; +import { + Button, + Form, + Label, + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, + Separator, +} from "@/ui"; import { useToast } from "@/ui/use-toast"; import { joiResolver } from "@hookform/resolvers/joi"; import { ICreateQuote_Request_DTO } from "@shared/contexts"; import Joi from "joi"; -import { useMemo } from "react"; +import { useEffect, useMemo, useState } from "react"; import { Controller, SubmitHandler, useForm } from "react-hook-form"; +import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import SpanishJoiMessages from "../../spanish-joi-messages.json"; import { useQuotes } from "./hooks"; -import { documentedLanguages } from "@/lib/languages"; interface QuoteDataForm extends ICreateQuote_Request_DTO {} export const QuoteCreate = () => { const navigate = useNavigate(); + const { i18n } = useTranslation(); const { toast } = useToast(); const { useCreate } = useQuotes(); - const { mutate, isPending } = useCreate(); + const { mutateAsync, isPending } = useCreate(); + const [createdQuoteId, setCreatedQuoteId] = useState(); + + const interfaceLanguage = i18n.resolvedLanguage ?? i18n.language; + const documentLanguage = documentedLanguages.some(({ code }) => code === interfaceLanguage) + ? interfaceLanguage + : "es"; const defaultValues = useMemo( () => ({ date: new Date(Date.now()).toUTCString(), - lang_code: "es", + lang_code: documentLanguage, customer_reference: "", customer_information: "", //reference: "", }), - [] + [documentLanguage] ); const form = useForm({ @@ -49,6 +67,9 @@ export const QuoteCreate = () => { customer_reference: Joi.string(), date: Joi.date().required(), customer_information: Joi.string().required(), + lang_code: Joi.string() + .valid(...documentedLanguages.map(({ code }) => code)) + .required(), }), { messages: { @@ -58,35 +79,35 @@ export const QuoteCreate = () => { ), }); - const { formState, reset, getValues, handleSubmit } = form; + const { formState, reset, handleSubmit } = form; const { isSubmitting, isDirty } = formState; useUnsavedChangesNotifier({ isDirty, }); + useEffect(() => { + if (createdQuoteId) { + navigate(`/quotes/edit/${createdQuoteId}`, { relative: "path" }); + } + }, [createdQuoteId, navigate]); + const onSubmit: SubmitHandler = async (formData) => { try { - mutate(formData, { - onError: (error) => { - console.debug(error); - toast({ - title: t("common.error"), - description: error.message, - variant: "destructive", - }); - }, - onSuccess: (data) => { - reset(getValues()); - toast({ - title: t("quotes.notifications.created"), - variant: "default", - }); - navigate(`/quotes/edit/${data.id}`, { relative: "path" }); - }, + const data = await mutateAsync(formData); + reset(formData); + toast({ + title: t("quotes.notifications.created"), + variant: "default", + }); + setCreatedQuoteId(data.id); + } catch (error) { + console.debug(error); + toast({ + title: t("common.error"), + description: (error as Error).message, + variant: "destructive", }); - } finally { - //setLoading(false); } }; @@ -120,7 +141,12 @@ export const QuoteCreate = () => { description={t("quotes.create.form_groups.general.desc")} footerActions={
- @@ -144,13 +170,18 @@ export const QuoteCreate = () => { />
- + ( )} /> -

{t("quotes.form_fields.lang_code.desc")}

+

+ {t("quotes.form_fields.lang_code.desc")} +