1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[12588],{12588:(e,t,s)=>{s.r(t),s.d(t,{NewScheduleDialog:()=>x});var n=s(95155),a=s(12115),l=s(85400),i=s(18720),o=s(51834),r=s(64269),d=s(66253),c=s(40157),m=s(96270);let u="h-11 w-full rounded-[10px] border border-ws-line bg-white px-3 text-[15px] text-ws-ink",h="flex flex-col gap-1.5 text-sm font-bold text-ws-ink";function x(e){let{open:t,onOpenChange:s,tools:a,onCreated:l,schedule:i}=e,r=()=>{s(!1),l()};return(0,n.jsx)(o.lG,{open:t,onOpenChange:s,children:(0,n.jsx)(o.Cf,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[520px]",children:t&&(i?(0,n.jsx)(f,{schedule:i,onDone:r}):(0,n.jsx)(p,{tools:a,onDone:r}))})})}function p(e){var t,s;let{tools:x,onDone:p}=e,f=new Date,g=(0,m.gD)(f),v=(0,m.gD)(new Date(f.getFullYear(),f.getMonth(),f.getDate()+1)),[y,b]=(0,a.useState)({clientId:"",templateId:"",deliveryMethod:"email",startDate:v,endDate:""}),[j,N]=(0,a.useState)("monthly"),[w,D]=(0,a.useState)(2),[S,C]=(0,a.useState)(""),A=j===m.We,[k,T]=(0,a.useState)(""),[M,E]=(0,a.useState)(!1),I=(0,l.Ay)("/api/clients",c.YA),L=null!=(s=null==(t=I.data)?void 0:t.clients)?s:[],P=e=>b(t=>({...t,...e})),q=L.find(e=>e.id===y.clientId),R=async e=>{e.preventDefault();let t=(0,m.Lk)({...y,daysBefore:A?w:void 0},g,L.find(e=>e.id===y.clientId));if(t)return void T(t);T(""),E(!0);try{let e=await fetch("/api/assessments/schedules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:y.clientId,assessmentTemplateId:y.templateId,frequency:j,deliveryMethod:y.deliveryMethod,...A?{daysBeforeAppointment:w,appointmentType:S||void 0}:{startDate:y.startDate},endDate:y.endDate||void 0})}),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||"The schedule could not be saved. Please try again.");i.o.success("Schedule saved"),p()}catch(e){T(e instanceof Error?e.message:"The schedule could not be saved. Please try again.")}finally{E(!1)}};return(0,n.jsxs)("form",{onSubmit:R,className:"flex flex-col gap-4",noValidate:!0,children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)(o.L3,{className:"text-[22px] font-extrabold",children:"New schedule"}),(0,n.jsx)(o.rr,{className:"text-sm text-ws-muted",children:"Sends a tool to a client again and again, or before each of their appointments, until the end date or until you pause it."})]}),(0,n.jsxs)("label",{className:h,children:[(0,n.jsxs)("span",{children:["Client",(0,n.jsx)("span",{className:"font-semibold text-[#b42318]",children:" (required)"})]}),(0,n.jsxs)("select",{className:u,value:y.clientId,onChange:e=>P({clientId:e.target.value}),required:!0,children:[(0,n.jsx)("option",{value:"",children:I.isLoading?"Loading clientsâ¦":"Choose a client"}),L.map(e=>(0,n.jsx)("option",{value:e.id,children:(0,d.X2)(e)},e.id))]})]}),(0,n.jsxs)("label",{className:h,children:[(0,n.jsxs)("span",{children:["Tool",(0,n.jsx)("span",{className:"font-semibold text-[#b42318]",children:" (required)"})]}),(0,n.jsxs)("select",{className:u,value:y.templateId,onChange:e=>P({templateId:e.target.value}),required:!0,children:[(0,n.jsx)("option",{value:"",children:"Choose a tool"}),x.map(e=>(0,n.jsxs)("option",{value:e.id,children:[e.name,e.fullName?" \xb7 ".concat(e.fullName):""]},e.id))]})]}),(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,n.jsxs)("label",{className:h,children:["How often",(0,n.jsxs)("select",{className:u,value:j,onChange:e=>N(e.target.value),children:[m.Lj.map(e=>{let[t,s]=e;return(0,n.jsx)("option",{value:t,children:s},t)}),(0,n.jsx)("option",{value:m.We,children:"Before each appointment"})]})]}),(0,n.jsxs)("fieldset",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)("legend",{className:"mb-1.5 text-sm font-bold text-ws-ink",children:"Send by"}),(0,n.jsx)("div",{className:"flex h-11 items-center gap-5 text-[15px]",children:["email","sms"].map(e=>(0,n.jsxs)("label",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"radio",name:"deliveryMethod",value:e,checked:y.deliveryMethod===e,onChange:()=>P({deliveryMethod:e}),className:"h-4 w-4 accent-ws-primary"}),"email"===e?"Email":"SMS"]},e))}),q&&(0,n.jsx)("span",{className:"text-xs font-medium text-ws-muted","aria-live":"polite",children:"email"===y.deliveryMethod?q.email?"Goes to ".concat(q.email):"This client has no email address.":q.mobile?"Goes to ".concat(q.mobile):"This client has no mobile number."})]})]}),A&&(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,n.jsxs)("label",{className:h,children:["Days before",(0,n.jsx)("input",{type:"number",min:1,max:14,className:u,value:w,onChange:e=>D(Number(e.target.value))})]}),(0,n.jsxs)("label",{className:h,children:["Appointment type",(0,n.jsx)("select",{className:u,value:S,onChange:e=>C(e.target.value),children:m.Au.map(e=>{let[t,s]=e;return(0,n.jsx)("option",{value:t,children:s},t)})})]}),(0,n.jsx)("p",{className:"text-xs font-medium text-ws-muted sm:col-span-2",children:"Goes out once for each of your appointments with this client, with the standard wording and the link only. Texts wait until 8 am. Nothing is sent if the client has no mobile or email for the way you choose. The type only narrows appointments booked here with a type; appointments from your practice system or receptionist always count."})]}),(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[!A&&(0,n.jsxs)("label",{className:h,children:[(0,n.jsxs)("span",{children:["Start date",(0,n.jsx)("span",{className:"font-semibold text-[#b42318]",children:" (required)"})]}),(0,n.jsx)("input",{type:"date",className:u,min:v,value:y.startDate,onChange:e=>P({startDate:e.target.value}),required:!0}),(0,n.jsx)("span",{className:"text-xs font-medium text-ws-muted",children:"The first one goes out on this day."})]}),(0,n.jsxs)("label",{className:h,children:["End date",(0,n.jsx)("input",{type:"date",className:u,min:A?v:y.startDate||v,value:y.endDate,onChange:e=>
1P({endDate:e.target.value})}),(0,n.jsx)("span",{className:"text-xs font-medium text-ws-muted",children:"Nothing is sent after this day. Leave blank to keep going until you pause it."})]})]}),k&&(0,n.jsx)("p",{role:"alert",className:"rounded-[10px] bg-ws-red-soft px-3.5 py-2.5 text-sm font-semibold text-ws-red",children:k}),(0,n.jsxs)("div",{className:"flex flex-col-reverse gap-2.5 sm:flex-row sm:justify-end",children:[(0,n.jsx)(o.HM,{type:"button",className:(0,r.cn)(d.Pz.base,d.Pz.sec),children:"Cancel"}),(0,n.jsx)("button",{type:"submit",className:(0,r.cn)(d.Pz.base,d.Pz.pri),disabled:M,children:M?"Savingâ¦":"Save schedule"})]})]})}function f(e){var t,s,l,c;let{schedule:x,onDone:p}=e,f=(0,m.gD)(new Date),g="email"===x.deliveryMethod||"sms"===x.deliveryMethod,v=x.frequency===m.We,[y,b]=(0,a.useState)(null!=(t=x.daysBeforeAppointment)?t:2),[j,N]=(0,a.useState)(x.frequency),[w,D]=(0,a.useState)(x.deliveryMethod),[S]=(0,a.useState)(()=>({nextDate:(0,m.gD)(new Date(x.nextSendDate)),endDate:x.endDate?(0,m.gD)(new Date(x.endDate)):""})),[C,A]=(0,a.useState)(S.nextDate),[k,T]=(0,a.useState)(S.endDate),[M,E]=(0,a.useState)(""),[I,L]=(0,a.useState)(!1),P=x.Client,q="custom"===x.frequency?[...m.Lj,["custom","Every ".concat(null!=(s=x.customDays)?s:7," days")]]:[...m.Lj],R=async e=>{e.preventDefault();let t=w!==x.deliveryMethod?P:null,s=v?!Number.isInteger(y)||y<1||y>14?"Choose 1 to 14 days before.":(0,m.dt)({deliveryMethod:w,nextDate:f,endDate:k},f,t):(0,m.dt)({deliveryMethod:w,nextDate:C===S.nextDate&&C<f?f:C,endDate:k},f,t);if(s)return void E(s);E(""),L(!0);try{let e=await fetch("/api/assessments/schedules/".concat(x.id),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({...j!==x.frequency&&{frequency:j},...v&&y!==x.daysBeforeAppointment&&{daysBeforeAppointment:y},...k!==S.endDate&&{endDate:k||null},...g&&w!==x.deliveryMethod&&{deliveryMethod:w},...g&&!v&&C!==S.nextDate&&{nextSendDate:C}})}),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||"The schedule could not be saved. Please try again.");i.o.success("Schedule saved"),p()}catch(e){E(e instanceof Error?e.message:"The schedule could not be saved. Please try again.")}finally{L(!1)}};return(0,n.jsxs)("form",{onSubmit:R,className:"flex flex-col gap-4",noValidate:!0,children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)(o.L3,{className:"text-[22px] font-extrabold",children:"Edit schedule"}),(0,n.jsxs)(o.rr,{className:"text-sm text-ws-muted",children:[x.bundleName||x.AssessmentTemplate.fullName||x.AssessmentTemplate.name,P?" for ".concat((0,d.X2)({firstName:null!=(l=P.firstName)?l:null,lastName:null!=(c=P.lastName)?c:null})):""]})]}),(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[v?(0,n.jsxs)("label",{className:h,children:["Days before each appointment",(0,n.jsx)("input",{type:"number",min:1,max:14,className:u,value:y,onChange:e=>b(Number(e.target.value))})]}):(0,n.jsxs)("label",{className:h,children:["How often",(0,n.jsx)("select",{className:u,value:j,onChange:e=>N(e.target.value),children:q.map(e=>{let[t,s]=e;return(0,n.jsx)("option",{value:t,children:s},t)})})]}),g&&(0,n.jsxs)("fieldset",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)("legend",{className:"mb-1.5 text-sm font-bold text-ws-ink",children:"Send by"}),(0,n.jsx)("div",{className:"flex h-11 items-center gap-5 text-[15px]",children:["email","sms"].map(e=>(0,n.jsxs)("label",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"radio",name:"deliveryMethod",value:e,checked:w===e,onChange:()=>D(e),className:"h-4 w-4 accent-ws-primary"}),"email"===e?"Email":"SMS"]},e))})]})]}),(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[g&&!v&&(0,n.jsxs)("label",{className:h,children:[(0,n.jsxs)("span",{children:["Next one goes out",(0,n.jsx)("span",{className:"font-semibold text-[#b42318]",children:" (required)"})]}),(0,n.jsx)("input",{type:"date",className:u,min:f,value:C,onChange:e=>A(e.target.value),required:!0}),(0,n.jsx)("span",{className:"text-xs font-medium text-ws-muted",children:"Later ones follow from this day."})]}),(0,n.jsxs)("label",{className:h,children:["End date",(0,n.jsx)("input",{type:"date",className:u,min:g&&!v?C:f,value:k,onChange:e=>T(e.target.value)}),(0,n.jsx)("span",{className:"text-xs font-medium text-ws-muted",children:"Nothing is sent after this day. Leave blank to keep going until you pause it."})]})]}),M&&(0,n.jsx)("p",{role:"alert",className:"rounded-[10px] bg-ws-red-soft px-3.5 py-2.5 text-sm font-semibold text-ws-red",children:M}),(0,n.jsxs)("div",{className:"flex flex-col-reverse gap-2.5 sm:flex-row sm:justify-end",children:[(0,n.jsx)(o.HM,{type:"button",className:(0,r.cn)(d.Pz.base,d.Pz.sec),children:"Cancel"}),(0,n.jsx)("button",{type:"submit",className:(0,r.cn)(d.Pz.base,d.Pz.pri),disabled:I,children:I?"Savingâ¦":"Save changes"})]})]})}},40157:(e,t,s)=>{s.d(t,{Rl:()=>v,Wc:()=>x,YA:()=>f,dE:()=>g});var n=s(95155),a=s(12115),l=s(85400),i=s(35299),o=s(37772),r=s(18720),d=s(3998),c=s(6259),m=s(98053),u=s(59443),h=s(94933);let x={completed:{label:"Completed",tone:"green"},failed:{label:"Not delivered",tone:"red"},expired:{label:"Expired",tone:"amber"},in_progress:{label:"Started",tone:"blue"},pending:{label:"Waiting",tone:"grey"}},p={email:"email",sms:"SMS",link:"link"},f=e=>fetch(e).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status))));function g(e){var t,s,n,a,l,i;if(e.isBundleInvitation&&e.bundleName)return e.bundleName;let o=null!=(i=null==(t=e.InvitationAssessments)?void 0:t.length)?i:0;return o>1?e.bundleName||"Bundle of ".concat(o):(null==(s=e.AssessmentTemplate)?void 0:s.name)||(null==(l=e.InvitationAssessments)||null==(a=l[0])||null==(n=a.AssessmentTemplate)?void 0:n.name)||"Assessment"}function v(e){let{url:t="/api/assessments/invitations",filter:s,showClient:v=!0,empty:y="No invitations here yet."}=e,{data:b,error:j,isLoading:N,mutate:w}=(0,l.Ay)(t,f,{refreshInterval:3e4}),[D,S]=(0,a.useState)(null),[C,A]=(0,a.useState)(null),k=(Array.isArray(b)?b:[]).filter(null!=s?s:()=>!0),T=async(e,t)=>{S(e.id);try{let s=await fetch("/api/assessments/invitations/".concat(e.id,"/remind"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:t})}),n=await s.json().catch(()=>({}));if(!s.ok){r.o.error(n.error||"Failed to send reminder",{description:n.hint||void 0}),(409===s.status||410===s.status)&&w();return}r.o.success("Reminder sent by ".concat("sms"===n.method?"SMS":"email"),n.expiryExtended?{description:"The due date was pushed back so they can still finish it."}:void 0),w()}catch(e){r.o.error("Failed to send reminder. Please try again.")}finally{S(null)}},M=async()=>
1{if(A(null),C){S(C.id);try{let e=await fetch("/api/assessments/invitations/".concat(C.id),{method:"DELETE"}),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||"Failed to cancel");r.o.success(t.revoked?"Invitation cancelled. The link no longer works; finished answers were kept.":"Invitation deleted. The link no longer works."),w()}catch(e){r.o.error(e instanceof Error?e.message:"Failed to cancel")}finally{S(null)}}};return j&&!b?(0,n.jsx)(h.p5,{what:"sent assessments",onRetry:()=>void w()}):N?(0,n.jsx)("div",{className:"flex justify-center py-10",children:(0,n.jsx)(i.A,{className:"h-6 w-6 animate-spin text-ws-muted",role:"status","aria-label":"Loading invitations"})}):0===k.length?(0,n.jsx)(h.AF,{title:y}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("ul",{className:"divide-y divide-ws-grey-soft overflow-hidden rounded-2xl border border-ws-border bg-white",children:k.map(e=>{var t,s,a,l,r,m,f;let y=x[(0,u.FV)(e)],b=(0,u.Vw)(e),j=[null==(t=e.Client)?void 0:t.firstName,null==(s=e.Client)?void 0:s.lastName].filter(Boolean).join(" "),N=[];return e.remindersSent&&N.push("".concat(e.remindersSent," reminder").concat(1===e.remindersSent?"":"s"," sent")+(e.lastReminderAt?", last ".concat(new Date(e.lastReminderAt).toLocaleDateString("en-AU")):"")),!e.isCompleted&&e.autoReminderDays&&N.push(e.autoReminderSentAt?"auto-reminder sent":"auto-reminder on day ".concat(e.autoReminderDays)),(0,n.jsxs)("li",{className:"flex flex-wrap items-center gap-3 px-5 py-3.5 text-sm",children:[(0,n.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[(0,n.jsxs)("span",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("strong",{children:g(e)}),b.total>1&&(0,n.jsxs)("span",{className:"text-xs font-semibold text-ws-muted",children:[b.completed," of ",b.total," done"]})]}),(0,n.jsx)("span",{className:"text-xs text-ws-muted",children:[v&&j?j:null,"sent by ".concat(null!=(f=p[e.deliveryMethod])?f:e.deliveryMethod).concat(e.sentAt?" on ".concat(new Date(e.sentAt).toLocaleDateString("en-AU")):""),e.expiresAt&&!e.isCompleted?"due ".concat(new Date(e.expiresAt).toLocaleDateString("en-AU")):null,...N].filter(Boolean).join(" \xb7 ")})]}),(0,n.jsx)(h.UT,{tone:y.tone,children:y.label}),(0,n.jsxs)(c.rI,{children:[(0,n.jsx)(c.ty,{asChild:!0,children:(0,n.jsx)(d.$,{variant:"ghost",size:"icon",className:"h-9 w-9",disabled:D===e.id,"aria-label":"Actions for ".concat(g(e)).concat(v&&j?" sent to ".concat(j):""),children:D===e.id?(0,n.jsx)(i.A,{className:"h-4 w-4 animate-spin"}):(0,n.jsx)(o.A,{className:"h-4 w-4"})})}),(0,n.jsxs)(c.SQ,{align:"end",children:[!e.isCompleted&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(c._2,{disabled:!(null==(a=e.Client)?void 0:a.email),onClick:()=>T(e,"email"),children:["Remind by email",!(null==(l=e.Client)?void 0:l.email)&&" (no email on file)"]}),(0,n.jsxs)(c._2,{disabled:!(null==(r=e.Client)?void 0:r.mobile),onClick:()=>T(e,"sms"),children:["Remind by SMS",!(null==(m=e.Client)?void 0:m.mobile)&&" (no mobile on file)"]}),(0,n.jsx)(c.mB,{})]}),(0,n.jsx)(c._2,{className:"text-destructive focus:text-destructive",onClick:()=>A(e),children:"Cancel invitation"})]})]})]},e.id)})}),(0,n.jsx)(m.AlertDialog,{open:!!C,onOpenChange:e=>!e&&A(null),children:(0,n.jsxs)(m.AlertDialogContent,{children:[(0,n.jsxs)(m.AlertDialogHeader,{children:[(0,n.jsxs)(m.AlertDialogTitle,{children:["Cancel ",C?g(C):"this invitation","?"]}),(0,n.jsxs)(m.AlertDialogDescription,{children:["The link stops working straight away.",C&&(0,u.Vw)(C).completed>0?" Answers already given are kept.":" Nothing has been answered yet."]})]}),(0,n.jsxs)(m.AlertDialogFooter,{children:[(0,n.jsx)(m.AlertDialogCancel,{children:"Keep it"}),(0,n.jsx)(m.AlertDialogAction,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:M,children:"Cancel invitation"})]})]})})]})}},66253:(e,t,s)=>{s.d(t,{NV:()=>l,Pz:()=>n,Re:()=>p,TN:()=>o,X2:()=>a,Z8:()=>x,bd:()=>m,gu:()=>h,qy:()=>r,sI:()=>u,sk:()=>d,vJ:()=>i});let n={base:"inline-flex h-11 items-center justify-center gap-2 rounded-[12px] px-[18px] text-sm font-bold whitespace-nowrap disabled:cursor-not-allowed disabled:opacity-50",pri:"bg-ws-primary text-white hover:bg-ws-primary-hover",sec:"border border-ws-line bg-white text-ws-ink hover:bg-[#eef2f8]",danger:"bg-[#b42318] text-white hover:bg-ws-red"};function a(e){return e.isAnonymous?e.anonymousCode||"Anonymous client":[e.firstName,e.lastName].filter(
1Boolean).join(" ").trim()||"Unnamed client"}function l(e){var t,s,n,a;return e.isAnonymous?"A":"".concat(null!=(n=null==(t=e.firstName)?void 0:t.trim()[0])?n:"").concat(null!=(a=null==(s=e.lastName)?void 0:s.trim()[0])?a:"").toUpperCase()||"?"}function i(e){return void 0===e?"â":null===e?"None booked":0===e?"Today":1===e?"Tomorrow":"In ".concat(e," days")}function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();if(!e)return null;let s=new Date(e).getTime();return Number.isNaN(s)?null:Math.floor((t-s)/315576e5)}function r(e){if(!e)return"";let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleDateString("en-AU",{day:"numeric",month:"short",year:"numeric"})}function d(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Date.now();if((null==e?void 0:e.urgency)==="declining"||(null==e?void 0:e.urgency)==="crisis")return{label:"Needs attention",tone:"red"};if(t){let e=Math.ceil((new Date(t).getTime()-s)/864e5);if(e<=0)return{label:"Referral has run out",tone:"amber"};if(e<=30)return{label:"Referral runs out in ".concat(e," day").concat(1===e?"":"s"),tone:"amber"}}let n=null==e?void 0:e.badges.find(e=>e.includes("overdue"));if(n)return{label:n[0].toUpperCase()+n.slice(1),tone:"amber"};let a=null==e?void 0:e.badges.find(e=>e.includes("pending assessment"));return a?{label:a[0].toUpperCase()+a.slice(1),tone:"grey"}:null}let c={sessions:"sessions",overview:"sessions",notes:"notes",documents:"notes",forms:"notes",messages:"messages",comms:"messages",communications:"messages",assessments:"assessments",outcomes:"assessments",insights:"insights",profile:"profile",clinical:"profile",healthcare:"profile"},m="family-graph",u=e=>e&&c[e]||"sessions",h=e=>!!(null==e?void 0:e.canEdit),x=e=>(null==e?void 0:e.accessType)==="owner"||(null==e?void 0:e.accessType)==="assigned"||(null==e?void 0:e.accessType)==="org_role"&&"full"===e.accessLevel;function p(e,t){var s,n;return null!=(n=null!=(s=e.find(e=>e.id===t))?s:e.find(e=>"active"===e.status))?n:e[0]}}}]);
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.