2 lines
3.0 KiB
JavaScript
2 lines
3.0 KiB
JavaScript
import{r as d,d as l,j as e,B as h}from"./index-B92aEPQH.js";import{F as g}from"./FormLabel-DFBiGE9d.js";import{F as p}from"./FormCheck-QYGhbIhB.js";import{M as x,a as f,b as j,c as C}from"./Modal-D4T7V4-p.js";function b({cohortId:o,value:t,onChange:s}){const[c,n]=d.useState([]),r=t.status==="cancelled"&&t.original!=="cancelled";d.useEffect(()=>{if(!r)return;let a=!0;return l("/api/cohorts?status=active&limit=100").then(m=>{a&&n((m.items||[]).filter(u=>u.id!==o))}).catch(()=>{a&&n([])}),()=>{a=!1}},[r,o]);const i=a=>s({...t,...a});return e.jsxs(e.Fragment,{children:[e.jsx(g,{children:"Status"}),e.jsxs("select",{className:"form-select",value:t.status,onChange:a=>i({status:a.target.value}),children:[e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"completed",children:"Completed"}),e.jsx("option",{value:"cancelled",children:"Cancelled"})]}),r?e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"form-text mb-1",children:"Upcoming sessions stop. Where should the patients go?"}),e.jsx(p,{type:"radio",id:"cancel-pool",name:"cancelAction",label:"Move all patients to the unassigned pool",checked:t.patientAction==="pool",onChange:()=>i({patientAction:"pool"})}),e.jsx(p,{type:"radio",id:"cancel-move",name:"cancelAction",label:"Move all patients to an existing cohort",checked:t.patientAction==="move",onChange:()=>i({patientAction:"move"})}),t.patientAction==="move"?e.jsxs("select",{className:"form-select mt-2",value:t.targetCohortId,onChange:a=>i({targetCohortId:a.target.value}),children:[e.jsx("option",{value:"",children:"Select cohort"}),c.map(a=>e.jsxs("option",{value:a.id,children:[a.name," · ",a.patientCount," patients"]},a.id))]}):null]}):null]})}function M(o){const t=o?.status==="confirmed"?"active":o?.status||"active";return{original:t,status:t,patientAction:"pool",targetCohortId:""}}function F(o){return o?.status==="cancelled"&&o.original!=="cancelled"&&o.patientAction==="move"&&!o.targetCohortId?"Select the cohort to move the patients into.":""}async function I(o,t,{force:s=!1}={}){!t||t.status===t.original||await l(`/api/cohorts/${o}/status`,{method:"POST",body:{status:t.status,patientAction:t.patientAction,targetCohortId:t.targetCohortId||null,force:s}})}async function k(o,t){return!t||t.status===t.original||t.status!=="cancelled"||t.patientAction!=="move"?[]:(await l(`/api/cohorts/${o}/status`,{method:"POST",body:{status:t.status,patientAction:t.patientAction,targetCohortId:t.targetCohortId||null,check:!0}}))?.warnings||[]}function N({warnings:o,busy:t,onCancel:s,onConfirm:c}){return e.jsxs(x,{show:o.length>0,onHide:s,children:[e.jsx(f,{closeButton:!0,children:e.jsx("h5",{className:"modal-title",children:"Target cohort does not fully match"})}),e.jsxs(j,{children:[e.jsx("ul",{className:"mb-2 ps-3",children:o.map(n=>e.jsx("li",{children:n},n))}),"Do you still want to move the patients?"]}),e.jsxs(C,{children:[e.jsx(h,{variant:"light",onClick:s,children:"Cancel"}),e.jsx(h,{variant:"warning",disabled:t,onClick:c,children:t?"Saving…":"Move anyway"})]})]})}export{b as C,N as a,F as b,M as c,k as d,I as s};
|