Files
adnexus/assets/Dashboard-DH4gv-qP.js
2026-09-20 08:53:09 -07:00

2 lines
15 KiB
JavaScript

import{r,j as e}from"./ui-SA1K2VdO.js";import{s as m}from"./client-Cs5qpnPJ.js";import{u as ee,B as u,C as p,d as h,a as N,b as w,c as S}from"./index-BBRaFEzF.js";import{I as v}from"./input-jTrHrzjY.js";import{T as V}from"./textarea-DFLoQ_kC.js";import{S as k,a as C,b as A,c as E,d as c}from"./select-CLfuir-h.js";import{b as se,c as te}from"./vendor-khT4bKqW.js";import{L as ae,D as F,z as q,E as P,b as re,H as ie,J as ne,K as ce}from"./utils-BOogt4zp.js";const be=()=>{const x=se(),[M]=te(),{toast:l}=ee(),[b,D]=r.useState(null),[d,z]=r.useState(null),[i,W]=r.useState(null),[O,X]=r.useState(!0),[f,I]=r.useState(!1),[T,B]=r.useState(!1),[g,$]=r.useState({subscribed:!1,subscription_status:"inactive"}),[L,H]=r.useState(0),[a,o]=r.useState({platform_type:"",company_name:"",website_url:"",monthly_volume:"",business_description:"",traffic_sources:"",audience_demographics:"",content_categories:"",targeting_capabilities:"",campaign_objectives:"",ad_formats:"",budget_range:"",industry_focus:""});r.useEffect(()=>{const s=M.get("payment");s==="success"?(l({title:"Payment Successful!",description:"Your subscription has been activated. Welcome to Adnexus Enterprise!"}),window.history.replaceState({},"","/dashboard")):s==="cancelled"&&(l({title:"Payment Cancelled",description:"Your payment was cancelled. You can try again anytime.",variant:"destructive"}),window.history.replaceState({},"","/dashboard"))},[M,l]);const y=r.useCallback(async(s=!1)=>{if(!d)return;const t=Date.now(),n=t-L;if(!(!s&&n<6e4)){B(!0),H(t);try{const{data:_,error:U}=await m.functions.invoke("check-subscription",{headers:{Authorization:`Bearer ${d.access_token}`}});if(U)throw U;$(_)}catch(_){console.error("Error checking subscription:",_)}finally{B(!1)}}},[d,L]),j=r.useCallback(async s=>{try{const{data:t,error:n}=await m.from("profiles").select("*").eq("user_id",s).single();if(n&&n.code!=="PGRST116")throw n;t&&(W(t),o({platform_type:t.platform_type||"",company_name:t.company_name||"",website_url:t.website_url||"",monthly_volume:t.monthly_volume||"",business_description:t.business_description||"",traffic_sources:t.traffic_sources||"",audience_demographics:t.audience_demographics||"",content_categories:t.content_categories||"",targeting_capabilities:t.targeting_capabilities||"",campaign_objectives:t.campaign_objectives||"",ad_formats:t.ad_formats||"",budget_range:t.budget_range||"",industry_focus:t.industry_focus||""}))}catch(t){console.error("Error loading profile:",t),l({title:"Error",description:"Failed to load your profile.",variant:"destructive"})}finally{X(!1)}},[l]);r.useEffect(()=>{const{data:{subscription:s}}=m.auth.onAuthStateChange((t,n)=>{z(n),D(n?.user??null),n?.user?setTimeout(()=>{j(n.user.id)},0):x("/auth")});return m.auth.getSession().then(({data:{session:t}})=>{z(t),D(t?.user??null),t?.user?j(t.user.id):x("/auth")}),()=>s.unsubscribe()},[x,j]),r.useEffect(()=>{i&&d&&y()},[i,d,y]);const Y=async s=>{if(s.preventDefault(),!!b?.id){I(!0);try{const t={platform_type:a.platform_type,company_name:a.company_name,website_url:a.website_url,monthly_volume:a.monthly_volume,business_description:a.business_description,approval_status:"pending"};a.traffic_sources&&(t.traffic_sources=a.traffic_sources),a.audience_demographics&&(t.audience_demographics=a.audience_demographics),a.content_categories&&(t.content_categories=a.content_categories),a.targeting_capabilities&&(t.targeting_capabilities=a.targeting_capabilities),a.campaign_objectives&&(t.campaign_objectives=a.campaign_objectives),a.ad_formats&&(t.ad_formats=a.ad_formats),a.budget_range&&(t.budget_range=a.budget_range),a.industry_focus&&(t.industry_focus=a.industry_focus);const{error:n}=await m.from("profiles").update(t).eq("user_id",b.id);if(n)throw n;l({title:"Information Submitted!",description:"Your information has been saved. To proceed with our services, please activate Adnexus Enterprise."}),j(b.id)}catch(t){console.error("Error updating profile:",t),l({title:"Error",description:t instanceof Error?t.message:"Failed to submit your information.",variant:"destructive"})}finally{I(!1)}}},G=async()=>{if(d)try{const{data:s,error:t}=await m.functions.invoke("create-checkout",{headers:{Authorization:`Bearer ${d.access_token}`}});if(t)throw t;window.open(s.url,"_blank")}catch(s){console.error("Error creating checkout:",s),l({title:"Error",description:s instanceof Error?s.message:"Failed to start subscription process.",variant:"destructive"})}},R=async()=>{if(d)try{const{data:s,error:t}=await m.functions.invoke("customer-portal",{headers:{Authorization:`Bearer ${d.access_token}`}});if(t)throw t;window.open(s.url,"_blank")}catch(s){console.error("Error opening customer portal:",s),l({title:"Error",description:s instanceof Error?s.message:"Failed to open billing portal.",variant:"destructive"})}},J=async()=>{try{await m.auth.signOut(),x("/auth")}catch(s){console.error("Error signing out:",s)}},K=s=>{switch(s){case"approved":return e.jsx(ce,{className:"w-5 h-5 text-success"});case"rejected":return e.jsx(ne,{className:"w-5 h-5 text-destructive"});default:return e.jsx(ie,{className:"w-5 h-5 text-warning"})}},Q=s=>{switch(s){case"approved":return"Approved";case"rejected":return"Rejected";default:return"Pending Review"}},Z=s=>{switch(s){case"approved":return"text-success";case"rejected":return"text-destructive";default:return"text-warning"}};return O?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading your dashboard..."})]})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border bg-card/50 backdrop-blur-sm",children:e.jsxs("div",{className:"container mx-auto px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"text-2xl font-bold",children:["Ad",e.jsx("span",{className:"text-gradient",children:"nexus"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Welcome, ",i?.full_name||b?.email]}),e.jsxs(u,{variant:"ghost",size:"sm",onClick:J,children:[e.jsx(ae,{size:16}),"Sign Out"]})]})]})}),e.jsxs("div",{className:"container mx-auto px-6 py-8 max-w-4xl",children:[e.jsx(p,{className:"mb-8 gradient-card backdrop-blur-sm border-primary/20",children:e.jsxs(h,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{className:"w-6 h-6 text-primary"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:"Adnexus Enterprise Status"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:g.subscribed?e.jsx("span",{className:"text-success",children:"Active - Adnexus Enterprise subscription confirmed"}):e.jsx("span",{className:"text-warning",children:"Inactive - Adnexus Enterprise required for service access"})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",onClick:()=>y(!0),disabled:T,children:T?"Checking...":"Refresh Status"}),g.subscribed?e.jsxs(u,{variant:"outline",size:"sm",onClick:R,children:[e.jsx(q,{className:"w-4 h-4 mr-2"}),"Manage Billing"]}):e.jsxs(u,{variant:"cta",size:"sm",onClick:G,children:[e.jsx(F,{className:"w-4 h-4 mr-2"}),"Activate Adnexus Enterprise"]})]})]}),!g.subscribed&&e.jsx("div",{className:"mt-4 p-4 bg-warning/10 border border-warning/20 rounded-lg",children:e.jsx("p",{className:"text-warning text-sm font-medium",children:"💡 Adnexus Enterprise ensures dedicated support and premium service delivery. Activate Adnexus Enterprise to begin working with our team."})})]})}),g.subscribed?e.jsxs(e.Fragment,{children:[i&&i.platform_type&&e.jsx(p,{className:"mb-8 gradient-card backdrop-blur-sm border-primary/20",children:e.jsxs(h,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[K(i.approval_status),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:"Application Status"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Your ",i.platform_type?.toUpperCase()," application is"," ",e.jsx("span",{className:Z(i.approval_status),children:Q(i.approval_status).toLowerCase()})]})]})]}),i.approval_status==="approved"&&e.jsx("div",{className:"mt-4 p-4 bg-success/10 border border-success/20 rounded-lg",children:e.jsx("p",{className:"text-success text-sm font-medium",children:"🎉 Congratulations! Your account has been approved. You can now access all platform features."})})]})}),e.jsxs(p,{className:"gradient-card backdrop-blur-sm border-primary/20",children:[e.jsxs(N,{children:[e.jsxs(w,{className:"flex items-center gap-2",children:[e.jsx(P,{size:20}),"Platform Setup"]}),e.jsx(S,{children:i?.platform_type?"Update your platform information and business details.":"Choose your platform type and provide your business details to get started."})]}),e.jsx(h,{children:e.jsxs("form",{onSubmit:Y,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Platform Type *"}),e.jsxs(k,{value:a.platform_type,onValueChange:s=>o({...a,platform_type:s}),children:[e.jsx(C,{children:e.jsx(A,{placeholder:"Select your platform type"})}),e.jsxs(E,{children:[e.jsx(c,{value:"SSP",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"Publisher Portal (SSP)"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Monetize your content and sell premium ad inventory"})]})}),e.jsx(c,{value:"DSP",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"Advertiser Portal (DSP)"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Buy premium CTV inventory and run targeted campaigns"})]})}),e.jsx(c,{value:"Agency",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"Agency Dashboard (AI Agency)"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Manage multiple clients with AI-powered optimization"})]})})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Company Name *"}),e.jsx(v,{type:"text",placeholder:"Your company name",value:a.company_name,onChange:s=>o({...a,company_name:s.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Website URL"}),e.jsx(v,{type:"url",placeholder:"https://yourwebsite.com",value:a.website_url,onChange:s=>o({...a,website_url:s.target.value})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Monthly Volume"}),e.jsxs(k,{value:a.monthly_volume,onValueChange:s=>o({...a,monthly_volume:s}),children:[e.jsx(C,{children:e.jsx(A,{placeholder:"Select your monthly volume"})}),e.jsxs(E,{children:[e.jsx(c,{value:"0-1M",children:"0 - 1M impressions"}),e.jsx(c,{value:"1M-10M",children:"1M - 10M impressions"}),e.jsx(c,{value:"10M-50M",children:"10M - 50M impressions"}),e.jsx(c,{value:"50M-100M",children:"50M - 100M impressions"}),e.jsx(c,{value:"100M+",children:"100M+ impressions"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Business Description"}),e.jsx(V,{placeholder:"Tell us about your business, advertising goals, and how you plan to use our platform...",value:a.business_description,onChange:s=>o({...a,business_description:s.target.value}),rows:4})]}),e.jsx(u,{type:"submit",variant:"cta",size:"lg",className:"w-full",disabled:f||!a.platform_type||!a.company_name,children:f?"Saving...":i?.platform_type?"Update Information":"Submit Information"})]})})]}),i?.approval_status==="approved"&&e.jsxs(p,{className:"mt-8 gradient-card backdrop-blur-sm border-primary/20",children:[e.jsxs(N,{children:[e.jsx(w,{children:"Platform Access"}),e.jsx(S,{children:"Your account is approved! Access your platform features below."})]}),e.jsx(h,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(u,{variant:"outline",size:"lg",className:"h-20",children:e.jsxs("div",{className:"text-center",children:[e.jsx(re,{className:"w-6 h-6 mx-auto mb-2"}),e.jsx("div",{className:"font-semibold",children:"Campaign Manager"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Manage campaigns and targeting"})]})}),e.jsx(u,{variant:"outline",size:"lg",className:"h-20",children:e.jsxs("div",{className:"text-center",children:[e.jsx(P,{className:"w-6 h-6 mx-auto mb-2"}),e.jsx("div",{className:"font-semibold",children:"Analytics Dashboard"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"View performance metrics"})]})}),e.jsx(u,{variant:"outline",size:"lg",className:"h-20",onClick:R,children:e.jsxs("div",{className:"text-center",children:[e.jsx(q,{className:"w-6 h-6 mx-auto mb-2"}),e.jsx("div",{className:"font-semibold",children:"Billing Portal"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Manage subscription"})]})})]})})]})]}):e.jsxs(p,{className:"gradient-card backdrop-blur-sm border-primary/20",children:[e.jsxs(N,{children:[e.jsxs(w,{className:"flex items-center gap-2",children:[e.jsx(P,{size:20}),"Contact Information"]}),e.jsx(S,{children:"Tell us about your business and what you'd like to explore with Adnexus. Activating Adnexus Enterprise will unlock full platform access."})]}),e.jsx(h,{children:e.jsxs("form",{onSubmit:Y,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Interest Area *"}),e.jsxs(k,{value:a.platform_type,onValueChange:s=>o({...a,platform_type:s}),children:[e.jsx(C,{children:e.jsx(A,{placeholder:"What would you like to connect with Adnexus about?"})}),e.jsxs(E,{children:[e.jsx(c,{value:"SSP",children:"Supply Side Platform (SSP) - Publisher Solutions"}),e.jsx(c,{value:"DSP",children:"Demand Side Platform (DSP) - Advertiser Solutions"}),e.jsx(c,{value:"ADX",children:"Ad Exchange (ADX) - Network & Agency Solutions"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Company Name *"}),e.jsx(v,{type:"text",placeholder:"Your company name",value:a.company_name,onChange:s=>o({...a,company_name:s.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Website URL"}),e.jsx(v,{type:"url",placeholder:"https://yourwebsite.com",value:a.website_url,onChange:s=>o({...a,website_url:s.target.value})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Business Description"}),e.jsx(V,{placeholder:"Tell us about your business, advertising goals, and what you'd like to explore with Adnexus...",value:a.business_description,onChange:s=>o({...a,business_description:s.target.value}),rows:4})]}),e.jsx(u,{type:"submit",variant:"cta",size:"lg",className:"w-full",disabled:f||!a.platform_type||!a.company_name,children:f?"Saving...":"Submit Contact Information"})]})})]})]})]})};export{be as default};