"use client"; import React, { useEffect, useState } from "react"; import { useSearchParams, useRouter } from "next/navigation"; import axios from "axios"; import { ApiServerBaseUrl } from "@/utils/baseurl.utils"; import { Instagram, BarChart3, MessageSquare, Shield, CheckCircle, Zap, Users, Clock } from "lucide-react"; type Status = | "checking" | "not_connected" | "finalizing" | "connected" | "error"; const SocialMediaConnect = () => { const [status, setStatus] = useState("checking"); const [error, setError] = useState(null); const searchParams = useSearchParams(); const router = useRouter(); // ---------------------- CHECK STATUS + FINALIZE AUTH ---------------------- useEffect(() => { async function checkStatus() { try { setError(null); setStatus("checking"); const userId = localStorage.getItem("user_email"); const res = await axios.get( `${ApiServerBaseUrl}/social/auth/status`, { params: { userId }, withCredentials: true } ); if (res.data.connected) { setStatus("connected"); } else { setStatus("not_connected"); } } catch (err: any) { console.error(err); setError("Failed to load status"); setStatus("error"); } } async function finalizeAuth(authToken: string) { try { setStatus("finalizing"); setError(null); const userId = localStorage.getItem("user_email"); const res = await axios.post( `${ApiServerBaseUrl}/social/auth/save-oauth`, { auth: authToken, userId }, { withCredentials: true } ); if (!res.data.ok) throw new Error("Failed to finalize auth"); const url = new URL(window.location.href); url.searchParams.delete("auth"); router.replace(url.pathname); await checkStatus(); } catch (err: any) { console.error(err); setError("Error finalizing connection"); setStatus("error"); } } async function init() { const auth = searchParams.get("auth"); if (auth) { await finalizeAuth(auth); } else { await checkStatus(); } } init(); }, [searchParams, router]); // ---------------------- DISCONNECT FB ACCOUNT ---------------------- const handleDisconnect = async () => { try { const userId = localStorage.getItem("user_email"); const res = await axios.post( `${ApiServerBaseUrl}/social/auth/disconnect`, { userId }, { withCredentials: true } ); if (res.data.ok) { setStatus("not_connected"); } } catch (err: any) { console.error(err); setError("Failed to remove connected account"); setStatus("error"); } }; // ---------------------- CONNECT BUTTON ---------------------- const handleConnect = () => { window.location.href = `${ApiServerBaseUrl}/social/auth/login`; }; // ---------------------- PAYMENT SESSION VALIDATION ---------------------- useEffect(() => { const storedUser = localStorage.getItem("userDetails"); if (!storedUser) return; const user = JSON.parse(storedUser); const role = user?.role; if (role === "admin" || role === "partner") { return; } const session = localStorage.getItem("payment_session"); if (role === "customer" && !session) { router.push("/pricing"); } }, [router]); // User-friendly features list const features = [ { icon: , title: "View Instagram Profile & Posts", description: "See your Instagram profile details and browse your published posts directly inside Social Buddy." }, { icon: , title: "Track Performance Insights", description: "Monitor key metrics like reach, impressions, and engagement to understand how your content is performing." }, { icon: , title: "Manage Comments Easily", description: "Reply to comments, hide inappropriate messages, or remove spam — all from one centralized place." } ]; // Benefits list const benefits = [ { icon: , text: "One dashboard for posts, insights, and comments" }, { icon: , text: "Saves time managing Instagram engagement" }, { icon: , text: "Helps you respond faster to your audience" }, { icon: , text: "Designed for businesses, creators, and agencies" } ]; return (
{/* Floating background bubbles */}
{/* Main Container */}
{/* Header Section */}

Social Buddy

Connect your Facebook and Instagram accounts to manage your posts, track performance, and handle comments — all from one simple dashboard.

{/* Left Column - Connection Status */}
{/* Connection Card */}

Connection Status

{/* Status Display */}
{status === "checking" && ( <>

Checking connection status...

)} {status === "finalizing" && ( <>

Finalizing connection...

)} {status === "connected" && ( <>

Instagram & Facebook connected successfully

Your accounts are linked and ready to use.

)} {status === "not_connected" && ( <>

No Facebook account connected

)} {status === "error" && ( <>

{error || "Connection error occurred"}

)}
{/* Action Buttons */}
{status === "not_connected" && ( )} {status === "connected" && ( <>

You can disconnect and reconnect your account anytime. Disconnecting will revoke Social Buddy's access to your Instagram data.

)}
{/* Features Grid */}

What You Can Do with Social Buddy

Social Buddy helps you stay on top of your Instagram presence without switching between apps.

{features.map((feature, index) => (
{feature.icon}

{feature.title}

{feature.description}

))}
{/* Privacy & Control Section */}

Privacy & Control

Social Buddy only accesses data needed to provide these features. All actions are performed manually by you, and you can disconnect your account at any time.

No automation — you stay fully in control
{/* Right Column - Benefits & Info */}
{/* Benefits Card */}

Why Use Social Buddy?

{benefits.map((benefit, index) => (
{benefit.icon}

{benefit.text}

))}
{/* Stats Preview */}
1
Dashboard
3
Core Features
{/* Quick Start Guide */}

Get Started in 3 Steps

  1. 1
    Click "Connect Instagram Account"
  2. 2
    Log in with your Facebook account
  3. 3
    Select your Instagram account and permissions
{/* Footer Note */}

© 2026 SocialBuddy. All rights reserved.

Powered by MetatronCube · Privacy Policy · Terms of Use

{/* Animation Styles */}
); }; export default SocialMediaConnect;