fix: refs #7322 handle null responses in client, agency and address fetching #1313

Merged
jtubau merged 8 commits from 7322-fixDestructuringErrorTicketSection into dev 2025-02-03 11:58:52 +00:00
4 changed files with 55 additions and 30 deletions
Showing only changes of commit b10cb9f09f - Show all commits

View File

@ -1,12 +1,21 @@
import axios from 'axios';
import agency from 'src/router/modules/agency';
export async function getAgencies(formData) {
export async function getAgencies(formData, client) {

incluye la opción de pasarle un filtro personalizado, al igual que se ha hecho en getClientRisk
El mismo cambio en getClient

incluye la opción de pasarle un filtro personalizado, al igual que se ha hecho en getClientRisk El mismo cambio en getClient
if (!formData.warehouseId || !formData.addressId || !formData.landed) return;
let defaultAgency = null;
let params = {
warehouseFk: formData.warehouseId,
addressFk: formData.addressId,
landed: formData.landed,
};
return await axios.get('Agencies/getAgenciesWithWarehouse', { params });
const { data } = await axios.get('Agencies/getAgenciesWithWarehouse', { params });
if(data && client) {
defaultAgency = data.find((agency) => agency.agencyModeFk === client.defaultAddress.agencyModeFk );
};
return {options: data, agency: defaultAgency}
}

View File

@ -38,6 +38,11 @@ onBeforeMount(async () => {
await onClientSelected(initialFormState);
});
function resetAgenciesSelector(formData) {
agenciesOptions.value = [];
formData.agencyModeId = null;
}
const fetchClient = async (formData) => {
const response = await getClient(formData.clientId);
if (!response) return;
@ -55,21 +60,21 @@ const fetchAddresses = async (formData) => {
};
const onClientSelected = async (formData) => {
resetAgenciesSelector(formData);
await fetchClient(formData);
await fetchAddresses(formData);
};
const fetchAvailableAgencies = async (formData) => {
const response = await getAgencies(formData);
resetAgenciesSelector(formData);
const response= await getAgencies(formData, selectedClient.value);
if (!response) return;
agenciesOptions.value = response.data;
const defaultAgency = agenciesOptions.value.find(
(agency) =>
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
);
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
const { options, agency } = response
if(options)
agenciesOptions.value = options;
if(agency)
formData.agencyModeId = agency;
};
const redirectToTicketList = (_, { id }) => {

View File

@ -38,6 +38,11 @@ onBeforeMount(async () => {
await onClientSelected(initialFormState);
});
function resetAgenciesSelector(formData) {
agenciesOptions.value = [];
if(formData) formData.agencyModeId = null;
}
const fetchClient = async (formData) => {
const response = await getClient(formData.clientId);
if (!response) return;
@ -55,21 +60,21 @@ const fetchAddresses = async (formData) => {
};
const onClientSelected = async (formData) => {
resetAgenciesSelector(formData);
await fetchClient(formData);
await fetchAddresses(formData);
};
const fetchAvailableAgencies = async (formData) => {
const response = await getAgencies(formData);
resetAgenciesSelector(formData);
const response= await getAgencies(formData, selectedClient.value);
if (!response) return;
agenciesOptions.value = response.data;
const defaultAgency = agenciesOptions.value.find(
(agency) =>
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
);
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
const { options, agency } = response
if(options)
agenciesOptions.value = options;
if(agency)
formData.agencyModeId = agency;
};
const redirectToTicketList = (_, { id }) => {

View File

@ -229,27 +229,33 @@ const columns = computed(() => [
],
},
]);
function resetAgenciesSelector(formData) {
agenciesOptions.value = [];
if(formData) formData.agencyModeId = null;
}
function redirectToLines(id) {
const url = `#/ticket/${id}/sale`;
window.open(url, '_blank');
}
const onClientSelected = async (formData) => {
const onClientSelected = async (formData) => {
resetAgenciesSelector(formData);
await fetchClient(formData);
await fetchAddresses(formData);
};
const fetchAvailableAgencies = async (formData) => {
const response = await getAgencies(formData);
resetAgenciesSelector(formData);
const response= await getAgencies(formData, selectedClient.value);
if (!response) return;
agenciesOptions.value = response.data;
const defaultAgency = agenciesOptions.value.find(
(agency) =>
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
);
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
const { options, agency } = response
if(options)
agenciesOptions.value = options;
if(agency)
formData.agencyModeId = agency;
};
const fetchClient = async (formData) => {