Files
igny8/frontend/dist/assets/js/pages-billing-CR09bFDK.js
Gitea Deploy 961362e088 Add SEO fields to Tasks model, improve content generation response handling, and enhance progress bar animation
- Added primary_keyword, secondary_keywords, tags, and categories fields to Tasks model
- Updated generate_content function to handle full JSON response with all SEO fields
- Improved progress bar animation: smooth 1% increments every 300ms
- Enhanced step detection for content generation vs clustering vs ideas
- Fixed progress modal to show correct messages for each function type
- Added comprehensive logging to Keywords and Tasks pages for AI functions
- Fixed error handling to show meaningful error messages instead of generic failures
2025-11-09 21:22:34 +00:00

2 lines
13 KiB
JavaScript

import{r as i,j as e}from"./vendor-react-core-DjsjKnCi.js";import{P as u}from"./page-analytics.tsx-1KCk8AGD.js";import{u as f}from"./page-reference-aC0iABvU.js";import{b,c as v,d as k,e as w}from"./page-dashboard-DxYTR5eF.js";import{C as o}from"./page-components.tsx-DYfg5dka.js";import{B as N}from"./page-clusters.config.tsx-9GAd-_h-.js";function C(){const a=f(),[n,g]=i.useState(null),[r,l]=i.useState(!0);i.useEffect(()=>{m()},[]);const m=async()=>{try{l(!0);const d=await b();g(d)}catch(d){a.error(`Failed to load credit balance: ${d.message}`)}finally{l(!1)}};return r?e.jsxs("div",{className:"p-6",children:[e.jsx(u,{title:"Credits"}),e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-gray-500",children:"Loading..."})})]}):e.jsxs("div",{className:"p-6",children:[e.jsx(u,{title:"Credits"}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Credit Balance"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Manage your AI credits and usage"})]}),n&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsxs(o,{className:"p-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("h3",{className:"text-sm font-medium text-gray-600 dark:text-gray-400",children:"Current Balance"})}),e.jsx("div",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:n.credits.toLocaleString()}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-2",children:"Available credits"})]}),e.jsxs(o,{className:"p-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("h3",{className:"text-sm font-medium text-gray-600 dark:text-gray-400",children:"Monthly Allocation"})}),e.jsx("div",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:n.plan_credits_per_month.toLocaleString()}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-2",children:"Credits per month"})]}),e.jsxs(o,{className:"p-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("h3",{className:"text-sm font-medium text-gray-600 dark:text-gray-400",children:"Used This Month"})}),e.jsx("div",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:n.credits_used_this_month.toLocaleString()}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-2",children:"Credits consumed"})]}),e.jsxs(o,{className:"p-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("h3",{className:"text-sm font-medium text-gray-600 dark:text-gray-400",children:"Remaining"})}),e.jsx("div",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:n.credits_remaining.toLocaleString()}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-2",children:"Credits remaining"})]})]})]})}const A=Object.freeze(Object.defineProperty({__proto__:null,default:C},Symbol.toStringTag,{value:"Module"}));function L(){const a=f(),[n,g]=i.useState([]),[r,l]=i.useState(!0),[m,d]=i.useState(1),[h,c]=i.useState(1);i.useEffect(()=>{j()},[m]);const j=async()=>{try{l(!0);const s=await v({page:m});g(s.results||[]),c(Math.ceil((s.count||0)/50))}catch(s){a.error(`Failed to load transactions: ${s.message}`)}finally{l(!1)}},p=s=>{switch(s){case"purchase":case"subscription":return"success";case"deduction":return"error";default:return"primary"}};return e.jsxs("div",{className:"p-6",children:[e.jsx(u,{title:"Credit Transactions"}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Credit Transactions"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"View all credit transactions and history"})]}),r?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-gray-500",children:"Loading..."})}):e.jsx(o,{className:"p-6",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Date"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Type"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Amount"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Balance After"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Description"})]})}),e.jsx("tbody",{children:n.map(s=>e.jsxs("tr",{className:"border-b border-gray-100 dark:border-gray-800",children:[e.jsx("td",{className:"py-3 px-4 text-sm text-gray-900 dark:text-white",children:new Date(s.created_at).toLocaleDateString()}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(N,{variant:"light",color:p(s.transaction_type),children:s.transaction_type_display})}),e.jsxs("td",{className:`py-3 px-4 text-sm font-medium ${s.amount>=0?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:[s.amount>=0?"+":"",s.amount.toLocaleString()]}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-900 dark:text-white",children:s.balance_after.toLocaleString()}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-600 dark:text-gray-400",children:s.description})]},s.id))})]})})})]})}const B=Object.freeze(Object.defineProperty({__proto__:null,default:L},Symbol.toStringTag,{value:"Module"}));function _(){const a=f(),[n,g]=i.useState([]),[r,l]=i.useState([]),[m,d]=i.useState(!0),[h,c]=i.useState(!0);i.useEffect(()=>{j(),p()},[]);const j=async()=>{try{d(!0);const t=await k({page:1});g(t.results||[])}catch(t){a.error(`Failed to load usage logs: ${t.message}`)}finally{d(!1)}},p=async()=>{try{c(!0);const t=await w();console.log("Usage limits response:",t),l(t.limits||[]),(!t.limits||t.limits.length===0)&&console.warn("No limits data received from API")}catch(t){console.error("Error loading usage limits:",t),a.error(`Failed to load usage limits: ${t.message}`),l([])}finally{c(!1)}},s={planner:r.filter(t=>t.category==="planner"),writer:r.filter(t=>t.category==="writer"),images:r.filter(t=>t.category==="images"),ai:r.filter(t=>t.category==="ai"),general:r.filter(t=>t.category==="general")};return console.log("[Usage Component] Render state:",{limitsLoading:h,limitsCount:r.length,groupedLimits:s,plannerCount:s.planner.length,writerCount:s.writer.length,imagesCount:s.images.length,aiCount:s.ai.length,generalCount:s.general.length}),e.jsxs("div",{className:"p-6",children:[e.jsx(u,{title:"Usage",description:"Monitor your plan limits and usage statistics"}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Acoount Limits & Usage"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Monitor your plan limits and usage statistics"})]}),!1,h?e.jsx(o,{className:"p-6 mb-8",children:e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx("div",{className:"text-gray-500",children:"Loading limits..."})})}):r.length===0?e.jsx(o,{className:"p-6 mb-8",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("p",{className:"mb-2 font-medium",children:"No usage limits data available."}),e.jsx("p",{className:"text-sm",children:"The API endpoint may not be responding or your account may not have a plan configured."}),e.jsx("p",{className:"text-xs mt-2 text-gray-400",children:"Check browser console for errors. Endpoint: /v1/billing/credits/usage/limits/"})]})}):e.jsxs("div",{className:"space-y-6 mb-8",children:[s.planner.length>0&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 dark:text-white mb-4",children:"Planner Limits"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:s.planner.map((t,x)=>e.jsx(y,{limit:t},x))})]}),s.writer.length>0&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 dark:text-white mb-4",children:"Writer Limits"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:s.writer.map((t,x)=>e.jsx(y,{limit:t},x))})]}),s.images.length>0&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 dark:text-white mb-4",children:"Image Generation Limits"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:s.images.map((t,x)=>e.jsx(y,{limit:t},x))})]}),s.ai.length>0&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 dark:text-white mb-4",children:"AI Credits"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:s.ai.map((t,x)=>e.jsx(y,{limit:t},x))})]}),s.general.length>0&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 dark:text-white mb-4",children:"General Limits"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:s.general.map((t,x)=>e.jsx(y,{limit:t},x))})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 dark:text-white mb-4",children:"Usage Logs"}),m?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-gray-500",children:"Loading..."})}):e.jsx(o,{className:"p-6",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Date"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Operation"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Credits Used"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Model"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Cost (USD)"})]})}),e.jsx("tbody",{children:n.map(t=>e.jsxs("tr",{className:"border-b border-gray-100 dark:border-gray-800",children:[e.jsx("td",{className:"py-3 px-4 text-sm text-gray-900 dark:text-white",children:new Date(t.created_at).toLocaleString()}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(N,{variant:"light",color:"primary",children:t.operation_type_display})}),e.jsx("td",{className:"py-3 px-4 text-sm font-medium text-gray-900 dark:text-white",children:t.credits_used}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-600 dark:text-gray-400",children:t.model_used||"N/A"}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-600 dark:text-gray-400",children:t.cost_usd?`$${parseFloat(t.cost_usd).toFixed(4)}`:"N/A"})]},t.id))})]})})})]})]})}function y({limit:a}){const n=c=>{switch(c){case"planner":return"blue";case"writer":return"green";case"images":return"purple";case"ai":return"orange";case"general":return"gray";default:return"gray"}},g=c=>c>=90?"danger":c>=75?"warning":"success",r=Math.min(a.percentage,100),l=g(r),m=n(a.category),d=l==="danger"?"bg-red-500":l==="warning"?"bg-yellow-500":"bg-green-500",h=l==="danger"?"text-red-600 dark:text-red-400":l==="warning"?"text-yellow-600 dark:text-yellow-400":"text-green-600 dark:text-green-400";return e.jsxs(o,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:a.title}),e.jsx(N,{variant:"light",color:m,children:a.category})]}),e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:a.used.toLocaleString()}),e.jsxs("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:["/ ",a.limit.toLocaleString()]}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:a.unit})]}),e.jsx("div",{className:"mt-2",children:e.jsx("div",{className:"w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2",children:e.jsx("div",{className:`h-2 rounded-full ${d}`,style:{width:`${r}%`}})})})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("span",{className:h,children:[a.available.toLocaleString()," available"]}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[r.toFixed(1),"% used"]})]})]})}const D=Object.freeze(Object.defineProperty({__proto__:null,default:_},Symbol.toStringTag,{value:"Module"}));export{A as C,B as T,D as U};