From ec2604b9abf3e8d6ee137e2e3f61491078c29456 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Thu, 4 Apr 2024 14:28:51 -0300 Subject: [PATCH] Fix customer samples create preview --- .../components/CustomerSamplesCreate.vue | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/pages/Customer/components/CustomerSamplesCreate.vue b/src/pages/Customer/components/CustomerSamplesCreate.vue index 2a22cf4ca..4a28a3061 100644 --- a/src/pages/Customer/components/CustomerSamplesCreate.vue +++ b/src/pages/Customer/components/CustomerSamplesCreate.vue @@ -102,29 +102,43 @@ const setInitialData = () => { sampleType.value = {}; }; -const getPreview = async () => { - const { addressId, companyId, recipientId } = initialData; - const path = `Clients/${route.params.id}/incoterms-authorization-html`; - const params = { - addressId, - companyId, - recipientId, - }; - const queryParams = Object.keys(params) - .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`) - .join('&'); - const url = `${path}?${queryParams}`; +const validateMessage = () => { + if (!initialData.recipient) return 'Email cannot be blank'; + if (!sampleType.value) return 'Choose a sample'; + if (sampleType.value.hasCompany && !initialData.companyFk) return 'Choose a company'; + if (sampleType.value.datepickerEnabled && !initialData.from) return 'Choose a date'; + return ''; +}; + +const setParams = (params) => { + if (sampleType.value.hasCompany) params.companyId = initialData.companyFk; + if (sampleType.value.datepickerEnabled) params.from = initialData.from; + if (initialData.addressId) params.addressId = initialData.addressId; +}; + +const getPreview = async () => { try { - const { data } = await axios.get(url); + const params = { + recipientId: route.params.id, + }; + const validationMessage = validateMessage(); + if (validationMessage) return notify(t(validationMessage), 'negative'); + + setParams(params); + + const path = `${sampleType.value.model}/${route.params.id}/${sampleType.value.code}-html`; + const { data } = await axios.get(path, { params }); + + if (!data) return; quasar.dialog({ component: CustomerSamplesPreview, componentProps: { htmlContent: data, }, }); - } catch (error) { - return error; + } catch (err) { + notify('Errors getting preview', 'negative'); } }; @@ -364,4 +378,8 @@ es: To who should the recipient replay?: ¿A quien debería responder el destinatario? Edit address: Editar dirección Preview: Vista previa + Email cannot be blank: Debes introducir un email + Choose a sample: Selecciona una plantilla + Choose a company: Selecciona una empresa + Choose a date: Selecciona una fecha