'use client'; import { InfoCircledIcon } from '@radix-ui/react-icons'; import dynamic from 'next/dynamic'; import Hero from 'components/modules/hero'; import ReusableSection from 'components/modules/reusable-section/reusable-section'; const USPSection = dynamic(() => import('components/modules/usp-section')); const Slider = dynamic(() => import('components/modules/slider')); const BlurbSection = dynamic(() => import('components/modules/blurb-section')); const FilteredProductList = dynamic(() => import('components/modules/filtered-product-list')); interface getContentComponentProps { _type: string; _key: number; disabled: boolean; } const getContentComponent = ({ _type, _key, disabled, ...rest }: getContentComponentProps) => { let Component: any; switch (_type) { case 'hero': Component = Hero; break; case 'slider': Component = Slider; break; case 'filteredProductList': Component = FilteredProductList; break; case 'blurbSection': if (disabled !== true) { Component = BlurbSection; } else { return; } break; case 'uspSection': if (disabled !== true) { Component = USPSection; } else { return; } break; case 'reusableSection': if (disabled !== true) { Component = ReusableSection; } else { return; } break; default: return (
{`No matching component (Type: ${_type})`}
); } return Component ? ( ) : (
Something else
); }; interface dynamicContentManagerProps { content: [] | any; } const DynamicContentManager = ({ content }: dynamicContentManagerProps) => { return (
{content?.map(getContentComponent)}
); }; export default DynamicContentManager;