initial commit
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import { listProductTypes } from "@lib/data/products";
|
||||
import { listRegions } from '@lib/data/regions';
|
||||
import { getProductCategories } from '@lib/data/categories';
|
||||
import { listProductTypes } from '@lib/data/products';
|
||||
import { listRegions } from '@lib/data/regions';
|
||||
|
||||
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
||||
import { ServiceCategory } from '../../_components/service-categories';
|
||||
|
||||
async function countryCodesLoader() {
|
||||
const countryCodes = await listRegions().then((regions) =>
|
||||
@@ -14,7 +16,9 @@ async function countryCodesLoader() {
|
||||
export const loadCountryCodes = cache(countryCodesLoader);
|
||||
|
||||
async function productCategoriesLoader() {
|
||||
const productCategories = await getProductCategories({ fields: "*products, *products.variants" });
|
||||
const productCategories = await getProductCategories({
|
||||
fields: '*products, *products.variants, is_active',
|
||||
});
|
||||
return productCategories.product_categories ?? [];
|
||||
}
|
||||
export const loadProductCategories = cache(productCategoriesLoader);
|
||||
@@ -29,25 +33,34 @@ async function analysesLoader() {
|
||||
const [countryCodes, productCategories] = await Promise.all([
|
||||
loadCountryCodes(),
|
||||
loadProductCategories(),
|
||||
]);
|
||||
]);
|
||||
const countryCode = countryCodes[0]!;
|
||||
|
||||
const category = productCategories.find(({ metadata }) => metadata?.page === 'order-analysis');
|
||||
|
||||
const category = productCategories.find(
|
||||
({ metadata }) => metadata?.page === 'order-analysis',
|
||||
);
|
||||
const serviceCategories = productCategories.filter(
|
||||
({ parent_category }) => parent_category?.handle === 'tto-categories',
|
||||
);
|
||||
console.log('serviceCategories', serviceCategories);
|
||||
return {
|
||||
analyses: category?.products?.map<OrderAnalysisCard>(({ title, description, subtitle, variants, status, metadata }) => {
|
||||
const variant = variants![0]!;
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
subtitle,
|
||||
variant: {
|
||||
id: variant.id,
|
||||
analyses:
|
||||
category?.products?.map<OrderAnalysisCard>(
|
||||
({ title, description, subtitle, variants, status, metadata }) => {
|
||||
const variant = variants![0]!;
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
subtitle,
|
||||
variant: {
|
||||
id: variant.id,
|
||||
},
|
||||
isAvailable:
|
||||
status === 'published' && !!metadata?.analysisIdOriginal,
|
||||
};
|
||||
},
|
||||
isAvailable: status === 'published' && !!metadata?.analysisIdOriginal,
|
||||
};
|
||||
}) ?? [],
|
||||
) ?? [],
|
||||
countryCode,
|
||||
}
|
||||
};
|
||||
}
|
||||
export const loadAnalyses = cache(analysesLoader);
|
||||
|
||||
49
app/home/(user)/_lib/server/load-tto-services.ts
Normal file
49
app/home/(user)/_lib/server/load-tto-services.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import { getProductCategories } from '@lib/data';
|
||||
|
||||
import { ServiceCategory } from '../../_components/service-categories';
|
||||
|
||||
async function ttoServicesLoader() {
|
||||
const response = await getProductCategories({
|
||||
fields: '*products, is_active, metadata',
|
||||
});
|
||||
console.log('response.product_categories', response.product_categories);
|
||||
const heroCategories = response.product_categories?.filter(
|
||||
({ parent_category, is_active, metadata }) =>
|
||||
parent_category?.handle === 'tto-categories' &&
|
||||
is_active &&
|
||||
metadata?.isHero,
|
||||
);
|
||||
|
||||
const ttoCategories = response.product_categories?.filter(
|
||||
({ parent_category, is_active, metadata }) =>
|
||||
parent_category?.handle === 'tto-categories' &&
|
||||
is_active &&
|
||||
!metadata?.isHero,
|
||||
);
|
||||
|
||||
return {
|
||||
heroCategories:
|
||||
heroCategories.map<ServiceCategory>(
|
||||
({ name, handle, metadata, description }) => ({
|
||||
name,
|
||||
handle,
|
||||
color:
|
||||
typeof metadata?.color === 'string' ? metadata.color : 'primary',
|
||||
description,
|
||||
}),
|
||||
) ?? [],
|
||||
ttoCategories:
|
||||
ttoCategories.map<ServiceCategory>(
|
||||
({ name, handle, metadata, description }) => ({
|
||||
name,
|
||||
handle,
|
||||
color:
|
||||
typeof metadata?.color === 'string' ? metadata.color : 'primary',
|
||||
description,
|
||||
}),
|
||||
) ?? [],
|
||||
};
|
||||
}
|
||||
export const loadTtoServices = cache(ttoServicesLoader);
|
||||
Reference in New Issue
Block a user