From 438ec6d75714e83f770a8c8d4ef252b42e8d938b Mon Sep 17 00:00:00 2001 From: Srinath Date: Wed, 4 Feb 2026 13:44:37 +0530 Subject: [PATCH] Addes style and offter amt --- .../ProductCatlogue/CatalogueTemplate4.jsx | 336 ++++++------------ 1 file changed, 110 insertions(+), 226 deletions(-) diff --git a/src/Pages/ProductCatlogue/CatalogueTemplate4.jsx b/src/Pages/ProductCatlogue/CatalogueTemplate4.jsx index d55ca25..04b48b5 100644 --- a/src/Pages/ProductCatlogue/CatalogueTemplate4.jsx +++ b/src/Pages/ProductCatlogue/CatalogueTemplate4.jsx @@ -2,8 +2,6 @@ import React, { useEffect, useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { getSession } from '../../Services/Others'; import Headerimg from '../../Images/cate-h.png'; -import { FaLocationDot } from 'react-icons/fa6'; -import { FaWhatsapp } from 'react-icons/fa'; import { GlobalCataloguedata, Branchname, @@ -15,7 +13,9 @@ const CatalogueTemplate4 = (props) => { const BrId = getSession('BranchId'); const Globalcataloguedata1 = useSelector(GlobalCataloguedata); const [Branchdatas, setBranchdatas] = useState(); - const [base64Image, setBase64Image] = useState(null); + console.log(Branchdatas, 'BranchdatasBranchdatas'); + + const ITEMS_PER_PAGE = 25; // 5x5 grid useEffect(() => { Branchdata(); @@ -31,239 +31,123 @@ const CatalogueTemplate4 = (props) => { function safeRound(amountStr) { if (amountStr == null) return '0.00'; - const cleaned = String(amountStr).replace(/[^0-9.-]+/g, ''); const num = Number(cleaned); - - return isNaN(num) ? '0.00' : num.toFixed(2); // return as string with 2 decimals + return isNaN(num) ? '0.00' : num.toFixed(2); } - useEffect(() => { - async function fetchImage() { - try { - const base64 = await imageUrlToBase64(Branchdatas?.[0]?.CompLogo); - setBase64Image(base64); - } catch (error) { - console.log('Error converting image', error.message); - } - } - if (Branchdatas?.[0]?.CompLogo) { - fetchImage(); - } - }, [Branchdatas?.[0]?.CompLogo]); - const imageUrlToBase64 = async (url) => { - try { - const response = await fetch(url); - const blob = await response.blob(); - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onloadend = () => resolve(reader.result); - reader.onerror = reject; - reader.readAsDataURL(blob); - }); - } catch (error) { - console.error('Error fetching or converting image:', error); - throw error; + // Split products into pages of 25 items each + const paginateProducts = (products) => { + const pages = []; + for (let i = 0; i < products.length; i += ITEMS_PER_PAGE) { + pages.push(products.slice(i, i + ITEMS_PER_PAGE)); } + return pages; }; + const pages = paginateProducts(Globalcataloguedata1 || []); + console.log(pages, 'pages574754783'); - return ( - <> -
- {/* Header Section */} -
- {Branchdatas?.map((item) => ( -
- Header - {props?.cat === 'Catalogue 4' && ( -
- FLAT 50% OFF -
- )} + // Header Component + const PageHeader = () => ( +
+ Header + {props?.cat === 'Catalogue 4' && ( +
+ {/* FLAT SPECIAL SAVINGS OFF */} + SPECIAL SAVINGS +
+ )} +
+ ); + + // Footer Component + const PageFooter = () => ( +
+
+

{Branchdatas?.[0]?.BrName}

+
+ {Branchdatas?.[0]?.Address1 && ( +
+ {Branchdatas?.[0]?.Address1}, {Branchdatas?.[0]?.Dist},{' '} + {Branchdatas?.[0]?.State}
- ))} -
- - {/* Content Section */} -
-
- {Globalcataloguedata1?.map((item) => ( -
- {item?.ProdName} - - {item?.ProdName} {item?.UomName} - -
-

- {props?.cat === 'Catalogue 4' && - `MRP:₹${safeRound(item?.SellPrice)}`} -

-
-
-

- {props?.cat === 'Catalogue 6' - ? ` ₹${safeRound(item?.SellPrice)} only` - : '15% off on MRP'} -

-
-
- ))} -
-
- - {/* Footer Section */} -
-

- {Branchdatas?.[0]?.BrName} -

-
- {Branchdatas?.[0]?.Address1 && ( -
- {Branchdatas?.[0]?.Address1}, {Branchdatas?.[0]?.Dist},{' '} - {Branchdatas?.[0]?.State} -
- )} - {Branchdatas?.[0]?.BrMobile && ( -
- FREE HOME DELIVERY: {Branchdatas?.[0]?.BrMobile} -
- )} -
+ )} + {/* {Branchdatas?.[0]?.BrMobile && ( +
+ FREE HOME DELIVERY: {Branchdatas?.[0]?.BrMobile} +
+ )} */}
- +
+ ); + + // Product Card Component + const getOfferText = (item, cat) => { + if (cat === 'Catalogue 6') { + return `₹${safeRound(item.SellPrice)} only`; + } + const offer = item?.OfferDtl?.[0]; + if (!offer) return null; + + if (offer.OfferName === 'Product offer') { + if (offer.ValueType === 'P') { + return `${offer.OfferAmt}% OFF`; + } + if (offer.ValueType === 'F') { + return `₹${offer.OfferAmt} OFF`; + } + } + return offer.OfferName; + }; + + const ProductCard = ({ item }) => ( +
+ {item?.ProdName} +
+ {item?.ProdName} {item?.UomName} +
+
+ {props?.cat === 'Catalogue 4' + ? `MRP: ₹${safeRound(item?.SellPrice)}` + : item?.OfferDtl?.[0]?.OfferName ? ( +
{item?.OfferDtl?.[0]?.OfferName}
) : 'No Offer' + } +
+ {( + props?.cat === 'Catalogue 6' || + item?.OfferDtl?.length > 0 + ) && ( +
+ {getOfferText(item, props?.cat)} +
+ )} + +
+ ); + + return ( +
+ {pages.map((pageProducts, pageIndex) => ( +
+ +
+
+ {pageProducts.map((item, index) => ( + + ))} +
+
+ + +
+ ))} +
); }; -export default CatalogueTemplate4; +export default CatalogueTemplate4; \ No newline at end of file