Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cefbc80c8 | |||
| 7519b0ea41 | |||
| 3e408f08c9 | |||
| 849ff046b9 | |||
| a4f5c9df37 | |||
| 18e1e5d5ef | |||
| 96b46b5ec5 | |||
| 84e66b850a | |||
| f08bc17768 | |||
| c2dae3421e | |||
| df14b5ba70 | |||
| 586649b40a | |||
| d2a346810e | |||
| ca4fb5dc2c | |||
| f22cc27581 | |||
| 3cbb3ffe27 | |||
| 0d1a2fc89e | |||
| 921cdb60cb | |||
| 5bfc5eda31 | |||
| 8e582cdfd5 | |||
| e13c33c514 | |||
| 93e5bd31ac | |||
| bb21d51d0c | |||
| 282ec7c7ea | |||
| 3ddd1d149b | |||
| 480f9310c6 | |||
| 4ff558d745 | |||
| 4f745c93c3 | |||
| 6373b5ea06 | |||
| 4d2b3e17b5 | |||
| 493be55972 | |||
| 3a886ec207 | |||
| 1be6979ab5 | |||
| 80ab56121a | |||
| ca6084197d | |||
| 65acbd32ab | |||
| 421a0d4dbe | |||
| d21ebfd001 | |||
| 51bcffe909 | |||
| 7a51c13052 | |||
| 7a96daee1c | |||
| 67978193ba | |||
| 9b94d81876 | |||
| 2dade11252 | |||
| 133cfea674 | |||
| 99d4f8ce22 | |||
| 405b18fb28 | |||
| 4a49487c77 | |||
| 4591aa0eca | |||
| 9346a0f432 | |||
| 2095c0060e | |||
| 8d99e049e6 | |||
| e2f8bd0110 | |||
| 89ceb71096 | |||
| 4b3707c37b | |||
| 880d6203a7 | |||
| e71c5c0f8b | |||
| 77c71a315d | |||
| 72f424682a | |||
| 0514de31b6 | |||
| 035db5c023 | |||
| 4e877df3bf | |||
| 2509960b1c | |||
| 109159b5f8 | |||
| 96ab94d27e |
@@ -1,69 +1,229 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
"use client";
|
||||||
|
|
||||||
interface TimelineBaseProps {
|
import { memo, Children } from "react";
|
||||||
items: Array<{
|
import { CardStackProps } from "./types";
|
||||||
id: string | number;
|
import GridLayout from "./layouts/grid/GridLayout";
|
||||||
content: React.ReactNode;
|
import AutoCarousel from "./layouts/carousels/AutoCarousel";
|
||||||
media: React.ReactNode;
|
import ButtonCarousel from "./layouts/carousels/ButtonCarousel";
|
||||||
reverse?: boolean;
|
import TimelineBase from "./layouts/timelines/TimelineBase";
|
||||||
}>;
|
import { gridConfigs } from "./layouts/grid/gridConfigs";
|
||||||
reverse?: boolean;
|
|
||||||
className?: string;
|
const CardStack = ({
|
||||||
containerClassName?: string;
|
children,
|
||||||
itemClassName?: string;
|
mode = "buttons",
|
||||||
mediaWrapperClassName?: string;
|
gridVariant = "uniform-all-items-equal",
|
||||||
numberClassName?: string;
|
uniformGridCustomHeightClasses,
|
||||||
contentWrapperClassName?: string;
|
gridRowsClassName,
|
||||||
gapClassName?: string;
|
itemHeightClassesOverride,
|
||||||
ariaLabel?: string;
|
animationType,
|
||||||
|
supports3DAnimation = false,
|
||||||
|
title,
|
||||||
|
titleSegments,
|
||||||
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
buttons,
|
||||||
|
buttonAnimation,
|
||||||
|
textboxLayout = "default",
|
||||||
|
useInvertedBackground,
|
||||||
|
carouselThreshold = 5,
|
||||||
|
bottomContent,
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
gridClassName = "",
|
||||||
|
carouselClassName = "",
|
||||||
|
carouselItemClassName = "",
|
||||||
|
controlsClassName = "",
|
||||||
|
textBoxClassName = "",
|
||||||
|
titleClassName = "",
|
||||||
|
titleImageWrapperClassName = "",
|
||||||
|
titleImageClassName = "",
|
||||||
|
descriptionClassName = "",
|
||||||
|
tagClassName = "",
|
||||||
|
buttonContainerClassName = "",
|
||||||
|
buttonClassName = "",
|
||||||
|
buttonTextClassName = "",
|
||||||
|
ariaLabel = "Card stack",
|
||||||
|
}: CardStackProps) => {
|
||||||
|
const childrenArray = Children.toArray(children);
|
||||||
|
const itemCount = childrenArray.length;
|
||||||
|
|
||||||
|
// Check if the current grid config has gridRows defined
|
||||||
|
const gridConfig = gridConfigs[gridVariant]?.[itemCount];
|
||||||
|
const hasFixedGridRows = gridConfig && 'gridRows' in gridConfig && gridConfig.gridRows;
|
||||||
|
|
||||||
|
// If grid has fixed row heights and we have uniformGridCustomHeightClasses,
|
||||||
|
// we need to use min-h-0 on md+ to prevent conflicts
|
||||||
|
let adjustedHeightClasses = uniformGridCustomHeightClasses;
|
||||||
|
if (hasFixedGridRows && uniformGridCustomHeightClasses) {
|
||||||
|
// Extract the mobile min-height and add md:min-h-0
|
||||||
|
const mobileMinHeight = uniformGridCustomHeightClasses.split(' ')[0];
|
||||||
|
adjustedHeightClasses = `${mobileMinHeight} md:min-h-0`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CardStack = React.forwardRef<HTMLDivElement, TimelineBaseProps>(
|
// Timeline layout for zigzag pattern (works best with 3-6 items)
|
||||||
(
|
if (gridVariant === "timeline" && itemCount >= 3 && itemCount <= 6) {
|
||||||
{
|
// Convert depth-3d to scale-rotate for timeline (doesn't support 3D)
|
||||||
items,
|
const timelineAnimationType = animationType === "depth-3d" ? "scale-rotate" : animationType;
|
||||||
reverse = false,
|
|
||||||
className,
|
|
||||||
containerClassName,
|
|
||||||
itemClassName,
|
|
||||||
mediaWrapperClassName,
|
|
||||||
numberClassName,
|
|
||||||
contentWrapperClassName,
|
|
||||||
gapClassName,
|
|
||||||
ariaLabel = 'Card stack timeline',
|
|
||||||
},
|
|
||||||
ref
|
|
||||||
) => {
|
|
||||||
const [windowHeight, setWindowHeight] = useState(0);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setWindowHeight(typeof window !== 'undefined' ? window.innerHeight : 0);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<TimelineBase
|
||||||
ref={ref}
|
variant={gridVariant}
|
||||||
className={`relative ${containerClassName || ''}`}
|
uniformGridCustomHeightClasses={adjustedHeightClasses}
|
||||||
aria-label={ariaLabel}
|
animationType={timelineAnimationType}
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={titleClassName}
|
||||||
|
titleImageWrapperClassName={titleImageWrapperClassName}
|
||||||
|
titleImageClassName={titleImageClassName}
|
||||||
|
descriptionClassName={descriptionClassName}
|
||||||
|
tagClassName={tagClassName}
|
||||||
|
buttonContainerClassName={buttonContainerClassName}
|
||||||
|
buttonClassName={buttonClassName}
|
||||||
|
buttonTextClassName={buttonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
>
|
>
|
||||||
{items.map((item, index) => (
|
{childrenArray}
|
||||||
<div key={item.id} className={`flex gap-4 ${itemClassName || ''}`}>
|
</TimelineBase>
|
||||||
<div className={`w-1/2 ${mediaWrapperClassName || ''}`}>
|
|
||||||
{item.media}
|
|
||||||
</div>
|
|
||||||
<div className={`w-1/2 flex items-center ${contentWrapperClassName || ''}`}>
|
|
||||||
<span className={`inline-block mr-4 ${numberClassName || ''}`}>
|
|
||||||
{item.id}
|
|
||||||
</span>
|
|
||||||
{item.content}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use grid for items below threshold, carousel for items at or above threshold
|
||||||
|
// Timeline with 7+ items will also use carousel
|
||||||
|
const useCarousel = itemCount >= carouselThreshold || (gridVariant === "timeline" && itemCount > 6);
|
||||||
|
|
||||||
|
// Grid layout for 1-4 items
|
||||||
|
if (!useCarousel) {
|
||||||
|
return (
|
||||||
|
<GridLayout
|
||||||
|
itemCount={itemCount}
|
||||||
|
gridVariant={gridVariant}
|
||||||
|
uniformGridCustomHeightClasses={adjustedHeightClasses}
|
||||||
|
gridRowsClassName={gridRowsClassName}
|
||||||
|
itemHeightClassesOverride={itemHeightClassesOverride}
|
||||||
|
animationType={animationType}
|
||||||
|
supports3DAnimation={supports3DAnimation}
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
bottomContent={bottomContent}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
gridClassName={gridClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={titleClassName}
|
||||||
|
titleImageWrapperClassName={titleImageWrapperClassName}
|
||||||
|
titleImageClassName={titleImageClassName}
|
||||||
|
descriptionClassName={descriptionClassName}
|
||||||
|
tagClassName={tagClassName}
|
||||||
|
buttonContainerClassName={buttonContainerClassName}
|
||||||
|
buttonClassName={buttonClassName}
|
||||||
|
buttonTextClassName={buttonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{childrenArray}
|
||||||
|
</GridLayout>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
CardStack.displayName = 'CardStack';
|
// Auto-scroll carousel for 5+ items
|
||||||
|
if (mode === "auto") {
|
||||||
|
// Convert depth-3d to scale-rotate for carousel (doesn't support 3D)
|
||||||
|
const carouselAnimationType = animationType === "depth-3d" ? "scale-rotate" : animationType;
|
||||||
|
|
||||||
export default CardStack;
|
return (
|
||||||
|
<AutoCarousel
|
||||||
|
uniformGridCustomHeightClasses={adjustedHeightClasses}
|
||||||
|
animationType={carouselAnimationType}
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
bottomContent={bottomContent}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
carouselClassName={carouselClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={titleClassName}
|
||||||
|
titleImageWrapperClassName={titleImageWrapperClassName}
|
||||||
|
titleImageClassName={titleImageClassName}
|
||||||
|
descriptionClassName={descriptionClassName}
|
||||||
|
tagClassName={tagClassName}
|
||||||
|
buttonContainerClassName={buttonContainerClassName}
|
||||||
|
buttonClassName={buttonClassName}
|
||||||
|
buttonTextClassName={buttonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{childrenArray}
|
||||||
|
</AutoCarousel>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Button-controlled carousel for 5+ items
|
||||||
|
// Convert depth-3d to scale-rotate for carousel (doesn't support 3D)
|
||||||
|
const carouselAnimationType = animationType === "depth-3d" ? "scale-rotate" : animationType;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ButtonCarousel
|
||||||
|
uniformGridCustomHeightClasses={adjustedHeightClasses}
|
||||||
|
animationType={carouselAnimationType}
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
bottomContent={bottomContent}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
carouselClassName={carouselClassName}
|
||||||
|
carouselItemClassName={carouselItemClassName}
|
||||||
|
controlsClassName={controlsClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={titleClassName}
|
||||||
|
titleImageWrapperClassName={titleImageWrapperClassName}
|
||||||
|
titleImageClassName={titleImageClassName}
|
||||||
|
descriptionClassName={descriptionClassName}
|
||||||
|
tagClassName={tagClassName}
|
||||||
|
buttonContainerClassName={buttonContainerClassName}
|
||||||
|
buttonClassName={buttonClassName}
|
||||||
|
buttonTextClassName={buttonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{childrenArray}
|
||||||
|
</ButtonCarousel>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
CardStack.displayName = "CardStack";
|
||||||
|
|
||||||
|
export default memo(CardStack);
|
||||||
|
|||||||
@@ -1,13 +1,187 @@
|
|||||||
|
import { useRef } from "react";
|
||||||
|
import { useGSAP } from "@gsap/react";
|
||||||
|
import gsap from "gsap";
|
||||||
|
import { ScrollTrigger } from "gsap/ScrollTrigger";
|
||||||
|
import type { CardAnimationType, GridVariant } from "../types";
|
||||||
import { useDepth3DAnimation } from "./useDepth3DAnimation";
|
import { useDepth3DAnimation } from "./useDepth3DAnimation";
|
||||||
import { useRef, useEffect } from "react";
|
|
||||||
|
|
||||||
export function useCardAnimation() {
|
gsap.registerPlugin(ScrollTrigger);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
|
||||||
const depth3D = useDepth3DAnimation();
|
|
||||||
|
|
||||||
useEffect(() => {
|
interface UseCardAnimationProps {
|
||||||
// Animation logic here
|
animationType: CardAnimationType | "depth-3d";
|
||||||
}, [depth3D]);
|
itemCount: number;
|
||||||
|
isGrid?: boolean;
|
||||||
return { containerRef, depth3D };
|
supports3DAnimation?: boolean;
|
||||||
|
gridVariant?: GridVariant;
|
||||||
|
useIndividualTriggers?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useCardAnimation = ({
|
||||||
|
animationType,
|
||||||
|
itemCount,
|
||||||
|
isGrid = true,
|
||||||
|
supports3DAnimation = false,
|
||||||
|
gridVariant,
|
||||||
|
useIndividualTriggers = false
|
||||||
|
}: UseCardAnimationProps) => {
|
||||||
|
const itemRefs = useRef<(HTMLElement | null)[]>([]);
|
||||||
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const perspectiveRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const bottomContentRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
|
// Enable 3D effect only when explicitly supported and conditions are met
|
||||||
|
const { isMobile } = useDepth3DAnimation({
|
||||||
|
itemRefs,
|
||||||
|
containerRef,
|
||||||
|
perspectiveRef,
|
||||||
|
isEnabled: animationType === "depth-3d" && isGrid && supports3DAnimation && gridVariant === "uniform-all-items-equal",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use scale-rotate as fallback when depth-3d conditions aren't met
|
||||||
|
const effectiveAnimationType =
|
||||||
|
animationType === "depth-3d" && (isMobile || !isGrid || gridVariant !== "uniform-all-items-equal")
|
||||||
|
? "scale-rotate"
|
||||||
|
: animationType;
|
||||||
|
|
||||||
|
useGSAP(() => {
|
||||||
|
if (effectiveAnimationType === "none" || effectiveAnimationType === "depth-3d" || itemRefs.current.length === 0) return;
|
||||||
|
|
||||||
|
const items = itemRefs.current.filter((el) => el !== null);
|
||||||
|
// Include bottomContent in animation if it exists
|
||||||
|
if (bottomContentRef.current) {
|
||||||
|
items.push(bottomContentRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effectiveAnimationType === "opacity") {
|
||||||
|
if (useIndividualTriggers) {
|
||||||
|
items.forEach((item) => {
|
||||||
|
gsap.fromTo(
|
||||||
|
item,
|
||||||
|
{ opacity: 0 },
|
||||||
|
{
|
||||||
|
opacity: 1,
|
||||||
|
duration: 1.25,
|
||||||
|
ease: "sine",
|
||||||
|
scrollTrigger: {
|
||||||
|
trigger: item,
|
||||||
|
start: "top 80%",
|
||||||
|
toggleActions: "play none none none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
gsap.fromTo(
|
||||||
|
items,
|
||||||
|
{ opacity: 0 },
|
||||||
|
{
|
||||||
|
opacity: 1,
|
||||||
|
duration: 1.25,
|
||||||
|
stagger: 0.15,
|
||||||
|
ease: "sine",
|
||||||
|
scrollTrigger: {
|
||||||
|
trigger: items[0],
|
||||||
|
start: "top 80%",
|
||||||
|
toggleActions: "play none none none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (effectiveAnimationType === "slide-up") {
|
||||||
|
items.forEach((item, index) => {
|
||||||
|
gsap.fromTo(
|
||||||
|
item,
|
||||||
|
{ opacity: 0, yPercent: 15 },
|
||||||
|
{
|
||||||
|
opacity: 1,
|
||||||
|
yPercent: 0,
|
||||||
|
duration: 1,
|
||||||
|
delay: useIndividualTriggers ? 0 : index * 0.15,
|
||||||
|
ease: "sine",
|
||||||
|
scrollTrigger: {
|
||||||
|
trigger: useIndividualTriggers ? item : items[0],
|
||||||
|
start: "top 80%",
|
||||||
|
toggleActions: "play none none none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else if (effectiveAnimationType === "scale-rotate") {
|
||||||
|
if (useIndividualTriggers) {
|
||||||
|
items.forEach((item) => {
|
||||||
|
gsap.fromTo(
|
||||||
|
item,
|
||||||
|
{ scaleX: 0, rotate: 10 },
|
||||||
|
{
|
||||||
|
scaleX: 1,
|
||||||
|
rotate: 0,
|
||||||
|
duration: 1,
|
||||||
|
ease: "power3",
|
||||||
|
scrollTrigger: {
|
||||||
|
trigger: item,
|
||||||
|
start: "top 80%",
|
||||||
|
toggleActions: "play none none none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
gsap.fromTo(
|
||||||
|
items,
|
||||||
|
{ scaleX: 0, rotate: 10 },
|
||||||
|
{
|
||||||
|
scaleX: 1,
|
||||||
|
rotate: 0,
|
||||||
|
duration: 1,
|
||||||
|
stagger: 0.15,
|
||||||
|
ease: "power3",
|
||||||
|
scrollTrigger: {
|
||||||
|
trigger: items[0],
|
||||||
|
start: "top 80%",
|
||||||
|
toggleActions: "play none none none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (effectiveAnimationType === "blur-reveal") {
|
||||||
|
if (useIndividualTriggers) {
|
||||||
|
items.forEach((item) => {
|
||||||
|
gsap.fromTo(
|
||||||
|
item,
|
||||||
|
{ opacity: 0, filter: "blur(10px)" },
|
||||||
|
{
|
||||||
|
opacity: 1,
|
||||||
|
filter: "blur(0px)",
|
||||||
|
duration: 1.2,
|
||||||
|
ease: "power2.out",
|
||||||
|
scrollTrigger: {
|
||||||
|
trigger: item,
|
||||||
|
start: "top 80%",
|
||||||
|
toggleActions: "play none none none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
gsap.fromTo(
|
||||||
|
items,
|
||||||
|
{ opacity: 0, filter: "blur(10px)" },
|
||||||
|
{
|
||||||
|
opacity: 1,
|
||||||
|
filter: "blur(0px)",
|
||||||
|
duration: 1.2,
|
||||||
|
stagger: 0.15,
|
||||||
|
ease: "power2.out",
|
||||||
|
scrollTrigger: {
|
||||||
|
trigger: items[0],
|
||||||
|
start: "top 80%",
|
||||||
|
toggleActions: "play none none none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [effectiveAnimationType, itemCount, useIndividualTriggers]);
|
||||||
|
|
||||||
|
return { itemRefs, containerRef, perspectiveRef, bottomContentRef };
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,14 +1,118 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useState, useRef, RefObject } from "react";
|
||||||
|
|
||||||
function useDepth3DAnimation() {
|
const MOBILE_BREAKPOINT = 768;
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const ANIMATION_SPEED = 0.05;
|
||||||
|
const ROTATION_SPEED = 0.1;
|
||||||
|
const MOUSE_MULTIPLIER = 0.5;
|
||||||
|
const ROTATION_MULTIPLIER = 0.25;
|
||||||
|
|
||||||
useEffect(() => {
|
interface UseDepth3DAnimationProps {
|
||||||
// Initialize 3D animation
|
itemRefs: RefObject<(HTMLElement | null)[]>;
|
||||||
}, []);
|
containerRef: RefObject<HTMLDivElement | null>;
|
||||||
|
perspectiveRef?: RefObject<HTMLDivElement | null>;
|
||||||
return containerRef;
|
isEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useDepth3DAnimation };
|
export const useDepth3DAnimation = ({
|
||||||
export default useDepth3DAnimation;
|
itemRefs,
|
||||||
|
containerRef,
|
||||||
|
perspectiveRef,
|
||||||
|
isEnabled,
|
||||||
|
}: UseDepth3DAnimationProps) => {
|
||||||
|
const [isMobile, setIsMobile] = useState(false);
|
||||||
|
|
||||||
|
// Detect mobile viewport
|
||||||
|
useEffect(() => {
|
||||||
|
const checkMobile = () => {
|
||||||
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
||||||
|
};
|
||||||
|
|
||||||
|
checkMobile();
|
||||||
|
window.addEventListener("resize", checkMobile);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("resize", checkMobile);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 3D mouse-tracking effect (desktop only)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEnabled || isMobile) return;
|
||||||
|
|
||||||
|
let animationFrameId: number;
|
||||||
|
let isAnimating = true;
|
||||||
|
|
||||||
|
// Apply perspective to the perspective ref (grid) if provided, otherwise to container (section)
|
||||||
|
const perspectiveElement = perspectiveRef?.current || containerRef.current;
|
||||||
|
if (perspectiveElement) {
|
||||||
|
perspectiveElement.style.perspective = "1200px";
|
||||||
|
perspectiveElement.style.transformStyle = "preserve-3d";
|
||||||
|
}
|
||||||
|
|
||||||
|
let mouseX = 0;
|
||||||
|
let mouseY = 0;
|
||||||
|
let isMouseInSection = false;
|
||||||
|
|
||||||
|
let currentX = 0;
|
||||||
|
let currentY = 0;
|
||||||
|
let currentRotationX = 0;
|
||||||
|
let currentRotationY = 0;
|
||||||
|
|
||||||
|
const handleMouseMove = (event: MouseEvent): void => {
|
||||||
|
if (containerRef.current) {
|
||||||
|
const rect = containerRef.current.getBoundingClientRect();
|
||||||
|
isMouseInSection =
|
||||||
|
event.clientX >= rect.left &&
|
||||||
|
event.clientX <= rect.right &&
|
||||||
|
event.clientY >= rect.top &&
|
||||||
|
event.clientY <= rect.bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMouseInSection) {
|
||||||
|
mouseX = (event.clientX / window.innerWidth) * 100 - 50;
|
||||||
|
mouseY = (event.clientY / window.innerHeight) * 100 - 50;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const animate = (): void => {
|
||||||
|
if (!isAnimating) return;
|
||||||
|
|
||||||
|
if (isMouseInSection) {
|
||||||
|
const distX = mouseX * MOUSE_MULTIPLIER - currentX;
|
||||||
|
const distY = mouseY * MOUSE_MULTIPLIER - currentY;
|
||||||
|
currentX += distX * ANIMATION_SPEED;
|
||||||
|
currentY += distY * ANIMATION_SPEED;
|
||||||
|
|
||||||
|
const distRotX = -mouseY * ROTATION_MULTIPLIER - currentRotationX;
|
||||||
|
const distRotY = mouseX * ROTATION_MULTIPLIER - currentRotationY;
|
||||||
|
currentRotationX += distRotX * ROTATION_SPEED;
|
||||||
|
currentRotationY += distRotY * ROTATION_SPEED;
|
||||||
|
} else {
|
||||||
|
currentX += -currentX * ANIMATION_SPEED;
|
||||||
|
currentY += -currentY * ANIMATION_SPEED;
|
||||||
|
currentRotationX += -currentRotationX * ROTATION_SPEED;
|
||||||
|
currentRotationY += -currentRotationY * ROTATION_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemRefs.current?.forEach((ref) => {
|
||||||
|
if (!ref) return;
|
||||||
|
ref.style.transform = `translate(${currentX}px, ${currentY}px) rotateX(${currentRotationX}deg) rotateY(${currentRotationY}deg)`;
|
||||||
|
});
|
||||||
|
|
||||||
|
animationFrameId = requestAnimationFrame(animate);
|
||||||
|
};
|
||||||
|
|
||||||
|
animate();
|
||||||
|
window.addEventListener("mousemove", handleMouseMove);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("mousemove", handleMouseMove);
|
||||||
|
if (animationFrameId) {
|
||||||
|
cancelAnimationFrame(animationFrameId);
|
||||||
|
}
|
||||||
|
isAnimating = false;
|
||||||
|
};
|
||||||
|
}, [isEnabled, isMobile, itemRefs, containerRef]);
|
||||||
|
|
||||||
|
return { isMobile };
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,37 +1,149 @@
|
|||||||
import React from "react";
|
"use client";
|
||||||
|
|
||||||
interface TimelineItem {
|
import React, { Children, useCallback } from "react";
|
||||||
id: string;
|
import { cls } from "@/lib/utils";
|
||||||
title: string;
|
import CardStackTextBox from "../../CardStackTextBox";
|
||||||
description: string;
|
import { useCardAnimation } from "../../hooks/useCardAnimation";
|
||||||
date?: string;
|
import type { LucideIcon } from "lucide-react";
|
||||||
}
|
import type { ButtonConfig, CardAnimationType, TitleSegment, ButtonAnimationType } from "../../types";
|
||||||
|
import type { TextboxLayout, InvertedBackground } from "@/providers/themeProvider/config/constants";
|
||||||
|
|
||||||
|
type TimelineVariant = "timeline";
|
||||||
|
|
||||||
interface TimelineBaseProps {
|
interface TimelineBaseProps {
|
||||||
items: TimelineItem[];
|
children: React.ReactNode;
|
||||||
layout?: "vertical" | "horizontal";
|
variant?: TimelineVariant;
|
||||||
animated?: boolean;
|
uniformGridCustomHeightClasses?: string;
|
||||||
|
animationType: CardAnimationType;
|
||||||
|
title?: string;
|
||||||
|
titleSegments?: TitleSegment[];
|
||||||
|
description?: string;
|
||||||
|
tag?: string;
|
||||||
|
tagIcon?: LucideIcon;
|
||||||
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
buttons?: ButtonConfig[];
|
||||||
|
buttonAnimation?: ButtonAnimationType;
|
||||||
|
textboxLayout?: TextboxLayout;
|
||||||
|
useInvertedBackground?: InvertedBackground;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
textBoxClassName?: string;
|
||||||
|
titleClassName?: string;
|
||||||
|
titleImageWrapperClassName?: string;
|
||||||
|
titleImageClassName?: string;
|
||||||
|
descriptionClassName?: string;
|
||||||
|
tagClassName?: string;
|
||||||
|
buttonContainerClassName?: string;
|
||||||
|
buttonClassName?: string;
|
||||||
|
buttonTextClassName?: string;
|
||||||
|
ariaLabel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TimelineBase: React.FC<TimelineBaseProps> = ({
|
const TimelineBase = ({
|
||||||
items,
|
children,
|
||||||
layout = "vertical", animated = true,
|
variant = "timeline",
|
||||||
className = ""}) => {
|
uniformGridCustomHeightClasses = "min-h-80 2xl:min-h-90",
|
||||||
|
animationType,
|
||||||
|
title,
|
||||||
|
titleSegments,
|
||||||
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
buttons,
|
||||||
|
buttonAnimation,
|
||||||
|
textboxLayout = "default",
|
||||||
|
useInvertedBackground,
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
textBoxClassName = "",
|
||||||
|
titleClassName = "",
|
||||||
|
titleImageWrapperClassName = "",
|
||||||
|
titleImageClassName = "",
|
||||||
|
descriptionClassName = "",
|
||||||
|
tagClassName = "",
|
||||||
|
buttonContainerClassName = "",
|
||||||
|
buttonClassName = "",
|
||||||
|
buttonTextClassName = "",
|
||||||
|
ariaLabel = "Timeline section",
|
||||||
|
}: TimelineBaseProps) => {
|
||||||
|
const childrenArray = Children.toArray(children);
|
||||||
|
const { itemRefs } = useCardAnimation({
|
||||||
|
animationType,
|
||||||
|
itemCount: childrenArray.length,
|
||||||
|
isGrid: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const getItemClasses = useCallback((index: number) => {
|
||||||
|
// Timeline variant - scattered/organic pattern
|
||||||
|
const alignmentClass =
|
||||||
|
index % 2 === 0 ? "self-start ml-0" : "self-end mr-0";
|
||||||
|
|
||||||
|
const marginClasses = cls(
|
||||||
|
index % 4 === 0 && "md:ml-0",
|
||||||
|
index % 4 === 1 && "md:mr-20",
|
||||||
|
index % 4 === 2 && "md:ml-15",
|
||||||
|
index % 4 === 3 && "md:mr-30"
|
||||||
|
);
|
||||||
|
|
||||||
|
return cls(alignmentClass, marginClasses);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`timeline ${layout} ${animated ? "animated" : ""} ${className}`}>
|
<section
|
||||||
{items.map((item) => (
|
className={cls(
|
||||||
<div key={item.id} className="timeline-item">
|
"relative py-20 w-full",
|
||||||
<div className="timeline-marker" />
|
useInvertedBackground && "bg-foreground",
|
||||||
<div className="timeline-content">
|
className
|
||||||
<h3 className="timeline-title">{item.title}</h3>
|
)}
|
||||||
<p className="timeline-description">{item.description}</p>
|
aria-label={ariaLabel}
|
||||||
{item.date && <p className="timeline-date">{item.date}</p>}
|
>
|
||||||
</div>
|
<div
|
||||||
|
className={cls("w-content-width mx-auto flex flex-col gap-6", containerClassName)}
|
||||||
|
>
|
||||||
|
{(title || titleSegments || description) && (
|
||||||
|
<CardStackTextBox
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={titleClassName}
|
||||||
|
titleImageWrapperClassName={titleImageWrapperClassName}
|
||||||
|
titleImageClassName={titleImageClassName}
|
||||||
|
descriptionClassName={descriptionClassName}
|
||||||
|
tagClassName={tagClassName}
|
||||||
|
buttonContainerClassName={buttonContainerClassName}
|
||||||
|
buttonClassName={buttonClassName}
|
||||||
|
buttonTextClassName={buttonTextClassName}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
className={cls(
|
||||||
|
"relative z-10 flex flex-col gap-6 md:gap-15"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{Children.map(childrenArray, (child, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className={cls("w-65 md:w-25", uniformGridCustomHeightClasses, getItemClasses(index))}
|
||||||
|
ref={(el) => { itemRefs.current[index] = el; }}
|
||||||
|
>
|
||||||
|
{child}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TimelineBase;
|
TimelineBase.displayName = "TimelineBase";
|
||||||
|
|
||||||
|
export default React.memo(TimelineBase);
|
||||||
|
|||||||
@@ -1,65 +1,131 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import ContactForm from "@/components/form/ContactForm";
|
||||||
import { Mail } from "lucide-react";
|
import HeroBackgrounds, { type HeroBackgroundVariantProps } from "@/components/background/HeroBackgrounds";
|
||||||
|
import { cls } from "@/lib/utils";
|
||||||
|
import { LucideIcon } from "lucide-react";
|
||||||
|
import { sendContactEmail } from "@/utils/sendContactEmail";
|
||||||
|
import type { ButtonAnimationType } from "@/types/button";
|
||||||
|
|
||||||
|
type ContactCenterBackgroundProps = Extract<
|
||||||
|
HeroBackgroundVariantProps,
|
||||||
|
| { variant: "plain" }
|
||||||
|
| { variant: "animated-grid" }
|
||||||
|
| { variant: "canvas-reveal" }
|
||||||
|
| { variant: "cell-wave" }
|
||||||
|
| { variant: "downward-rays-animated" }
|
||||||
|
| { variant: "downward-rays-animated-grid" }
|
||||||
|
| { variant: "downward-rays-static" }
|
||||||
|
| { variant: "downward-rays-static-grid" }
|
||||||
|
| { variant: "gradient-bars" }
|
||||||
|
| { variant: "radial-gradient" }
|
||||||
|
| { variant: "rotated-rays-animated" }
|
||||||
|
| { variant: "rotated-rays-animated-grid" }
|
||||||
|
| { variant: "rotated-rays-static" }
|
||||||
|
| { variant: "rotated-rays-static-grid" }
|
||||||
|
| { variant: "sparkles-gradient" }
|
||||||
|
>;
|
||||||
|
|
||||||
interface ContactCenterProps {
|
interface ContactCenterProps {
|
||||||
tag: string;
|
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
tagIcon?: React.ComponentType<{ className?: string }>;
|
tag: string;
|
||||||
background?: { variant: string };
|
tagIcon?: LucideIcon;
|
||||||
useInvertedBackground?: boolean;
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
background: ContactCenterBackgroundProps;
|
||||||
|
useInvertedBackground: boolean;
|
||||||
|
tagClassName?: string;
|
||||||
inputPlaceholder?: string;
|
inputPlaceholder?: string;
|
||||||
buttonText?: string;
|
buttonText?: string;
|
||||||
termsText?: string;
|
termsText?: string;
|
||||||
|
onSubmit?: (email: string) => void;
|
||||||
|
ariaLabel?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
contentClassName?: string;
|
||||||
|
titleClassName?: string;
|
||||||
|
descriptionClassName?: string;
|
||||||
|
formWrapperClassName?: string;
|
||||||
|
formClassName?: string;
|
||||||
|
inputClassName?: string;
|
||||||
|
buttonClassName?: string;
|
||||||
|
buttonTextClassName?: string;
|
||||||
|
termsClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ContactCenter: React.FC<ContactCenterProps> = ({
|
const ContactCenter = ({
|
||||||
tag,
|
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
inputPlaceholder = "Enter your email", buttonText = "Sign Up", termsText = "By clicking Sign Up you're confirming that you agree with our Terms and Conditions.", className = ""}) => {
|
tag,
|
||||||
const [email, setEmail] = useState("");
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
background,
|
||||||
|
useInvertedBackground,
|
||||||
|
tagClassName = "",
|
||||||
|
inputPlaceholder = "Enter your email",
|
||||||
|
buttonText = "Sign Up",
|
||||||
|
termsText = "By clicking Sign Up you're confirming that you agree with our Terms and Conditions.",
|
||||||
|
onSubmit,
|
||||||
|
ariaLabel = "Contact section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
contentClassName = "",
|
||||||
|
titleClassName = "",
|
||||||
|
descriptionClassName = "",
|
||||||
|
formWrapperClassName = "",
|
||||||
|
formClassName = "",
|
||||||
|
inputClassName = "",
|
||||||
|
buttonClassName = "",
|
||||||
|
buttonTextClassName = "",
|
||||||
|
termsClassName = "",
|
||||||
|
}: ContactCenterProps) => {
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = async (email: string) => {
|
||||||
e.preventDefault();
|
try {
|
||||||
console.log("Email submitted:", email);
|
await sendContactEmail({ email });
|
||||||
setEmail("");
|
console.log("Email send successfully");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to send email:", error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={`py-20 px-4 ${className}`}>
|
<section aria-label={ariaLabel} className={cls("relative py-20 w-full", useInvertedBackground && "bg-foreground", className)}>
|
||||||
<div className="max-w-2xl mx-auto text-center">
|
<div className={cls("w-content-width mx-auto relative z-10", containerClassName)}>
|
||||||
<div className="mb-4 flex justify-center">
|
<div className={cls("relative w-full card p-6 md:p-0 py-20 md:py-20 rounded-theme-capped flex items-center justify-center", contentClassName)}>
|
||||||
<span className="text-sm font-semibold text-blue-600">{tag}</span>
|
<div className="relative z-10 w-full md:w-1/2">
|
||||||
</div>
|
<ContactForm
|
||||||
<h2 className="text-4xl font-bold mb-4">{title}</h2>
|
tag={tag}
|
||||||
<p className="text-lg text-gray-600 mb-8">{description}</p>
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
<form onSubmit={handleSubmit} className="max-w-md mx-auto mb-4">
|
title={title}
|
||||||
<div className="flex gap-2 mb-4">
|
description={description}
|
||||||
<input
|
useInvertedBackground={useInvertedBackground}
|
||||||
type="email"
|
inputPlaceholder={inputPlaceholder}
|
||||||
value={email}
|
buttonText={buttonText}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
termsText={termsText}
|
||||||
placeholder={inputPlaceholder}
|
onSubmit={handleSubmit}
|
||||||
required
|
centered={true}
|
||||||
className="flex-1 px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
tagClassName={tagClassName}
|
||||||
|
titleClassName={titleClassName}
|
||||||
|
descriptionClassName={descriptionClassName}
|
||||||
|
formWrapperClassName={cls("md:w-8/10 2xl:w-6/10", formWrapperClassName)}
|
||||||
|
formClassName={formClassName}
|
||||||
|
inputClassName={inputClassName}
|
||||||
|
buttonClassName={buttonClassName}
|
||||||
|
buttonTextClassName={buttonTextClassName}
|
||||||
|
termsClassName={termsClassName}
|
||||||
/>
|
/>
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
|
|
||||||
>
|
|
||||||
{buttonText}
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-gray-500">{termsText}</p>
|
<div className="absolute inset w-full h-full z-0 rounded-theme-capped overflow-hidden" >
|
||||||
</form>
|
<HeroBackgrounds {...background} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ContactCenter.displayName = "ContactCenter";
|
||||||
|
|
||||||
export default ContactCenter;
|
export default ContactCenter;
|
||||||
|
|||||||
@@ -1,93 +1,164 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import ContactForm from "@/components/form/ContactForm";
|
||||||
|
import MediaContent from "@/components/shared/MediaContent";
|
||||||
|
import HeroBackgrounds, { type HeroBackgroundVariantProps } from "@/components/background/HeroBackgrounds";
|
||||||
|
import { cls } from "@/lib/utils";
|
||||||
|
import { useButtonAnimation } from "@/components/hooks/useButtonAnimation";
|
||||||
|
import { LucideIcon } from "lucide-react";
|
||||||
|
import { sendContactEmail } from "@/utils/sendContactEmail";
|
||||||
|
import type { ButtonAnimationType } from "@/types/button";
|
||||||
|
|
||||||
|
type ContactSplitBackgroundProps = Extract<
|
||||||
|
HeroBackgroundVariantProps,
|
||||||
|
| { variant: "plain" }
|
||||||
|
| { variant: "animated-grid" }
|
||||||
|
| { variant: "canvas-reveal" }
|
||||||
|
| { variant: "cell-wave" }
|
||||||
|
| { variant: "downward-rays-animated" }
|
||||||
|
| { variant: "downward-rays-animated-grid" }
|
||||||
|
| { variant: "downward-rays-static" }
|
||||||
|
| { variant: "downward-rays-static-grid" }
|
||||||
|
| { variant: "gradient-bars" }
|
||||||
|
| { variant: "radial-gradient" }
|
||||||
|
| { variant: "rotated-rays-animated" }
|
||||||
|
| { variant: "rotated-rays-animated-grid" }
|
||||||
|
| { variant: "rotated-rays-static" }
|
||||||
|
| { variant: "rotated-rays-static-grid" }
|
||||||
|
| { variant: "sparkles-gradient" }
|
||||||
|
>;
|
||||||
|
|
||||||
interface ContactSplitProps {
|
interface ContactSplitProps {
|
||||||
tag: string;
|
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
tagIcon?: React.ComponentType<{ className?: string }>;
|
tag: string;
|
||||||
background?: { variant: string };
|
tagIcon?: LucideIcon;
|
||||||
useInvertedBackground?: boolean;
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
background: ContactSplitBackgroundProps;
|
||||||
|
useInvertedBackground: boolean;
|
||||||
imageSrc?: string;
|
imageSrc?: string;
|
||||||
videoSrc?: string;
|
videoSrc?: string;
|
||||||
|
imageAlt?: string;
|
||||||
|
videoAriaLabel?: string;
|
||||||
mediaPosition?: "left" | "right";
|
mediaPosition?: "left" | "right";
|
||||||
|
mediaAnimation: ButtonAnimationType;
|
||||||
inputPlaceholder?: string;
|
inputPlaceholder?: string;
|
||||||
buttonText?: string;
|
buttonText?: string;
|
||||||
termsText?: string;
|
termsText?: string;
|
||||||
|
onSubmit?: (email: string) => void;
|
||||||
|
ariaLabel?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
contentClassName?: string;
|
||||||
|
contactFormClassName?: string;
|
||||||
|
tagClassName?: string;
|
||||||
|
titleClassName?: string;
|
||||||
|
descriptionClassName?: string;
|
||||||
|
formWrapperClassName?: string;
|
||||||
|
formClassName?: string;
|
||||||
|
inputClassName?: string;
|
||||||
|
buttonClassName?: string;
|
||||||
|
buttonTextClassName?: string;
|
||||||
|
termsClassName?: string;
|
||||||
|
mediaWrapperClassName?: string;
|
||||||
|
mediaClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ContactSplit: React.FC<ContactSplitProps> = ({
|
const ContactSplit = ({
|
||||||
tag,
|
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
background,
|
||||||
|
useInvertedBackground,
|
||||||
imageSrc,
|
imageSrc,
|
||||||
videoSrc,
|
videoSrc,
|
||||||
mediaPosition = "right", inputPlaceholder = "Enter your email", buttonText = "Sign Up", termsText = "By clicking Sign Up you're confirming that you agree with our Terms and Conditions.", className = ""}) => {
|
imageAlt = "",
|
||||||
const [email, setEmail] = useState("");
|
videoAriaLabel = "Contact section video",
|
||||||
|
mediaPosition = "right",
|
||||||
|
mediaAnimation,
|
||||||
|
inputPlaceholder = "Enter your email",
|
||||||
|
buttonText = "Sign Up",
|
||||||
|
termsText = "By clicking Sign Up you're confirming that you agree with our Terms and Conditions.",
|
||||||
|
onSubmit,
|
||||||
|
ariaLabel = "Contact section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
contentClassName = "",
|
||||||
|
contactFormClassName = "",
|
||||||
|
tagClassName = "",
|
||||||
|
titleClassName = "",
|
||||||
|
descriptionClassName = "",
|
||||||
|
formWrapperClassName = "",
|
||||||
|
formClassName = "",
|
||||||
|
inputClassName = "",
|
||||||
|
buttonClassName = "",
|
||||||
|
buttonTextClassName = "",
|
||||||
|
termsClassName = "",
|
||||||
|
mediaWrapperClassName = "",
|
||||||
|
mediaClassName = "",
|
||||||
|
}: ContactSplitProps) => {
|
||||||
|
const { containerRef: mediaContainerRef } = useButtonAnimation({ animationType: mediaAnimation });
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = async (email: string) => {
|
||||||
e.preventDefault();
|
try {
|
||||||
console.log("Email submitted:", email);
|
await sendContactEmail({ email });
|
||||||
setEmail("");
|
console.log("Email send successfully");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to send email:", error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const formContent = (
|
const contactContent = (
|
||||||
<div className="flex-1">
|
<div className="relative card rounded-theme-capped p-6 py-15 md:py-6 flex items-center justify-center">
|
||||||
<div className="mb-4 text-sm font-semibold text-blue-600">{tag}</div>
|
<ContactForm
|
||||||
<h2 className="text-3xl font-bold mb-4">{title}</h2>
|
tag={tag}
|
||||||
<p className="text-gray-600 mb-8">{description}</p>
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
title={title}
|
||||||
<div className="flex gap-2">
|
description={description}
|
||||||
<input
|
useInvertedBackground={useInvertedBackground}
|
||||||
type="email"
|
inputPlaceholder={inputPlaceholder}
|
||||||
value={email}
|
buttonText={buttonText}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
termsText={termsText}
|
||||||
placeholder={inputPlaceholder}
|
onSubmit={handleSubmit}
|
||||||
required
|
centered={true}
|
||||||
className="flex-1 px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className={cls("w-full", contactFormClassName)}
|
||||||
|
tagClassName={tagClassName}
|
||||||
|
titleClassName={titleClassName}
|
||||||
|
descriptionClassName={descriptionClassName}
|
||||||
|
formWrapperClassName={cls("w-full md:w-8/10 2xl:w-7/10", formWrapperClassName)}
|
||||||
|
formClassName={formClassName}
|
||||||
|
inputClassName={inputClassName}
|
||||||
|
buttonClassName={buttonClassName}
|
||||||
|
buttonTextClassName={buttonTextClassName}
|
||||||
|
termsClassName={termsClassName}
|
||||||
/>
|
/>
|
||||||
<button
|
<div className="absolute inset w-full h-full z-0 rounded-theme-capped overflow-hidden" >
|
||||||
type="submit"
|
<HeroBackgrounds {...background} />
|
||||||
className="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
|
|
||||||
>
|
|
||||||
{buttonText}
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-gray-500">{termsText}</p>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const mediaContent = imageSrc || videoSrc ? (
|
const mediaContent = (
|
||||||
<div className="flex-1">
|
<div ref={mediaContainerRef} className={cls("overflow-hidden rounded-theme-capped card h-130", mediaWrapperClassName)}>
|
||||||
{imageSrc && (
|
<MediaContent
|
||||||
<img
|
imageSrc={imageSrc}
|
||||||
src={imageSrc}
|
videoSrc={videoSrc}
|
||||||
alt="Contact"
|
imageAlt={imageAlt}
|
||||||
className="w-full h-full object-cover rounded-lg"
|
videoAriaLabel={videoAriaLabel}
|
||||||
|
imageClassName={cls("relative z-1 w-full h-full object-cover", mediaClassName)}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
{videoSrc && (
|
|
||||||
<video
|
|
||||||
src={videoSrc}
|
|
||||||
autoPlay
|
|
||||||
loop
|
|
||||||
muted
|
|
||||||
className="w-full h-full object-cover rounded-lg"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
) : null;
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={`py-20 px-4 ${className}`}>
|
<section aria-label={ariaLabel} className={cls("relative py-20 w-full", useInvertedBackground && "bg-foreground", className)}>
|
||||||
<div className="max-w-6xl mx-auto">
|
<div className={cls("w-content-width mx-auto relative z-10", containerClassName)}>
|
||||||
<div className="flex flex-col lg:flex-row gap-12 items-center">
|
<div className={cls("grid grid-cols-1 md:grid-cols-2 gap-6 md:auto-rows-fr", contentClassName)}>
|
||||||
{mediaPosition === "left" && mediaContent}
|
{mediaPosition === "left" && mediaContent}
|
||||||
{formContent}
|
{contactContent}
|
||||||
{mediaPosition === "right" && mediaContent}
|
{mediaPosition === "right" && mediaContent}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -95,4 +166,6 @@ const ContactSplit: React.FC<ContactSplitProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ContactSplit.displayName = "ContactSplit";
|
||||||
|
|
||||||
export default ContactSplit;
|
export default ContactSplit;
|
||||||
|
|||||||
@@ -1,81 +1,214 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import TextAnimation from "@/components/text/TextAnimation";
|
||||||
|
import Button from "@/components/button/Button";
|
||||||
|
import Input from "@/components/form/Input";
|
||||||
|
import Textarea from "@/components/form/Textarea";
|
||||||
|
import MediaContent from "@/components/shared/MediaContent";
|
||||||
|
import { cls, shouldUseInvertedText } from "@/lib/utils";
|
||||||
|
import { useTheme } from "@/providers/themeProvider/ThemeProvider";
|
||||||
|
import { useButtonAnimation } from "@/components/hooks/useButtonAnimation";
|
||||||
|
import { getButtonProps } from "@/lib/buttonUtils";
|
||||||
|
import type { AnimationType } from "@/components/text/types";
|
||||||
|
import type { ButtonAnimationType } from "@/types/button";
|
||||||
|
import {sendContactEmail} from "@/utils/sendContactEmail";
|
||||||
|
|
||||||
interface ContactSplitFormProps {
|
export interface InputField {
|
||||||
tag: string;
|
name: string;
|
||||||
title: string;
|
type: string;
|
||||||
description: string;
|
placeholder: string;
|
||||||
formFields?: Array<{ name: string; label: string; type: string; required?: boolean }>;
|
required?: boolean;
|
||||||
buttonText?: string;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ContactSplitForm: React.FC<ContactSplitFormProps> = ({
|
export interface TextareaField {
|
||||||
tag,
|
name: string;
|
||||||
|
placeholder: string;
|
||||||
|
rows?: number;
|
||||||
|
required?: boolean;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ContactSplitFormProps {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
inputs: InputField[];
|
||||||
|
textarea?: TextareaField;
|
||||||
|
useInvertedBackground: boolean;
|
||||||
|
imageSrc?: string;
|
||||||
|
videoSrc?: string;
|
||||||
|
imageAlt?: string;
|
||||||
|
videoAriaLabel?: string;
|
||||||
|
mediaPosition?: "left" | "right";
|
||||||
|
mediaAnimation: ButtonAnimationType;
|
||||||
|
buttonText?: string;
|
||||||
|
onSubmit?: (data: Record<string, string>) => void;
|
||||||
|
ariaLabel?: string;
|
||||||
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
contentClassName?: string;
|
||||||
|
formCardClassName?: string;
|
||||||
|
titleClassName?: string;
|
||||||
|
descriptionClassName?: string;
|
||||||
|
buttonClassName?: string;
|
||||||
|
buttonTextClassName?: string;
|
||||||
|
mediaWrapperClassName?: string;
|
||||||
|
mediaClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ContactSplitForm = ({
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
formFields = [
|
inputs,
|
||||||
{ name: "name", label: "Name", type: "text", required: true },
|
textarea,
|
||||||
{ name: "email", label: "Email", type: "email", required: true },
|
useInvertedBackground,
|
||||||
{ name: "message", label: "Message", type: "textarea", required: true },
|
imageSrc,
|
||||||
],
|
videoSrc,
|
||||||
buttonText = "Send", className = ""}) => {
|
imageAlt = "",
|
||||||
const [formData, setFormData] = useState<Record<string, string>>({});
|
videoAriaLabel = "Contact section video",
|
||||||
|
mediaPosition = "right",
|
||||||
|
mediaAnimation,
|
||||||
|
buttonText = "Submit",
|
||||||
|
onSubmit,
|
||||||
|
ariaLabel = "Contact section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
contentClassName = "",
|
||||||
|
formCardClassName = "",
|
||||||
|
titleClassName = "",
|
||||||
|
descriptionClassName = "",
|
||||||
|
buttonClassName = "",
|
||||||
|
buttonTextClassName = "",
|
||||||
|
mediaWrapperClassName = "",
|
||||||
|
mediaClassName = "",
|
||||||
|
}: ContactSplitFormProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle);
|
||||||
|
const { containerRef: mediaContainerRef } = useButtonAnimation({ animationType: mediaAnimation });
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
// Validate minimum inputs requirement
|
||||||
const { name, value } = e.target;
|
if (inputs.length < 2) {
|
||||||
setFormData((prev) => ({ ...prev, [name]: value }));
|
throw new Error("ContactSplitForm requires at least 2 inputs");
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
// Initialize form data dynamically
|
||||||
|
const initialFormData: Record<string, string> = {};
|
||||||
|
inputs.forEach(input => {
|
||||||
|
initialFormData[input.name] = "";
|
||||||
|
});
|
||||||
|
if (textarea) {
|
||||||
|
initialFormData[textarea.name] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const [formData, setFormData] = useState(initialFormData);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log("Form submitted:", formData);
|
try {
|
||||||
setFormData({});
|
await sendContactEmail({ formData });
|
||||||
|
console.log("Email send successfully");
|
||||||
|
setFormData(initialFormData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to send email:", error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
const getButtonConfigProps = () => {
|
||||||
<section className={`py-20 px-4 ${className}`}>
|
if (theme.defaultButtonVariant === "hover-bubble") {
|
||||||
<div className="max-w-2xl mx-auto">
|
return { bgClassName: "w-full" };
|
||||||
<div className="mb-4 text-sm font-semibold text-blue-600">{tag}</div>
|
}
|
||||||
<h2 className="text-3xl font-bold mb-4">{title}</h2>
|
if (theme.defaultButtonVariant === "icon-arrow") {
|
||||||
<p className="text-gray-600 mb-8">{description}</p>
|
return { className: "justify-between" };
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
const formContent = (
|
||||||
{formFields.map((field) => (
|
<div className={cls("card rounded-theme-capped p-6 md:p-10 flex items-center justify-center", formCardClassName)}>
|
||||||
<div key={field.name}>
|
<form onSubmit={handleSubmit} className="relative z-1 w-full flex flex-col gap-6">
|
||||||
<label className="block text-sm font-medium mb-2">{field.label}</label>
|
<div className="w-full flex flex-col gap-0 text-center">
|
||||||
{field.type === "textarea" ? (
|
<TextAnimation
|
||||||
<textarea
|
type={theme.defaultTextAnimation as AnimationType}
|
||||||
name={field.name}
|
text={title}
|
||||||
value={formData[field.name] || ""}
|
variant="trigger"
|
||||||
onChange={handleChange}
|
className={cls("text-4xl font-medium leading-[1.175] text-balance", shouldUseLightText ? "text-background" : "text-foreground", titleClassName)}
|
||||||
required={field.required}
|
|
||||||
className="w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
rows={4}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<input
|
<TextAnimation
|
||||||
type={field.type}
|
type={theme.defaultTextAnimation as AnimationType}
|
||||||
name={field.name}
|
text={description}
|
||||||
value={formData[field.name] || ""}
|
variant="words-trigger"
|
||||||
onChange={handleChange}
|
className={cls("text-base leading-[1.15] text-balance", shouldUseLightText ? "text-background" : "text-foreground", descriptionClassName)}
|
||||||
required={field.required}
|
/>
|
||||||
className="w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
</div>
|
||||||
|
|
||||||
|
<div className="w-full flex flex-col gap-4">
|
||||||
|
{inputs.map((input) => (
|
||||||
|
<Input
|
||||||
|
key={input.name}
|
||||||
|
type={input.type}
|
||||||
|
placeholder={input.placeholder}
|
||||||
|
value={formData[input.name] || ""}
|
||||||
|
onChange={(value) => setFormData({ ...formData, [input.name]: value })}
|
||||||
|
required={input.required}
|
||||||
|
ariaLabel={input.placeholder}
|
||||||
|
className={input.className}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{textarea && (
|
||||||
|
<Textarea
|
||||||
|
placeholder={textarea.placeholder}
|
||||||
|
value={formData[textarea.name] || ""}
|
||||||
|
onChange={(value) => setFormData({ ...formData, [textarea.name]: value })}
|
||||||
|
required={textarea.required}
|
||||||
|
rows={textarea.rows || 5}
|
||||||
|
ariaLabel={textarea.placeholder}
|
||||||
|
className={textarea.className}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
))}
|
<Button
|
||||||
<button
|
{...getButtonProps(
|
||||||
|
{ text: buttonText, props: getButtonConfigProps() },
|
||||||
|
0,
|
||||||
|
theme.defaultButtonVariant,
|
||||||
|
cls("w-full", buttonClassName),
|
||||||
|
cls("text-base", buttonTextClassName)
|
||||||
|
)}
|
||||||
type="submit"
|
type="submit"
|
||||||
className="w-full px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
|
/>
|
||||||
>
|
</div>
|
||||||
{buttonText}
|
|
||||||
</button>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const mediaContent = (
|
||||||
|
<div ref={mediaContainerRef} className={cls("overflow-hidden rounded-theme-capped card md:relative md:h-full", mediaWrapperClassName)}>
|
||||||
|
<MediaContent
|
||||||
|
imageSrc={imageSrc}
|
||||||
|
videoSrc={videoSrc}
|
||||||
|
imageAlt={imageAlt}
|
||||||
|
videoAriaLabel={videoAriaLabel}
|
||||||
|
imageClassName={cls("w-full md:absolute md:inset-0 md:h-full object-cover", mediaClassName)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section aria-label={ariaLabel} className={cls("relative py-20 w-full", useInvertedBackground && "bg-foreground", className)}>
|
||||||
|
<div className={cls("w-content-width mx-auto", containerClassName)}>
|
||||||
|
<div className={cls("grid grid-cols-1 md:grid-cols-2 gap-6 md:auto-rows-fr", contentClassName)}>
|
||||||
|
{mediaPosition === "left" && mediaContent}
|
||||||
|
{formContent}
|
||||||
|
{mediaPosition === "right" && mediaContent}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ContactSplitForm.displayName = "ContactSplitForm";
|
||||||
|
|
||||||
export default ContactSplitForm;
|
export default ContactSplitForm;
|
||||||
|
|||||||
@@ -1,70 +1,248 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import { memo } from "react";
|
||||||
|
import CardStack from "@/components/cardStack/CardStack";
|
||||||
|
import Button from "@/components/button/Button";
|
||||||
|
import PricingBadge from "@/components/shared/PricingBadge";
|
||||||
|
import PricingFeatureList from "@/components/shared/PricingFeatureList";
|
||||||
|
import { getButtonProps } from "@/lib/buttonUtils";
|
||||||
|
import { cls, shouldUseInvertedText } from "@/lib/utils";
|
||||||
|
import { useTheme } from "@/providers/themeProvider/ThemeProvider";
|
||||||
|
import type { LucideIcon } from "lucide-react";
|
||||||
|
import type { ButtonConfig, CardAnimationType, TitleSegment, ButtonAnimationType } from "@/components/cardStack/types";
|
||||||
|
import type { TextboxLayout, InvertedBackground } from "@/providers/themeProvider/config/constants";
|
||||||
|
|
||||||
|
type PricingPlan = {
|
||||||
|
id: string;
|
||||||
|
badge: string;
|
||||||
|
badgeIcon?: LucideIcon;
|
||||||
|
price: string;
|
||||||
|
subtitle: string;
|
||||||
|
buttons: ButtonConfig[];
|
||||||
|
features: string[];
|
||||||
|
};
|
||||||
|
|
||||||
interface PricingCardEightProps {
|
interface PricingCardEightProps {
|
||||||
plans: Array<{
|
plans: PricingPlan[];
|
||||||
id: string;
|
carouselMode?: "auto" | "buttons";
|
||||||
title: string;
|
uniformGridCustomHeightClasses?: string;
|
||||||
price: string;
|
animationType: CardAnimationType;
|
||||||
period: string;
|
|
||||||
features: string[];
|
|
||||||
button: { text: string; href?: string; onClick?: () => void };
|
|
||||||
imageSrc?: string;
|
|
||||||
}>;
|
|
||||||
title: string;
|
title: string;
|
||||||
|
titleSegments?: TitleSegment[];
|
||||||
description: string;
|
description: string;
|
||||||
|
tag?: string;
|
||||||
|
tagIcon?: LucideIcon;
|
||||||
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
buttons?: ButtonConfig[];
|
||||||
|
buttonAnimation?: ButtonAnimationType;
|
||||||
|
textboxLayout: TextboxLayout;
|
||||||
|
useInvertedBackground: InvertedBackground;
|
||||||
|
ariaLabel?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
cardClassName?: string;
|
||||||
|
textBoxTitleClassName?: string;
|
||||||
|
textBoxTitleImageWrapperClassName?: string;
|
||||||
|
textBoxTitleImageClassName?: string;
|
||||||
|
textBoxDescriptionClassName?: string;
|
||||||
|
badgeClassName?: string;
|
||||||
|
priceClassName?: string;
|
||||||
|
subtitleClassName?: string;
|
||||||
|
planButtonContainerClassName?: string;
|
||||||
|
planButtonClassName?: string;
|
||||||
|
featuresClassName?: string;
|
||||||
|
featureItemClassName?: string;
|
||||||
|
gridClassName?: string;
|
||||||
|
carouselClassName?: string;
|
||||||
|
controlsClassName?: string;
|
||||||
|
textBoxClassName?: string;
|
||||||
|
textBoxTagClassName?: string;
|
||||||
|
textBoxButtonContainerClassName?: string;
|
||||||
|
textBoxButtonClassName?: string;
|
||||||
|
textBoxButtonTextClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PricingCardEight: React.FC<PricingCardEightProps> = ({
|
interface PricingCardItemProps {
|
||||||
plans,
|
plan: PricingPlan;
|
||||||
title,
|
shouldUseLightText: boolean;
|
||||||
description,
|
cardClassName?: string;
|
||||||
className = ""}) => {
|
badgeClassName?: string;
|
||||||
return (
|
priceClassName?: string;
|
||||||
<section className={`py-20 px-4 ${className}`}>
|
subtitleClassName?: string;
|
||||||
<div className="max-w-6xl mx-auto">
|
planButtonContainerClassName?: string;
|
||||||
<h2 className="text-4xl font-bold text-center mb-4">{title}</h2>
|
planButtonClassName?: string;
|
||||||
<p className="text-gray-600 text-center mb-12">{description}</p>
|
featuresClassName?: string;
|
||||||
|
featureItemClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
const PricingCardItem = memo(({
|
||||||
{plans.map((plan) => (
|
plan,
|
||||||
<div key={plan.id} className="border border-gray-200 rounded-lg overflow-hidden hover:shadow-lg transition-shadow">
|
shouldUseLightText,
|
||||||
{plan.imageSrc && (
|
cardClassName = "",
|
||||||
<img
|
badgeClassName = "",
|
||||||
src={plan.imageSrc}
|
priceClassName = "",
|
||||||
alt={plan.title}
|
subtitleClassName = "",
|
||||||
className="w-full h-64 object-cover"
|
planButtonContainerClassName = "",
|
||||||
|
planButtonClassName = "",
|
||||||
|
featuresClassName = "",
|
||||||
|
featureItemClassName = "",
|
||||||
|
}: PricingCardItemProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const getButtonConfigProps = () => {
|
||||||
|
if (theme.defaultButtonVariant === "hover-bubble") {
|
||||||
|
return { bgClassName: "w-full" };
|
||||||
|
}
|
||||||
|
if (theme.defaultButtonVariant === "icon-arrow") {
|
||||||
|
return { className: "justify-between" };
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cls("relative h-full card text-foreground rounded-theme-capped p-3 flex flex-col gap-3", cardClassName)}>
|
||||||
|
<div className="relative secondary-button p-3 flex flex-col gap-3 rounded-theme-capped" >
|
||||||
|
<PricingBadge
|
||||||
|
badge={plan.badge}
|
||||||
|
badgeIcon={plan.badgeIcon}
|
||||||
|
className={badgeClassName}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div className="relative z-1 flex flex-col gap-1">
|
||||||
|
<div className="text-5xl font-medium text-foreground">
|
||||||
|
{plan.price}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="text-base text-foreground">
|
||||||
|
{plan.subtitle}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{plan.buttons && plan.buttons.length > 0 && (
|
||||||
|
<div className={cls("relative z-1 w-full flex flex-col gap-3", planButtonContainerClassName)}>
|
||||||
|
{plan.buttons.slice(0, 2).map((button, index) => (
|
||||||
|
<Button
|
||||||
|
key={`${button.text}-${index}`}
|
||||||
|
{...getButtonProps(
|
||||||
|
{ ...button, props: { ...button.props, ...getButtonConfigProps() } },
|
||||||
|
index,
|
||||||
|
theme.defaultButtonVariant,
|
||||||
|
cls("w-full", planButtonClassName)
|
||||||
)}
|
)}
|
||||||
<div className="p-6">
|
/>
|
||||||
<h3 className="text-2xl font-bold mb-2">{plan.title}</h3>
|
|
||||||
<div className="mb-6">
|
|
||||||
<span className="text-3xl font-bold">{plan.price}</span>
|
|
||||||
<span className="text-gray-600 ml-2">{plan.period}</span>
|
|
||||||
</div>
|
|
||||||
<ul className="mb-6 space-y-3">
|
|
||||||
{plan.features.map((feature, idx) => (
|
|
||||||
<li key={idx} className="text-gray-700 flex items-center">
|
|
||||||
<span className="text-green-500 mr-3">✓</span>
|
|
||||||
{feature}
|
|
||||||
</li>
|
|
||||||
))}
|
))}
|
||||||
</ul>
|
</div>
|
||||||
<button
|
)}
|
||||||
onClick={plan.button.onClick}
|
</div>
|
||||||
className="w-full px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
|
|
||||||
|
<div className="p-3 pt-0" >
|
||||||
|
<PricingFeatureList
|
||||||
|
features={plan.features}
|
||||||
|
shouldUseLightText={shouldUseLightText}
|
||||||
|
className={cls("mt-1", featuresClassName)}
|
||||||
|
featureItemClassName={featureItemClassName}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
PricingCardItem.displayName = "PricingCardItem";
|
||||||
|
|
||||||
|
const PricingCardEight = ({
|
||||||
|
plans,
|
||||||
|
carouselMode = "buttons",
|
||||||
|
uniformGridCustomHeightClasses,
|
||||||
|
animationType,
|
||||||
|
title,
|
||||||
|
titleSegments,
|
||||||
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
buttons,
|
||||||
|
buttonAnimation,
|
||||||
|
textboxLayout,
|
||||||
|
useInvertedBackground,
|
||||||
|
ariaLabel = "Pricing section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
cardClassName = "",
|
||||||
|
textBoxTitleClassName = "",
|
||||||
|
textBoxTitleImageWrapperClassName = "",
|
||||||
|
textBoxTitleImageClassName = "",
|
||||||
|
textBoxDescriptionClassName = "",
|
||||||
|
badgeClassName = "",
|
||||||
|
priceClassName = "",
|
||||||
|
subtitleClassName = "",
|
||||||
|
planButtonContainerClassName = "",
|
||||||
|
planButtonClassName = "",
|
||||||
|
featuresClassName = "",
|
||||||
|
featureItemClassName = "",
|
||||||
|
gridClassName = "",
|
||||||
|
carouselClassName = "",
|
||||||
|
controlsClassName = "",
|
||||||
|
textBoxClassName = "",
|
||||||
|
textBoxTagClassName = "",
|
||||||
|
textBoxButtonContainerClassName = "",
|
||||||
|
textBoxButtonClassName = "",
|
||||||
|
textBoxButtonTextClassName = "",
|
||||||
|
}: PricingCardEightProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CardStack
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
mode={carouselMode}
|
||||||
|
gridVariant="uniform-all-items-equal"
|
||||||
|
uniformGridCustomHeightClasses={uniformGridCustomHeightClasses}
|
||||||
|
animationType={animationType}
|
||||||
|
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
gridClassName={gridClassName}
|
||||||
|
carouselClassName={carouselClassName}
|
||||||
|
controlsClassName={controlsClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={textBoxTitleClassName}
|
||||||
|
titleImageWrapperClassName={textBoxTitleImageWrapperClassName}
|
||||||
|
titleImageClassName={textBoxTitleImageClassName}
|
||||||
|
descriptionClassName={textBoxDescriptionClassName}
|
||||||
|
tagClassName={textBoxTagClassName}
|
||||||
|
buttonContainerClassName={textBoxButtonContainerClassName}
|
||||||
|
buttonClassName={textBoxButtonClassName}
|
||||||
|
buttonTextClassName={textBoxButtonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
>
|
>
|
||||||
{plan.button.text}
|
{plans.map((plan, index) => (
|
||||||
</button>
|
<PricingCardItem
|
||||||
</div>
|
key={`${plan.id}-${index}`}
|
||||||
</div>
|
plan={plan}
|
||||||
|
shouldUseLightText={shouldUseLightText}
|
||||||
|
cardClassName={cardClassName}
|
||||||
|
badgeClassName={badgeClassName}
|
||||||
|
priceClassName={priceClassName}
|
||||||
|
subtitleClassName={subtitleClassName}
|
||||||
|
planButtonContainerClassName={planButtonContainerClassName}
|
||||||
|
planButtonClassName={planButtonClassName}
|
||||||
|
featuresClassName={featuresClassName}
|
||||||
|
featureItemClassName={featureItemClassName}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</CardStack>
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PricingCardEight.displayName = "PricingCardEight";
|
||||||
|
|
||||||
export default PricingCardEight;
|
export default PricingCardEight;
|
||||||
|
|||||||
@@ -1,29 +1,238 @@
|
|||||||
import React from 'react';
|
"use client";
|
||||||
|
|
||||||
interface Product {
|
import { memo, useCallback } from "react";
|
||||||
id: string;
|
import { useRouter } from "next/navigation";
|
||||||
name: string;
|
import CardStack from "@/components/cardStack/CardStack";
|
||||||
price: string;
|
import ProductImage from "@/components/shared/ProductImage";
|
||||||
imageSrc: string;
|
import { cls, shouldUseInvertedText } from "@/lib/utils";
|
||||||
imageAlt?: string;
|
import { useTheme } from "@/providers/themeProvider/ThemeProvider";
|
||||||
}
|
import { useProducts } from "@/hooks/useProducts";
|
||||||
|
import type { Product } from "@/lib/api/product";
|
||||||
|
import type { LucideIcon } from "lucide-react";
|
||||||
|
import type { ButtonConfig, GridVariant, CardAnimationType, TitleSegment, ButtonAnimationType } from "@/components/cardStack/types";
|
||||||
|
import type { TextboxLayout, InvertedBackground } from "@/providers/themeProvider/config/constants";
|
||||||
|
|
||||||
|
type ProductCardFourGridVariant = Exclude<GridVariant, "timeline" | "items-top-row-full-width-bottom" | "full-width-top-items-bottom-row">;
|
||||||
|
|
||||||
|
type ProductCard = Product & {
|
||||||
|
variant: string;
|
||||||
|
};
|
||||||
|
|
||||||
interface ProductCardFourProps {
|
interface ProductCardFourProps {
|
||||||
products: Product[];
|
products?: ProductCard[];
|
||||||
|
carouselMode?: "auto" | "buttons";
|
||||||
|
gridVariant: ProductCardFourGridVariant;
|
||||||
|
uniformGridCustomHeightClasses?: string;
|
||||||
|
animationType: CardAnimationType;
|
||||||
|
title: string;
|
||||||
|
titleSegments?: TitleSegment[];
|
||||||
|
description: string;
|
||||||
|
tag?: string;
|
||||||
|
tagIcon?: LucideIcon;
|
||||||
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
buttons?: ButtonConfig[];
|
||||||
|
buttonAnimation?: ButtonAnimationType;
|
||||||
|
textboxLayout: TextboxLayout;
|
||||||
|
useInvertedBackground: InvertedBackground;
|
||||||
|
ariaLabel?: string;
|
||||||
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
textBoxTitleClassName?: string;
|
||||||
|
textBoxTitleImageWrapperClassName?: string;
|
||||||
|
textBoxTitleImageClassName?: string;
|
||||||
|
textBoxDescriptionClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
cardPriceClassName?: string;
|
||||||
|
cardVariantClassName?: string;
|
||||||
|
actionButtonClassName?: string;
|
||||||
|
gridClassName?: string;
|
||||||
|
carouselClassName?: string;
|
||||||
|
controlsClassName?: string;
|
||||||
|
textBoxClassName?: string;
|
||||||
|
textBoxTagClassName?: string;
|
||||||
|
textBoxButtonContainerClassName?: string;
|
||||||
|
textBoxButtonClassName?: string;
|
||||||
|
textBoxButtonTextClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductCardFour: React.FC<ProductCardFourProps> = ({ products }) => {
|
interface ProductCardItemProps {
|
||||||
|
product: ProductCard;
|
||||||
|
shouldUseLightText: boolean;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
cardPriceClassName?: string;
|
||||||
|
cardVariantClassName?: string;
|
||||||
|
actionButtonClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductCardItem = memo(({
|
||||||
|
product,
|
||||||
|
shouldUseLightText,
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
cardPriceClassName = "",
|
||||||
|
cardVariantClassName = "",
|
||||||
|
actionButtonClassName = "",
|
||||||
|
}: ProductCardItemProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 gap-4">
|
<article
|
||||||
{products.map((product) => (
|
className={cls("card group relative h-full flex flex-col gap-4 cursor-pointer p-4 rounded-theme-capped", cardClassName)}
|
||||||
<div key={product.id} className="product-card">
|
onClick={product.onProductClick}
|
||||||
<img src={product.imageSrc} alt={product.imageAlt || product.name} />
|
role="article"
|
||||||
<h3>{product.name}</h3>
|
aria-label={`${product.name} - ${product.price}`}
|
||||||
<p className="text-lg font-semibold">{product.price}</p>
|
>
|
||||||
|
<ProductImage
|
||||||
|
imageSrc={product.imageSrc}
|
||||||
|
imageAlt={product.imageAlt || product.name}
|
||||||
|
isFavorited={product.isFavorited}
|
||||||
|
onFavoriteToggle={product.onFavorite}
|
||||||
|
showActionButton={true}
|
||||||
|
actionButtonAriaLabel={`View ${product.name} details`}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
actionButtonClassName={actionButtonClassName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<div className="flex items-center justify-between gap-4">
|
||||||
|
<div className="flex flex-col gap-0 flex-1 min-w-0">
|
||||||
|
<h3 className={cls("text-base font-medium leading-[1.3]", shouldUseLightText ? "text-background" : "text-foreground", cardNameClassName)}>
|
||||||
|
{product.name}
|
||||||
|
</h3>
|
||||||
|
<p className={cls("text-sm leading-[1.3]", shouldUseLightText ? "text-background/60" : "text-foreground/60", cardVariantClassName)}>
|
||||||
|
{product.variant}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<p className={cls("text-base font-medium leading-[1.3] flex-shrink-0", shouldUseLightText ? "text-background" : "text-foreground", cardPriceClassName)}>
|
||||||
|
{product.price}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
ProductCardItem.displayName = "ProductCardItem";
|
||||||
|
|
||||||
|
const ProductCardFour = ({
|
||||||
|
products: productsProp,
|
||||||
|
carouselMode = "buttons",
|
||||||
|
gridVariant,
|
||||||
|
uniformGridCustomHeightClasses = "min-h-95 2xl:min-h-105",
|
||||||
|
animationType,
|
||||||
|
title,
|
||||||
|
titleSegments,
|
||||||
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
buttons,
|
||||||
|
buttonAnimation,
|
||||||
|
textboxLayout,
|
||||||
|
useInvertedBackground,
|
||||||
|
ariaLabel = "Product section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
textBoxTitleClassName = "",
|
||||||
|
textBoxTitleImageWrapperClassName = "",
|
||||||
|
textBoxTitleImageClassName = "",
|
||||||
|
textBoxDescriptionClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
cardPriceClassName = "",
|
||||||
|
cardVariantClassName = "",
|
||||||
|
actionButtonClassName = "",
|
||||||
|
gridClassName = "",
|
||||||
|
carouselClassName = "",
|
||||||
|
controlsClassName = "",
|
||||||
|
textBoxClassName = "",
|
||||||
|
textBoxTagClassName = "",
|
||||||
|
textBoxButtonContainerClassName = "",
|
||||||
|
textBoxButtonClassName = "",
|
||||||
|
textBoxButtonTextClassName = "",
|
||||||
|
}: ProductCardFourProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const router = useRouter();
|
||||||
|
const { products: fetchedProducts, isLoading } = useProducts();
|
||||||
|
const isFromApi = fetchedProducts.length > 0;
|
||||||
|
const products = (isFromApi ? fetchedProducts : productsProp) as ProductCard[];
|
||||||
|
const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle);
|
||||||
|
|
||||||
|
const handleProductClick = useCallback((product: ProductCard) => {
|
||||||
|
if (isFromApi) {
|
||||||
|
router.push(`/shop/${product.id}`);
|
||||||
|
} else {
|
||||||
|
product.onProductClick?.();
|
||||||
|
}
|
||||||
|
}, [isFromApi, router]);
|
||||||
|
|
||||||
|
|
||||||
|
if (isLoading && !productsProp) {
|
||||||
|
return (
|
||||||
|
<div className="w-content-width mx-auto py-20 text-center">
|
||||||
|
<p className="text-foreground">Loading products...</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!products || products.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CardStack
|
||||||
|
mode={carouselMode}
|
||||||
|
gridVariant={gridVariant}
|
||||||
|
uniformGridCustomHeightClasses={uniformGridCustomHeightClasses}
|
||||||
|
animationType={animationType}
|
||||||
|
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
gridClassName={gridClassName}
|
||||||
|
carouselClassName={carouselClassName}
|
||||||
|
controlsClassName={controlsClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={textBoxTitleClassName}
|
||||||
|
titleImageWrapperClassName={textBoxTitleImageWrapperClassName}
|
||||||
|
titleImageClassName={textBoxTitleImageClassName}
|
||||||
|
descriptionClassName={textBoxDescriptionClassName}
|
||||||
|
tagClassName={textBoxTagClassName}
|
||||||
|
buttonContainerClassName={textBoxButtonContainerClassName}
|
||||||
|
buttonClassName={textBoxButtonClassName}
|
||||||
|
buttonTextClassName={textBoxButtonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{products?.map((product, index) => (
|
||||||
|
<ProductCardItem
|
||||||
|
key={`${product.id}-${index}`}
|
||||||
|
product={{ ...product, onProductClick: () => handleProductClick(product) }}
|
||||||
|
shouldUseLightText={shouldUseLightText}
|
||||||
|
cardClassName={cardClassName}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
cardNameClassName={cardNameClassName}
|
||||||
|
cardPriceClassName={cardPriceClassName}
|
||||||
|
cardVariantClassName={cardVariantClassName}
|
||||||
|
actionButtonClassName={actionButtonClassName}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</CardStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProductCardFour.displayName = "ProductCardFour";
|
||||||
|
|
||||||
export default ProductCardFour;
|
export default ProductCardFour;
|
||||||
|
|||||||
@@ -1,29 +1,226 @@
|
|||||||
import React from 'react';
|
"use client";
|
||||||
|
|
||||||
interface Product {
|
import { memo, useCallback } from "react";
|
||||||
id: string;
|
import { useRouter } from "next/navigation";
|
||||||
name: string;
|
import { ArrowUpRight } from "lucide-react";
|
||||||
price: string;
|
import CardStack from "@/components/cardStack/CardStack";
|
||||||
imageSrc: string;
|
import ProductImage from "@/components/shared/ProductImage";
|
||||||
imageAlt?: string;
|
import { cls, shouldUseInvertedText } from "@/lib/utils";
|
||||||
}
|
import { useTheme } from "@/providers/themeProvider/ThemeProvider";
|
||||||
|
import { useProducts } from "@/hooks/useProducts";
|
||||||
|
import type { Product } from "@/lib/api/product";
|
||||||
|
import type { LucideIcon } from "lucide-react";
|
||||||
|
import type { ButtonConfig, GridVariant, CardAnimationType, TitleSegment, ButtonAnimationType } from "@/components/cardStack/types";
|
||||||
|
import type { TextboxLayout, InvertedBackground } from "@/providers/themeProvider/config/constants";
|
||||||
|
|
||||||
|
type ProductCardOneGridVariant = Exclude<GridVariant, "timeline">;
|
||||||
|
|
||||||
|
type ProductCard = Product;
|
||||||
|
|
||||||
interface ProductCardOneProps {
|
interface ProductCardOneProps {
|
||||||
products: Product[];
|
products?: ProductCard[];
|
||||||
|
carouselMode?: "auto" | "buttons";
|
||||||
|
gridVariant: ProductCardOneGridVariant;
|
||||||
|
uniformGridCustomHeightClasses?: string;
|
||||||
|
animationType: CardAnimationType;
|
||||||
|
title: string;
|
||||||
|
titleSegments?: TitleSegment[];
|
||||||
|
description: string;
|
||||||
|
tag?: string;
|
||||||
|
tagIcon?: LucideIcon;
|
||||||
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
buttons?: ButtonConfig[];
|
||||||
|
buttonAnimation?: ButtonAnimationType;
|
||||||
|
textboxLayout: TextboxLayout;
|
||||||
|
useInvertedBackground: InvertedBackground;
|
||||||
|
ariaLabel?: string;
|
||||||
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
textBoxTitleClassName?: string;
|
||||||
|
textBoxTitleImageWrapperClassName?: string;
|
||||||
|
textBoxTitleImageClassName?: string;
|
||||||
|
textBoxDescriptionClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
cardPriceClassName?: string;
|
||||||
|
gridClassName?: string;
|
||||||
|
carouselClassName?: string;
|
||||||
|
controlsClassName?: string;
|
||||||
|
textBoxClassName?: string;
|
||||||
|
textBoxTagClassName?: string;
|
||||||
|
textBoxButtonContainerClassName?: string;
|
||||||
|
textBoxButtonClassName?: string;
|
||||||
|
textBoxButtonTextClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductCardOne: React.FC<ProductCardOneProps> = ({ products }) => {
|
interface ProductCardItemProps {
|
||||||
|
product: ProductCard;
|
||||||
|
shouldUseLightText: boolean;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
cardPriceClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductCardItem = memo(({
|
||||||
|
product,
|
||||||
|
shouldUseLightText,
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
cardPriceClassName = "",
|
||||||
|
}: ProductCardItemProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 gap-4">
|
<article
|
||||||
{products.map((product) => (
|
className={cls("card group relative h-full flex flex-col gap-4 cursor-pointer p-4 rounded-theme-capped", cardClassName)}
|
||||||
<div key={product.id} className="product-card">
|
onClick={product.onProductClick}
|
||||||
<img src={product.imageSrc} alt={product.imageAlt || product.name} />
|
role="article"
|
||||||
<h3>{product.name}</h3>
|
aria-label={`${product.name} - ${product.price}`}
|
||||||
<p className="text-lg font-semibold">{product.price}</p>
|
>
|
||||||
|
<ProductImage
|
||||||
|
imageSrc={product.imageSrc}
|
||||||
|
imageAlt={product.imageAlt || product.name}
|
||||||
|
isFavorited={product.isFavorited}
|
||||||
|
onFavoriteToggle={product.onFavorite}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="relative z-1 flex items-center justify-between gap-4">
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<h3 className={cls("text-base font-medium truncate leading-[1.3]", shouldUseLightText ? "text-background" : "text-foreground", cardNameClassName)}>
|
||||||
|
{product.name}
|
||||||
|
</h3>
|
||||||
|
<p className={cls("text-2xl font-medium leading-[1.3]", shouldUseLightText ? "text-background" : "text-foreground", cardPriceClassName)}>
|
||||||
|
{product.price}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="relative cursor-pointer primary-button h-10 w-auto aspect-square rounded-theme flex items-center justify-center flex-shrink-0"
|
||||||
|
aria-label={`View ${product.name} details`}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<ArrowUpRight className="h-4/10 text-primary-cta-text transition-transform duration-300 group-hover:rotate-45" strokeWidth={1.5} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
ProductCardItem.displayName = "ProductCardItem";
|
||||||
|
|
||||||
|
const ProductCardOne = ({
|
||||||
|
products: productsProp,
|
||||||
|
carouselMode = "buttons",
|
||||||
|
gridVariant,
|
||||||
|
uniformGridCustomHeightClasses = "min-h-95 2xl:min-h-105",
|
||||||
|
animationType,
|
||||||
|
title,
|
||||||
|
titleSegments,
|
||||||
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
buttons,
|
||||||
|
buttonAnimation,
|
||||||
|
textboxLayout,
|
||||||
|
useInvertedBackground,
|
||||||
|
ariaLabel = "Product section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
textBoxTitleClassName = "",
|
||||||
|
textBoxTitleImageWrapperClassName = "",
|
||||||
|
textBoxTitleImageClassName = "",
|
||||||
|
textBoxDescriptionClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
cardPriceClassName = "",
|
||||||
|
gridClassName = "",
|
||||||
|
carouselClassName = "",
|
||||||
|
controlsClassName = "",
|
||||||
|
textBoxClassName = "",
|
||||||
|
textBoxTagClassName = "",
|
||||||
|
textBoxButtonContainerClassName = "",
|
||||||
|
textBoxButtonClassName = "",
|
||||||
|
textBoxButtonTextClassName = "",
|
||||||
|
}: ProductCardOneProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const router = useRouter();
|
||||||
|
const { products: fetchedProducts, isLoading } = useProducts();
|
||||||
|
const isFromApi = fetchedProducts.length > 0;
|
||||||
|
const products = isFromApi ? fetchedProducts : productsProp;
|
||||||
|
const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle);
|
||||||
|
|
||||||
|
const handleProductClick = useCallback((product: ProductCard) => {
|
||||||
|
if (isFromApi) {
|
||||||
|
router.push(`/shop/${product.id}`);
|
||||||
|
} else {
|
||||||
|
product.onProductClick?.();
|
||||||
|
}
|
||||||
|
}, [isFromApi, router]);
|
||||||
|
|
||||||
|
if (isLoading && !productsProp) {
|
||||||
|
return (
|
||||||
|
<div className="w-content-width mx-auto py-20 text-center">
|
||||||
|
<p className="text-foreground">Loading products...</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!products || products.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CardStack
|
||||||
|
mode={carouselMode}
|
||||||
|
gridVariant={gridVariant}
|
||||||
|
uniformGridCustomHeightClasses={uniformGridCustomHeightClasses}
|
||||||
|
animationType={animationType}
|
||||||
|
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
gridClassName={gridClassName}
|
||||||
|
carouselClassName={carouselClassName}
|
||||||
|
controlsClassName={controlsClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={textBoxTitleClassName}
|
||||||
|
titleImageWrapperClassName={textBoxTitleImageWrapperClassName}
|
||||||
|
titleImageClassName={textBoxTitleImageClassName}
|
||||||
|
descriptionClassName={textBoxDescriptionClassName}
|
||||||
|
tagClassName={textBoxTagClassName}
|
||||||
|
buttonContainerClassName={textBoxButtonContainerClassName}
|
||||||
|
buttonClassName={textBoxButtonClassName}
|
||||||
|
buttonTextClassName={textBoxButtonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{products?.map((product, index) => (
|
||||||
|
<ProductCardItem
|
||||||
|
key={`${product.id}-${index}`}
|
||||||
|
product={{ ...product, onProductClick: () => handleProductClick(product) }}
|
||||||
|
shouldUseLightText={shouldUseLightText}
|
||||||
|
cardClassName={cardClassName}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
cardNameClassName={cardNameClassName}
|
||||||
|
cardPriceClassName={cardPriceClassName}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</CardStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProductCardOne.displayName = "ProductCardOne";
|
||||||
|
|
||||||
export default ProductCardOne;
|
export default ProductCardOne;
|
||||||
|
|||||||
@@ -1,29 +1,283 @@
|
|||||||
import React from 'react';
|
"use client";
|
||||||
|
|
||||||
interface Product {
|
import { memo, useState, useCallback } from "react";
|
||||||
id: string;
|
import { useRouter } from "next/navigation";
|
||||||
name: string;
|
import { Plus, Minus } from "lucide-react";
|
||||||
price: string;
|
import CardStack from "@/components/cardStack/CardStack";
|
||||||
imageSrc: string;
|
import ProductImage from "@/components/shared/ProductImage";
|
||||||
imageAlt?: string;
|
import QuantityButton from "@/components/shared/QuantityButton";
|
||||||
}
|
import Button from "@/components/button/Button";
|
||||||
|
import { useTheme } from "@/providers/themeProvider/ThemeProvider";
|
||||||
|
import { useProducts } from "@/hooks/useProducts";
|
||||||
|
import { getButtonProps } from "@/lib/buttonUtils";
|
||||||
|
import { cls, shouldUseInvertedText } from "@/lib/utils";
|
||||||
|
import type { Product } from "@/lib/api/product";
|
||||||
|
import type { LucideIcon } from "lucide-react";
|
||||||
|
import type { ButtonConfig, ButtonAnimationType, GridVariant, CardAnimationType, TitleSegment } from "@/components/cardStack/types";
|
||||||
|
import type { CTAButtonVariant, ButtonPropsForVariant } from "@/components/button/types";
|
||||||
|
import type { TextboxLayout, InvertedBackground } from "@/providers/themeProvider/config/constants";
|
||||||
|
|
||||||
|
type ProductCardThreeGridVariant = Exclude<GridVariant, "timeline" | "items-top-row-full-width-bottom" | "full-width-top-items-bottom-row">;
|
||||||
|
|
||||||
|
type ProductCard = Product & {
|
||||||
|
onQuantityChange?: (quantity: number) => void;
|
||||||
|
initialQuantity?: number;
|
||||||
|
priceButtonProps?: Partial<ButtonPropsForVariant<CTAButtonVariant>>;
|
||||||
|
};
|
||||||
|
|
||||||
interface ProductCardThreeProps {
|
interface ProductCardThreeProps {
|
||||||
products: Product[];
|
products?: ProductCard[];
|
||||||
|
carouselMode?: "auto" | "buttons";
|
||||||
|
gridVariant: ProductCardThreeGridVariant;
|
||||||
|
uniformGridCustomHeightClasses?: string;
|
||||||
|
animationType: CardAnimationType;
|
||||||
|
title: string;
|
||||||
|
titleSegments?: TitleSegment[];
|
||||||
|
description: string;
|
||||||
|
tag?: string;
|
||||||
|
tagIcon?: LucideIcon;
|
||||||
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
buttons?: ButtonConfig[];
|
||||||
|
buttonAnimation?: ButtonAnimationType;
|
||||||
|
textboxLayout: TextboxLayout;
|
||||||
|
useInvertedBackground: InvertedBackground;
|
||||||
|
ariaLabel?: string;
|
||||||
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
textBoxTitleClassName?: string;
|
||||||
|
textBoxTitleImageWrapperClassName?: string;
|
||||||
|
textBoxTitleImageClassName?: string;
|
||||||
|
textBoxDescriptionClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
quantityControlsClassName?: string;
|
||||||
|
gridClassName?: string;
|
||||||
|
carouselClassName?: string;
|
||||||
|
controlsClassName?: string;
|
||||||
|
textBoxClassName?: string;
|
||||||
|
textBoxTagClassName?: string;
|
||||||
|
textBoxButtonContainerClassName?: string;
|
||||||
|
textBoxButtonClassName?: string;
|
||||||
|
textBoxButtonTextClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductCardThree: React.FC<ProductCardThreeProps> = ({ products }) => {
|
|
||||||
|
interface ProductCardItemProps {
|
||||||
|
product: ProductCard;
|
||||||
|
shouldUseLightText: boolean;
|
||||||
|
isFromApi: boolean;
|
||||||
|
onBuyClick?: (productId: string, quantity: number) => void;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
quantityControlsClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductCardItem = memo(({
|
||||||
|
product,
|
||||||
|
shouldUseLightText,
|
||||||
|
isFromApi,
|
||||||
|
onBuyClick,
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
quantityControlsClassName = "",
|
||||||
|
}: ProductCardItemProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const [quantity, setQuantity] = useState(product.initialQuantity || 1);
|
||||||
|
|
||||||
|
const handleIncrement = useCallback((e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
const newQuantity = quantity + 1;
|
||||||
|
setQuantity(newQuantity);
|
||||||
|
product.onQuantityChange?.(newQuantity);
|
||||||
|
}, [quantity, product]);
|
||||||
|
|
||||||
|
const handleDecrement = useCallback((e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
if (quantity > 1) {
|
||||||
|
const newQuantity = quantity - 1;
|
||||||
|
setQuantity(newQuantity);
|
||||||
|
product.onQuantityChange?.(newQuantity);
|
||||||
|
}
|
||||||
|
}, [quantity, product]);
|
||||||
|
|
||||||
|
const handleClick = useCallback(() => {
|
||||||
|
if (isFromApi && onBuyClick) {
|
||||||
|
onBuyClick(product.id, quantity);
|
||||||
|
} else {
|
||||||
|
product.onProductClick?.();
|
||||||
|
}
|
||||||
|
}, [isFromApi, onBuyClick, product, quantity]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 gap-4">
|
<article
|
||||||
{products.map((product) => (
|
className={cls("card group relative h-full flex flex-col gap-4 cursor-pointer p-4 rounded-theme-capped", cardClassName)}
|
||||||
<div key={product.id} className="product-card">
|
onClick={handleClick}
|
||||||
<img src={product.imageSrc} alt={product.imageAlt || product.name} />
|
role="article"
|
||||||
<h3>{product.name}</h3>
|
aria-label={`${product.name} - ${product.price}`}
|
||||||
<p className="text-lg font-semibold">{product.price}</p>
|
>
|
||||||
|
<ProductImage
|
||||||
|
imageSrc={product.imageSrc}
|
||||||
|
imageAlt={product.imageAlt || product.name}
|
||||||
|
isFavorited={product.isFavorited}
|
||||||
|
onFavoriteToggle={product.onFavorite}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="relative z-1 flex flex-col gap-3">
|
||||||
|
<h3 className={cls("text-xl font-medium leading-[1.15] truncate", shouldUseLightText ? "text-background" : "text-foreground", cardNameClassName)}>
|
||||||
|
{product.name}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between gap-4">
|
||||||
|
<div className={cls("flex items-center gap-2", quantityControlsClassName)}>
|
||||||
|
<QuantityButton
|
||||||
|
onClick={handleDecrement}
|
||||||
|
ariaLabel="Decrease quantity"
|
||||||
|
Icon={Minus}
|
||||||
|
/>
|
||||||
|
<span className={cls("text-base font-medium min-w-[2ch] text-center leading-[1]", shouldUseLightText ? "text-background" : "text-foreground")}>
|
||||||
|
{quantity}
|
||||||
|
</span>
|
||||||
|
<QuantityButton
|
||||||
|
onClick={handleIncrement}
|
||||||
|
ariaLabel="Increase quantity"
|
||||||
|
Icon={Plus}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
{...getButtonProps(
|
||||||
|
{
|
||||||
|
text: product.price,
|
||||||
|
props: product.priceButtonProps,
|
||||||
|
},
|
||||||
|
0,
|
||||||
|
theme.defaultButtonVariant
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
ProductCardItem.displayName = "ProductCardItem";
|
||||||
|
|
||||||
|
const ProductCardThree = ({
|
||||||
|
products: productsProp,
|
||||||
|
carouselMode = "buttons",
|
||||||
|
gridVariant,
|
||||||
|
uniformGridCustomHeightClasses = "min-h-95 2xl:min-h-105",
|
||||||
|
animationType,
|
||||||
|
title,
|
||||||
|
titleSegments,
|
||||||
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
buttons,
|
||||||
|
buttonAnimation,
|
||||||
|
textboxLayout,
|
||||||
|
useInvertedBackground,
|
||||||
|
ariaLabel = "Product section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
textBoxTitleClassName = "",
|
||||||
|
textBoxTitleImageWrapperClassName = "",
|
||||||
|
textBoxTitleImageClassName = "",
|
||||||
|
textBoxDescriptionClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
quantityControlsClassName = "",
|
||||||
|
gridClassName = "",
|
||||||
|
carouselClassName = "",
|
||||||
|
controlsClassName = "",
|
||||||
|
textBoxClassName = "",
|
||||||
|
textBoxTagClassName = "",
|
||||||
|
textBoxButtonContainerClassName = "",
|
||||||
|
textBoxButtonClassName = "",
|
||||||
|
textBoxButtonTextClassName = "",
|
||||||
|
}: ProductCardThreeProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const router = useRouter();
|
||||||
|
const { products: fetchedProducts, isLoading } = useProducts();
|
||||||
|
const isFromApi = fetchedProducts.length > 0;
|
||||||
|
const products = (isFromApi ? fetchedProducts : productsProp) as ProductCard[];
|
||||||
|
const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle);
|
||||||
|
|
||||||
|
const handleProductClick = useCallback((product: ProductCard) => {
|
||||||
|
if (isFromApi) {
|
||||||
|
router.push(`/shop/${product.id}`);
|
||||||
|
} else {
|
||||||
|
product.onProductClick?.();
|
||||||
|
}
|
||||||
|
}, [isFromApi, router]);
|
||||||
|
|
||||||
|
if (isLoading && !productsProp) {
|
||||||
|
return (
|
||||||
|
<div className="w-content-width mx-auto py-20 text-center">
|
||||||
|
<p className="text-foreground">Loading products...</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!products || products.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CardStack
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
mode={carouselMode}
|
||||||
|
gridVariant={gridVariant}
|
||||||
|
uniformGridCustomHeightClasses={uniformGridCustomHeightClasses}
|
||||||
|
animationType={animationType}
|
||||||
|
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
gridClassName={gridClassName}
|
||||||
|
carouselClassName={carouselClassName}
|
||||||
|
controlsClassName={controlsClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={textBoxTitleClassName}
|
||||||
|
titleImageWrapperClassName={textBoxTitleImageWrapperClassName}
|
||||||
|
titleImageClassName={textBoxTitleImageClassName}
|
||||||
|
descriptionClassName={textBoxDescriptionClassName}
|
||||||
|
tagClassName={textBoxTagClassName}
|
||||||
|
buttonContainerClassName={textBoxButtonContainerClassName}
|
||||||
|
buttonClassName={textBoxButtonClassName}
|
||||||
|
buttonTextClassName={textBoxButtonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{products?.map((product, index) => (
|
||||||
|
<ProductCardItem
|
||||||
|
key={`${product.id}-${index}`}
|
||||||
|
product={{ ...product, onProductClick: () => handleProductClick(product) }}
|
||||||
|
shouldUseLightText={shouldUseLightText}
|
||||||
|
isFromApi={isFromApi}
|
||||||
|
cardClassName={cardClassName}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
cardNameClassName={cardNameClassName}
|
||||||
|
quantityControlsClassName={quantityControlsClassName}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</CardStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProductCardThree.displayName = "ProductCardThree";
|
||||||
|
|
||||||
export default ProductCardThree;
|
export default ProductCardThree;
|
||||||
|
|||||||
@@ -1,29 +1,267 @@
|
|||||||
import React from 'react';
|
"use client";
|
||||||
|
|
||||||
interface Product {
|
import { memo, useCallback } from "react";
|
||||||
id: string;
|
import { useRouter } from "next/navigation";
|
||||||
name: string;
|
import { Star } from "lucide-react";
|
||||||
price: string;
|
import CardStack from "@/components/cardStack/CardStack";
|
||||||
imageSrc: string;
|
import ProductImage from "@/components/shared/ProductImage";
|
||||||
imageAlt?: string;
|
import { cls, shouldUseInvertedText } from "@/lib/utils";
|
||||||
}
|
import { useTheme } from "@/providers/themeProvider/ThemeProvider";
|
||||||
|
import { useProducts } from "@/hooks/useProducts";
|
||||||
|
import type { Product } from "@/lib/api/product";
|
||||||
|
import type { LucideIcon } from "lucide-react";
|
||||||
|
import type { ButtonConfig, GridVariant, CardAnimationType, TitleSegment, ButtonAnimationType } from "@/components/cardStack/types";
|
||||||
|
import type { TextboxLayout, InvertedBackground } from "@/providers/themeProvider/config/constants";
|
||||||
|
|
||||||
|
type ProductCardTwoGridVariant = Exclude<GridVariant, "timeline" | "one-large-right-three-stacked-left" | "items-top-row-full-width-bottom" | "full-width-top-items-bottom-row" | "one-large-left-three-stacked-right">;
|
||||||
|
|
||||||
|
type ProductCard = Product & {
|
||||||
|
brand: string;
|
||||||
|
rating: number;
|
||||||
|
reviewCount: string;
|
||||||
|
};
|
||||||
|
|
||||||
interface ProductCardTwoProps {
|
interface ProductCardTwoProps {
|
||||||
products: Product[];
|
products?: ProductCard[];
|
||||||
|
carouselMode?: "auto" | "buttons";
|
||||||
|
gridVariant: ProductCardTwoGridVariant;
|
||||||
|
uniformGridCustomHeightClasses?: string;
|
||||||
|
animationType: CardAnimationType;
|
||||||
|
title: string;
|
||||||
|
titleSegments?: TitleSegment[];
|
||||||
|
description: string;
|
||||||
|
tag?: string;
|
||||||
|
tagIcon?: LucideIcon;
|
||||||
|
tagAnimation?: ButtonAnimationType;
|
||||||
|
buttons?: ButtonConfig[];
|
||||||
|
buttonAnimation?: ButtonAnimationType;
|
||||||
|
textboxLayout: TextboxLayout;
|
||||||
|
useInvertedBackground: InvertedBackground;
|
||||||
|
ariaLabel?: string;
|
||||||
|
className?: string;
|
||||||
|
containerClassName?: string;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
textBoxTitleClassName?: string;
|
||||||
|
textBoxTitleImageWrapperClassName?: string;
|
||||||
|
textBoxTitleImageClassName?: string;
|
||||||
|
textBoxDescriptionClassName?: string;
|
||||||
|
cardBrandClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
cardPriceClassName?: string;
|
||||||
|
cardRatingClassName?: string;
|
||||||
|
actionButtonClassName?: string;
|
||||||
|
gridClassName?: string;
|
||||||
|
carouselClassName?: string;
|
||||||
|
controlsClassName?: string;
|
||||||
|
textBoxClassName?: string;
|
||||||
|
textBoxTagClassName?: string;
|
||||||
|
textBoxButtonContainerClassName?: string;
|
||||||
|
textBoxButtonClassName?: string;
|
||||||
|
textBoxButtonTextClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductCardTwo: React.FC<ProductCardTwoProps> = ({ products }) => {
|
interface ProductCardItemProps {
|
||||||
|
product: ProductCard;
|
||||||
|
shouldUseLightText: boolean;
|
||||||
|
cardClassName?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
cardBrandClassName?: string;
|
||||||
|
cardNameClassName?: string;
|
||||||
|
cardPriceClassName?: string;
|
||||||
|
cardRatingClassName?: string;
|
||||||
|
actionButtonClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductCardItem = memo(({
|
||||||
|
product,
|
||||||
|
shouldUseLightText,
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
cardBrandClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
cardPriceClassName = "",
|
||||||
|
cardRatingClassName = "",
|
||||||
|
actionButtonClassName = "",
|
||||||
|
}: ProductCardItemProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 gap-4">
|
<article
|
||||||
{products.map((product) => (
|
className={cls("card group relative h-full flex flex-col gap-4 cursor-pointer p-4 rounded-theme-capped", cardClassName)}
|
||||||
<div key={product.id} className="product-card">
|
onClick={product.onProductClick}
|
||||||
<img src={product.imageSrc} alt={product.imageAlt || product.name} />
|
role="article"
|
||||||
<h3>{product.name}</h3>
|
aria-label={`${product.brand} ${product.name} - ${product.price}`}
|
||||||
<p className="text-lg font-semibold">{product.price}</p>
|
>
|
||||||
</div>
|
<ProductImage
|
||||||
|
imageSrc={product.imageSrc}
|
||||||
|
imageAlt={product.imageAlt || `${product.brand} ${product.name}`}
|
||||||
|
isFavorited={product.isFavorited}
|
||||||
|
onFavoriteToggle={product.onFavorite}
|
||||||
|
showActionButton={true}
|
||||||
|
actionButtonAriaLabel={`View ${product.name} details`}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
actionButtonClassName={actionButtonClassName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="relative z-1 flex-1 min-w-0 flex flex-col gap-2">
|
||||||
|
<p className={cls("text-sm leading-[1]", shouldUseLightText ? "text-background" : "text-foreground", cardBrandClassName)}>
|
||||||
|
{product.brand}
|
||||||
|
</p>
|
||||||
|
<div className="flex flex-col gap-1" >
|
||||||
|
<h3 className={cls("text-xl font-medium truncate leading-[1.15]", shouldUseLightText ? "text-background" : "text-foreground", cardNameClassName)}>
|
||||||
|
{product.name}
|
||||||
|
</h3>
|
||||||
|
<div className={cls("flex items-center gap-2", cardRatingClassName)}>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
{[...Array(5)].map((_, i) => (
|
||||||
|
<Star
|
||||||
|
key={i}
|
||||||
|
className={cls(
|
||||||
|
"h-4 w-auto",
|
||||||
|
i < Math.floor(product.rating)
|
||||||
|
? "text-accent fill-accent"
|
||||||
|
: "text-accent opacity-20"
|
||||||
|
)}
|
||||||
|
strokeWidth={1.5}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
<span className={cls("text-sm leading-[1.3]", shouldUseLightText ? "text-background" : "text-foreground")}>
|
||||||
|
({product.reviewCount})
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className={cls("text-2xl font-medium leading-[1.3]", shouldUseLightText ? "text-background" : "text-foreground", cardPriceClassName)}>
|
||||||
|
{product.price}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
ProductCardItem.displayName = "ProductCardItem";
|
||||||
|
|
||||||
|
const ProductCardTwo = ({
|
||||||
|
products: productsProp,
|
||||||
|
carouselMode = "buttons",
|
||||||
|
gridVariant,
|
||||||
|
uniformGridCustomHeightClasses = "min-h-95 2xl:min-h-105",
|
||||||
|
animationType,
|
||||||
|
title,
|
||||||
|
titleSegments,
|
||||||
|
description,
|
||||||
|
tag,
|
||||||
|
tagIcon,
|
||||||
|
tagAnimation,
|
||||||
|
buttons,
|
||||||
|
buttonAnimation,
|
||||||
|
textboxLayout,
|
||||||
|
useInvertedBackground,
|
||||||
|
ariaLabel = "Product section",
|
||||||
|
className = "",
|
||||||
|
containerClassName = "",
|
||||||
|
cardClassName = "",
|
||||||
|
imageClassName = "",
|
||||||
|
textBoxTitleClassName = "",
|
||||||
|
textBoxTitleImageWrapperClassName = "",
|
||||||
|
textBoxTitleImageClassName = "",
|
||||||
|
textBoxDescriptionClassName = "",
|
||||||
|
cardBrandClassName = "",
|
||||||
|
cardNameClassName = "",
|
||||||
|
cardPriceClassName = "",
|
||||||
|
cardRatingClassName = "",
|
||||||
|
actionButtonClassName = "",
|
||||||
|
gridClassName = "",
|
||||||
|
carouselClassName = "",
|
||||||
|
controlsClassName = "",
|
||||||
|
textBoxClassName = "",
|
||||||
|
textBoxTagClassName = "",
|
||||||
|
textBoxButtonContainerClassName = "",
|
||||||
|
textBoxButtonClassName = "",
|
||||||
|
textBoxButtonTextClassName = "",
|
||||||
|
}: ProductCardTwoProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const router = useRouter();
|
||||||
|
const { products: fetchedProducts, isLoading } = useProducts();
|
||||||
|
const isFromApi = fetchedProducts.length > 0;
|
||||||
|
const products = (fetchedProducts.length > 0 ? fetchedProducts : productsProp) as ProductCard[];
|
||||||
|
const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle);
|
||||||
|
|
||||||
|
const handleProductClick = useCallback((product: ProductCard) => {
|
||||||
|
if (isFromApi) {
|
||||||
|
router.push(`/shop/${product.id}`);
|
||||||
|
} else {
|
||||||
|
product.onProductClick?.();
|
||||||
|
}
|
||||||
|
}, [isFromApi, router]);
|
||||||
|
|
||||||
|
const customGridRows = (gridVariant === "bento-grid" || gridVariant === "bento-grid-inverted")
|
||||||
|
? "md:grid-rows-[22rem_22rem] 2xl:grid-rows-[26rem_26rem]"
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (isLoading && !productsProp) {
|
||||||
|
return (
|
||||||
|
<div className="w-content-width mx-auto py-20 text-center">
|
||||||
|
<p className="text-foreground">Loading products...</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!products || products.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CardStack
|
||||||
|
useInvertedBackground={useInvertedBackground}
|
||||||
|
mode={carouselMode}
|
||||||
|
gridVariant={gridVariant}
|
||||||
|
uniformGridCustomHeightClasses={uniformGridCustomHeightClasses}
|
||||||
|
gridRowsClassName={customGridRows}
|
||||||
|
animationType={animationType}
|
||||||
|
|
||||||
|
title={title}
|
||||||
|
titleSegments={titleSegments}
|
||||||
|
description={description}
|
||||||
|
tag={tag}
|
||||||
|
tagIcon={tagIcon}
|
||||||
|
tagAnimation={tagAnimation}
|
||||||
|
buttons={buttons}
|
||||||
|
buttonAnimation={buttonAnimation}
|
||||||
|
textboxLayout={textboxLayout}
|
||||||
|
className={className}
|
||||||
|
containerClassName={containerClassName}
|
||||||
|
gridClassName={gridClassName}
|
||||||
|
carouselClassName={carouselClassName}
|
||||||
|
controlsClassName={controlsClassName}
|
||||||
|
textBoxClassName={textBoxClassName}
|
||||||
|
titleClassName={textBoxTitleClassName}
|
||||||
|
titleImageWrapperClassName={textBoxTitleImageWrapperClassName}
|
||||||
|
titleImageClassName={textBoxTitleImageClassName}
|
||||||
|
descriptionClassName={textBoxDescriptionClassName}
|
||||||
|
tagClassName={textBoxTagClassName}
|
||||||
|
buttonContainerClassName={textBoxButtonContainerClassName}
|
||||||
|
buttonClassName={textBoxButtonClassName}
|
||||||
|
buttonTextClassName={textBoxButtonTextClassName}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{products?.map((product, index) => (
|
||||||
|
<ProductCardItem
|
||||||
|
key={`${product.id}-${index}`}
|
||||||
|
product={{ ...product, onProductClick: () => handleProductClick(product) }}
|
||||||
|
shouldUseLightText={shouldUseLightText}
|
||||||
|
cardClassName={cardClassName}
|
||||||
|
imageClassName={imageClassName}
|
||||||
|
cardBrandClassName={cardBrandClassName}
|
||||||
|
cardNameClassName={cardNameClassName}
|
||||||
|
cardPriceClassName={cardPriceClassName}
|
||||||
|
cardRatingClassName={cardRatingClassName}
|
||||||
|
actionButtonClassName={actionButtonClassName}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</CardStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProductCardTwo.displayName = "ProductCardTwo";
|
||||||
|
|
||||||
export default ProductCardTwo;
|
export default ProductCardTwo;
|
||||||
|
|||||||
@@ -1,75 +1,117 @@
|
|||||||
import { useState, useCallback } from "react";
|
"use client";
|
||||||
|
|
||||||
interface CheckoutItem {
|
import { useState } from "react";
|
||||||
id: string;
|
import { Product } from "@/lib/api/product";
|
||||||
name: string;
|
|
||||||
price: number;
|
export type CheckoutItem = {
|
||||||
|
productId: string;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
}
|
imageSrc?: string;
|
||||||
|
imageAlt?: string;
|
||||||
interface CheckoutState {
|
metadata?: {
|
||||||
items: CheckoutItem[];
|
brand?: string;
|
||||||
total: number;
|
variant?: string;
|
||||||
loading: boolean;
|
rating?: number;
|
||||||
error: string | null;
|
reviewCount?: string;
|
||||||
}
|
[key: string]: string | number | undefined;
|
||||||
|
};
|
||||||
const useCheckout = () => {
|
|
||||||
const [state, setState] = useState<CheckoutState>({
|
|
||||||
items: [],
|
|
||||||
total: 0,
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const addItem = useCallback((item: CheckoutItem) => {
|
|
||||||
setState((prev) => ({
|
|
||||||
...prev,
|
|
||||||
items: [...prev.items, item],
|
|
||||||
total: prev.total + item.price * item.quantity,
|
|
||||||
}));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const removeItem = useCallback((itemId: string) => {
|
|
||||||
setState((prev) => {
|
|
||||||
const item = prev.items.find((i) => i.id === itemId);
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
items: prev.items.filter((i) => i.id !== itemId),
|
|
||||||
total: prev.total - (item ? item.price * item.quantity : 0),
|
|
||||||
};
|
};
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const clearCart = useCallback(() => {
|
export type CheckoutResult = {
|
||||||
setState({
|
success: boolean;
|
||||||
items: [],
|
url?: string;
|
||||||
total: 0,
|
error?: string;
|
||||||
loading: false,
|
};
|
||||||
error: null,
|
|
||||||
});
|
export function useCheckout() {
|
||||||
}, []);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const checkout = async (items: CheckoutItem[], options?: { successUrl?: string; cancelUrl?: string }): Promise<CheckoutResult> => {
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
|
||||||
|
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;
|
||||||
|
|
||||||
|
if (!apiUrl || !projectId) {
|
||||||
|
const errorMsg = "NEXT_PUBLIC_API_URL or NEXT_PUBLIC_PROJECT_ID not configured";
|
||||||
|
setError(errorMsg);
|
||||||
|
return { success: false, error: errorMsg };
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
const checkout = useCallback(async () => {
|
|
||||||
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
||||||
try {
|
try {
|
||||||
console.log("Processing checkout with items:", state.items);
|
|
||||||
setState((prev) => ({ ...prev, loading: false }));
|
const response = await fetch(`${apiUrl}/stripe/project/checkout-session`, {
|
||||||
} catch (err) {
|
method: "POST",
|
||||||
setState((prev) => ({
|
headers: {
|
||||||
...prev,
|
"Content-Type": "application/json",
|
||||||
loading: false,
|
},
|
||||||
error: err instanceof Error ? err.message : "Checkout failed"}));
|
body: JSON.stringify({
|
||||||
|
projectId,
|
||||||
|
items,
|
||||||
|
successUrl: options?.successUrl || window.location.href,
|
||||||
|
cancelUrl: options?.cancelUrl || window.location.href,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
const errorMsg = errorData.message || `Request failed with status ${response.status}`;
|
||||||
|
setError(errorMsg);
|
||||||
|
return { success: false, error: errorMsg };
|
||||||
}
|
}
|
||||||
}, [state.items]);
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.data.url) {
|
||||||
|
window.location.href = data.data.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: true, url: data.data.url };
|
||||||
|
} catch (err) {
|
||||||
|
const errorMsg = err instanceof Error ? err.message : "Failed to create checkout session";
|
||||||
|
setError(errorMsg);
|
||||||
|
return { success: false, error: errorMsg };
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const buyNow = async (product: Product | string, quantity: number = 1): Promise<CheckoutResult> => {
|
||||||
|
const successUrl = new URL(window.location.href);
|
||||||
|
successUrl.searchParams.set("success", "true");
|
||||||
|
|
||||||
|
if (typeof product === "string") {
|
||||||
|
return checkout([{ productId: product, quantity }], { successUrl: successUrl.toString() });
|
||||||
|
}
|
||||||
|
|
||||||
|
let metadata: CheckoutItem["metadata"] = {};
|
||||||
|
|
||||||
|
if (product.metadata && Object.keys(product.metadata).length > 0) {
|
||||||
|
const { imageSrc, imageAlt, images, ...restMetadata } = product.metadata;
|
||||||
|
metadata = restMetadata;
|
||||||
|
} else {
|
||||||
|
if (product.brand) metadata.brand = product.brand;
|
||||||
|
if (product.variant) metadata.variant = product.variant;
|
||||||
|
if (product.rating !== undefined) metadata.rating = product.rating;
|
||||||
|
if (product.reviewCount) metadata.reviewCount = product.reviewCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkout([{
|
||||||
|
productId: product.id,
|
||||||
|
quantity,
|
||||||
|
imageSrc: product.imageSrc,
|
||||||
|
imageAlt: product.imageAlt,
|
||||||
|
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
||||||
|
}], { successUrl: successUrl.toString() });
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
|
||||||
addItem,
|
|
||||||
removeItem,
|
|
||||||
clearCart,
|
|
||||||
checkout,
|
checkout,
|
||||||
|
buyNow,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
clearError: () => setError(null),
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export default useCheckout;
|
|
||||||
@@ -1,38 +1,45 @@
|
|||||||
import { useState, useEffect } from 'react';
|
"use client";
|
||||||
|
|
||||||
interface Product {
|
import { useEffect, useState } from "react";
|
||||||
id: string;
|
import { Product, fetchProduct } from "@/lib/api/product";
|
||||||
name: string;
|
|
||||||
price: string;
|
|
||||||
imageSrc: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useProduct(productId: string) {
|
export function useProduct(productId: string) {
|
||||||
const [product, setProduct] = useState<Product | null>(null);
|
const [product, setProduct] = useState<Product | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<Error | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchProduct = async () => {
|
let isMounted = true;
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
// Simulate fetch
|
|
||||||
const response = await fetch(`/api/products/${productId}`);
|
|
||||||
const data = await response.json();
|
|
||||||
setProduct(data);
|
|
||||||
setError(null);
|
|
||||||
} catch (err) {
|
|
||||||
setError('Failed to fetch product');
|
|
||||||
setProduct(null);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (productId) {
|
async function loadProduct() {
|
||||||
fetchProduct();
|
if (!productId) {
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const data = await fetchProduct(productId);
|
||||||
|
if (isMounted) {
|
||||||
|
setProduct(data);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (isMounted) {
|
||||||
|
setError(err instanceof Error ? err : new Error("Failed to fetch product"));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (isMounted) {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadProduct();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMounted = false;
|
||||||
|
};
|
||||||
}, [productId]);
|
}, [productId]);
|
||||||
|
|
||||||
return { product, loading, error };
|
return { product, isLoading, error };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +1,115 @@
|
|||||||
import { useState, useEffect } from "react";
|
"use client";
|
||||||
|
|
||||||
interface CatalogProduct {
|
import { useState, useMemo, useCallback } from "react";
|
||||||
id: string;
|
import { useRouter } from "next/navigation";
|
||||||
category?: string;
|
import { useProducts } from "./useProducts";
|
||||||
name: string;
|
import type { Product } from "@/lib/api/product";
|
||||||
price: string;
|
import type { CatalogProduct } from "@/components/ecommerce/productCatalog/ProductCatalogItem";
|
||||||
rating: number;
|
import type { ProductVariant } from "@/components/ecommerce/productDetail/ProductDetailCard";
|
||||||
reviewCount?: string;
|
|
||||||
imageSrc: string;
|
export type SortOption = "Newest" | "Price: Low-High" | "Price: High-Low";
|
||||||
imageAlt?: string;
|
|
||||||
|
interface UseProductCatalogOptions {
|
||||||
|
basePath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useProductCatalog = () => {
|
export function useProductCatalog(options: UseProductCatalogOptions = {}) {
|
||||||
const [products, setProducts] = useState<CatalogProduct[]>([]);
|
const { basePath = "/shop" } = options;
|
||||||
const [loading, setLoading] = useState(true);
|
const router = useRouter();
|
||||||
const [error, setError] = useState<string | null>(null);
|
const { products: fetchedProducts, isLoading } = useProducts();
|
||||||
|
|
||||||
useEffect(() => {
|
const [search, setSearch] = useState("");
|
||||||
const fetchProducts = async () => {
|
const [category, setCategory] = useState("All");
|
||||||
try {
|
const [sort, setSort] = useState<SortOption>("Newest");
|
||||||
setLoading(true);
|
|
||||||
const mockProducts: CatalogProduct[] = [
|
const handleProductClick = useCallback((productId: string) => {
|
||||||
{
|
router.push(`${basePath}/${productId}`);
|
||||||
id: "1", category: "Electronics", name: "Laptop Pro", price: "$999.99", rating: 4.5,
|
}, [router, basePath]);
|
||||||
reviewCount: "128", imageSrc: "/products/laptop.jpg", imageAlt: "Laptop Pro"},
|
|
||||||
{
|
const catalogProducts: CatalogProduct[] = useMemo(() => {
|
||||||
id: "2", category: "Electronics", name: "Wireless Mouse", price: "$29.99", rating: 4,
|
if (fetchedProducts.length === 0) return [];
|
||||||
reviewCount: "87", imageSrc: "/products/mouse.jpg", imageAlt: "Wireless Mouse"},
|
|
||||||
];
|
return fetchedProducts.map((product) => ({
|
||||||
setProducts(mockProducts);
|
id: product.id,
|
||||||
setError(null);
|
name: product.name,
|
||||||
} catch (err) {
|
price: product.price,
|
||||||
setError(err instanceof Error ? err.message : "Failed to fetch products");
|
imageSrc: product.imageSrc,
|
||||||
} finally {
|
imageAlt: product.imageAlt || product.name,
|
||||||
setLoading(false);
|
rating: product.rating || 0,
|
||||||
|
reviewCount: product.reviewCount,
|
||||||
|
category: product.brand,
|
||||||
|
onProductClick: () => handleProductClick(product.id),
|
||||||
|
}));
|
||||||
|
}, [fetchedProducts, handleProductClick]);
|
||||||
|
|
||||||
|
const categories = useMemo(() => {
|
||||||
|
const categorySet = new Set<string>();
|
||||||
|
catalogProducts.forEach((product) => {
|
||||||
|
if (product.category) {
|
||||||
|
categorySet.add(product.category);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return Array.from(categorySet).sort();
|
||||||
|
}, [catalogProducts]);
|
||||||
|
|
||||||
|
const filteredProducts = useMemo(() => {
|
||||||
|
let result = catalogProducts;
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
const q = search.toLowerCase();
|
||||||
|
result = result.filter(
|
||||||
|
(p) =>
|
||||||
|
p.name.toLowerCase().includes(q) ||
|
||||||
|
(p.category?.toLowerCase().includes(q) ?? false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category !== "All") {
|
||||||
|
result = result.filter((p) => p.category === category);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sort === "Price: Low-High") {
|
||||||
|
result = [...result].sort(
|
||||||
|
(a, b) =>
|
||||||
|
parseFloat(a.price.replace("$", "").replace(",", "")) -
|
||||||
|
parseFloat(b.price.replace("$", "").replace(",", ""))
|
||||||
|
);
|
||||||
|
} else if (sort === "Price: High-Low") {
|
||||||
|
result = [...result].sort(
|
||||||
|
(a, b) =>
|
||||||
|
parseFloat(b.price.replace("$", "").replace(",", "")) -
|
||||||
|
parseFloat(a.price.replace("$", "").replace(",", ""))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, [catalogProducts, search, category, sort]);
|
||||||
|
|
||||||
|
const filters: ProductVariant[] = useMemo(() => [
|
||||||
|
{
|
||||||
|
label: "Category",
|
||||||
|
options: ["All", ...categories],
|
||||||
|
selected: category,
|
||||||
|
onChange: setCategory,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Sort",
|
||||||
|
options: ["Newest", "Price: Low-High", "Price: High-Low"] as SortOption[],
|
||||||
|
selected: sort,
|
||||||
|
onChange: (value) => setSort(value as SortOption),
|
||||||
|
},
|
||||||
|
], [categories, category, sort]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
products: filteredProducts,
|
||||||
|
isLoading,
|
||||||
|
search,
|
||||||
|
setSearch,
|
||||||
|
category,
|
||||||
|
setCategory,
|
||||||
|
sort,
|
||||||
|
setSort,
|
||||||
|
filters,
|
||||||
|
categories,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
fetchProducts();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return { products, loading, error };
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useProductCatalog;
|
|
||||||
|
|||||||
@@ -1,46 +1,196 @@
|
|||||||
import { useState, useEffect } from "react";
|
"use client";
|
||||||
|
|
||||||
interface ProductDetail {
|
import { useState, useMemo, useCallback } from "react";
|
||||||
id: string;
|
import { useProduct } from "./useProduct";
|
||||||
name: string;
|
import type { Product } from "@/lib/api/product";
|
||||||
price: string;
|
import type { ProductVariant } from "@/components/ecommerce/productDetail/ProductDetailCard";
|
||||||
description: string;
|
import type { ExtendedCartItem } from "./useCart";
|
||||||
imageSrc: string;
|
|
||||||
imageAlt?: string;
|
interface ProductImage {
|
||||||
rating: number;
|
src: string;
|
||||||
reviewCount?: string;
|
alt: string;
|
||||||
inStock: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const useProductDetail = (productId: string) => {
|
interface ProductMeta {
|
||||||
const [product, setProduct] = useState<ProductDetail | null>(null);
|
salePrice?: string;
|
||||||
const [loading, setLoading] = useState(true);
|
ribbon?: string;
|
||||||
const [error, setError] = useState<string | null>(null);
|
inventoryStatus?: string;
|
||||||
|
inventoryQuantity?: number;
|
||||||
|
sku?: string;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
export function useProductDetail(productId: string) {
|
||||||
const fetchProduct = async () => {
|
const { product, isLoading, error } = useProduct(productId);
|
||||||
|
const [selectedQuantity, setSelectedQuantity] = useState(1);
|
||||||
|
const [selectedVariants, setSelectedVariants] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
|
const images = useMemo<ProductImage[]>(() => {
|
||||||
|
if (!product) return [];
|
||||||
|
|
||||||
|
if (product.images && product.images.length > 0) {
|
||||||
|
return product.images.map((src, index) => ({
|
||||||
|
src,
|
||||||
|
alt: product.imageAlt || `${product.name} - Image ${index + 1}`,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return [{
|
||||||
|
src: product.imageSrc,
|
||||||
|
alt: product.imageAlt || product.name,
|
||||||
|
}];
|
||||||
|
}, [product]);
|
||||||
|
|
||||||
|
const meta = useMemo<ProductMeta>(() => {
|
||||||
|
if (!product?.metadata) return {};
|
||||||
|
|
||||||
|
const metadata = product.metadata;
|
||||||
|
|
||||||
|
let salePrice: string | undefined;
|
||||||
|
const onSaleValue = metadata.onSale;
|
||||||
|
const onSale = String(onSaleValue) === "true" || onSaleValue === 1 || String(onSaleValue) === "1";
|
||||||
|
const salePriceValue = metadata.salePrice;
|
||||||
|
|
||||||
|
if (onSale && salePriceValue !== undefined && salePriceValue !== null) {
|
||||||
|
if (typeof salePriceValue === 'number') {
|
||||||
|
salePrice = `$${salePriceValue.toFixed(2)}`;
|
||||||
|
} else {
|
||||||
|
const salePriceStr = String(salePriceValue);
|
||||||
|
salePrice = salePriceStr.startsWith('$') ? salePriceStr : `$${salePriceStr}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let inventoryQuantity: number | undefined;
|
||||||
|
if (metadata.inventoryQuantity !== undefined) {
|
||||||
|
const qty = metadata.inventoryQuantity;
|
||||||
|
inventoryQuantity = typeof qty === 'number' ? qty : parseInt(String(qty), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
salePrice,
|
||||||
|
ribbon: metadata.ribbon ? String(metadata.ribbon) : undefined,
|
||||||
|
inventoryStatus: metadata.inventoryStatus ? String(metadata.inventoryStatus) : undefined,
|
||||||
|
inventoryQuantity,
|
||||||
|
sku: metadata.sku ? String(metadata.sku) : undefined,
|
||||||
|
};
|
||||||
|
}, [product]);
|
||||||
|
|
||||||
|
const variants = useMemo<ProductVariant[]>(() => {
|
||||||
|
if (!product) return [];
|
||||||
|
|
||||||
|
const variantList: ProductVariant[] = [];
|
||||||
|
|
||||||
|
if (product.metadata?.variantOptions) {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
const variantOptionsStr = String(product.metadata.variantOptions);
|
||||||
const mockProduct: ProductDetail = {
|
const parsedOptions = JSON.parse(variantOptionsStr);
|
||||||
id: productId,
|
|
||||||
name: "Sample Product", price: "$99.99", description: "A great product with excellent features", imageSrc: "/products/sample.jpg", imageAlt: "Sample Product", rating: 4.5,
|
if (Array.isArray(parsedOptions)) {
|
||||||
reviewCount: "42", inStock: true,
|
parsedOptions.forEach((option: any) => {
|
||||||
};
|
if (option.name && option.values) {
|
||||||
setProduct(mockProduct);
|
const values = typeof option.values === 'string'
|
||||||
setError(null);
|
? option.values.split(',').map((v: string) => v.trim())
|
||||||
} catch (err) {
|
: Array.isArray(option.values)
|
||||||
setError(err instanceof Error ? err.message : "Failed to fetch product");
|
? option.values.map((v: any) => String(v).trim())
|
||||||
} finally {
|
: [String(option.values)];
|
||||||
setLoading(false);
|
|
||||||
|
if (values.length > 0) {
|
||||||
|
const optionLabel = option.name;
|
||||||
|
const currentSelected = selectedVariants[optionLabel] || values[0];
|
||||||
|
|
||||||
|
variantList.push({
|
||||||
|
label: optionLabel,
|
||||||
|
options: values,
|
||||||
|
selected: currentSelected,
|
||||||
|
onChange: (value) => {
|
||||||
|
setSelectedVariants((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[optionLabel]: value,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Failed to parse variantOptions:", error);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if (productId) {
|
|
||||||
fetchProduct();
|
|
||||||
}
|
}
|
||||||
}, [productId]);
|
|
||||||
|
|
||||||
return { product, loading, error };
|
if (variantList.length === 0 && product.brand) {
|
||||||
|
variantList.push({
|
||||||
|
label: "Brand",
|
||||||
|
options: [product.brand],
|
||||||
|
selected: product.brand,
|
||||||
|
onChange: () => { },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variantList.length === 0 && product.variant) {
|
||||||
|
const variantOptions = product.variant.includes('/')
|
||||||
|
? product.variant.split('/').map(v => v.trim())
|
||||||
|
: [product.variant];
|
||||||
|
|
||||||
|
const variantLabel = "Variant";
|
||||||
|
const currentSelected = selectedVariants[variantLabel] || variantOptions[0];
|
||||||
|
|
||||||
|
variantList.push({
|
||||||
|
label: variantLabel,
|
||||||
|
options: variantOptions,
|
||||||
|
selected: currentSelected,
|
||||||
|
onChange: (value) => {
|
||||||
|
setSelectedVariants((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[variantLabel]: value,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return variantList;
|
||||||
|
}, [product, selectedVariants]);
|
||||||
|
|
||||||
|
const quantityVariant = useMemo<ProductVariant>(() => ({
|
||||||
|
label: "Quantity",
|
||||||
|
options: Array.from({ length: 10 }, (_, i) => String(i + 1)),
|
||||||
|
selected: String(selectedQuantity),
|
||||||
|
onChange: (value) => setSelectedQuantity(parseInt(value, 10)),
|
||||||
|
}), [selectedQuantity]);
|
||||||
|
|
||||||
|
const createCartItem = useCallback((): ExtendedCartItem | null => {
|
||||||
|
if (!product) return null;
|
||||||
|
|
||||||
|
const variantStrings = Object.entries(selectedVariants).map(
|
||||||
|
([label, value]) => `${label}: ${value}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (variantStrings.length === 0 && product.variant) {
|
||||||
|
variantStrings.push(`Variant: ${product.variant}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const variantId = Object.values(selectedVariants).join('-') || 'default';
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: `${product.id}-${variantId}-${selectedQuantity}`,
|
||||||
|
productId: product.id,
|
||||||
|
name: product.name,
|
||||||
|
variants: variantStrings,
|
||||||
|
price: product.price,
|
||||||
|
quantity: selectedQuantity,
|
||||||
|
imageSrc: product.imageSrc,
|
||||||
|
imageAlt: product.imageAlt || product.name,
|
||||||
};
|
};
|
||||||
|
}, [product, selectedVariants, selectedQuantity]);
|
||||||
|
|
||||||
export default useProductDetail;
|
return {
|
||||||
|
product,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
images,
|
||||||
|
meta,
|
||||||
|
variants,
|
||||||
|
quantityVariant,
|
||||||
|
selectedQuantity,
|
||||||
|
selectedVariants,
|
||||||
|
createCartItem,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,36 +1,39 @@
|
|||||||
import { useState, useEffect } from 'react';
|
"use client";
|
||||||
|
|
||||||
interface Product {
|
import { useEffect, useState } from "react";
|
||||||
id: string;
|
import { Product, fetchProducts } from "@/lib/api/product";
|
||||||
name: string;
|
|
||||||
price: string;
|
|
||||||
imageSrc: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useProducts() {
|
export function useProducts() {
|
||||||
const [products, setProducts] = useState<Product[]>([]);
|
const [products, setProducts] = useState<Product[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<Error | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchProducts = async () => {
|
let isMounted = true;
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
// Simulate fetch
|
|
||||||
const response = await fetch('/api/products');
|
|
||||||
const data = await response.json();
|
|
||||||
setProducts(data);
|
|
||||||
setError(null);
|
|
||||||
} catch (err) {
|
|
||||||
setError('Failed to fetch products');
|
|
||||||
setProducts([]);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchProducts();
|
async function loadProducts() {
|
||||||
|
try {
|
||||||
|
const data = await fetchProducts();
|
||||||
|
if (isMounted) {
|
||||||
|
setProducts(data);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (isMounted) {
|
||||||
|
setError(err instanceof Error ? err : new Error("Failed to fetch products"));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (isMounted) {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadProducts();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMounted = false;
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return { products, loading, error };
|
return { products, isLoading, error };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,219 @@
|
|||||||
export interface Product {
|
export type Product = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
price: string;
|
price: string;
|
||||||
imageSrc: string;
|
imageSrc: string;
|
||||||
imageAlt?: string;
|
imageAlt?: string;
|
||||||
|
images?: string[];
|
||||||
|
brand?: string;
|
||||||
|
variant?: string;
|
||||||
|
rating?: number;
|
||||||
|
reviewCount?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
priceId?: string;
|
||||||
|
metadata?: {
|
||||||
|
[key: string]: string | number | undefined;
|
||||||
|
};
|
||||||
|
onFavorite?: () => void;
|
||||||
|
onProductClick?: () => void;
|
||||||
|
isFavorited?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultProducts: Product[] = [
|
||||||
|
{
|
||||||
|
id: "1",
|
||||||
|
name: "Classic White Sneakers",
|
||||||
|
price: "$129",
|
||||||
|
brand: "Nike",
|
||||||
|
variant: "White / Size 42",
|
||||||
|
rating: 4.5,
|
||||||
|
reviewCount: "128",
|
||||||
|
imageSrc: "https://webuild-dev.s3.eu-north-1.amazonaws.com/default/placeholder3.avif",
|
||||||
|
imageAlt: "Classic white sneakers",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "2",
|
||||||
|
name: "Leather Crossbody Bag",
|
||||||
|
price: "$89",
|
||||||
|
brand: "Coach",
|
||||||
|
variant: "Brown / Medium",
|
||||||
|
rating: 4.8,
|
||||||
|
reviewCount: "256",
|
||||||
|
imageSrc: "https://webuild-dev.s3.eu-north-1.amazonaws.com/default/placeholder4.webp",
|
||||||
|
imageAlt: "Brown leather crossbody bag",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "3",
|
||||||
|
name: "Wireless Headphones",
|
||||||
|
price: "$199",
|
||||||
|
brand: "Sony",
|
||||||
|
variant: "Black",
|
||||||
|
rating: 4.7,
|
||||||
|
reviewCount: "512",
|
||||||
|
imageSrc: "https://webuild-dev.s3.eu-north-1.amazonaws.com/default/placeholder3.avif",
|
||||||
|
imageAlt: "Black wireless headphones",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "4",
|
||||||
|
name: "Minimalist Watch",
|
||||||
|
price: "$249",
|
||||||
|
brand: "Fossil",
|
||||||
|
variant: "Silver / 40mm",
|
||||||
|
rating: 4.6,
|
||||||
|
reviewCount: "89",
|
||||||
|
imageSrc: "https://webuild-dev.s3.eu-north-1.amazonaws.com/default/placeholder4.webp",
|
||||||
|
imageAlt: "Silver minimalist watch",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
function formatPrice(amount: number, currency: string): string {
|
||||||
|
const formatter = new Intl.NumberFormat("en-US", {
|
||||||
|
style: "currency",
|
||||||
|
currency: currency.toUpperCase(),
|
||||||
|
minimumFractionDigits: 0,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
});
|
||||||
|
return formatter.format(amount / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchProducts(): Promise<Product[]> {
|
export async function fetchProducts(): Promise<Product[]> {
|
||||||
try {
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
|
||||||
const response = await fetch('/api/products');
|
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch products');
|
if (!apiUrl || !projectId) {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
return response.json();
|
|
||||||
|
try {
|
||||||
|
const url = `${apiUrl}/stripe/project/products?projectId=${projectId}&expandDefaultPrice=true`;
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = await response.json();
|
||||||
|
const data = resp.data.data || resp.data;
|
||||||
|
|
||||||
|
if (!Array.isArray(data) || data.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.map((product: any) => {
|
||||||
|
const metadata: Record<string, string | number | undefined> = {};
|
||||||
|
if (product.metadata && typeof product.metadata === 'object') {
|
||||||
|
Object.keys(product.metadata).forEach(key => {
|
||||||
|
const value = product.metadata[key];
|
||||||
|
if (value !== null && value !== undefined) {
|
||||||
|
const numValue = parseFloat(value);
|
||||||
|
metadata[key] = isNaN(numValue) ? value : numValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const imageSrc = product.images?.[0] || product.imageSrc || "https://webuild-dev.s3.eu-north-1.amazonaws.com/default/placeholder3.avif";
|
||||||
|
const imageAlt = product.imageAlt || product.name || "";
|
||||||
|
const images = product.images && Array.isArray(product.images) && product.images.length > 0
|
||||||
|
? product.images
|
||||||
|
: [imageSrc];
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: product.id || String(Math.random()),
|
||||||
|
name: product.name || "Untitled Product",
|
||||||
|
description: product.description || "",
|
||||||
|
price: product.default_price?.unit_amount
|
||||||
|
? formatPrice(product.default_price.unit_amount, product.default_price.currency || "usd")
|
||||||
|
: product.price || "$0",
|
||||||
|
priceId: product.default_price?.id || product.priceId,
|
||||||
|
imageSrc,
|
||||||
|
imageAlt,
|
||||||
|
images,
|
||||||
|
brand: product.metadata?.brand || product.brand || "",
|
||||||
|
variant: product.metadata?.variant || product.variant || "",
|
||||||
|
rating: product.metadata?.rating ? parseFloat(product.metadata.rating) : undefined,
|
||||||
|
reviewCount: product.metadata?.reviewCount || undefined,
|
||||||
|
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
||||||
|
};
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching products:', error);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchProduct(productId: string): Promise<Product | null> {
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
|
||||||
|
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;
|
||||||
|
|
||||||
|
if (!apiUrl || !projectId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = `${apiUrl}/stripe/project/products/${productId}?projectId=${projectId}&expandDefaultPrice=true`;
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = await response.json();
|
||||||
|
const product = resp.data?.data || resp.data || resp;
|
||||||
|
|
||||||
|
if (!product || typeof product !== 'object') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const metadata: Record<string, string | number | undefined> = {};
|
||||||
|
if (product.metadata && typeof product.metadata === 'object') {
|
||||||
|
Object.keys(product.metadata).forEach(key => {
|
||||||
|
const value = product.metadata[key];
|
||||||
|
if (value !== null && value !== undefined && value !== '') {
|
||||||
|
const numValue = parseFloat(String(value));
|
||||||
|
metadata[key] = isNaN(numValue) ? String(value) : numValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let priceValue = product.price;
|
||||||
|
if (!priceValue && product.default_price?.unit_amount) {
|
||||||
|
priceValue = formatPrice(product.default_price.unit_amount, product.default_price.currency || "usd");
|
||||||
|
}
|
||||||
|
if (!priceValue) {
|
||||||
|
priceValue = "$0";
|
||||||
|
}
|
||||||
|
|
||||||
|
const imageSrc = product.images?.[0] || product.imageSrc || "https://webuild-dev.s3.eu-north-1.amazonaws.com/default/placeholder3.avif";
|
||||||
|
const imageAlt = product.imageAlt || product.name || "";
|
||||||
|
const images = product.images && Array.isArray(product.images) && product.images.length > 0
|
||||||
|
? product.images
|
||||||
|
: [imageSrc];
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: product.id || String(Math.random()),
|
||||||
|
name: product.name || "Untitled Product",
|
||||||
|
description: product.description || "",
|
||||||
|
price: priceValue,
|
||||||
|
priceId: product.default_price?.id || product.priceId,
|
||||||
|
imageSrc,
|
||||||
|
imageAlt,
|
||||||
|
images,
|
||||||
|
brand: product.metadata?.brand || product.brand || "",
|
||||||
|
variant: product.metadata?.variant || product.variant || "",
|
||||||
|
rating: product.metadata?.rating ? parseFloat(String(product.metadata.rating)) : undefined,
|
||||||
|
reviewCount: product.metadata?.reviewCount || undefined,
|
||||||
|
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user