feat(MED-131): show package analysis elements in comparison modal
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import { listProductTypes, listProducts, listRegions } from "@lib/data";
|
||||
import { getAnalysisElementOriginalIds, listProductTypes, listProducts } from "@lib/data/products";
|
||||
import { listRegions } from '@lib/data/regions';
|
||||
import { AnalysisElement, getAnalysisElements } from '~/lib/services/analysis-element.service';
|
||||
|
||||
async function countryCodesLoader() {
|
||||
const countryCodes = await listRegions().then((regions) =>
|
||||
@@ -22,13 +24,21 @@ async function analysisPackagesLoader() {
|
||||
|
||||
const productType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
|
||||
if (!productType) {
|
||||
return { analysisPackages: [], countryCode };
|
||||
return { analysisElements: [], analysisPackages: [], countryCode };
|
||||
}
|
||||
|
||||
const { response } = await listProducts({
|
||||
countryCode,
|
||||
queryParams: { limit: 100, "type_id[0]": productType.id },
|
||||
});
|
||||
return { analysisPackages: response.products, countryCode };
|
||||
const analysisPackages = response.products;
|
||||
let analysisElements: AnalysisElement[] = [];
|
||||
const analysisElementOriginalIds = await getAnalysisElementOriginalIds(analysisPackages);
|
||||
|
||||
if (analysisElementOriginalIds.length) {
|
||||
analysisElements = await getAnalysisElements({ originalIds: analysisElementOriginalIds });
|
||||
}
|
||||
|
||||
return { analysisElements, analysisPackages, countryCode };
|
||||
}
|
||||
export const loadAnalysisPackages = cache(analysisPackagesLoader);
|
||||
|
||||
Reference in New Issue
Block a user