PageSourceSearch

https://operative.sh/assets/Subscription-BiosCvYu.js

js operative.sh collected 2026-10-06 13:07:24 UTC 11,910 bytes, 1 lines download raw bytes

1import{j as e}from"./radix-ui-D_YMhc6v.js";import{r as l}from"./react-vendor-BqOCPj-l.js";import{a as q,s as p}from"./index-Bhz-ryDV.js";import{B as c}from"./button-5wiC_sbr.js";import{C as f}from"./card-3Y0Otrpc.js";import{c as t}from"./utils-BKRJTgLo.js";import"./3d-libs-g-QDITcl.js";import"./codemirror-DHtFBOYj.js";import"./supabase-BcYt2yoD.js";import"./react-router-B9vunL96.js";import"./icons-DL3gPZab.js";import"./utils-b36dzZfP.js";const y=!1,j="https://operative-backend-1.onrender.com",D=["100 API requests per month"],M=["10,000 API requests per month","Priority support"],R=["10,000 API requests per user per month","API for testing on demand","Run tests on every pull request","24/7 support from founders"];function X(){const{theme:r}=q(),[n,E]=l.useState(null),[L,w]=l.useState(!0),[v,d]=l.useState(null),[F,k]=l.useState(!1),[o,b]=l.useState(!1),[S,N]=l.useState(null);l.useEffect(()=>{(async()=>{try{await $()}catch(a){console.error("Error fetching user:",a),d("Failed to load user data"),w(!1)}})()},[]),l.useEffect(()=>{S&&B()},[S]);const $=async()=>{try{const{data:{session:s},error:a}=await p.auth.getSession();if(a)throw a;s?N(s.user):(N(null),d("No authenticated user session found."))}catch(s){console.error("Error in fetchUser:",s),d("Failed to fetch user data."),N(null)}},B=async()=>{w(!0),d(null);try{const{data:{session:s},error:a}=await p.auth.getSession();if(a)throw a;if(!s)throw new Error("Authentication token not available.");const i=await fetch(`${j}/api/subscription`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.access_token}`}});if(!i.ok){let u=`Failed to fetch subscription: ${i.statusText}`;try{const m=await i.json();u=m.detail||m.message||JSON.stringify(m)}catch{}throw new Error(u)}const g=await i.json();typeof g.is_subscribed!="boolean"&&console.warn("Fetched subscription data might be missing is_subscribed field."),E(g)}catch(s){console.error("Error fetching subscription:",s),d(s.message||"Failed to load subscription data")}finally{w(!1)}},C=async()=>{b(!0);try{const{data:{session:s}}=await p.auth.getSession();if(!s)return;const a=await fetch(`${j}/api/plans`,{headers:{Authorization:`Bearer ${s.access_token}`}});if(!a.ok)throw new Error("Could not fetch plans");const g=(await a.json()).find(U=>U.name==="Standard");if(!g)throw new Error("Standard plan not found");const u=await fetch(`${j}/api/subscription/checkout`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.access_token}`},body:JSON.stringify({plan_id:g.id})});if(!u.ok)throw new Error("Failed to create checkout session");const{checkout_url:m}=await u.json();window.location.href=m}catch(s){console.error("Error creating checkout session:",s),d(s.message||"Failed to initiate subscription")}finally{b(!1)}},A=async()=>{if(confirm("You will be redirected to Stripe to manage your subscription. Continue?")){b(!0);try{const{data:{session:s}}=await p.auth.getSession();if(!s)throw new Error("You must be logged in to manage your subscription");const a=await fetch(`${j}/api/subscription/portal`,{method:"POST",headers:{Authorization:`Bearer ${s.access_token}`}});if(!a.ok)throw new Error("Failed to create billing portal session");const{portal_url:i}=await a.json();if(!i)throw new Error("Billing portal URL missing from response");window.location.href=i}catch(s){console.error("Error opening billing portal:",s),d(s.message||"Failed to open billing portal")}finally{b(!1)}}},P=s=>new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"});if(L)return e.jsx("div",{className:"flex justify-center items-center h-40",children:e.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-t-2 border-b-2 border-green-500"})});if(v)return e.jsx(f,{className:t("p-6 shadow-sm",r==="dark"?"bg-black border-gray-800":"bg-white border-gray-200"),children:e.jsx("div",{className:"p-4 rounded-lg bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300",children:v})});const _=s=>n?.plan_name?.toLowerCase()===s.toLowerCase(),h=_("free"),x=_("standard");return e.jsxs("div",{className:t("space-y-6",r==="dark"?"text-white":"text-gray-900"),children:[e.jsxs(f,{className:t("p-6 shadow-sm",r==="dark"?"bg-black border-gray-800":"bg-white border-gray-200"),children:[e.jsx("h2",{className:t("text-xl font-semibold mb-4",r==="dark"?"text-white":"text-gray-900"),children:"Current Subscription"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:t("p-4 rounded-lg border",r==="dark"?"border-gray-800 bg-gray-900/50":"border-gray-200 bg-gray-50"),children:e.jsxs("div",{className:"flex flex-wrap justify-between items-center",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:t("text-lg font-medium",r==="dark"?"text-white":"text-gray-900"),children:[n?.plan_name||"Free"," Plan"]}),e.jsx("p",{className:t("text-sm mt-1",r==="dark"?"text-gray-400":"text-gray-500"),children:x?"Standard plan with 10,000 requests per month and priority support":"Free tier with 100 requests per month"})]}),n?.current_period_end&&!h&&e.jsx("div",{className:t("text-sm",r==="dark"?"text-gray-400":"text-gray-500"),children:n.cancel_at_period_end?`Expires on ${P(n.current_period_end)}`:`Renews on ${P(n.current_period_end)}`})]})}),n&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between mb-1",children:[e.jsx("span",{className:t("text-sm font-medium",r==="dark"?"text-gray-300":"text-gray-700"),children:"API Requests"}),e.jsxs("span",{className:t("text-sm",r==="dark"?"text-gray-400":"text-gray-500"),children:[n.usage," / ",n.limit," requests"]})]}),e.jsx("div",{className:"w-full h-2 bg-gray-200 rounded-full overflow-hidden dark:bg-gray-700",children:e.jsx("div",{className:"h-full bg-green-500 rounded-full",style:{width:`${Math.min(n.usage/n.limit*100,100)}%`}})})]}),e.jsx("div",{className:"flex gap-3 mt-6",children:h?e.jsx(c,{onClick:()=>k(!0),disabled:o,children:o?"Processing...":"Upgrade to Standard"}):n?.cancel_at_period_end?e.jsx(c,{onClick:C,disabled:o,children:o?"Processing...":"Reactivate Subscription"}):e.jsx(c,{variant:"destructive",onClick:A,disabled:o,children:o?"Processing...":"Cancel Subscription"})})]})]}),e.jsxs(f,{className:t("p-6 shadow-sm",r==="dark"?"bg-black border-gray-800":"bg-white border-gray-200"),children:[e.jsx("h2",{className:t("text-xl font-semibold mb-4",r==="dark"?"text-white":"text-gray-900"),children:"Plan Comparison"}),e.jsxs("div",{className:"grid md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:t("p-6 rounded-lg border",r==="dark"?h?"border-green-700 bg-green-900/10":"border-gray-800 bg-gray-900/50":h?"border-green-300 bg-green-50":"border-gray-200 bg-gray-50"),children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:t("text-lg font-medium",r==="dark"?"text-white":"text-gray-900"),children:"Free"}),h&&e.jsx("span",{className:t("px-2 py-1 text-xs font-medium rounded-full",r==="dark"?"bg-green-900 text-green-300":"bg-green-100 text-green-800"),children:"Current Plan"})]}),e.jsxs("div",{className:t("text-3xl font-bold mb-4",r==="dark"?"text-white":"text-gray-900"),children:["$0"," ",e.jsx("span",{className:t("text-sm font-normal",r==="dark"?"text-gray-400":"text-gray-500"),children:"/ month"})]}),e.jsx("ul",{className:"space-y-2 mb-6",children:D.map((s,a)=>e.jsxs("li",{className:"flex items-center",children:[e.jsx("svg",{className:"h-5 w-5 text-green-500 mr-2",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("span",{className:t("text-sm",r==="dark"?"text-gray-300":"text-gray-700"),children:s})]},a))})]}),e.jsxs("div",{className:t("p-6 rounded-lg border",r==="dark"?x?"border-green-700 bg-green-900/10":"border-gray-800 bg-gray-900/50":x?"border-green-300 bg-green-50":"border-gray-200 bg-gray-50"),children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:t("text-lg font-medium",r==="dark"?"text-white":"text-gray-900"),children:"Standard"}),x&&e.jsx("span",{className:t("px-2 py-1 text-xs font-medium rounded-full",r==="dark"?"bg-green-900 text-green-300":"bg-green-100 text-green-800"),children:"Current Plan"})]}),e.jsxs("div",{className:t("text-3xl font-bold mb-4",r==="dark"?"text-white":"text-gray-900"),children:["$29"," ",e.jsx("span",{className:t("text-sm font-normal",r==="dark"?"text-gray-400":"text-gray-500"),children:"/ month"})]}),e.jsx("ul",{className:"space-y-2 mb-6",children:M.map((s,a)=>e.jsxs("li",{className:"flex items-center",children:[e.jsx("svg",{className:"h-5 w-5 text-green-500 mr-2",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("span",{className:t("text-sm",r==="dark"?"text-gray-300":"text-gray-700"),children:s})]},a))}),!x&&e.jsx(c,{className:"w-full",onClick:()=>k(!0),disabled:o,children:o?"Processing...":"Upgrade to Standard"})]}),e.jsxs("div",{className:t("p-6 rounded-lg border",r==="dark"?"border-gray-800 bg-gray-900/50":"border-gray-200 bg-gray-50"),children:[e.jsx("div",{className:"flex justify-between items-center mb-4",children:e.jsx("h3",{className:t("text-lg font-medium",r==="dark"?"text-white":"text-gray-900"),children:"Pro"})}),e.jsxs("div",{className:t("text-3xl font-bold mb-4",r==="dark"?"text-white":"text-gray-900"),children:["Custom"," ",e.jsx("span",{className:t("text-sm font-normal",r==="dark"?"text-gray-400":"text-gray-500"),children:"/ month"})]}),e.jsx("ul",{className:"space-y-2 mb-6",children:R.map((s,a)=>e.jsxs("li",{className:"flex items-center",children:[e.jsx("svg",{className:"h-5 w-5 text-green-500 mr-2",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("span",{className:t("text-sm",r==="dark"?"text-gray-300":"text-gray-700"),children:s})]},a))}),e.jsx("a",{href:"https://calendly.com/chris-operative/30min",target:"_blank",rel:"noopener noreferrer",className:"w-full",children:e.jsx(c,{variant:"outline",className:t("w-full",r==="dark"?"text-blue-400 border-blue-700 hover:bg-blue-900/40 hover:border-blue-500 hover:text-white":""),children:"Book a Call"})})]})]})]}),F&&e.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex justify-center items-center z-50 p-4",children:e.jsxs(f,{className:t("w-full max-w-md p-6 rounded-lg shadow-xl",r==="dark"?"bg-black border-gray-800":"bg-white border-gray-200"),children:[e.jsx("h2",{className:t("text-xl font-semibold mb-4",r==="dark"?"text-white":"text-gray-900"),children:"Upgrade to Standard Plan"}),e.jsx("p",{className:t("mb-4",r==="dark"?"text-gray-300":"text-gray-600"),children:"You'll be redirected to Stripe to complete your payment. Your subscription will be active immediately after successful payment."}),e.jsx("div",{className:t("p-4 rounded-lg border mb-6",r==="dark"?"border-gray-800 bg-gray-900/50":"border-gray-200 bg-gray-50"),children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:t("font-medium",r==="dark"?"text-white":"text-gray-900"),children:"Standard Plan"}),e.jsx("p",{className:t("text-sm",r==="dark"?"text-gray-400":"text-gray-500"),children:"Monthly subscription"})]}),e.jsx("div",{className:t("text-xl font-bold",r==="dark"?"text-white":"text-gray-900"),children:"$29"})]})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c,{variant:"outline",onClick:()=>k(!1),className:r==="dark"?"bg-gray-900 text-white hover:bg-gray-800":"text-gray-400 border-gray-700 hover:text-white hover:bg-gray-800",children:"Cancel"}),e.jsx(c,{onClick:C,disabled:o,className:r==="dark"?"bg-white text-black hover:bg-gray-100":"",children:o?"Processing...":"Proceed to Stripe"})]})]})})]})}export{X as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.