diff --git a/src/layout/headers/header-com/menus.jsx b/src/layout/headers/header-com/menus.jsx index e69de29..93cfd77 100644 --- a/src/layout/headers/header-com/menus.jsx +++ b/src/layout/headers/header-com/menus.jsx @@ -0,0 +1,120 @@ +import React from "react"; +import menu_data from "@/data/menu-data"; +import Link from "next/link"; +import Image from "next/image"; +import OfferCouponArea from "@/components/offerHeader/OfferCouponArea"; +import { useGetProductTypeQuery } from "@/redux/features/productApi"; +import { HomeNewArrivalPrdLoader } from "@/components/loader"; +import ErrorMsg from "@/components/common/error-msg"; +import ProductItem from "@/components/products/electronics/product-item"; + +const Menus = () => { + const { data: products, isError, isLoading } = useGetProductTypeQuery({ + type: 'electronics', + query: 'new=true' + }); + + // decide what to render + let content = null; + + if (isLoading) { + content = ( + + ); + } + + if (!isLoading && isError) { + content = ; + } + + if (!isLoading && !isError && products?.data?.length === 0) { + content = ; + } + + if (!isLoading && !isError && products?.data?.length > 0) { + const product_items = products.data; + + content = ( +
+ {product_items.slice(0, 4).map((item) => ( +
+ +
+ ))} +
+ ); + } else { + // If there are no products or an error occurs, set content to an empty array + content = []; + } + return ( +
    + {menu_data.map((menu) => + menu.homes ? ( +
  • + {menu.title} +
    +
    + {content} +
    + {/* */} +
    + {menu.home_pages.map((home, i) => ( +
    +
    + {/* +
    + home img +
    +
    +
    {home.title}
    +
    + */} +
    +
    + ))} +
    +
    +
  • + ) : menu.products ? ( +
  • + {menu.title} +
      + {menu.product_pages.map((p, i) => ( +
    • + + {p.title} + +
        + {p.mega_menus.map((m, i) => ( +
      • + {m.title} +
      • + ))} +
      +
    • + ))} +
    +
  • + ) : menu.sub_menu ? ( +
  • + {menu.title} +
      + {menu.sub_menus.map((b, i) => ( +
    • + {b.title} +
    • + ))} +
    +
  • + ) : ( +
  • + {menu.title} +
  • + ) + )} +
+ ); +}; + +export default Menus;