PageSourceSearch

https://analyticsindiamag.com/assets/AccountSubscription-C7I-NEqS.js

js analyticsindiamag.com collected 2026-09-24 08:26:48 UTC 19,075 bytes, 1 lines download raw bytes

1import{u as W,r as n,s as k,j as e,L as x,M as F,m as g,bq as L,f as I,a2 as X,e as Z,a as ee,z as se,H as ae,b2 as te,b1 as G,B as v,o as R,S as ie,F as z,b3 as re,a3 as B,N as w}from"./index-KSWbwNeY.js";import ne from"./Footer-DPSMpmUX.js";import{P as le}from"./ProfileSidebar-RSiubeOO.js";import{L as q}from"./label-ndOKmXJw.js";import{T as de}from"./trophy-DOqUgSiA.js";import{C as $}from"./calendar-Cdsbx2VF.js";import{A as ce,h as me,a as oe,b as xe,c as ue,d as he,e as pe,f as fe,g as ge}from"./alert-dialog-DFWe8irl.js";import{D as je,a as be,b as ye,c as Ne}from"./dialog-Bpfij23O.js";import{T as ve}from"./triangle-alert-D2A9IHcD.js";import{R as we}from"./receipt-DgWJf9Ou.js";import{P as H}from"./printer-C8Q1PzYy.js";import{f}from"./format-hhvI2L0z.js";import"./twitter-yEUqfNJX.js";import"./linkedin-B1bA0DJP.js";import"./youtube-CwivUiPT.js";import"./facebook-DahhNxAJ.js";import"./trash-2-CwcwS_bf.js";import"./lock-DNHSxtLD.js";import"./monitor-DWTsCiB7.js";import"./index-BpbyRUKB.js";import"./en-US-BOoww7nS.js";const ke=()=>{const{user:l}=W(),[j,c]=n.useState(!0),[u,i]=n.useState(!1),[m,b]=n.useState({game_emails_enabled:!1,daily_result_emails:!0,streak_reminder_emails:!0,weekly_summary_emails:!0});n.useEffect(()=>{l&&P()},[l]);const P=async()=>{if(l)try{const{data:a,error:d}=await k.from("profiles").select("game_emails_enabled, daily_result_emails, streak_reminder_emails, weekly_summary_emails").eq("id",l.id).single();if(d)throw d;a&&b({game_emails_enabled:a.game_emails_enabled??!1,daily_result_emails:a.daily_result_emails??!0,streak_reminder_emails:a.streak_reminder_emails??!0,weekly_summary_emails:a.weekly_summary_emails??!0})}catch(a){console.error("Error fetching email preferences:",a)}finally{c(!1)}},D=async(a,d)=>{if(!l)return;i(!0);const y={...m,[a]:d};b(y);try{const{error:h}=await k.from("profiles").update({[a]:d}).eq("id",l.id);if(h)throw h;I.success("Email preferences updated")}catch(h){console.error("Error updating preference:",h),I.error("Failed to update preferences"),b(m)}finally{i(!1)}};if(j)return e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(x,{className:"w-6 h-6 animate-spin text-muted-foreground"})});if(!l)return e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(F,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Sign in to manage email notifications"})]});const _=[{key:"daily_result_emails",label:"Daily Results",description:"Get your score and streak after each daily challenge",icon:de},{key:"streak_reminder_emails",label:"Streak Reminders",description:"Receive a reminder when your streak is at risk",icon:X},{key:"weekly_summary_emails",label:"Weekly Summary",description:"Get a weekly digest of your game performance",icon:$}];return e.jsxs(g.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-gradient-to-r from-primary/10 to-accent/10 border border-primary/20",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/20",children:e.jsx(F,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(q,{htmlFor:"game-emails",className:"text-base font-medium",children:"Game Email Notifications"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Enable emails for game performance updates"})]})]}),e.jsx(L,{id:"game-emails",checked:m.game_emails_enabled,onCheckedChange:a=>D("game_emails_enabled",a),disabled:u})]}),e.jsx(g.div,{animate:{opacity:m.game_emails_enabled?1:.5,pointerEvents:m.game_emails_enabled?"auto":"none"},className:"space-y-3",children:_.map((a,d)=>e.jsxs(g.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},transition:{delay:d*.1},className:"flex items-center justify-between p-3 rounded-lg bg-card/50 border border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(a.icon,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx(q,{htmlFor:a.key,className:"text-sm font-medium",children:a.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.description})]})]}),e.jsx(L,{id:a.key,checked:m[a.key],onCheckedChange:y=>D(a.key,y),disabled:u||!m.game_emails_enabled})]},a.key))})]})},Ue=()=>{var T;const l=Z(),{toast:j}=ee(),{user:c,loading:u}=W(),{status:i,loading:m,cancelSubscription:b,formatPrice:P,checkStatus:D}=se(),[_,a]=n.useState([]),[d,y]=n.useState([]),[h,O]=n.useState(!0),[U,V]=n.useState(!0),[C,E]=n.useState(!1),[t,Y]=n.useState(null),[S,M]=n.useState(null);n.useEffect(()=>{!u&&!c&&l("/auth?redirect=/account/subscription")},[c,u,l]),n.useEffect(()=>{async function s(){if(!c)return;const[r,p]=await Promise.all([k.from("payment_history").select("*").eq("user_id",c.id).order("created_at",{ascending:!1}).limit(20),k.from("invoices").select("*").eq("user_id",c.id).order("invoice_date",{ascending:!1}).limit(20)]);!r.error&&r.data&&a(r.data),!p.error&&p.data&&y(p.data),O(!1),V(!1)}s()},[c]);const o=(s,r="INR")=>new Intl.NumberFormat("en-IN",{style:"currency",currency:r,minimumFractionDigits:0}).format(s/100),K=async()=>{E(!0);try{await b(!1),j({title:"Subscription cancelled",description:"Your subscription will end at the current billing period."})}catch(s){j({title:"Error",description:s.message||"Failed to cancel subscription",variant:"destructive"})}finally{E(!1)}},A=async s=>{M(s);try{const{data:r,error:p}=await k.functions.invoke("generate-invoice-pdf",{body:{invoice_id:s}});if(p)throw p;const N=window.open("","_blank");N&&(N.document.write(r),N.document.close(),N.focus(),setTimeout(()=>{N.print()},500))}catch{j({title:"Error",description:"Failed to generate invoice",variant:"destructive"})}finally{M(null)}},J=s=>{switch(s){case"active":return e.jsx(w,{className:"bg-emerald-500/10 text-emerald-600 border-emerald-500/20 text-xs font-medium",children:"Active"});case"cancelled":return e.jsx(w,{className:"bg-amber-500/10 text-amber-600 border-amber-500/20 text-xs font-medium",children:"Cancelled"});case"expired":return e.jsx(w,{className:"bg-rose-500/10 text-rose-600 border-rose-500/20 text-xs font-medium",children:"Expired"});
1case"pending":return e.jsx(w,{className:"bg-sky-500/10 text-sky-600 border-sky-500/20 text-xs font-medium",children:"Pending"});default:return e.jsx(w,{variant:"outline",className:"text-xs",children:s})}},Q=s=>{switch(s){case"captured":case"success":case"completed":return e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-emerald-600",children:[e.jsx(B,{className:"h-3 w-3"})," Paid"]});case"failed":return e.jsx("span",{className:"text-xs text-rose-600",children:"Failed"});case"pending":return e.jsx("span",{className:"text-xs text-amber-600",children:"Pending"});default:return e.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:s})}};return u||m?e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-slate-50 to-white dark:from-slate-950 dark:to-slate-900 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 animate-fade-in",children:[e.jsx(x,{className:"h-6 w-6 animate-spin text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]})}):c?e.jsxs("div",{className:"min-h-screen bg-gradient-to-b from-slate-50 to-white dark:from-slate-950 dark:to-slate-900",children:[e.jsxs(ae,{children:[e.jsx("title",{children:"Subscription | AIM"}),e.jsx("meta",{name:"description",content:"Manage your subscription and billing."})]}),e.jsxs("main",{className:"container mx-auto px-4 md:px-12 lg:px-16 py-8 max-w-6xl",children:[e.jsxs(g.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"mb-8",children:[e.jsx("h1",{className:"text-2xl md:text-3xl tracking-tight font-sans font-normal",children:"Account Settings"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage your subscription and billing"})]}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-8",children:[e.jsx(g.aside,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.1},className:"w-full lg:w-56 flex-shrink-0",children:e.jsx("div",{className:"lg:sticky lg:top-24",children:e.jsx(le,{})})}),e.jsxs(g.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2},className:"flex-1 max-w-2xl space-y-4",children:[e.jsx("div",{className:"rounded-xl border bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm shadow-sm overflow-hidden mb-4 animate-fade-in",style:{animationDelay:"50ms"},children:i.hasSubscription&&i.subscription?e.jsxs("div",{className:"p-5",children:[e.jsx("div",{className:"flex items-start justify-between gap-4 mb-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-amber-400 to-orange-500 flex items-center justify-center shadow-lg shadow-amber-500/20",children:e.jsx(te,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"font-semibold",children:i.subscription.planName}),J(i.subscription.status)]}),e.jsxs("p",{className:"text-xs text-muted-foreground capitalize mt-0.5",children:[i.subscription.billingPeriod," billing"]})]})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 py-3 px-4 rounded-lg bg-slate-50 dark:bg-slate-800/50 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx($,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] text-muted-foreground uppercase tracking-wide",children:i.subscription.cancelAtPeriodEnd?"Ends":"Renews"}),e.jsx("p",{className:"text-sm font-medium",children:i.subscription.currentPeriodEnd?f(new Date(i.subscription.currentPeriodEnd),"MMM d, yyyy"):"N/A"})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] text-muted-foreground uppercase tracking-wide",children:"Via"}),e.jsx("p",{className:"text-sm font-medium capitalize",children:"Stripe"})]})]})]}),i.subscription.cancelAtPeriodEnd&&e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-amber-50 dark:bg-amber-950/30 border border-amber-200/50 dark:border-amber-800/50 mb-4 animate-fade-in",children:[e.jsx(ve,{className:"h-4 w-4 text-amber-600 flex-shrink-0"}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:["Subscription ends ",f(new Date(i.subscription.currentPeriodEnd),"MMMM d, yyyy")]})]}),i.subscription.status==="active"&&!i.subscription.cancelAtPeriodEnd&&e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(v,{asChild:!0,variant:"outline",size:"sm",className:"text-xs h-8",children:e.jsx(R,{to:"/subscribe",children:"Change Plan"})}),e.jsxs(ce,{children:[e.jsx(me,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"sm",className:"text-xs h-8 text-muted-foreground hover:text-destructive",children:"Cancel"})}),e.jsxs(oe,{className:"max-w-sm",children:[e.jsxs(xe,{children:[e.jsx(ue,{className:"text-lg",children:"Cancel subscription?"}),e.jsxs(he,{className:"text-sm",children:["You'll retain access until"," ",i.subscription.currentPeriodEnd?f(new Date(i.subscription.currentPeriodEnd),"MMMM d, yyyy"):"the billing period ends","."]})]}),e.jsxs(pe,{children:[e.jsx(fe,{className:"h-9",children:"Keep"}),e.jsx(ge,{onClick:K,disabled:C,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90 h-9",children:C?e.jsx(x,{className:"h-4 w-4 animate-spin"}):"Cancel"})]})]})]})]})]}):e.jsxs("div",{className:"p-6 text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-gradient-to-br from-slate-100 to-slate-200 dark:from-slate-800 dark:to-slate-700 flex items-center justify-center mx-auto mb-3",children:e.jsx(ie,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("h3",{className:"font-medium mb-1 font-sans",children:"No active subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Unlock premium content and exclusive features."}),e.jsx(v,{asChild:!0,size:"sm",className:"h-9",children:e.jsx(R,{to:"/subscribe",children:"View Plans"})})]})}),e.jsxs("div",{className:"rounded-xl border bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm shadow-sm overflow-hidden mb-4 animate-fade-in",style:{animationDelay:"100ms"},children:[e.jsx("div",{className:"px-5 py-3 border-b bg-slate-50/50 dark:bg-slate-800/30",children:e.jsxs("h3",{className:"font-medium text-sm flex items-center gap-2 font-sans",children:[e.jsx(we,{className:"h-4 w-4 text-muted-foreground"}),"Payments"]})}),e.jsx("div",{className:"p-4",children:h?e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(x,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):_.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No payments yet"}):e.jsx("div",{className:"space-y-2",children:_.map((s,r)=>e.jsxs("div",{className:"flex items-center justify-between py-2.5 px-3 rounded-lg hover:bg-slate-50 dark:hover:bg-slate-800/50 transition-colors animate-fade-in",style:{animationDelay:`${r*30}ms`},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-emerald-500/10 flex items-center justify-center",children:e.jsx(G,{className:"h-4 w-4 text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:o(s.amount,s.currency)}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:f(new Date(s.created_at),"MMM d, yyyy")})]})]}),Q(s.status)]},s.id))})})]}),e.jsxs("div",{className:"rounded-xl border bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm shadow-sm overflow-hidden mb-4 animate-fade-in",style:{animationDelay:"150ms"},children:[e.jsx("div",{className:"px-5 py-3 border-b bg-slate-50/50 dark:bg-slate-800/30",children:e.jsxs("h3",{className:"font-medium text-sm flex items-center gap-2 font-sans",children:[e.jsx(z,{className:"h-4 w-4 text-muted-foreground"}),"Invoices"]})}),e.jsx("div",{className:"p-4",children:U?e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(x,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):d.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No invoices yet"}):e.jsx("div",{className:"space-y-2",children:d.map((s,r)=>e.jsxs("div",{className:"flex items-center justify-between py-2.5 px-3 rounded-lg hover:bg-slate-50 dark:hover:bg-slate-800/50 transition-colors animate-fade-in",style:{animationDelay:`${r*30}ms`},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-sky-500/10 flex items-center justify-center",children:e.jsx(z,{className:"h-4 w-4 text-sky-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium font-mono",children:s.invoice_number}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:f(new Date(s.invoice_date),"MMM d, yyyy")})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:o(s.total_amount)}),e.jsx(v,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>A(s.id),disabled:S===s.id,children:S===s.id?e.jsx(x,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(H,{className:"h-3.5 w-3.5"})})]})]},s.id))})})]}),e.jsxs("div",{className:"rounded-xl border bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm shadow-sm overflow-hidden mb-4 animate-fade-in",style:{animationDelay:"175ms"},children:[e.jsx("div",{className:"px-5 py-3 border-b bg-slate-50/50 dark:bg-slate-800/30",children:e.jsxs("h3",{className:"font-medium text-sm flex items-center gap-2 font-sans",children:[e.jsx(re,{className:"h-4 w-4 text-muted-foreground"}),"Game Notifications"]})}),e.jsx("div",{className:"p-4",children:e.jsx(ke,{})})]}),i.hasSubscription&&e.jsxs("div",{className:"rounded-xl border bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm shadow-sm overflow-hidden animate-fade-in",style:{animationDelay:"200ms"},children:[e.jsx("div",{className:"px-5 py-3 border-b bg-slate-50/50 dark:bg-slate-800/30",children:e.jsx("h3",{className:"font-medium text-sm",children:"What's included"})}),e.jsx("div",{className:"p-4",children:e.jsx("div",{className:"grid grid-cols-2 gap-2",children:["Unlimited premium articles","Early access content","Ad-free experience","Offline reading","Priority support",((T=i.subscription)==null?void 0:T.includesPrint)&&"Print edition"].filter(
1Boolean).map((s,r)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm py-1 animate-fade-in",style:{animationDelay:`${200+r*50}ms`},children:[e.jsx(B,{className:"h-3.5 w-3.5 text-emerald-500 flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:s})]},r))})})]})]})]})]}),e.jsx(je,{open:!!t,onOpenChange:()=>Y(null),children:e.jsxs(be,{className:"max-w-sm",children:[e.jsx(ye,{children:e.jsxs(Ne,{className:"text-base",children:["Invoice ",t==null?void 0:t.invoice_number]})}),t&&e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Date"}),e.jsx("p",{className:"font-medium",children:f(new Date(t.invoice_date),"dd MMM yyyy")})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Plan"}),e.jsx("p",{className:"font-medium",children:t.plan_name})]})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Subtotal"}),e.jsx("span",{children:o(t.subtotal)})]}),t.cgst_amount>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between text-muted-foreground text-xs",children:[e.jsx("span",{children:"CGST (9%)"}),e.jsx("span",{children:o(t.cgst_amount)})]}),e.jsxs("div",{className:"flex justify-between text-muted-foreground text-xs",children:[e.jsx("span",{children:"SGST (9%)"}),e.jsx("span",{children:o(t.sgst_amount)})]})]}),t.igst_amount>0&&e.jsxs("div",{className:"flex justify-between text-muted-foreground text-xs",children:[e.jsx("span",{children:"IGST (18%)"}),e.jsx("span",{children:o(t.igst_amount)})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"flex justify-between font-medium",children:[e.jsx("span",{children:"Total"}),e.jsx("span",{children:o(t.total_amount)})]})]}),e.jsxs("div",{className:"pt-3 text-[11px] text-muted-foreground border-t space-y-0.5",children:[e.jsx("p",{children:t.company_name}),e.jsxs("p",{children:["GSTIN: ",t.company_gstin," • HSN: ",t.hsn_code]})]}),e.jsxs(v,{onClick:()=>A(t.id),className:"w-full h-9 text-sm",disabled:S===t.id,children:[S===t.id?e.jsx(x,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(H,{className:"h-4 w-4 mr-2"}),"Download PDF"]})]})]})}),e.jsx(ne,{})]}):null};export{Ue 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.