VirtualPR/frontend/dist/assets/profile-DvyYZO4G.js

2 lines
11 KiB
JavaScript

import{b as ce,D as me,r,j as e,C as he,R as F,l as i,B as p,d as C}from"./index-B92aEPQH.js";import{D as ue}from"./DateField-Czgv6mdL.js";import{P as ge}from"./PageBreadcrumb-Dsn9CkpH.js";import{u as xe,W as pe}from"./useSettings-B5rMnTFQ.js";import{m as je,i as fe}from"./mobile-CfiPsqNQ.js";import{C as D,a as A}from"./Card-DPmHd5BI.js";import{F as n}from"./FormLabel-DFBiGE9d.js";import{F as c}from"./FormControl-BhzYseFY.js";import{F as S}from"./FormCheck-QYGhbIhB.js";import{M as ve,a as we,b as be,c as Ce}from"./Modal-D4T7V4-p.js";import"./PageMetaData-DFmRpQLs.js";import"./FormContext-IkkKm1bh.js";function f(t){return String(t).padStart(2,"0")}function Se(){const t=new Date;return{date:`${t.getFullYear()}-${f(t.getMonth()+1)}-${f(t.getDate())}`,startTime:`${f(t.getHours())}:${f(t.getMinutes())}`}}function W(t,h){const[v,k,w]=t.split("-").map(Number),[y,l]=(h||"00:00").split(":").map(Number),o=new Date(v,k-1,w,y,l);return o.setHours(o.getHours()+1),`${f(o.getHours())}:${f(o.getMinutes())}`}function se(){const{date:t,startTime:h}=Se();return{title:"",date:t,startTime:h,endTime:W(t,h),autoAdmit:!0,allowMicVideo:!0}}function Oe(){const{user:t,refresh:h}=ce(),{settings:v}=xe(),k=t?.role?.systemKey==="educator",[w,y]=me(),[l,o]=r.useState({firstName:"",lastName:"",email:"",phone:"",role:"",specializations:[],availableSlots:[],availableStartWeekdays:[],maxCohorts:""}),[u,N]=r.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[O,E]=r.useState(""),[z,$]=r.useState(""),[q,M]=r.useState(""),[L,H]=r.useState(""),[B,g]=r.useState(""),[U,j]=r.useState(""),[V,R]=r.useState(!1),[K,Y]=r.useState(!1),[Z,_]=r.useState(!1),[I,J]=r.useState(!1),[te,P]=r.useState(!1),[d,x]=r.useState(se),[Q,G]=r.useState(""),[X,ee]=r.useState(!1),[T,b]=r.useState(""),ae=t?.googleCalendar||{connected:!1,email:""};r.useEffect(()=>{t&&o({firstName:t.firstName||"",lastName:t.lastName||"",email:t.email||"",phone:t.phone||"",role:t.role?.name||"",specializations:t.specializations||[],availableSlots:t.availableSlots||[],availableStartWeekdays:t.availableStartWeekdays||[],maxCohorts:t.maxCohorts??""})},[t]),r.useEffect(()=>{const a=w.get("google");if(!a)return;a==="connected"?(j("Google Calendar connected."),g(""),b(""),h().catch(()=>{})):(g("Could not connect Google Calendar. Try again."),j(""),b(""));const s=new URLSearchParams(w);s.delete("google"),y(s,{replace:!0})},[w,y,h]);const le=async()=>{g(""),j(""),b(""),_(!0);try{const a=await C("/api/google/connect");if(!a?.url)throw new Error("Google Calendar is not configured");window.location.href=a.url}catch(a){g(a.message),_(!1)}},re=()=>{x(se()),G(""),P(!0)},ne=async a=>{a.preventDefault(),G(""),ee(!0);try{const s=await C("/api/google/events",{method:"POST",body:{title:d.title,date:d.date,startTime:d.startTime.slice(0,5),endTime:d.endTime.slice(0,5),timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,autoAdmit:d.autoAdmit,allowMicVideo:d.allowMicVideo}});P(!1),g(""),j(s.meetUrl?"Event created. Google Meet link:":"Event created."),b(s.meetUrl||s.htmlLink||"")}catch(s){G(s.message)}finally{ee(!1)}},oe=async()=>{g(""),j(""),b(""),J(!0);try{await C("/api/google/disconnect",{method:"POST"}),await h(),j("Google Calendar disconnected.")}catch(a){g(a.message)}finally{J(!1)}},ie=async a=>{if(a.preventDefault(),E(""),$(""),String(l.phone||"").trim()&&!fe(l.phone)){E("Mobile must be 10 digits.");return}R(!0);try{await C("/api/auth/profile",{method:"PATCH",body:{firstName:l.firstName,lastName:l.lastName,phone:l.phone,specializations:l.specializations,availableSlots:l.availableSlots,availableStartWeekdays:l.availableStartWeekdays,maxCohorts:l.maxCohorts===""?null:Number(l.maxCohorts)}}),await h(),$("Profile updated.")}catch(s){E(s.message)}finally{R(!1)}},de=async a=>{if(a.preventDefault(),M(""),H(""),u.newPassword!==u.confirmPassword){M("New password and confirmation do not match.");return}Y(!0);try{await C("/api/auth/change-password",{method:"POST",body:{currentPassword:u.currentPassword,newPassword:u.newPassword}}),N({currentPassword:"",newPassword:"",confirmPassword:""}),H("Password changed.")}catch(s){M(s.message)}finally{Y(!1)}};return e.jsxs(he,{fluid:!0,children:[e.jsx(ge,{title:"My profile"}),e.jsxs(F,{className:"g-3",children:[e.jsx(i,{lg:7,children:e.jsx(D,{children:e.jsxs(A,{children:[e.jsx("h5",{className:"mb-3",children:"Personal details"}),O?e.jsx("div",{className:"alert alert-danger",children:O}):null,z?e.jsx("div",{className:"alert alert-success",children:z}):null,e.jsxs("form",{onSubmit:ie,children:[e.jsxs(F,{className:"g-3",children:[e.jsxs(i,{md:6,children:[e.jsx(n,{children:"First name"}),e.jsx(c,{value:l.firstName,onChange:a=>o(s=>({...s,firstName:a.target.value})),required:!0})]}),e.jsxs(i,{md:6,children:[e.jsx(n,{children:"Last name"}),e.jsx(c,{value:l.lastName,onChange:a=>o(s=>({...s,lastName:a.target.value})),required:!0})]}),e.jsxs(i,{md:6,children:[e.jsx(n,{children:"Email"}),e.jsx(c,{value:l.email,disabled:!0})]}),e.jsxs(i,{md:6,children:[e.jsx(n,{children:"Phone"}),e.jsx(c,{inputMode:"numeric",maxLength:10,value:l.phone,onChange:a=>o(s=>({...s,phone:je(a.target.value)}))})]}),e.jsxs(i,{md:6,children:[e.jsx(n,{children:"Role"}),e.jsx(c,{value:l.role,disabled:!0})]}),k?e.jsxs(e.Fragment,{children:[e.jsxs(i,{xs:12,children:[e.jsx(n,{children:"Specializations"}),e.jsx("div",{className:"d-flex flex-wrap gap-3",children:[...v?.diseaseTypes||[],"both"].filter((a,s,m)=>m.indexOf(a)===s).map(a=>e.jsx(S,{type:"checkbox",id:`profile-spec-${a}`,label:a,checked:l.specializations.includes(a),onChange:()=>o(s=>({...s,specializations:s.specializations.includes(a)?s.specializations.filter(m=>m!==a):[...s.specializations,a]}))},a))})]}),e.jsxs(i,{xs:12,children:[e.jsx(n,{children:"Available slots"}),e.jsx("div",{className:"d-flex flex-wrap gap-3",children:(v?.slots||[]).map(a=>e.jsx(S,{type:"checkbox",id:`profile-slot-${a.label}`,label:a.label,checked:l.availableSlots.includes(a.label),onChange:()=>o(s=>({...s,availableSlots:s.availableSlots.includes(a.label)?s.availableSlots.filter(m=>m!==a.label):[...s.availableSlots,a.label]}))},a.label))})]}),e.jsxs(i,{xs:12,children:[e.jsx(n,{children:"Available start weekdays"}),e.jsx("div",{className:"d-flex flex-wrap gap-3",children:(v?.cohortStartWeekdays||[1,2]).map(a=>e.jsx(S,{type:"checkbox",id:`profile-wd-${a}`,label:pe[a],checked:l.availableStartWeekdays.includes(a),onChange:()=>o(s=>({...s,availableStartWeekdays:s.availableStartWeekdays.includes(a)?s.availableStartWeekdays.filter(m=>m!==a):[...s.availableStartWeekdays,a]}))},a))})]}),e.jsxs(i,{md:6,children:[e.jsx(n,{children:"Max cohorts"}),e.jsx(c,{type:"number",min:1,max:20,value:l.maxCohorts,onChange:a=>o(s=>({...s,maxCohorts:a.target.value}))})]})]}):null]}),e.jsx(p,{type:"submit",className:"mt-4",disabled:V,children:V?"Saving...":"Save details"})]})]})})}),e.jsxs(i,{lg:5,children:[e.jsx(D,{children:e.jsxs(A,{children:[e.jsx("h5",{className:"mb-3",children:"Change password"}),q?e.jsx("div",{className:"alert alert-danger",children:q}):null,L?e.jsx("div",{className:"alert alert-success",children:L}):null,e.jsxs("form",{onSubmit:de,children:[e.jsxs("div",{className:"mb-3",children:[e.jsx(n,{children:"Current password"}),e.jsx(c,{type:"password",value:u.currentPassword,onChange:a=>N(s=>({...s,currentPassword:a.target.value})),required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx(n,{children:"New password"}),e.jsx(c,{type:"password",minLength:6,value:u.newPassword,onChange:a=>N(s=>({...s,newPassword:a.target.value})),required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx(n,{children:"Confirm new password"}),e.jsx(c,{type:"password",minLength:6,value:u.confirmPassword,onChange:a=>N(s=>({...s,confirmPassword:a.target.value})),required:!0})]}),e.jsx(p,{type:"submit",disabled:K,children:K?"Updating...":"Update password"})]})]})}),e.jsx(D,{className:"mt-3",children:e.jsxs(A,{children:[e.jsx("h5",{className:"mb-3",children:"Google Calendar"}),B?e.jsx("div",{className:"alert alert-danger",children:B}):null,U?e.jsxs("div",{className:"alert alert-success",children:[U,T?e.jsx("div",{className:"mt-2",children:e.jsx("a",{href:T,target:"_blank",rel:"noreferrer",children:T})}):null]}):null,ae.connected?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-muted mb-3",children:["Connected as ",e.jsx("strong",{children:ae.email||"Google account"}),". Each morning, today's cohort sessions are created as Calendar events with Google Meet links on this account."]}),e.jsxs("div",{className:"d-flex flex-wrap gap-2",children:[e.jsx(p,{onClick:re,children:"Create event"}),e.jsx(p,{variant:"outline-danger",onClick:oe,disabled:I,children:I?"Disconnecting...":"Disconnect"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted mb-3",children:"Connect Google Calendar so the app can create events with a Google Meet link."}),e.jsx(p,{onClick:le,disabled:Z,children:Z?"Redirecting...":"Connect Google Calendar"})]})]})})]})]}),e.jsx(ve,{show:te,onHide:()=>P(!1),children:e.jsxs("form",{onSubmit:ne,children:[e.jsx(we,{closeButton:!0,children:e.jsx("h5",{className:"modal-title",children:"Create Google Calendar event"})}),e.jsxs(be,{children:[Q?e.jsx("div",{className:"alert alert-danger",children:Q}):null,e.jsxs("div",{className:"mb-3",children:[e.jsx(n,{children:"Event title"}),e.jsx(c,{value:d.title,onChange:a=>x(s=>({...s,title:a.target.value})),placeholder:"Pulmonary rehab session",required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx(n,{children:"Date"}),e.jsx(ue,{value:d.date,onChange:a=>x(s=>({...s,date:a,endTime:W(a,s.startTime)})),required:!0})]}),e.jsxs(F,{className:"g-3",children:[e.jsxs(i,{md:6,children:[e.jsx(n,{children:"Start time"}),e.jsx(c,{type:"time",value:d.startTime,onChange:a=>{const s=a.target.value;x(m=>({...m,startTime:s,endTime:W(m.date,s)}))},required:!0})]}),e.jsxs(i,{md:6,children:[e.jsx(n,{children:"End time"}),e.jsx(c,{type:"time",value:d.endTime,onChange:a=>x(s=>({...s,endTime:a.target.value})),required:!0})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(S,{type:"switch",id:"autoAdmit",label:"Auto-admit participants (no waiting room)",checked:d.autoAdmit,onChange:a=>x(s=>({...s,autoAdmit:a.target.checked}))}),e.jsx("div",{className:"form-text mb-2",children:"Anyone with the link can join without you admitting them."}),e.jsx(S,{type:"switch",id:"allowMicVideo",label:"Allow mic and video for participants",checked:d.allowMicVideo,onChange:a=>x(s=>({...s,allowMicVideo:a.target.checked}))}),e.jsx("div",{className:"form-text",children:"Joiners enter as contributors so they can use mic and camera. Google cannot turn devices on automatically."})]})]}),e.jsxs(Ce,{children:[e.jsx(p,{variant:"light",type:"button",onClick:()=>P(!1),children:"Cancel"}),e.jsx(p,{type:"submit",disabled:X,children:X?"Creating...":"Create event"})]})]})})]})}export{Oe as default};