-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dmitriyKvant/feat/product-card
Feat/product card
- Loading branch information
Showing
53 changed files
with
683 additions
and
677 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.turbo | ||
|
||
.env | ||
.yarn/unplugged | ||
.yarn/unplugged | ||
node_modules |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
import { HydrationBoundary, dehydrate } from "@tanstack/react-query" | ||
|
||
import { getProduct } from "@/entities/product" | ||
|
||
import { queryClient } from "@/shared/api" | ||
|
||
import { ProductDetailsCard } from "./ui/product-details-card" | ||
|
||
export default async function ProductPage({ params }: { params: { slug: string } }) { | ||
const res = await fetch( | ||
`${process.env.NEXT_PUBLIC_CMS_API_URL}/products?populate=*&filters[slug]=${params.slug}`, | ||
await queryClient.prefetchQuery({ | ||
queryKey: ["products", params.slug], | ||
queryFn: () => getProduct(params.slug), | ||
}) | ||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<ProductDetailsCard slug={params.slug} /> | ||
</HydrationBoundary> | ||
) | ||
const data = await res.json() | ||
console.log(data.data) | ||
return <div>{params.slug}</div> | ||
} |
66 changes: 66 additions & 0 deletions
66
apps/client/src/app/(public)/product/[slug]/ui/product-details-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use client" | ||
|
||
import { Spacer } from "@nextui-org/spacer" | ||
|
||
import { CartAddButton } from "@/features/cart" | ||
import { SelectSize } from "@/features/select-size" | ||
import { WhishlistAddButton } from "@/features/whishlist" | ||
|
||
import { useProduct } from "@/entities/product" | ||
|
||
import { ProductDetailsCarousel } from "./product-details-carousel" | ||
import { ProductDetailsDescription } from "./product-details-description" | ||
import { ProductDetailsInfo } from "./product-details-info" | ||
|
||
type TypeProductDetailsCardProps = { | ||
slug: string | ||
} | ||
|
||
export const ProductDetailsCard: React.FC<TypeProductDetailsCardProps> = ({ slug }) => { | ||
const { isPending, data } = useProduct(slug) | ||
if (isPending) { | ||
return ( | ||
<div className="container flex justify-between pt-[160px] content-offset"> | ||
<ProductDetailsCarousel isLoaded={!isPending} /> | ||
<div> | ||
<ProductDetailsInfo isLoaded={!isPending} /> | ||
<Spacer y={20} /> | ||
<SelectSize isLoaded={!isPending} /> | ||
<Spacer y={10} /> | ||
<CartAddButton isLoaded={!isPending} /> | ||
<Spacer y={3} /> | ||
<WhishlistAddButton isLoaded={!isPending} /> | ||
<Spacer y={10} /> | ||
<ProductDetailsDescription isLoaded={!isPending} /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div className="container flex justify-between pt-[160px] content-offset"> | ||
<div> | ||
{data?.map((product) => ( | ||
<ProductDetailsCarousel | ||
key={product.id} | ||
{...product.attributes} | ||
/> | ||
))} | ||
</div> | ||
{data?.map((product) => ( | ||
<div key={product.id}> | ||
<ProductDetailsInfo {...product.attributes} /> | ||
<Spacer y={20} /> | ||
<SelectSize {...product.attributes} /> | ||
<Spacer y={10} /> | ||
<CartAddButton /> | ||
<Spacer y={3} /> | ||
<WhishlistAddButton /> | ||
<Spacer y={10} /> | ||
{product.attributes.description && ( | ||
<ProductDetailsDescription description={product.attributes.description} /> | ||
)} | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
apps/client/src/app/(public)/product/[slug]/ui/product-details-carousel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Skeleton } from "@nextui-org/skeleton" | ||
import Autoplay from "embla-carousel-autoplay" | ||
import Image from "next/image" | ||
|
||
import type { IProductAttributes } from "@/entities/product" | ||
|
||
import { Carousel, CarouselContent, CarouselItem } from "@/shared/ui" | ||
|
||
interface IProductDetailsCarouselProps extends Required<Pick<IProductAttributes, "images">> { | ||
isLoaded?: boolean | ||
} | ||
|
||
interface IProductDetailsCarouselSkeletonProps extends Partial<Pick<IProductAttributes, "images">> { | ||
isLoaded: boolean | ||
} | ||
|
||
export const ProductDetailsCarousel: React.FC< | ||
IProductDetailsCarouselProps | IProductDetailsCarouselSkeletonProps | ||
> = ({ images, isLoaded = true }) => { | ||
return ( | ||
<Carousel | ||
className="w-[537px]" | ||
plugins={[ | ||
Autoplay({ | ||
delay: 3000, | ||
stopOnMouseEnter: true, | ||
stopOnInteraction: false, | ||
}), | ||
]} | ||
opts={{ | ||
loop: true, | ||
}}> | ||
<Skeleton | ||
isLoaded={isLoaded} | ||
className="h-[671.25px]"> | ||
<CarouselContent className="ml-0"> | ||
{images?.data.map((image) => ( | ||
<CarouselItem key={image.id}> | ||
<Image | ||
src={image.attributes.url ?? ""} | ||
alt={image.attributes.alternativeText ?? "Sneakers"} | ||
width={537} | ||
height={671.25} | ||
/> | ||
</CarouselItem> | ||
))} | ||
</CarouselContent> | ||
</Skeleton> | ||
</Carousel> | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
apps/client/src/app/(public)/product/[slug]/ui/product-details-description.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Skeleton } from "@nextui-org/skeleton" | ||
import Markdown from "react-markdown" | ||
|
||
import type { IProductAttributes } from "@/entities/product" | ||
|
||
interface IProductDetailsDescriptionProps | ||
extends Required<Pick<IProductAttributes, "description">> { | ||
isLoaded?: boolean | ||
} | ||
|
||
interface IProductDetailsDescriptionSkeletonProps | ||
extends Partial<Pick<IProductAttributes, "description">> { | ||
isLoaded: boolean | ||
} | ||
|
||
export const ProductDetailsDescription: React.FC< | ||
IProductDetailsDescriptionProps | IProductDetailsDescriptionSkeletonProps | ||
> = ({ description, isLoaded = true }) => { | ||
return ( | ||
<div> | ||
<Skeleton | ||
className="h-[28px] w-[150px]" | ||
isLoaded={isLoaded}> | ||
<h3 className="text-lg font-bold">Product Details</h3> | ||
</Skeleton> | ||
<Skeleton | ||
className="mt-[20px] h-[280px] w-[408px]" | ||
isLoaded={isLoaded}> | ||
<Markdown className="markdown">{description}</Markdown> | ||
</Skeleton> | ||
</div> | ||
) | ||
} |
65 changes: 65 additions & 0 deletions
65
apps/client/src/app/(public)/product/[slug]/ui/product-details-info.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Skeleton } from "@nextui-org/skeleton" | ||
|
||
import type { IProductAttributes } from "@/entities/product" | ||
|
||
import { findDiscountPercentage } from "@/shared/lib" | ||
|
||
interface ProductDetailsInfoProps | ||
extends Pick<IProductAttributes, "discountPrice" | "price" | "title" | "sex"> { | ||
isLoaded?: boolean | ||
} | ||
|
||
interface ProductDetailsInfoSkeletonProps | ||
extends Pick<Partial<IProductAttributes>, "discountPrice" | "price" | "title" | "sex"> { | ||
isLoaded: boolean | ||
} | ||
|
||
export const ProductDetailsInfo: React.FC< | ||
ProductDetailsInfoProps | ProductDetailsInfoSkeletonProps | ||
> = ({ discountPrice, sex, price, title, isLoaded = true }) => { | ||
return ( | ||
<div className="flex w-[408px] flex-col gap-y-[20px]"> | ||
<div className="font-semibold"> | ||
<Skeleton | ||
isLoaded={isLoaded} | ||
className="h-[45px] w-[330px]"> | ||
<h1 className="text-4xl">{title}</h1> | ||
</Skeleton> | ||
<Skeleton | ||
isLoaded={isLoaded} | ||
className="mt-[7.5px] h-[28px] w-[150px]"> | ||
<p className="text-lg">{sex === "man" ? "Men's Shoes" : "Women's Shoes"}</p> | ||
</Skeleton> | ||
</div> | ||
<div> | ||
<div className="flex justify-between"> | ||
<Skeleton | ||
isLoaded={isLoaded} | ||
className="h-[28px] w-[240px]"> | ||
<div className="flex items-center gap-x-[8px]"> | ||
<p className="text-lg font-semibold">MRP : ₹{discountPrice}</p> | ||
<p className="line-through">₹{price}</p> | ||
</div> | ||
</Skeleton> | ||
<Skeleton | ||
className="h-[28px] w-[100px]" | ||
isLoaded={isLoaded}> | ||
{discountPrice && price && ( | ||
<p className="text-right font-medium text-green"> | ||
{findDiscountPercentage(price, discountPrice)}% off | ||
</p> | ||
)} | ||
</Skeleton> | ||
</div> | ||
<Skeleton | ||
isLoaded={isLoaded} | ||
className="mt-[5px] w-full"> | ||
<div className="font-medium text-gray"> | ||
<p>incl. of taxes</p> | ||
<p>(Also includes all applicable duties)</p> | ||
</div> | ||
</Skeleton> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
"use client" | ||
|
||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query" | ||
import { useState } from "react" | ||
import { QueryClientProvider } from "@tanstack/react-query" | ||
|
||
export const TanstackProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [queryClient] = useState( | ||
() => | ||
new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
staleTime: 60 * 1000, | ||
}, | ||
}, | ||
}), | ||
) | ||
import { queryClient } from "@/shared/api" | ||
|
||
export const TanstackProvider = ({ children }: { children: React.ReactNode }) => { | ||
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
@tailwind components; | ||
|
||
@layer components { | ||
.markdown ul { | ||
@apply mt-[20px] flex flex-col gap-y-[10px]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.