3 lines
19 KiB
JavaScript
3 lines
19 KiB
JavaScript
import{r as O,u as pe,j as r,c as ge,a as ye,g as ve,b as be,d as J,L as xe,e as le,f as ue,h as je,i as we,k as Ve,C as Se,R as re,l as se,m as Q,B as ce,n as Ce}from"./index-B92aEPQH.js";import{P as Ee}from"./PageBreadcrumb-Dsn9CkpH.js";import{S as Ne,r as Oe}from"./SessionVitalsModal-DDMDFsin.js";import{C as ie,a as oe}from"./Card-DPmHd5BI.js";import{T as Pe}from"./Table-BCHyhTAY.js";import"./PageMetaData-DFmRpQLs.js";import"./Modal-D4T7V4-p.js";import"./FormCheck-QYGhbIhB.js";import"./FormContext-IkkKm1bh.js";import"./FormControl-BhzYseFY.js";const he=O.forwardRef(({bsPrefix:o,bg:V="primary",pill:g=!1,text:f,className:S,as:d="span",...i},l)=>{const c=pe(o,"badge");return r.jsx(d,{ref:l,...i,className:ge(S,c,g&&"rounded-pill",f&&`text-${f}`,V&&`bg-${V}`)})});he.displayName="Badge";var X={},Z={exports:{}},Re=Z.exports,de;function Fe(){return de||(de=1,(function(o,V){(function(g,f){f(V)})(Re,(function(g){var f=function(){return f=Object.assign||function(d){for(var i,l=1,c=arguments.length;l<c;l++)for(var n in i=arguments[l])Object.prototype.hasOwnProperty.call(i,n)&&(d[n]=i[n]);return d},f.apply(this,arguments)},S=(function(){function d(i,l,c){var n=this;this.endVal=l,this.options=c,this.version="2.9.0",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,useIndianSeparators:!1,smartEasingThreshold:999,smartEasingAmount:333,separator:",",decimal:".",prefix:"",suffix:"",enableScrollSpy:!1,scrollSpyDelay:200,scrollSpyOnce:!1},this.finalEndVal=null,this.useEasing=!0,this.countDown=!1,this.error="",this.startVal=0,this.paused=!0,this.once=!1,this.count=function(m){n.startTime||(n.startTime=m);var p=m-n.startTime;n.remaining=n.duration-p,n.useEasing?n.countDown?n.frameVal=n.startVal-n.easingFn(p,0,n.startVal-n.endVal,n.duration):n.frameVal=n.easingFn(p,n.startVal,n.endVal-n.startVal,n.duration):n.frameVal=n.startVal+(n.endVal-n.startVal)*(p/n.duration);var y=n.countDown?n.frameVal<n.endVal:n.frameVal>n.endVal;n.frameVal=y?n.endVal:n.frameVal,n.frameVal=Number(n.frameVal.toFixed(n.options.decimalPlaces)),n.printValue(n.frameVal),p<n.duration?n.rAF=requestAnimationFrame(n.count):n.finalEndVal!==null?n.update(n.finalEndVal):n.options.onCompleteCallback&&n.options.onCompleteCallback()},this.formatNumber=function(m){var p,y,E,b,M=m<0?"-":"";p=Math.abs(m).toFixed(n.options.decimalPlaces);var G=(p+="").split(".");if(y=G[0],E=G.length>1?n.options.decimal+G[1]:"",n.options.useGrouping){b="";for(var v=3,T=0,P=0,k=y.length;P<k;++P)n.options.useIndianSeparators&&P===4&&(v=2,T=1),P!==0&&T%v==0&&(b=n.options.separator+b),T++,b=y[k-P-1]+b;y=b}return n.options.numerals&&n.options.numerals.length&&(y=y.replace(/[0-9]/g,(function(R){return n.options.numerals[+R]})),E=E.replace(/[0-9]/g,(function(R){return n.options.numerals[+R]}))),M+n.options.prefix+y+E+n.options.suffix},this.easeOutExpo=function(m,p,y,E){return y*(1-Math.pow(2,-10*m/E))*1024/1023+p},this.options=f(f({},this.defaults),c),this.formattingFn=this.options.formattingFn?this.options.formattingFn:this.formatNumber,this.easingFn=this.options.easingFn?this.options.easingFn:this.easeOutExpo,this.el=typeof i=="string"?document.getElementById(i):i,l=l??this.parse(this.el.innerHTML),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.endVal=this.validateValue(l),this.options.decimalPlaces=Math.max(this.options.decimalPlaces),this.resetDuration(),this.options.separator=String(this.options.separator),this.useEasing=this.options.useEasing,this.options.separator===""&&(this.options.useGrouping=!1),this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined",typeof window<"u"&&this.options.enableScrollSpy&&(this.error?console.error(this.error,i):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push((function(){return n.handleScroll(n)})),window.onscroll=function(){window.onScrollFns.forEach((function(m){return m()}))},this.handleScroll(this)))}return d.prototype.handleScroll=function(i){if(i&&window&&!i.once){var l=window.innerHeight+window.scrollY,c=i.el.getBoundingClientRect(),n=c.top+window.pageYOffset,m=c.top+c.height+window.pageYOffset;m<l&&m>window.scrollY&&i.paused?(i.paused=!1,setTimeout((function(){return i.start()}),i.options.scrollSpyDelay),i.options.scrollSpyOnce&&(i.once=!0)):(window.scrollY>m||n>l)&&!i.paused&&i.reset()}},d.prototype.determineDirectionAndSmartEasing=function(){var i=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>i;var l=i-this.startVal;if(Math.abs(l)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=i;var c=this.countDown?1:-1;this.endVal=i+c*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=i,this.finalEndVal=null;this.finalEndVal!==null?this.useEasing=!1:this.useEasing=this.options.useEasing},d.prototype.start=function(i){this.error||(this.options.onStartCallback&&this.options.onStartCallback(),i&&(this.options.onCompleteCallback=i),this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},d.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},d.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},d.prototype.update=function(i){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(i),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,this.finalEndVal==null&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},d.prototype.printValue=function(i){var l;if(this.el){var c=this.formattingFn(i);!((l=this.options.plugin)===null||l===void 0)&&l.render?this.options.plugin.render(this.el,c):this.el.tagName==="INPUT"?this.el.value=c:this.el.tagName==="text"||this.el.tagName==="tspan"?this.el.textContent=c:this.el.innerHTML=c}},d.prototype.ensureNumber=function(i){return typeof i=="number"&&!isNaN(i)},d.prototype.validateValue=function(i){var l=Number(i);return this.ensureNumber(l)?l:(this.error="[CountUp] invalid start or end value: ".concat(i),null)},d.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},d.prototype.parse=function(i){var l=function(p){return p.replace(/([.,' ])/g,"\\$1")},c=l(this.options.separator),n=l(this.options.decimal),m=i.replace(new RegExp(c,"g"),"").replace(new RegExp(n,"g"),".");return parseFloat(m)},d})();g.CountUp=S}))})(Z,Z.exports)),Z.exports}var fe;function Ue(){if(fe)return X;fe=1,Object.defineProperty(X,"__esModule",{value:!0});var o=ye(),V=Fe();function g(a,t){var e=a==null?null:typeof Symbol<"u"&&a[Symbol.iterator]||a["@@iterator"];if(e!=null){var s,u,h,F,C=[],x=!0,j=!1;try{if(h=(e=e.call(a)).next,t!==0)for(;!(x=(s=h.call(e)).done)&&(C.push(s.value),C.length!==t);x=!0);}catch(w){j=!0,u=w}finally{try{if(!x&&e.return!=null&&(F=e.return(),Object(F)!==F))return}finally{if(j)throw u}}return C}}function f(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(u){return Object.getOwnPropertyDescriptor(a,u).enumerable})),e.push.apply(e,s)}return e}function S(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?f(Object(e),!0).forEach(function(s){l(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):f(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function d(a,t){if(typeof a!="object"||!a)return a;var e=a[Symbol.toPrimitive];if(e!==void 0){var s=e.call(a,t);if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(a)}function i(a){var t=d(a,"string");return typeof t=="symbol"?t:String(t)}function l(a,t,e){return t=i(t),t in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function c(){return c=Object.assign?Object.assign.bind():function(a){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(a[s]=e[s])}return a},c.apply(this,arguments)}function n(a,t){if(a==null)return{};var e={},s=Object.keys(a),u,h;for(h=0;h<s.length;h++)u=s[h],!(t.indexOf(u)>=0)&&(e[u]=a[u]);return e}function m(a,t){if(a==null)return{};var e=n(a,t),s,u;if(Object.getOwnPropertySymbols){var h=Object.getOwnPropertySymbols(a);for(u=0;u<h.length;u++)s=h[u],!(t.indexOf(s)>=0)&&Object.prototype.propertyIsEnumerable.call(a,s)&&(e[s]=a[s])}return e}function p(a,t){return y(a)||g(a,t)||E(a,t)||M()}function y(a){if(Array.isArray(a))return a}function E(a,t){if(a){if(typeof a=="string")return b(a,t);var e=Object.prototype.toString.call(a).slice(8,-1);if(e==="Object"&&a.constructor&&(e=a.constructor.name),e==="Map"||e==="Set")return Array.from(a);if(e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return b(a,t)}}function b(a,t){(t==null||t>a.length)&&(t=a.length);for(var e=0,s=new Array(t);e<t;e++)s[e]=a[e];return s}function M(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
||
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var G=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?o.useLayoutEffect:o.useEffect;function v(a){var t=o.useRef(a);return G(function(){t.current=a}),o.useCallback(function(){for(var e=arguments.length,s=new Array(e),u=0;u<e;u++)s[u]=arguments[u];return t.current.apply(void 0,s)},[])}var T=function(t,e){var s=e.decimal,u=e.decimals,h=e.duration,F=e.easingFn,C=e.end,x=e.formattingFn,j=e.numerals,w=e.prefix,_=e.separator,L=e.start,z=e.suffix,q=e.useEasing,D=e.useGrouping,U=e.useIndianSeparators,$=e.enableScrollSpy,N=e.scrollSpyDelay,H=e.scrollSpyOnce,B=e.plugin;return new V.CountUp(t,C,{startVal:L,duration:h,decimal:s,decimalPlaces:u,easingFn:F,formattingFn:x,numerals:j,separator:_,prefix:w,suffix:z,plugin:B,useEasing:q,useIndianSeparators:U,useGrouping:D,enableScrollSpy:$,scrollSpyDelay:N,scrollSpyOnce:H})},P=["ref","startOnMount","enableReinitialize","delay","onEnd","onStart","onPauseResume","onReset","onUpdate"],k={decimal:".",separator:",",delay:null,prefix:"",suffix:"",duration:2,start:0,decimals:0,startOnMount:!0,enableReinitialize:!0,useEasing:!0,useGrouping:!0,useIndianSeparators:!1},R=function(t){var e=Object.fromEntries(Object.entries(t).filter(function(A){var K=p(A,2),ee=K[1];return ee!==void 0})),s=o.useMemo(function(){return S(S({},k),e)},[t]),u=s.ref,h=s.startOnMount,F=s.enableReinitialize,C=s.delay,x=s.onEnd,j=s.onStart,w=s.onPauseResume,_=s.onReset,L=s.onUpdate,z=m(s,P),q=o.useRef(),D=o.useRef(),U=o.useRef(!1),$=v(function(){return T(typeof u=="string"?u:u.current,z)}),N=v(function(A){var K=q.current;if(K&&!A)return K;var ee=$();return q.current=ee,ee}),H=v(function(){var A=function(){return N(!0).start(function(){x?.({pauseResume:B,reset:I,start:W,update:Y})})};C&&C>0?D.current=setTimeout(A,C*1e3):A(),j?.({pauseResume:B,reset:I,update:Y})}),B=v(function(){N().pauseResume(),w?.({reset:I,start:W,update:Y})}),I=v(function(){N().el&&(D.current&&clearTimeout(D.current),N().reset(),_?.({pauseResume:B,start:W,update:Y}))}),Y=v(function(A){N().update(A),L?.({pauseResume:B,reset:I,start:W})}),W=v(function(){I(),H()}),ae=v(function(A){h&&(A&&I(),H())});return o.useEffect(function(){U.current?F&&ae(!0):(U.current=!0,ae())},[F,U,ae,C,t.start,t.suffix,t.prefix,t.duration,t.separator,t.decimals,t.decimal,t.formattingFn]),o.useEffect(function(){return function(){I()}},[I]),{start:W,pauseResume:B,reset:I,update:Y,getCountUp:N}},te=["className","redraw","containerProps","children","style"],ne=function(t){var e=t.className,s=t.redraw,u=t.containerProps,h=t.children,F=t.style,C=m(t,te),x=o.useRef(null),j=o.useRef(!1),w=R(S(S({},C),{},{ref:x,startOnMount:typeof h!="function"||t.delay===0,enableReinitialize:!1})),_=w.start,L=w.reset,z=w.update,q=w.pauseResume,D=w.getCountUp,U=v(function(){_()}),$=v(function(B){t.preserveValue||L(),z(B)}),N=v(function(){if(typeof t.children=="function"&&!(x.current instanceof Element)){console.error(`Couldn't find attached element to hook the CountUp instance into! Try to attach "containerRef" from the render prop to a an Element, eg. <span ref={containerRef} />.`);return}D()});o.useEffect(function(){N()},[N]),o.useEffect(function(){j.current&&$(t.end)},[t.end,$]);var H=s&&t;return o.useEffect(function(){s&&j.current&&U()},[U,s,H]),o.useEffect(function(){!s&&j.current&&U()},[U,s,t.start,t.suffix,t.prefix,t.duration,t.separator,t.decimals,t.decimal,t.className,t.formattingFn]),o.useEffect(function(){j.current=!0},[]),typeof h=="function"?h({countUpRef:x,start:_,reset:L,update:z,pauseResume:q,getCountUp:D}):o.createElement("span",c({className:e,ref:x,style:F},u),typeof t.start<"u"?D().formattingFn(t.start):"")};return X.default=ne,X.useCountUp=R,X}var Ae=Ue();const Me=ve(Ae),me=({item:o})=>{const{title:V,iconBg:g,icon:f,prefix:S,suffix:d,value:i}=o;return r.jsx(ie,{children:r.jsx(oe,{children:r.jsxs("div",{className:"d-flex justify-content-between align-items-center",children:[r.jsx("div",{className:"avatar fs-60 avatar-img-size flex-shrink-0",children:r.jsx("span",{className:`avatar-title bg-${g}-subtle text-${g} rounded-circle fs-24`,children:r.jsx(f,{})})}),r.jsxs("div",{className:"text-end",children:[r.jsx("h3",{className:"mb-2 fw-normal",children:r.jsx("span",{children:r.jsx(Me,{end:i,suffix:d,prefix:S})})}),r.jsx("p",{className:"mb-0 text-muted",children:r.jsx("span",{children:V})})]})]})})})};function Te(o){if(!o)return"";const[V,g,f]=o.split("-").map(Number);return new Date(V,g-1,f).toLocaleDateString(void 0,{weekday:"long",day:"numeric",month:"short",year:"numeric"})}function De(o){return o?[o.firstName,o.lastName].filter(Boolean).join(" "):""}function Ye(){const{can:o,user:V,isAdmin:g}=be(),[f,S]=O.useState({patients:0,pending:0,confirmed:0,rejected:0,users:0}),[d,i]=O.useState([]),[l,c]=O.useState({date:"",googleConnected:!0,canGenerate:!1}),[n,m]=O.useState(!0),[p,y]=O.useState(!1),[E,b]=O.useState(""),[M,G]=O.useState(null),[v,T]=O.useState(null),[P,k]=O.useState(""),R=V?.role?.systemKey==="educator",te=async()=>{m(!0),b("");try{const e=await J("/api/dashboard/meetings");i(e.meetings||[]),c({date:e.date||"",googleConnected:e.googleConnected!==!1,canGenerate:!!e.canGenerate})}catch(e){b(e.message||"Could not load today's meetings")}finally{m(!1)}};O.useEffect(()=>{J("/api/dashboard/stats").then(S).catch(()=>{}),te().catch(()=>{}),g&&J("/api/dashboard/coordinator").then(G).catch(()=>{})},[]);const ne=async()=>{y(!0),b("");try{const e=await J("/api/dashboard/meetings/generate",{method:"POST",body:{}});i(e.meetings||[]),c({date:e.date||l.date,googleConnected:e.googleConnected!==!1,canGenerate:!!e.canGenerate})}catch(e){b(e.message||"Could not generate meetings")}finally{y(!1)}},a=async e=>{k("");try{const s=await J(`/api/cohort-sessions/${e.id}`);T(Oe(s))}catch(s){k(s.message||"Could not open vitals")}},t=[...o("onboarding","view")?[{title:"Patients",value:f.patients,icon:xe,iconBg:"primary",url:"/onboarding"},{title:"Pending",value:f.pending,icon:le,iconBg:"warning",url:"/onboarding?list=pending"},{title:"Confirmed",value:f.confirmed,icon:ue,iconBg:"success",url:"/onboarding?list=confirmed"},{title:"Rejected",value:f.rejected,icon:je,iconBg:"danger",url:"/onboarding?list=rejected"}]:[],...g&&M?[{title:"Pending payments",value:M.pendingPayments,icon:le,iconBg:"warning",url:"/onboarding?list=pending"},{title:"Unmatched pool",value:M.unmatchedPool,icon:we,iconBg:"info",url:"/matching"},{title:"Leave to approve",value:M.leaveToApprove,icon:Ve,iconBg:"danger",url:"/leaves"},{title:"Reassignment queue",value:M.reassignmentQueue,icon:ue,iconBg:"secondary",url:"/matching"}]:[]];return r.jsxs(Se,{fluid:!0,children:[r.jsx(Ee,{title:"Dashboard"}),r.jsx(re,{children:r.jsx(se,{children:r.jsx(ie,{children:r.jsxs(oe,{children:[r.jsx("h5",{className:"mb-2",children:"Welcome to VirtualPR"}),r.jsx("p",{className:"text-muted mb-3",children:"Manage pulmonary rehab patients, cohorts, and PRT access from this dashboard."}),r.jsxs("div",{className:"d-flex flex-wrap gap-2",children:[o("onboarding","add")?r.jsx(Q,{className:"btn btn-success",to:"/onboarding/new",children:"Add patient"}):null,o("onboarding","view")?r.jsx(Q,{className:"btn btn-outline-success",to:"/onboarding",children:"Patients"}):null,o("users","view")?r.jsx(Q,{className:"btn btn-outline-secondary",to:"/users",children:"Manage users"}):null]})]})})})}),t.length?r.jsx(re,{className:"row-cols-xxl-4 row-cols-md-2 row-cols-1",children:t.map(e=>r.jsx(se,{children:e.url?r.jsx(Q,{to:e.url,className:"text-reset",children:r.jsx(me,{item:e})}):r.jsx(me,{item:e})},e.title))}):null,r.jsx(re,{children:r.jsx(se,{children:r.jsx(ie,{children:r.jsxs(oe,{children:[r.jsxs("div",{className:"d-flex flex-wrap justify-content-between align-items-start gap-2 mb-3",children:[r.jsxs("div",{children:[r.jsx("h5",{className:"mb-1",children:"Today's meetings"}),r.jsxs("p",{className:"text-muted mb-0",children:[l.date?Te(l.date):"Cohort sessions for today",R?" · repeat Meet series from your Google Calendar":" · one repeating Meet per cohort"]})]}),l.canGenerate?r.jsx(ce,{variant:"outline-primary",size:"sm",onClick:ne,disabled:p,children:p?"Creating meetings...":"Create repeat meetings"}):null]}),R&&!l.googleConnected?r.jsxs("div",{className:"alert alert-warning",children:["Connect Google Calendar on your ",r.jsx(Q,{to:"/profile",children:"Profile"})," so this morning's cohort sessions can get a Meet link from your account."]}):null,E?r.jsx("div",{className:"alert alert-danger",children:E}):null,P?r.jsx("div",{className:"alert alert-danger",children:P}):null,n?r.jsx("p",{className:"text-muted mb-0",children:"Loading today's meetings..."}):d.length?r.jsxs(Pe,{responsive:!0,className:"mb-0 align-middle",children:[r.jsx("thead",{children:r.jsxs("tr",{children:[r.jsx("th",{children:"Time"}),r.jsx("th",{children:"Cohort"}),g?r.jsx("th",{children:"Virtual PRT"}):null,r.jsx("th",{children:"Meet"})]})}),r.jsx("tbody",{children:d.map(e=>r.jsxs("tr",{children:[r.jsxs("td",{className:"text-nowrap",children:[e.startTime,e.endTime?` – ${e.endTime}`:""]}),r.jsxs("td",{children:[r.jsx("div",{className:"fw-semibold",children:e.cohort?.name||e.title}),e.status==="failed"?r.jsx("div",{className:"small text-danger",children:e.error||"Could not create Meet link"}):null]}),g?r.jsx("td",{children:De(e.virtualPrt)}):null,r.jsx("td",{children:r.jsxs("div",{className:"d-flex flex-wrap align-items-center gap-2",children:[e.meetUrl?r.jsxs("a",{className:"btn btn-sm btn-success",href:e.meetUrl,target:"_blank",rel:"noreferrer",children:[r.jsx(Ce,{className:"me-1"}),"Join Meet"]}):e.status==="failed"?r.jsx(he,{bg:"danger",children:"Failed"}):r.jsx("span",{className:"text-muted",children:"Pending"}),r.jsx(ce,{size:"sm",variant:"outline-primary",onClick:()=>a(e),children:"Vitals"})]})})]},e.id))})]}):r.jsx("p",{className:"text-muted mb-0",children:R?"No cohort session is scheduled for you today (or it falls on a holiday / leave day).":"No cohort sessions are scheduled today."})]})})})}),r.jsx(Ne,{roster:v,onChange:T,onClose:()=>T(null)})]})}export{Ye as default};
|