refactor: make dynamic config loader json file and create template for 3bear design

This commit is contained in:
Nam Doan
2025-11-24 15:42:38 +07:00
parent 51d6ee2051
commit 1bace8a023
12 changed files with 580 additions and 41 deletions
+8 -4
View File
@@ -4,15 +4,17 @@ import { listCartOptions, retrieveCart } from "@lib/data/cart"
import { retrieveCustomer } from "@lib/data/customer"
import { getBaseURL } from "@lib/util/env"
import { StoreCartShippingOption } from "@medusajs/types"
import { DynamicLayoutRenderer } from "../../../vibentec/renderer"
import { LayoutContext, LayoutComponentNode, } from "../../../vibentec/component-map"
import { LayoutContext, LayoutComponentNode } from "vibentec/component-map"
import { DynamicLayoutRenderer } from "vibentec/renderer"
import { loadDesignConfig } from "vibentec/configloader"
import { DESIGN_JSON_FILE } from "./config-json-file"
export const metadata: Metadata = {
metadataBase: new URL(getBaseURL()),
}
export default async function PageLayout(props: { children: React.ReactNode }) {
// Choose which design JSON to load. Swap this constant as needed.
const customer = await retrieveCustomer()
const cart = await retrieveCart()
let shippingOptions: StoreCartShippingOption[] = []
@@ -23,14 +25,16 @@ export default async function PageLayout(props: { children: React.ReactNode }) {
shippingOptions = shipping_options
}
const nodes: LayoutComponentNode[] = await loadDesignConfig()
const nodes: LayoutComponentNode[] = await loadDesignConfig(
DESIGN_JSON_FILE[1].file
)
const context: LayoutContext = {
customer,
cart,
shippingOptions,
contentChildren: props.children,
designId: DESIGN_JSON_FILE[1].id,
}
return <DynamicLayoutRenderer nodes={nodes} context={context} />
}