chore: setup project for production
This commit is contained in:
94
components/products/AddToCardLeftSection.jsx
Normal file
94
components/products/AddToCardLeftSection.jsx
Normal file
@@ -0,0 +1,94 @@
|
||||
"use client";
|
||||
import React, { useContext, useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import ProductContext from "@/app/contexts/productContext";
|
||||
import { backendUrl } from "@/utils/axios";
|
||||
import Image from "next/image";
|
||||
|
||||
const ProductGallery = ({ productId }) => {
|
||||
const { products } = useContext(ProductContext);
|
||||
|
||||
const [currentImageIndex, setCurrentImageIndex] = useState(0);
|
||||
|
||||
const nextImage = () => {
|
||||
setCurrentImageIndex((prevIndex) => (prevIndex + 1) % productImages.length);
|
||||
};
|
||||
|
||||
const prevImage = () => {
|
||||
setCurrentImageIndex(
|
||||
(prevIndex) =>
|
||||
(prevIndex - 1 + productImages.length) % productImages.length
|
||||
);
|
||||
};
|
||||
const product = products?.find((pr) => pr.id == productId);
|
||||
if (!product) {
|
||||
return null;
|
||||
}
|
||||
const productImages = product?.images?.map((img) => img.image) || [];
|
||||
|
||||
return (
|
||||
<div className="flex flex-col md:flex-row gap-4 p-4 sm:w-[70%] ">
|
||||
<div className="hidden md:flex flex-col gap-2">
|
||||
{productImages?.map((src, index) => (
|
||||
<Image
|
||||
key={index}
|
||||
src={`${backendUrl}${src}`}
|
||||
alt={`Thumbnail ${index + 1}`}
|
||||
width={160} // Width of w-40 (160px)
|
||||
height={128} // Height of h-32 (128px)
|
||||
className="object-cover cursor-pointer border border-gray-300 hover:border-blue-500"
|
||||
onClick={() => setCurrentImageIndex(index)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex-grow h-full">
|
||||
<Card className="p-4 h-[380px] sm:h-[80vh]">
|
||||
{/* Main image with carousel controls */}
|
||||
<div className="relative mb-4 h-full">
|
||||
<Image
|
||||
src={`${backendUrl}${productImages[currentImageIndex]}`}
|
||||
alt="Main product"
|
||||
width={500}
|
||||
height={500}
|
||||
className="object-cover w-full h-full"
|
||||
/>
|
||||
<Button
|
||||
className="absolute top-1/2 left-2 transform -translate-y-1/2 md:hidden"
|
||||
onClick={prevImage}
|
||||
variant="ghost"
|
||||
>
|
||||
<ChevronLeft />
|
||||
</Button>
|
||||
<Button
|
||||
className="absolute top-1/2 right-2 transform -translate-y-1/2 md:hidden"
|
||||
onClick={nextImage}
|
||||
variant="ghost"
|
||||
>
|
||||
<ChevronRight />
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
<div className="my-6">
|
||||
<div className="flex gap-3">
|
||||
<h3 className="p-1 px-2 rounded-3xl border text-xs border-yellow-700">
|
||||
A+ Grade
|
||||
</h3>
|
||||
<h3 className="p-1 px-2 rounded-3xl border text-xs border-yellow-700">
|
||||
IRL Certified
|
||||
</h3>
|
||||
<h3 className="p-1 px-2 rounded-3xl border text-xs border-yellow-700">
|
||||
Expert Rating
|
||||
</h3>
|
||||
</div>
|
||||
<h2 className="mt-3">Note: Free Shipping on order above $ 300</h2>
|
||||
<h2 className="my-1">100% Secured Payment</h2>
|
||||
<h2>Authenticity Guaranteed</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProductGallery;
|
||||
207
components/products/AddToCardRightSection.jsx
Normal file
207
components/products/AddToCardRightSection.jsx
Normal file
@@ -0,0 +1,207 @@
|
||||
"use client";
|
||||
import React, { useContext, useState } from "react";
|
||||
import { Plus, Minus } from "lucide-react";
|
||||
import ProductContext from "@/app/contexts/productContext";
|
||||
import { backendUrl } from "@/utils/axios";
|
||||
import { useCurrency } from "@/app/contexts/currencyContext";
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
|
||||
function ProductDetails({ productId }) {
|
||||
const [quantity, setQuantity] = useState(1);
|
||||
const [selectedSize, setSelectedSize] = useState(null);
|
||||
const [selectedDesign, setSelectedDesign] = useState(null);
|
||||
const [termsAccepted, setTermsAccepted] = useState(false);
|
||||
const { products, cartFn } = useContext(ProductContext);
|
||||
const { formatPrice, isLoading } = useCurrency();
|
||||
|
||||
const product = products?.find((pr) => pr.id == productId);
|
||||
React.useEffect(() => {
|
||||
if (product && product.variants?.length > 0) {
|
||||
setSelectedSize(product.variants[0]?.size?.size_name || "");
|
||||
setSelectedDesign(product.design_associations?.[0]?.design?.id || "");
|
||||
}
|
||||
}, [product]);
|
||||
|
||||
if (!product) return null;
|
||||
|
||||
const hasVariants = product.variants?.length > 0;
|
||||
const hasDesigns = product.design_associations?.length > 0;
|
||||
|
||||
const selectedVariant = hasVariants
|
||||
? product.variants.find((v) => v.size.size_name === selectedSize)
|
||||
: null;
|
||||
|
||||
const currentPrice = selectedVariant?.price || product.price || 0;
|
||||
const designPrice = hasDesigns
|
||||
? product.design_associations.find((d) => d.design.id === selectedDesign)
|
||||
?.design.design_price || 0
|
||||
: 0;
|
||||
|
||||
const totalPrice = currentPrice + designPrice;
|
||||
|
||||
return (
|
||||
<div className="max-w-xl p-6 space-y-6">
|
||||
<div className="flex justify-between items-start">
|
||||
<h1 className="text-2xl font-semibold">{product.product_name}</h1>
|
||||
</div>
|
||||
|
||||
{hasVariants ? (
|
||||
<div className="flex items-center">
|
||||
<span className="text-2xl text-[#C17A0F]">
|
||||
{isLoading ? (
|
||||
<span>Loading...</span>
|
||||
) : (
|
||||
<span>{formatPrice(totalPrice)}</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="ml-2 text-sm">INR</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-2xl text-[#C17A0F]">Price on request</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-4">
|
||||
{hasVariants && (
|
||||
<div>
|
||||
<h3 className="text-sm mb-2">Select Size</h3>
|
||||
<div className="flex space-x-4">
|
||||
{product.variants.map((variant) => (
|
||||
<button
|
||||
key={variant.size.id}
|
||||
className={`px-4 py-2 border rounded ${
|
||||
selectedSize === variant.size.size_name
|
||||
? "border-[#C17A0F]"
|
||||
: "border-gray-300"
|
||||
}`}
|
||||
onClick={() => setSelectedSize(variant.size.size_name)}
|
||||
>
|
||||
{variant.size.size_name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasDesigns && (
|
||||
<div>
|
||||
<h3 className="text-sm mb-2">Select Your Design</h3>
|
||||
<div className="grid grid-cols-4 gap-4">
|
||||
{product.design_associations.map((design) => (
|
||||
<button
|
||||
key={design.id}
|
||||
className={`p-2 border rounded text-center ${
|
||||
selectedDesign === design.design.id
|
||||
? "border-[#C17A0F]"
|
||||
: "border-gray-300"
|
||||
}`}
|
||||
onClick={() => setSelectedDesign(design.design.id)}
|
||||
>
|
||||
<div className="h-12 w-12 mx-auto mb-2 bg-gray-200">
|
||||
<Image
|
||||
src={`${backendUrl}${design.design.design_icon}`}
|
||||
alt={design.design.design_name}
|
||||
width={48}
|
||||
height={48}
|
||||
className="w-full h-full object-cover rounded-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="text-sm">{design.design.design_name}</div>
|
||||
<div className="text-sm text-gray-500">
|
||||
{isLoading ? (
|
||||
<span>Loading...</span>
|
||||
) : (
|
||||
<span>{formatPrice(design.design.design_price)}</span>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
{product?.product_category?.category_name && (
|
||||
<h3 className="text-sm mb-2">
|
||||
Category: {product.product_category.category_name}
|
||||
</h3>
|
||||
)}
|
||||
{product?.product_subcategory?.subcategory_name && (
|
||||
<p className="text-sm">
|
||||
Subcategory: {product.product_subcategory.subcategory_name}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{hasVariants && (
|
||||
<>
|
||||
<div className="flex items-center justify-between border rounded-md p-2 w-32">
|
||||
<button
|
||||
onClick={() => setQuantity(Math.max(1, quantity - 1))}
|
||||
className="p-2"
|
||||
>
|
||||
<Minus className="w-4 h-4" />
|
||||
</button>
|
||||
<span>{quantity}</span>
|
||||
<button
|
||||
onClick={() => setQuantity(quantity + 1)}
|
||||
className="p-2"
|
||||
disabled={quantity >= selectedVariant?.stock}
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="text-sm">
|
||||
Stock:{" "}
|
||||
{selectedVariant?.stock > 0 ? "available" : "Not Available"}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className="text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="mr-2"
|
||||
checked={termsAccepted}
|
||||
onChange={(e) => setTermsAccepted(e.target.checked)}
|
||||
/>
|
||||
<span>I agree with the </span>
|
||||
<Link href="/policies/terms-of-services" className="text-blue-600">
|
||||
terms of services
|
||||
</Link>
|
||||
<span> and </span>
|
||||
<Link href="/policies/refund-policy" className="text-blue-600">
|
||||
return And Cancellation policy
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{hasVariants && selectedVariant?.stock > 0 ? (
|
||||
<button
|
||||
onClick={() => cartFn(selectedVariant.id, selectedDesign, quantity)}
|
||||
disabled={!termsAccepted}
|
||||
className={`w-full py-3 rounded-md ${
|
||||
termsAccepted
|
||||
? "bg-[#C17A0F] text-white cursor-pointer"
|
||||
: "bg-gray-300 text-gray-500 cursor-not-allowed"
|
||||
}`}
|
||||
>
|
||||
ADD TO CART
|
||||
</button>
|
||||
) : (
|
||||
<button className="w-full bg-[#C17A0F] text-white py-3 rounded-md">
|
||||
REQUEST PRICE
|
||||
</button>
|
||||
)}
|
||||
|
||||
<div className="mt-8 border-t pt-6">
|
||||
<h2 className="text-xl font-semibold mb-4">Product Description</h2>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: product.description }}
|
||||
className="text-sm prose prose-sm max-w-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProductDetails;
|
||||
63
components/products/RelatedProductCards.jsx
Normal file
63
components/products/RelatedProductCards.jsx
Normal file
@@ -0,0 +1,63 @@
|
||||
"use client";
|
||||
import React, { useContext } from "react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { productsCards } from "@/utils";
|
||||
import ProductContext from "@/app/contexts/productContext";
|
||||
import { backendUrl } from "@/utils/axios";
|
||||
|
||||
const RelatedProductCards = ({ productId }) => {
|
||||
const { products } = useContext(ProductContext);
|
||||
|
||||
if (!products) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const product = products?.find((pr) => pr.id == productId);
|
||||
const relatedProducts = products?.filter(
|
||||
(prod) => prod.product_category.id == product.id && prod.id != productId
|
||||
);
|
||||
|
||||
if (relatedProducts.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className="container mx-auto min-h-[70vh] px-4 py-8 max-w-8xl ">
|
||||
<div className="text-center mb-12">
|
||||
<h1 className="font-serif capitalize tracking-wide font-semibold text-5xl text-slate-800 mb-4">
|
||||
You may also like
|
||||
</h1>
|
||||
</div>
|
||||
<div className="overflow-x-auto sm:pl-[400px] hide-navbar gap-5 flex items-center justify-center">
|
||||
{relatedProducts.map((product) => (
|
||||
<Link href={`/products/${product.id}`} key={product.id}>
|
||||
<div
|
||||
key={product.id}
|
||||
className="relative bg-[#EDE8E0] overflow-hidden sm:h-[350px] sm:w-[300px] "
|
||||
>
|
||||
<div className="absolute top-0 left-0 bg-[#C19A5B] text-white py-1 px-3 rounded-br-lg z-10">
|
||||
Exclusive
|
||||
</div>
|
||||
<div className="sm:h-[300px] h-[200px] w-[200px] sm:w-[300px] flex items-center justify-center overflow-hidden">
|
||||
<Image
|
||||
src={`${backendUrl}${product?.images[0]?.image}`}
|
||||
alt={`Logo for ${product.title}`}
|
||||
width={300}
|
||||
height={300}
|
||||
className="w-full h-full object-cover hover:scale-125 transition-transform ease-in-out duration-300"
|
||||
/>
|
||||
</div>
|
||||
<div className="p-4 ">
|
||||
<h3 className="text-center text-[1rem] uppercase text-gray-800">
|
||||
{product.title}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RelatedProductCards;
|
||||
49
components/products/RelatedVideos.jsx
Normal file
49
components/products/RelatedVideos.jsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import React from 'react';
|
||||
|
||||
const RelatedVideos = () => {
|
||||
return (
|
||||
<>
|
||||
<h1 className='sm:text-5xl text-2xl my-7 text-zinc-800 font-semibold text-center '>Videos of Related Products</h1>
|
||||
<div className='flex min-h-[30vh] gap-8 overflow-x-auto p-4 hide-navbar'>
|
||||
<iframe
|
||||
className='w-[400px] h-[200px] sm:h-[200px] sm:w-[800px]'
|
||||
src="https://www.youtube.com/embed/6BdXUaqEkkw"
|
||||
title="Powerful Surya (Sun) Mantra from Veda and Purana | Surya Beej Mantra 11 Times each | Beej Mantra"
|
||||
frameBorder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerPolicy="strict-origin-when-cross-origin"
|
||||
allowFullScreen
|
||||
></iframe>
|
||||
<iframe
|
||||
className='w-[400px] h-[200px] sm:h-[200px] sm:w-[800px]'
|
||||
src="https://www.youtube.com/embed/-iAAhrVtllk"
|
||||
title="Powerful Shukra (Venus) Mantra | Vedic Puranic and Beej Mantra | 11 Times Each | Shukra Mantra"
|
||||
frameBorder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerPolicy="strict-origin-when-cross-origin"
|
||||
allowFullScreen
|
||||
></iframe>
|
||||
<iframe
|
||||
className='w-[400px] h-[200px] sm:h-[200px] sm:w-[800px]'
|
||||
src="https://www.youtube.com/embed/0zX7RyTYFxo"
|
||||
title="Powerful Mars Mangal Mantra | Vedic, Puranic and Beej | Chanted 11 times Powerful Mantra"
|
||||
frameBorder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerPolicy="strict-origin-when-cross-origin"
|
||||
allowFullScreen
|
||||
></iframe>
|
||||
<iframe
|
||||
className='w-[400px] h-[200px] sm:h-[200px] sm:w-[800px]'
|
||||
src="https://www.youtube.com/embed/MLapeBFvk9s"
|
||||
title="Powerful Brihaspati (Guru) Jupiter Mantra | Vedic, Puranic & Beej Mantra | Chanted 11 Times each"
|
||||
frameBorder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerPolicy="strict-origin-when-cross-origin"
|
||||
allowFullScreen
|
||||
></iframe>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default RelatedVideos;
|
||||
Reference in New Issue
Block a user