PageSourceSearch

https://diveos.pro/assets/SalesDashboard-BmFUWP_c.js

js diveos.pro collected 2026-10-09 22:03:55 UTC 6,873 bytes, 1 lines download raw bytes

1import{a as T,r as a,s as o,j as e,am as B,a0 as m,B as n,at as F,e as l,ah as h,E as H,aM as $,ai as K}from"./index-C8n-dv4k.js";import{I as M}from"./input-Db8KoBTY.js";import{C as u,c as f,a as U,b as Y,d as q}from"./card-ioOl0MgW.js";import{D as G,a as J,b as Q,c as V,d as W}from"./dialog-66nD1cLG.js";import{R as k}from"./refresh-cw-Cjtp5an-.js";import{P as X}from"./plus-BbXKZIBR.js";import{f as S}from"./formatDistanceToNow-Czsgs30p.js";import"./constructNow-BGHm0ff8.js";import"./differenceInCalendarMonths-BhZc9zkC.js";import"./endOfMonth-D_DATFGe.js";function ce(){const{user:x,signOut:R,setActiveCenterId:O}=T(),[j,I]=a.useState([]),[v,L]=a.useState([]),[g,p]=a.useState(null),[N,A]=a.useState(!0),[d,w]=a.useState(!1),[c,b]=a.useState(""),[P,y]=a.useState(!1),r=a.useCallback(async()=>{var i;const[s,t]=await Promise.all([o.from("demo_tenants").select("*").order("created_at",{ascending:!1}),o.functions.invoke("list-invited-centers")]);I(s.data||[]),L(((i=t.data)==null?void 0:i.centers)||[]),A(!1)},[]);a.useEffect(()=>{r()},[r]);const C=async()=>{if(!c.trim()){l.error("Please enter a demo name");return}w(!0);try{const{data:s,error:t}=await o.functions.invoke("create-demo-environment",{body:{demo_name:c.trim()}});if(t)throw t;if(s!=null&&s.error)throw new Error(s.error);l.success(`Demo "${c}" created!`),b(""),y(!1),r()}catch(s){l.error(s.message||"Failed to create demo")}finally{w(!1)}},z=s=>{O(s),window.location.href="/today"},D=s=>s.status!=="active"||new Date(s.expires_at)<new Date,_=j.filter(s=>!D(s)),E=j.filter(s=>D(s));return e.jsxs("div",{className:"min-h-[100dvh] bg-background",children:[e.jsx("header",{className:"border-b bg-card",children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4 h-14 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:B,alt:"DiveOS",className:"h-9 w-auto"}),e.jsx(m,{variant:"secondary",className:"text-xs",children:"Sales Demo Portal"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground hidden sm:inline",children:x==null?void 0:x.email}),e.jsx(n,{variant:"ghost",size:"icon",onClick:R,children:e.jsx(F,{className:"h-4 w-4"})})]})]})}),e.jsxs("main",{className:"max-w-5xl mx-auto px-4 py-8 space-y-8",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Center Invitations"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Status of invitations sent to new dive center admins."})]}),N?null:v.length===0?e.jsx(u,{children:e.jsx(f,{className:"py-8 text-center text-sm text-muted-foreground",children:"No invitations sent yet."})}):e.jsx("div",{className:"border rounded-lg divide-y bg-card",children:v.map(s=>{const t=!!s.admin_activated_at;return e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:s.center_name||"Unnamed center"}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:[s.invited_admin_email,s.invited_at&&e.jsxs(e.Fragment,{children:[" · invited ",S(new Date(s.invited_at),{addSuffix:!0})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t?e.jsx(m,{className:"bg-emerald-600 hover:bg-emerald-600 text-white",children:"Account activated"}):e.jsx(m,{variant:"outline",className:"border-amber-500 text-amber-700",children:"Awaiting activation"}),!t&&e.jsxs(n,{size:"sm",variant:"outline",disabled:g===s.id||!s.invited_admin_email,onClick:async()=>{if(s.invited_admin_email){p(s.id);try{const{error:i}=await o.functions.invoke("invite-center-admin",{body:{email:s.invited_admin_email,center_id:s.id,center_name:s.center_name,redirect_to:`${window.location.origin}/accept-invite`}});if(i)throw i;l.success("Invitation re-sent"),r()}catch(i){l.error(i.message||"Could not resend")}finally{p(null)}}},children:[g===s.id?e.jsx(h,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(k,{className:"h-3.5 w-3.5 mr-1.5"}),"Resend"]})]})]},s.id)})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Demo Environments"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Create isolated demos for client presentations. Each expires after 24h."})]}),e.jsxs(G,{open:P,onOpenChange:y,children:[e.jsx(J,{asChild:!0,children:e.jsxs(n,{children:[e.jsx(X,{className:"h-4 w-4 mr-2"})," New Demo"]})}),e.jsxs(Q,{children:[e.jsx(V,{children:e.jsx(W,{children:"Create Demo Environment"})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{htmlFor:"demo-name",children:"Client / Demo Name"}),e.jsx(M,{id:"demo-name",placeholder:"e.g. Yoshiyuki Dive Center",value:c,onChange:s=>b(s.target.value),onKeyDown:s=>s.key==="Enter"&&C(),disabled:d}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"A fully isolated environment will be created with sample data — boats, staff, guests, and trips for 7 days."})]}),e.jsxs(n,{onClick:C,disabled:d,className:"w-full",children:[d&&e.jsx(h,{className:"h-4 w-4 mr-2 animate-spin"}),d?"Creating...":"Create Demo"]})]})]})]})]}),N?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(h,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):_.length===0?e.jsx(u,{children:e.jsx(f,{className:"py-12 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:"No active demos. Create one to get started!"})})}):e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:_.map(s=>e.jsxs(u,{className:"relative",children:[e.jsxs(U,{className:"pb-2",children:[e.jsx(Y,{className:"text-base",children:s.demo_name}),e.jsxs(q,{className:"flex items-center gap-1",children:[e.jsx($,{className:"h-3 w-3"}),"Expires ",S(new Date(s.expires_at),{addSuffix:!0})]})]}),e.jsx(f,{className:"flex gap-2",children:e.jsxs(n,{size:"sm",onClick:()=>z(s.center_id),className:"flex-1",children:[e.jsx(K,{className:"h-3.5 w-3.5 mr-1.5"})," Enter Demo"]})})]},s.id))}),E.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Expired / Deleted"}),e.jsx("div",{className:"space-y-2",children:E.slice(0,10).map(s=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/50 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:s.demo_name}),e.jsx(m,{variant:"outline",className:"text-xs",children:s.status})]},s.id))})]}),e.jsx("div",{className:"flex justify-center",children:e.jsxs(n,{variant:"ghost",size:"sm",onClick:r,children:[e.jsx(k,{className:"h-3.5 w-3.5 mr-1.5"})," Refresh"]})})]})]})}export{ce 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.