Create a new CMS component
-
Begin by creating a new component in the appropriate feature folder.
shop/client/features/account/components/invoices/InvoicesComponent.tsx
export function InvoicesComponent() {return <div></div>;} -
In the
cmsfolder, create a new CMS-specific component that references the component created in step 1.shop/client/features/cms/components/invoice/CmsInvoicesComponent.tsx
import { InvoicesComponent } from 'shop/client/features/account/components/invoices/InvoicesComponent';function CmsInvoicesComponent() {return <InvoicesComponent />;}export default CmsInvoicesComponent; -
Add an
index.tsfile next to the CMS component and export the component wrapped in aLoadableto enable lazy loading.shop/client/features/cms/components/invoice/index.ts
import Loadable from 'shop/client/components/support/loadable/Loadable';export default Loadable({ factory: () => import('shop/client/features/cms/components/invoice/CmsInvoicesComponent') }); -
Update the
CMSComponentTypeCodeconstant by adding a new entry that corresponds to thetypeCodeprovided by the backend for your component.shop/client/constants/cms.ts
export const enum CMSComponentTypeCode {//...INVOICES = 'CmsInvoicesComponent'} -
Register the component in the component registry.
shop/client/features/cms/components/support/registry/CMSComponentRegistry.ts
import InvoicesComponent from 'shop/client/features/cms/components/invoice';//...CMSComponentRegistry.register(CMSComponentTypeCode.INVOICES, InvoicesComponent); -
Test your component by mocking a CMS component