Initial commit

This commit is contained in:
DK
2026-02-09 16:35:03 +00:00
commit b4ffc30cf1
656 changed files with 77229 additions and 0 deletions

106
src/lib/api/blog.ts Normal file
View File

@@ -0,0 +1,106 @@
export type BlogPost = {
id: string;
category: string;
title: string;
excerpt: string;
imageSrc: string;
imageAlt?: string;
authorName: string;
authorAvatar: string;
date: string;
onBlogClick?: () => void;
};
export const defaultPosts: BlogPost[] = [
{
id: "1",
category: "Design",
title: "UX review presentations",
excerpt: "How do you create compelling presentations that wow your colleagues and impress your managers?",
imageSrc: "/placeholders/placeholder3.avif",
imageAlt: "Abstract design with purple and silver tones",
authorName: "Olivia Rhye",
authorAvatar: "/placeholders/placeholder3.avif",
date: "20 Jan 2025",
},
{
id: "2",
category: "Development",
title: "Building scalable applications",
excerpt: "Learn the best practices for building applications that can handle millions of users.",
imageSrc: "/placeholders/placeholder4.webp",
imageAlt: "Development workspace",
authorName: "John Smith",
authorAvatar: "/placeholders/placeholder4.webp",
date: "18 Jan 2025",
},
{
id: "3",
category: "Marketing",
title: "Content strategy essentials",
excerpt: "Discover how to create a content strategy that drives engagement and conversions.",
imageSrc: "/placeholders/placeholder3.avif",
imageAlt: "Marketing strategy board",
authorName: "Sarah Johnson",
authorAvatar: "/placeholders/placeholder3.avif",
date: "15 Jan 2025",
},
{
id: "4",
category: "Product",
title: "Product management 101",
excerpt: "Everything you need to know to become an effective product manager in 2025.",
imageSrc: "/placeholders/placeholder4.webp",
imageAlt: "Product planning session",
authorName: "Mike Davis",
authorAvatar: "/placeholders/placeholder4.webp",
date: "12 Jan 2025",
},
];
export async function fetchBlogPosts(): Promise<BlogPost[]> {
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;
if (!apiUrl || !projectId) {
console.warn("NEXT_PUBLIC_API_URL or NEXT_PUBLIC_PROJECT_ID not configured");
return [];
}
try {
const url = `${apiUrl}/posts/${projectId}?status=published`;
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
console.warn(`API request failed with status ${response.status}`);
return [];
}
const resp = await response.json();
const data = resp.data;
if (!Array.isArray(data) || data.length === 0) {
return [];
}
return data.map((post: any) => ({
id: post.id || String(Math.random()),
category: post.category || "General",
title: post.title || "Untitled",
excerpt: post.excerpt || post.content?.slice(0, 30) || "",
imageSrc: post.imageUrl || "/placeholders/placeholder3.avif",
imageAlt: post.imageAlt || post.title || "",
authorName: post.author?.name || "Anonymous",
authorAvatar: post.author?.avatar || "/placeholders/placeholder3.avif",
date: post.date || post.createdAt || new Date().toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" }),
}));
} catch (error) {
console.error("Error fetching posts:", error);
return [];
}
}

219
src/lib/api/product.ts Normal file
View File

@@ -0,0 +1,219 @@
export type Product = {
id: string;
name: string;
price: string;
imageSrc: string;
imageAlt?: string;
images?: string[];
brand?: string;
variant?: string;
rating?: number;
reviewCount?: 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: "/placeholders/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: "/placeholders/placeholder4.webp",
imageAlt: "Brown leather crossbody bag",
},
{
id: "3",
name: "Wireless Headphones",
price: "$199",
brand: "Sony",
variant: "Black",
rating: 4.7,
reviewCount: "512",
imageSrc: "/placeholders/placeholder3.avif",
imageAlt: "Black wireless headphones",
},
{
id: "4",
name: "Minimalist Watch",
price: "$249",
brand: "Fossil",
variant: "Silver / 40mm",
rating: 4.6,
reviewCount: "89",
imageSrc: "/placeholders/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[]> {
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;
if (!apiUrl || !projectId) {
return [];
}
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 || "/placeholders/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) {
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 || "/placeholders/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;
}
}

114
src/lib/buttonUtils.ts Normal file
View File

