From b89955eecf94c6ff3cf1cd9ef9226e96bbaacf45 Mon Sep 17 00:00:00 2001 From: Rostislav Vitek Date: Fri, 17 Nov 2023 16:22:10 +0100 Subject: [PATCH] WIP --- storefront/components/Basic/Image/Image.tsx | 54 +++++++++---------- .../Blocks/BlogPreview/BlogPreviewMain.tsx | 2 +- .../Blocks/BlogPreview/BlogPreviewSide.tsx | 2 +- .../Blocks/OrderSummary/SingleProduct.tsx | 2 +- .../OrderSummary/TransportAndPayment.tsx | 4 +- .../Blocks/Product/AddToCartPopup.tsx | 7 ++- .../Product/ProductsList/ProductListItem.tsx | 2 +- .../SimpleNavigationListItem.tsx | 2 +- .../Layout/Footer/FooterCopyright.tsx | 2 +- .../AutocompleteSearchPopup.tsx | 2 +- .../Layout/Header/Cart/CartListItem.tsx | 6 ++- .../components/Layout/Header/Logo/Logo.tsx | 6 +-- .../Navigation/NavigationItemColumn.tsx | 2 +- .../NotificationBars/NotificationBars.tsx | 2 +- .../BlogArticle/BlogArticleDetailContent.tsx | 6 ++- .../Pages/BlogCategory/BlogArticlesList.tsx | 2 +- .../Pages/BrandDetail/BrandDetailContent.tsx | 2 +- .../Pages/Cart/CartList/CartListItem.tsx | 2 +- .../CategoryBestsellersListItem.tsx | 2 +- .../Pages/Customer/OrdersContent.tsx | 2 +- .../TransportAndPaymentSelectItemLabel.tsx | 7 ++- .../ProductComparisonHeadItem.tsx | 2 +- .../ProductComparisonHeadSticky.tsx | 2 +- .../ProductDetail/ProductDetailGallery.tsx | 2 +- .../ProductDetailVariantsTable.tsx | 2 +- .../Pages/StoreDetail/StoreDetailContent.tsx | 2 +- storefront/next.config.js | 11 ++++ 27 files changed, 81 insertions(+), 58 deletions(-) diff --git a/storefront/components/Basic/Image/Image.tsx b/storefront/components/Basic/Image/Image.tsx index 969d9f2c08..3e7a6254c9 100644 --- a/storefront/components/Basic/Image/Image.tsx +++ b/storefront/components/Basic/Image/Image.tsx @@ -1,20 +1,18 @@ -import { ImageFragmentApi } from 'graphql/generated'; import { twMergeCustom } from 'helpers/twMerge'; -import { ImgHTMLAttributes } from 'react'; +import NextImage, { ImageProps } from 'next/image'; +import { ImgHTMLAttributes, useState } from 'react'; -type ImageProps = { - image: ImageFragmentApi | null | undefined; +type ShopsysImageProps = { + src: string | null | undefined; alt: string | null | undefined; loading?: ImgHTMLAttributes['loading']; - width?: string | number; - height?: string | number; wrapperClassName?: string; -}; +} & Omit; const getDataTestId = (dataTestId?: string) => dataTestId ?? 'basic-image'; -export const Image: FC = ({ - image, +export const Image: FC = ({ + src, alt, loading, dataTestId, @@ -22,37 +20,33 @@ export const Image: FC = ({ height, className, wrapperClassName, + fill, }) => { const imageTwClass = twMergeCustom( 'object-contain [image-rendering:-webkit-optimize-contrast] max-w-full max-h-full mx-auto', className, ); + const [imageUrl, setImageUrl] = useState(src ?? '/images/optimized-noimage.webp'); - if (!image) { - return ( -
- {alt -
- ); + let testIdentifier = getDataTestId(dataTestId); + if (!src) { + testIdentifier += '-empty'; } return ( - - {image.name + `${src}?width=${width || '0'}`} loading={loading} - src={image.url} - width={width} + src={imageUrl} + width={width ?? 160} + onError={() => setImageUrl('/images/optimized-noimage.webp')} /> - + ); }; diff --git a/storefront/components/Blocks/BlogPreview/BlogPreviewMain.tsx b/storefront/components/Blocks/BlogPreview/BlogPreviewMain.tsx index d36b873252..92f2610e0f 100644 --- a/storefront/components/Blocks/BlogPreview/BlogPreviewMain.tsx +++ b/storefront/components/Blocks/BlogPreview/BlogPreviewMain.tsx @@ -22,7 +22,7 @@ export const BlogPreviewMain: FC = ({ articles }) => ( {article.mainImage?.name diff --git a/storefront/components/Blocks/BlogPreview/BlogPreviewSide.tsx b/storefront/components/Blocks/BlogPreview/BlogPreviewSide.tsx index 9447c80e4c..25ec45146f 100644 --- a/storefront/components/Blocks/BlogPreview/BlogPreviewSide.tsx +++ b/storefront/components/Blocks/BlogPreview/BlogPreviewSide.tsx @@ -16,7 +16,7 @@ export const BlogPreviewSide: FC = ({ articles }) => ( {article.mainImage?.name diff --git a/storefront/components/Blocks/OrderSummary/SingleProduct.tsx b/storefront/components/Blocks/OrderSummary/SingleProduct.tsx index f442e174dd..8acafba4eb 100644 --- a/storefront/components/Blocks/OrderSummary/SingleProduct.tsx +++ b/storefront/components/Blocks/OrderSummary/SingleProduct.tsx @@ -17,7 +17,7 @@ export const SingleProduct: FC = ({ item }) => { {item.product.mainImage?.name
diff --git a/storefront/components/Blocks/OrderSummary/TransportAndPayment.tsx b/storefront/components/Blocks/OrderSummary/TransportAndPayment.tsx index c12be4b573..4d05f5ec30 100644 --- a/storefront/components/Blocks/OrderSummary/TransportAndPayment.tsx +++ b/storefront/components/Blocks/OrderSummary/TransportAndPayment.tsx @@ -33,7 +33,7 @@ export const TransportAndPayment: FC = ({ payment, tra {transport.name} - {transport.name} + {transport.name} @@ -46,7 +46,7 @@ export const TransportAndPayment: FC = ({ payment, tra {payment.name} - {payment.name} + {payment.name} diff --git a/storefront/components/Blocks/Product/AddToCartPopup.tsx b/storefront/components/Blocks/Product/AddToCartPopup.tsx index c818fe02c4..782aa163fb 100644 --- a/storefront/components/Blocks/Product/AddToCartPopup.tsx +++ b/storefront/components/Blocks/Product/AddToCartPopup.tsx @@ -39,7 +39,12 @@ export const AddToCartPopup: FC = ({ onCloseCallback, added > {!!product.mainImage && (
- {product.mainImage.name + {product.mainImage.name
)}
diff --git a/storefront/components/Blocks/Product/ProductsList/ProductListItem.tsx b/storefront/components/Blocks/Product/ProductsList/ProductListItem.tsx index dd6fc62373..01515ae808 100644 --- a/storefront/components/Blocks/Product/ProductsList/ProductListItem.tsx +++ b/storefront/components/Blocks/Product/ProductsList/ProductListItem.tsx @@ -78,7 +78,7 @@ export const ProductListItem = forwardRef( {product.mainImage?.name {!!product.flags.length && (
diff --git a/storefront/components/Blocks/SimpleNavigation/SimpleNavigationListItem.tsx b/storefront/components/Blocks/SimpleNavigation/SimpleNavigationListItem.tsx index 5e8e979ff1..471c85501a 100644 --- a/storefront/components/Blocks/SimpleNavigation/SimpleNavigationListItem.tsx +++ b/storefront/components/Blocks/SimpleNavigation/SimpleNavigationListItem.tsx @@ -35,7 +35,7 @@ export const SimpleNavigationListItem: FC = ({ {itemImage.name )} diff --git a/storefront/components/Layout/Footer/FooterCopyright.tsx b/storefront/components/Layout/Footer/FooterCopyright.tsx index 20a041e6c6..30f7504c64 100644 --- a/storefront/components/Layout/Footer/FooterCopyright.tsx +++ b/storefront/components/Layout/Footer/FooterCopyright.tsx @@ -1,5 +1,5 @@ +import { Image } from 'components/Basic/Image/Image'; import useTranslation from 'next-translate/useTranslation'; -import Image from 'next/image'; const TEST_IDENTIFIER = 'layout-footer-footercopyright'; diff --git a/storefront/components/Layout/Header/AutocompleteSearch/AutocompleteSearchPopup.tsx b/storefront/components/Layout/Header/AutocompleteSearch/AutocompleteSearchPopup.tsx index 74632ad03d..e978c8ccb3 100644 --- a/storefront/components/Layout/Header/AutocompleteSearch/AutocompleteSearchPopup.tsx +++ b/storefront/components/Layout/Header/AutocompleteSearch/AutocompleteSearchPopup.tsx @@ -121,7 +121,7 @@ export const AutocompleteSearchPopup: FC = ({ {product.mainImage?.name diff --git a/storefront/components/Layout/Header/Cart/CartListItem.tsx b/storefront/components/Layout/Header/Cart/CartListItem.tsx index bcbee1de29..8b876f8c1f 100644 --- a/storefront/components/Layout/Header/Cart/CartListItem.tsx +++ b/storefront/components/Layout/Header/Cart/CartListItem.tsx @@ -23,7 +23,11 @@ export const ListItem: FC = ({ cartItem: { product, uuid, quantit className="flex w-full items-center gap-x-3 border-b border-greyLighter py-3" data-testid={TEST_IDENTIFIER} > - {product.mainImage?.name + {product.mainImage?.name ( <> - = ({ columnCate {columnCategory.mainImage?.name diff --git a/storefront/components/Layout/NotificationBars/NotificationBars.tsx b/storefront/components/Layout/NotificationBars/NotificationBars.tsx index 3e0a8ffead..c437c489d5 100644 --- a/storefront/components/Layout/NotificationBars/NotificationBars.tsx +++ b/storefront/components/Layout/NotificationBars/NotificationBars.tsx @@ -46,7 +46,7 @@ export const NotificationBars: FC = memo(function NotificationBars() { {item.mainImage.name
)} diff --git a/storefront/components/Pages/BlogArticle/BlogArticleDetailContent.tsx b/storefront/components/Pages/BlogArticle/BlogArticleDetailContent.tsx index 637b83943b..a88da3526f 100644 --- a/storefront/components/Pages/BlogArticle/BlogArticleDetailContent.tsx +++ b/storefront/components/Pages/BlogArticle/BlogArticleDetailContent.tsx @@ -19,7 +19,11 @@ export const BlogArticleDetailContent: FC = ({ bl
{blogArticle.mainImage && (
- {blogArticle.mainImage.name + {blogArticle.mainImage.name
)} diff --git a/storefront/components/Pages/BlogCategory/BlogArticlesList.tsx b/storefront/components/Pages/BlogCategory/BlogArticlesList.tsx index 2534f355b8..1c121bd921 100644 --- a/storefront/components/Pages/BlogCategory/BlogArticlesList.tsx +++ b/storefront/components/Pages/BlogCategory/BlogArticlesList.tsx @@ -20,7 +20,7 @@ export const BlogArticlesList: FC = ({ blogArticles }) => {blogArticle.mainImage?.name
diff --git a/storefront/components/Pages/BrandDetail/BrandDetailContent.tsx b/storefront/components/Pages/BrandDetail/BrandDetailContent.tsx index c03df543c9..da0862accf 100644 --- a/storefront/components/Pages/BrandDetail/BrandDetailContent.tsx +++ b/storefront/components/Pages/BrandDetail/BrandDetailContent.tsx @@ -21,7 +21,7 @@ export const BrandDetailContent: FC = ({ brand }) => {

{brand.seoH1 !== null ? brand.seoH1 : brand.name}

- {brand.mainImage?.name + {brand.mainImage?.name
= ({ {product.mainImage?.name
diff --git a/storefront/components/Pages/CategoryDetail/CategoryBestsellers/CategoryBestsellersListItem.tsx b/storefront/components/Pages/CategoryDetail/CategoryBestsellers/CategoryBestsellersListItem.tsx index 29c368621d..9deb857310 100644 --- a/storefront/components/Pages/CategoryDetail/CategoryBestsellers/CategoryBestsellersListItem.tsx +++ b/storefront/components/Pages/CategoryDetail/CategoryBestsellers/CategoryBestsellersListItem.tsx @@ -38,7 +38,7 @@ export const CategoryBestsellersListItem: FC = alt={product.fullName} className="max-h-[80px] max-w-[80px]" dataTestId={TEST_IDENTIFIER + 'image'} - image={product.mainImage} + src={product.mainImage?.url} /> {product.fullName} diff --git a/storefront/components/Pages/Customer/OrdersContent.tsx b/storefront/components/Pages/Customer/OrdersContent.tsx index 26132312d7..9fd3b20f8b 100644 --- a/storefront/components/Pages/Customer/OrdersContent.tsx +++ b/storefront/components/Pages/Customer/OrdersContent.tsx @@ -110,7 +110,7 @@ export const OrdersContent: FC = ({ isLoading, orders, total alt={order.transport.mainImage?.name || order.transport.name} className="h-9 w-9" height={20} - image={order.transport.mainImage} + src={order.transport.mainImage?.url} width={36} /> {order.transport.name} diff --git a/storefront/components/Pages/Order/TransportAndPayment/TransportAndPaymentSelect/TransportAndPaymentSelectItemLabel.tsx b/storefront/components/Pages/Order/TransportAndPayment/TransportAndPaymentSelect/TransportAndPaymentSelectItemLabel.tsx index 4f942ce7f5..845558c2f1 100644 --- a/storefront/components/Pages/Order/TransportAndPayment/TransportAndPaymentSelect/TransportAndPaymentSelectItemLabel.tsx +++ b/storefront/components/Pages/Order/TransportAndPayment/TransportAndPaymentSelect/TransportAndPaymentSelectItemLabel.tsx @@ -29,7 +29,12 @@ export const TransportAndPaymentSelectItemLabel: FC - {image?.name} + {image?.name
{name}
diff --git a/storefront/components/Pages/ProductComparison/ProductComparisonHeadItem.tsx b/storefront/components/Pages/ProductComparison/ProductComparisonHeadItem.tsx index c28face2a2..e04da387fc 100644 --- a/storefront/components/Pages/ProductComparison/ProductComparisonHeadItem.tsx +++ b/storefront/components/Pages/ProductComparison/ProductComparisonHeadItem.tsx @@ -40,7 +40,7 @@ export const ProductComparisonHeadItem: FC = ({
- {product.mainImage?.name + {product.mainImage?.name
= style={index === 0 ? { marginLeft: -props.tableMarginLeft } : undefined} > - {product.mainImage?.name + {product.mainImage?.name
diff --git a/storefront/components/Pages/ProductDetail/ProductDetailGallery.tsx b/storefront/components/Pages/ProductDetail/ProductDetailGallery.tsx index 8d5e237259..50bd9b9bfd 100644 --- a/storefront/components/Pages/ProductDetail/ProductDetailGallery.tsx +++ b/storefront/components/Pages/ProductDetail/ProductDetailGallery.tsx @@ -36,7 +36,7 @@ export const ProductDetailGallery: FC = ({ flags, ima alt={mainImage?.name || productName} className="max-h-[460px] w-auto" height={400} - image={mainImage} + src={mainImage?.url} wrapperClassName="block h-full" /> diff --git a/storefront/components/Pages/ProductDetail/ProductDetailVariantsTable.tsx b/storefront/components/Pages/ProductDetail/ProductDetailVariantsTable.tsx index 912a4e4dc3..6e5836631e 100644 --- a/storefront/components/Pages/ProductDetail/ProductDetailVariantsTable.tsx +++ b/storefront/components/Pages/ProductDetail/ProductDetailVariantsTable.tsx @@ -32,7 +32,7 @@ export const ProductVariantsTable: FC = ({ isSellingD > {variant.mainImage?.name diff --git a/storefront/components/Pages/StoreDetail/StoreDetailContent.tsx b/storefront/components/Pages/StoreDetail/StoreDetailContent.tsx index eacd883f9f..07e1489f19 100644 --- a/storefront/components/Pages/StoreDetail/StoreDetailContent.tsx +++ b/storefront/components/Pages/StoreDetail/StoreDetailContent.tsx @@ -119,7 +119,7 @@ export const StoreDetailContent: FC = ({ store }) => { {image.name
))} diff --git a/storefront/next.config.js b/storefront/next.config.js index ae82fb46cc..4314d87add 100644 --- a/storefront/next.config.js +++ b/storefront/next.config.js @@ -20,6 +20,17 @@ const nextConfig = { disableClientWebpackPlugin: process.env.APP_ENV === 'development', hideSourceMaps: true, }, + images: { + loader: 'custom', + remotePatterns: [ + { + hostname: process.env.DOMAIN_HOSTNAME_1, + }, + { + hostname: process.env.DOMAIN_HOSTNAME_2, + }, + ], + }, serverRuntimeConfig: { internalGraphqlEndpoint: `${process.env.INTERNAL_ENDPOINT}graphql/`, },