Adding a new banner type
This document will guide you through the process on how to create a new banner type in the shophub project.
Type Package
- Extend the BannerTypename Enum
- Begin by expanding the
BannerTypenameenum with your desired new banner name.
- Add a ShopHub Type for Your Banner
- Navigate to
shophub/componentsand add the corresponding ShopHub type for your new banner. - Ensure you import the type in the top-level
index.tsbarrel file and re-export it under theshophubnamespace.
- Update the merge type
- Update the merging banner type called
anyBanner, which can be found inside theshophub/componentsfolder.
💡
After making these changes, rebuild your types to ensure they are available throughout the project.To rebuild types execute this command in your project root:
yarn types:initBackend Package
- Add a New Schema
- Create a new schema for your banner in the backend under
src/db/schema/builder. - Don’t forget to export the created schema from the
index.tsbarrel export file!
- Generate Controller and Service Files
- Use the following NestJS CLI command to generate your controller:
nest g controller cms/banner/<your-banner-name> --no-spec💡
Following the naming convention, the name of the banner should be in kebab-case.- To generate the service file, replace
controllerwithservicein the command above. Both the controller and service files will be placed in the appropriate directory and automatically registered in the module file.
- Create DTOs
- Inside your newly created banner folder, create a
dtodirectory and add the necessary DTO (Data Transfer Object) files. - Export these DTOs from a
barrel exportfor ease of use.
- Define CRUD Functions
- Implement the following standard CRUD operations in the service file:
create()getById()getAll()updateById()deleteById()
- Link Service and Controller
- Connect the CRUD operations in your service file to the appropriate controller functions.
- Update the getReferencedBanner function
- Update the function that fetches the banners for a webpage within it's switch statement. The file can be found in
cms/referenced-banner/referenced-banner.service.ts.
Frontend Package
- Create a New Banner Component
- Create a folder for your new banner component under the
shophubdirectory.
- Update the Banner Switch Statement
- In the
shophub/BannerElem.tsxfile, add your banner component to the switch statement. - Make sure it is wrapped inside a
bannerWrappercomponent, similar to the existing banners.
- Update the LCP evaluator
- The hook found in
hooks/useLcpEvaluator.tscontains a function calleddetermineNewBannerLCPValue, which returns a priority value based on the banner type. The number is determined based on if the banner contains any media that potentially has to be loaded eager as it could be considered the largest contentful paint of the website and the size of the banner as banner with a lot of height takes a way a lot of space that could potentially contain a largest contentful paint. So banners with media and a lot of height should get a high number, while banners that are text based or very small in height, should have a low priority number.
- (Optional) Update the Media checker function
- If the added banner type contains media, please also update the
checkGridWrapperForMediafunction, found in the same file.