@@ -0,0 +1,114 @@
import { cls } from "./utils";
import { hasBgClassName } from "@/components/button/types";
import type { CTAButtonVariant, ButtonPropsForVariant } from "@/components/button/types";
import type { ButtonConfig } from "@/types/button";
export const getButtonProps = (
button: ButtonConfig,
index: number,
variant: CTAButtonVariant,
buttonClassName?: string,
buttonTextClassName?: string
): ButtonPropsForVariant<CTAButtonVariant> => {
const isPrimary = index === 0;
const buttonBgClass = isPrimary ? "primary-button" : "secondary-button";
const buttonTextClass = isPrimary ? "" : "text-foreground";
// Base props shared by all variants
const baseProps = {
text: button.text,
variant,
href: button.href,
onClick: button.onClick,
};
// directional-hover variant (needs circleClassName handling)
if (variant === "directional-hover") {
const circleClass = isPrimary ? "bg-foreground" : "bg-foreground/5";
const { bgClassName, textClassName, circleClassName } = (button.props || {}) as { bgClassName?: string; textClassName?: string; circleClassName?: string };
return {
...button.props,
...baseProps,
className: cls(buttonTextClass, buttonClassName, button.props?.className),
bgClassName: cls(buttonBgClass, bgClassName),
textClassName: cls(buttonTextClassName, textClassName),
circleClassName: cls(circleClass, circleClassName),
} as ButtonPropsForVariant<CTAButtonVariant>;
}
// Variants with bgClassName (text-stagger, shift-hover, bounce-effect)
if (hasBgClassName(variant)) {
const { bgClassName, textClassName } = (button.props || {}) as { bgClassName?: string; textClassName?: string };
return {
...button.props,
...baseProps,
className: cls(buttonTextClass, buttonClassName, button.props?.className),
bgClassName: cls(buttonBgClass, bgClassName),
textClassName: cls(buttonTextClassName, textClassName),
} as ButtonPropsForVariant<CTAButtonVariant>;
}
// icon-arrow variant
if (variant === "icon-arrow") {
const iconBgClass = isPrimary ? "secondary-button text-foreground" : "primary-button text-background";
const { textClassName, iconClassName } = (button.props || {}) as { textClassName?: string; iconClassName?: string };
return {
...button.props,
...baseProps,
className: cls(buttonBgClass, buttonTextClass, buttonClassName, button.props?.className),
textClassName: cls(buttonTextClassName, textClassName),
iconClassName: cls(iconBgClass, iconClassName),
} as ButtonPropsForVariant<CTAButtonVariant>;
}
// expand-hover variant
if (variant === "expand-hover") {
const iconBgClass = isPrimary ? "secondary-button" : "primary-button";
const iconTextClass = isPrimary ? "text-foreground" : "text-background";
const hoverTextClass = isPrimary ? "md:group-hover:text-foreground" : "md:group-hover:text-background";
const { textClassName, iconClassName, iconBgClassName } = (button.props || {}) as { textClassName?: string; iconClassName?: string; iconBgClassName?: string };
return {
...button.props,
...baseProps,
className: cls(buttonBgClass, buttonTextClass, buttonClassName, button.props?.className),
textClassName: cls(hoverTextClass, buttonTextClassName, textClassName),
iconClassName: cls(iconTextClass, iconClassName),
iconBgClassName: cls(iconBgClass, iconBgClassName),
} as ButtonPropsForVariant<CTAButtonVariant>;
}
// hover-bubble variant
if (variant === "hover-bubble") {
const iconBgClass = isPrimary ? "secondary-button text-foreground" : "primary-button text-background";
const baseTextClass = isPrimary ? "text-background" : "text-foreground";
const { bgClassName, textClassName, iconClassName } = (button.props || {}) as { bgClassName?: string; textClassName?: string; iconClassName?: string };
return {
...button.props,
...baseProps,
className: cls(buttonClassName, button.props?.className),
bgClassName: cls(buttonBgClass, bgClassName),
textClassName: cls(baseTextClass, buttonTextClassName, textClassName),
iconClassName: cls(iconBgClass, iconClassName),
} as ButtonPropsForVariant<CTAButtonVariant>;
}
// slide-background variant
if (variant === "slide-background") {
const baseTextClass = isPrimary ? "" : "text-foreground";
const { textClassName } = (button.props || {}) as { textClassName?: string };
return {
...button.props,
...baseProps,
className: cls(buttonBgClass, buttonClassName, button.props?.className),
textClassName: cls(baseTextClass, buttonTextClassName, textClassName),
} as ButtonPropsForVariant<CTAButtonVariant>;
}
// hover-magnetic variant (default fallback)
return {
...button.props,
...baseProps,
className: cls(buttonBgClass, buttonTextClass, buttonClassName, button.props?.className),
textClassName: cls(buttonTextClassName, buttonTextClass),
} as ButtonPropsForVariant<CTAButtonVariant>;
};

20
src/lib/utils.ts Normal file
View File

@@ -0,0 +1,20 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import type { CardStyleVariant } from "@/providers/themeProvider/config/types";
export function cn(...inputs: (string | undefined | null | false)[]) {
return inputs.filter(Boolean).join(" ");
}
export function cls(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
// Check if text should use inverted color based on cardStyle
export function shouldUseInvertedText(useInvertedBackground: "noInvert" | "invertDefault" | undefined, cardStyle: CardStyleVariant): boolean {
if (!useInvertedBackground || useInvertedBackground === "noInvert") return false;
const lightCardStyles: CardStyleVariant[] = [];
return lightCardStyles.includes(cardStyle);
}