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