Fix customer samples create preview
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
William Buezas 2024-04-04 14:28:51 -03:00
parent 87f376464b
commit ec2604b9ab
1 changed files with 33 additions and 15 deletions

View File

@ -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
</i18n>