"use client"; import { useState, useEffect } from "react"; import Image from "next/image"; import UploadArea from "@/components/UploadArea"; import { useAuth } from "@/lib/auth-context"; import { NavigationMenu, NavigationMenuList, NavigationMenuItem, NavigationMenuLink, } from "@/components/ui/navigation-menu"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { ChevronDownIcon } from "lucide-react"; export default function Home() { const { isAuthenticated, user, logout } = useAuth(); const [showSuccess, setShowSuccess] = useState(false); const [userSubscription, setUserSubscription] = useState(null); // Check for success message in URL useEffect(() => { if (typeof window !== "undefined") { const urlParams = new URLSearchParams(window.location.search); if (urlParams.get("success") === "true") { setShowSuccess(true); // Remove the query parameter from URL window.history.replaceState({}, "", window.location.pathname); // Hide after 5 seconds setTimeout(() => setShowSuccess(false), 5000); } } }, []); // Fetch user subscription when authenticated useEffect(() => { const fetchUserSubscription = async () => { if (!isAuthenticated || !user?.id) return; try { const response = await fetch("/api/subscriptions/me", { headers: { "user-id": user.id, }, }); if (response.ok) { const data = await response.json(); setUserSubscription(data.subscription); } } catch (error) { console.error("Error fetching subscription:", error); } }; fetchUserSubscription(); }, [isAuthenticated, user]); // Get user initials for the circle icon const getUserInitials = () => { if (!user) return "U"; const firstName = user.FirstName || ""; const lastName = user.LastName || ""; return (firstName.charAt(0) + lastName.charAt(0)).toUpperCase() || "U"; }; // Handle subscription button click const handleSubscribe = async (tier: string) => { if (!isAuthenticated) { // Redirect to login window.location.href = "/login?redirect=/"; return; } // Check if user already has an active subscription if (userSubscription && userSubscription.status === "ACTIVE") { alert( "You already have an active subscription. Please manage it from the My Subscriptions page." ); return; } // Show loading state setLoading(true); try { const response = await fetch("/api/create-checkout-session", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ tier, userId: user?.id, }), }); // Check if response is JSON before parsing const contentType = response.headers.get("content-type"); if (!contentType || !contentType.includes("application/json")) { throw new Error( "Invalid response from server. Please check your Stripe configuration." ); } const data = await response.json(); if (!response.ok) { const errorMessage = data.error || "Failed to create checkout session"; console.error("Payment API error:", errorMessage); alert(errorMessage); setLoading(false); return; } // Redirect to Stripe Checkout if (data.url) { window.location.href = data.url; } else { alert("No checkout URL received"); setLoading(false); } } catch (error) { console.error("Payment error:", error); alert("Failed to start payment process. Please try again."); setLoading(false); } }; const [loading, setLoading] = useState(false); return (
{/* Success Message Banner */} {showSuccess && (
Subscription successful! Welcome to Reya Render.
)} {/* Sticky Navigation */} {/* Main Content */}

Welcome to reYa Render

Whether you're working on animations, visualizations, or still images, our render farm is optimized to deliver high-quality results efficiently. Simply upload your files, and our system will take care of the rendering process, saving you time and computing power so you can focus on the creative side of your work.

3D Model
{/* Subscription Status Indicator */} {isAuthenticated && userSubscription && userSubscription.status === "ACTIVE" && (

✓ You have an active {userSubscription.tier} subscription

Member since{" "} {new Date(userSubscription.created_at).toLocaleDateString()}

Manage Subscription
)} {/* Pricing Section */}

Available Plans

{/* Basic Plan */}
Basic
€9.99{" "} /month
  • 250 GB storage
  • Custom subdomain
  • Unlimited downloads
  • Password protected links
  • Basic analytics
{/* Standard Plan */}
Standard
€19.99{" "} /month
  • 500 GB storage
  • Custom subdomain
  • Unlimited downloads
  • Password protected links
  • Basic analytics
  • Custom branding & logo
  • Priority support
{/* Premium Plan */}
Premium
€39.99{" "} /month
  • 1 TB storage
  • Custom subdomain
  • Unlimited downloads
  • Password protected links
  • Basic analytics
  • Custom branding & logo
  • Priority support
  • Multiple user accounts
  • Team management
); }