Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vitek-rostislav committed Nov 24, 2023
1 parent de1dc8b commit b89955e
Show file tree
Hide file tree
Showing 27 changed files with 81 additions and 58 deletions.
54 changes: 24 additions & 30 deletions storefront/components/Basic/Image/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,52 @@
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<HTMLImageElement>['loading'];
width?: string | number;
height?: string | number;
wrapperClassName?: string;
};
} & Omit<ImageProps, 'src'>;

const getDataTestId = (dataTestId?: string) => dataTestId ?? 'basic-image';

export const Image: FC<ImageProps> = ({
image,
export const Image: FC<ShopsysImageProps> = ({
src,
alt,
loading,
dataTestId,
width,
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 (
<div className={wrapperClassName}>
<img
alt={alt || ''}
className={twMergeCustom('h-auto w-full', imageTwClass)}
data-testid={getDataTestId(dataTestId) + '-empty'}
height={height || 160}
src="/images/optimized-noimage.webp"
width={width || 160}
/>
</div>
);
let testIdentifier = getDataTestId(dataTestId);
if (!src) {
testIdentifier += '-empty';
}

return (
<picture className={wrapperClassName}>
<img
alt={image.name || alt || ''}
className={imageTwClass}
height={height}
<div className={wrapperClassName}>
<NextImage
alt={alt}
className={twMergeCustom('h-auto w-full', imageTwClass)}
data-testid={testIdentifier}
fill={fill}
height={height ?? 160}
loader={({ src, width }) => `${src}?width=${width || '0'}`}
loading={loading}
src={image.url}
width={width}
src={imageUrl}
width={width ?? 160}
onError={() => setImageUrl('/images/optimized-noimage.webp')}
/>
</picture>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const BlogPreviewMain: FC<MainProps> = ({ articles }) => (
<Image
alt={article.mainImage?.name || article.name}
className="rounded"
image={article.mainImage}
src={article.mainImage?.url}
/>
</ArticleLink>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const BlogPreviewSide: FC<SideProps> = ({ articles }) => (
<Image
alt={article.mainImage?.name || article.name}
className="rounded"
image={article.mainImage}
src={article.mainImage?.url}
/>
</ArticleLink>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SingleProduct: FC<SingleProductProps> = ({ item }) => {
<Image
alt={item.product.mainImage?.name || item.product.fullName}
className="mr-4 h-14 w-14"
image={item.product.mainImage}
src={item.product.mainImage?.url}
/>

<div className="flex flex-1 items-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const TransportAndPayment: FC<TransportAndPaymentProps> = ({ payment, tra
<OrderSummaryTextAndImage dataTestId={TEST_IDENTIFIER + '-transport-name'}>
{transport.name}
<span className="inline-block align-bottom">
<Image alt={transport.name} className="h-8 w-8" image={transport.mainImage} />
<Image alt={transport.name} className="h-8 w-8" src={transport.mainImage?.url} />
</span>
</OrderSummaryTextAndImage>
<OrderSummaryPrice dataTestId={TEST_IDENTIFIER + '-transport-price'}>
Expand All @@ -46,7 +46,7 @@ export const TransportAndPayment: FC<TransportAndPaymentProps> = ({ payment, tra
<OrderSummaryTextAndImage dataTestId={TEST_IDENTIFIER + '-payment-name'}>
{payment.name}
<span className="inline-block align-bottom">
<Image alt={payment.name} className="h-8 w-8" image={payment.mainImage} />
<Image alt={payment.name} className="h-8 w-8" src={payment.mainImage?.name} />
</span>
</OrderSummaryTextAndImage>
<OrderSummaryPrice dataTestId={TEST_IDENTIFIER + '-payment-price'}>
Expand Down
7 changes: 6 additions & 1 deletion storefront/components/Blocks/Product/AddToCartPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export const AddToCartPopup: FC<AddToCartPopupProps> = ({ onCloseCallback, added
>
{!!product.mainImage && (
<div className="mb-4 flex w-24 items-center justify-center md:mb-0">
<Image alt={product.mainImage.name || product.fullName} image={product.mainImage} />
<Image
alt={product.mainImage.name || product.fullName}
height={48}
src={product.mainImage.url}
width={72}
/>
</div>
)}
<div className="w-full md:pl-4 lg:flex lg:items-center lg:justify-between">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const ProductListItem = forwardRef<HTMLLIElement, ProductItemProps>(
<Image
alt={product.mainImage?.name || product.fullName}
className="h-40 justify-center lg:hover:mix-blend-multiply"
image={product.mainImage}
src={product.mainImage?.url}
/>
{!!product.flags.length && (
<div className="absolute top-3 left-4 flex flex-col">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const SimpleNavigationListItem: FC<SimpleNavigationListItemProps> = ({
<Image
alt={itemImage.name || listedItem.name}
className="h-12 min-w-[64px] mix-blend-multiply"
image={itemImage}
src={itemImage.url}
width={64}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion storefront/components/Layout/Footer/FooterCopyright.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const AutocompleteSearchPopup: FC<AutocompleteProps> = ({
<Image
alt={product.mainImage?.name || product.fullName}
className="flex h-16 w-20 items-center justify-center"
image={product.mainImage}
src={product.mainImage?.url}
wrapperClassName={imageTwClass}
/>

Expand Down
6 changes: 5 additions & 1 deletion storefront/components/Layout/Header/Cart/CartListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export const ListItem: FC<ListItemProps> = ({ cartItem: { product, uuid, quantit
className="flex w-full items-center gap-x-3 border-b border-greyLighter py-3"
data-testid={TEST_IDENTIFIER}
>
<Image alt={product.mainImage?.name || product.fullName} className="h-11 w-11" image={product.mainImage} />
<Image
alt={product.mainImage?.name || product.fullName}
className="h-11 w-11"
src={product.mainImage?.url}
/>

<ExtendedNextLink
className="flex-1 cursor-pointer text-sm font-bold text-greyDark no-underline outline-none"
Expand Down
6 changes: 3 additions & 3 deletions storefront/components/Layout/Header/Logo/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ExtendedNextLink } from 'components/Basic/ExtendedNextLink/ExtendedNextLink';
import { LogoMetadata } from 'components/Basic/Head/LogoMetadata';
import { Image } from 'components/Basic/Image/Image';
import { twMergeCustom } from 'helpers/twMerge';
import NextImage from 'next/image';

const TEST_IDENTIFIER = 'layout-header-logo';

export const Logo: FC = () => (
<>
<LogoMetadata />
<ExtendedNextLink className="flex-1 vl:flex-none" href="/" type="homepage">
<NextImage
<Image
priority
alt="Shopsys logo"
className={twMergeCustom('flex w-32 max-w-full lg:w-40')}
data-testid={TEST_IDENTIFIER}
dataTestId={TEST_IDENTIFIER}
height={38}
src="/images/logo.svg"
width={163}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const NavigationItemColumn: FC<NavigationItemColumnProps> = ({ columnCate
<Image
alt={columnCategory.mainImage?.name || columnCategory.name}
className="h-16 mix-blend-multiply"
image={columnCategory.mainImage}
src={columnCategory.mainImage?.url}
/>
</ExtendedNextLink>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const NotificationBars: FC = memo(function NotificationBars() {
<Image
alt={item.mainImage.name || item.text}
className="mr-3"
image={item.mainImage}
src={item.mainImage.url}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export const BlogArticleDetailContent: FC<BlogArticleDetailContentProps> = ({ bl
<div className="mb-12 flex w-full flex-col">
{blogArticle.mainImage && (
<div className="mb-10 flex overflow-hidden">
<Image alt={blogArticle.mainImage.name || blogArticle.name} image={blogArticle.mainImage} />
<Image
alt={blogArticle.mainImage.name || blogArticle.name}
src={blogArticle.mainImage.url}
width={960}
/>
</div>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const BlogArticlesList: FC<BlogArticlesListProps> = ({ blogArticles }) =>
<ExtendedNextLink href={blogArticle.link} type="blogArticle">
<Image
alt={blogArticle.mainImage?.name || blogArticle.name}
image={blogArticle.mainImage}
src={blogArticle.mainImage?.url}
/>
</ExtendedNextLink>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const BrandDetailContent: FC<BrandDetailContentProps> = ({ brand }) => {
<h1 className="mb-3">{brand.seoH1 !== null ? brand.seoH1 : brand.name}</h1>
<div className="mb-5 flex w-full flex-col justify-start md:flex-row">
<div className="mr-5 min-w-[13.75rem] self-start" data-testid={TEST_IDENTIFIER + 'image'}>
<Image alt={brand.mainImage?.name || brand.name} image={brand.mainImage} />
<Image alt={brand.mainImage?.name || brand.name} src={brand.mainImage?.url} />
</div>
<div
className="self-start md:self-center [&>section]:text-base [&>section]:text-dark"
Expand Down
2 changes: 1 addition & 1 deletion storefront/components/Pages/Cart/CartList/CartListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const CartListItem: FC<CartListItemProps> = ({
<Image
alt={product.mainImage?.name || product.fullName}
className="h-14"
image={product.mainImage}
src={product.mainImage?.url}
/>
</ExtendedNextLink>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const CategoryBestsellersListItem: FC<CategoryBestsellersListItemProps> =
alt={product.fullName}
className="max-h-[80px] max-w-[80px]"
dataTestId={TEST_IDENTIFIER + 'image'}
image={product.mainImage}
src={product.mainImage?.url}
/>
<span>{product.fullName}</span>
</ExtendedNextLink>
Expand Down
2 changes: 1 addition & 1 deletion storefront/components/Pages/Customer/OrdersContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const OrdersContent: FC<OrdersContentProps> = ({ 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}
/>
<span className="flex-1">{order.transport.name}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export const TransportAndPaymentSelectItemLabel: FC<TransportAndPaymentSelectIte

return (
<div className="flex w-full flex-row items-center gap-3" data-testid={TEST_IDENTIFIER}>
<Image alt={image?.name} className="h-6 w-11 shrink-0 basis-11" image={image} wrapperClassName="shrink-0" />
<Image
alt={image?.name ?? name}
className="h-6 w-11 shrink-0 basis-11"
src={image?.url}
wrapperClassName="shrink-0"
/>

<div className="flex flex-1 flex-col text-sm lg:flex-auto lg:basis-full lg:flex-row lg:items-center lg:gap-3">
<div data-testid={TEST_IDENTIFIER + '-name'}>{name}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ProductComparisonHeadItem: FC<ProductComparisonItemProps> = ({
<div className="flex h-[365px] w-[182px] flex-col gap-2 sm:w-[205px]">
<div className="flex flex-col items-center ">
<div className="flex h-[185px] w-full items-center justify-center pt-4 pb-3">
<Image alt={product.mainImage?.name || product.fullName} image={product.mainImage} />
<Image alt={product.mainImage?.name || product.fullName} src={product.mainImage?.url} />
</div>
<ExtendedNextLink
className="text-primary no-underline hover:no-underline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ProductComparisonHeadSticky: FC<ProductComparisonHeadStickyProps> =
style={index === 0 ? { marginLeft: -props.tableMarginLeft } : undefined}
>
<a className="w-16" href={product.slug}>
<Image alt={product.mainImage?.name || product.fullName} image={product.mainImage} />
<Image alt={product.mainImage?.name || product.fullName} src={product.mainImage?.url} />
</a>
<div className="ml-2 flex flex-1 flex-col">
<a className="text-xs no-underline hover:no-underline" href={product.slug}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const ProductDetailGallery: FC<ProductDetailGalleryProps> = ({ flags, ima
alt={mainImage?.name || productName}
className="max-h-[460px] w-auto"
height={400}
image={mainImage}
src={mainImage?.url}
wrapperClassName="block h-full"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const ProductVariantsTable: FC<ProductVariantsTableProps> = ({ isSellingD
>
<Image
alt={variant.mainImage?.name || variant.fullName}
image={variant.mainImage}
src={variant.mainImage?.url}
wrapperClassName="flex h-48 lg:h-16 lg:w-16"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const StoreDetailContent: FC<StoreDetailContentProps> = ({ store }) => {
<Image
alt={image.name || `${store.storeName}-${index}`}
className="cursor-pointer"
image={image}
src={image.url}
/>
</div>
))}
Expand Down
11 changes: 11 additions & 0 deletions storefront/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/`,
},
Expand Down

0 comments on commit b89955e

Please sign in to comment.