mario-education 2.0.320-staging → 2.0.321-staging
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),ye=require("reactstrap"),f=require("mario-core"),se=require("./constants-B6E1hV91.cjs"),T=require("react"),ne=require("react-redux"),je=require("formik"),ke=require("yup"),x=require("@mui/material"),xe=require("@mui/x-date-pickers"),Pe=require("moment"),P=require("./VisibilityOff-BhNQngQ7.cjs"),Ee=require("./constants-BQStoA5a.cjs"),Ce=require("./DoneCheckInIcon-7Q31KvHI.cjs"),be=require("./userService-DsbgpY7L.cjs"),Me=require("./styles.module-CHKJJ8Zm.cjs"),Le=require("./AdapterMoment-B-q0UCj0.cjs"),Se=require("./Visibility-DkiY7AJ3.cjs"),O=require("./FormControl-XyHwl_OA.cjs"),ve=require("./IconButton-DqJhaxgx.cjs"),De=require("react-router-dom"),Ie=require("date-fns");function $e(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const m in t)if(m!=="default"){const _=Object.getOwnPropertyDescriptor(t,m);Object.defineProperty(o,m,_.get?_:{enumerable:!0,get:()=>t[m]})}}return o.default=t,Object.freeze(o)}const E=$e(ke),He="_name_1koi9_205",Fe="_role_1koi9_217",qe="_item_1koi9_230",Oe="_gender_1koi9_323",Be="_gender__item_1koi9_328",n={"profile-value":"_profile-value_1koi9_77","input-error":"_input-error_1koi9_94","user-profile-container-admin":"_user-profile-container-admin_1koi9_122","user-profile-container-admin__left":"_user-profile-container-admin__left_1koi9_135","user-profile-container-admin__left--information":"_user-profile-container-admin__left--information_1koi9_146","image-user-container":"_image-user-container_1koi9_154","image-user-container__image":"_image-user-container__image_1koi9_169","image-user-container__edit-btn":"_image-user-container__edit-btn_1koi9_176","image-user-container__delete-btn":"_image-user-container__delete-btn_1koi9_190","name-role-container":"_name-role-container_1koi9_205",name:He,role:Fe,"user-profile-container-admin__left--btn-control":"_user-profile-container-admin__left--btn-control_1koi9_224",item:qe,"item-active":"_item-active_1koi9_246","user-profile-container-admin__right":"_user-profile-container-admin__right_1koi9_274","edit-profile-container":"_edit-profile-container_1koi9_285","edit-profile-container__title":"_edit-profile-container__title_1koi9_290","edit-profile-container__form":"_edit-profile-container__form_1koi9_297","edit-profile-container__form--row":"_edit-profile-container__form--row_1koi9_302","edit-profile-container__form--field":"_edit-profile-container__form--field_1koi9_307",gender:Oe,gender__item:Be,"edit-profile-container__form--width-50":"_edit-profile-container__form--width-50_1koi9_334","edit-profile-container__form--width-30":"_edit-profile-container__form--width-30_1koi9_337","edit-profile-container__form--width-70":"_edit-profile-container__form--width-70_1koi9_340","edit-profile-container__form--btn-group":"_edit-profile-container__form--btn-group_1koi9_343","btn-save":"_btn-save_1koi9_349","btn-cancel":"_btn-cancel_1koi9_371"};var W=(t=>(t.Info="info",t.ForgotPassword="forgotPassword",t.DownloadUserData="downloadUserData",t.ChangePassword="changePassword",t))(W||{});const de=[{value:"info",label:"Personal Information",icon:"/images/user/User.svg",isControl:!0},{value:"changePassword",label:"Change Password",icon:"/images/user/Lock.svg",isControl:!1},{value:"forgotPassword",label:"Send Forgot Password Link",icon:"/images/user/Lock.svg",isControl:!1},{value:"downloadUserData",label:"Download User Data",icon:"/images/user/Log-out.svg",isControl:!1}],we=["Admin","Assistant","Teacher","Counselor","General ED teacher","SecondaryTeacher","Parent","Student"],Ve=we,Ge=we,ze=we.filter(t=>t!=="SecondaryTeacher"),Ye=t=>t==="both"?["MS","ES","HS"]:[t.toUpperCase()],Je=t=>t==="both"?"ES, MS, HS":t.toUpperCase(),pe=(t,o,m)=>{if(m){if(G.includes(m))return"hs";if(V.includes(m))return"ms";if(B.includes(m))return"es"}const _=(t||"").toUpperCase();if(_==="ES, MS"||_==="ES, MS, HS"||_.includes(","))return"both";if(_==="ES")return"es";if(_==="HS")return"hs";if(_==="MS")return"ms";const g=(o||[]).includes("MS"),u=(o||[]).includes("ES"),R=(o||[]).includes("HS");return R&&!g&&!u?"hs":(g||R)&&u?"both":u&&!g?"es":"ms"},h={ADMIN:"Admin",TEACHER:"Teacher",ASSISTANT:"Assistant",EDUTEACHER:"General ED teacher",STUDENT:"Student",PARENT:"Parent"},Ke=[{value:!0,label:"Active"},{value:!1,label:"Inactive"}],ue=["K","1","2","3","4","5","6","7","8","9","10","11","12",...se.isMalvernCollege?["12/13"]:[],...se.isSaisSchool?["PCS"]:[]],B=["K","1","2","3","4","5",...se.isMalvernCollege?["6"]:[]],V=[...se.isMalvernCollege?[]:["6"],"7","8"],G=["9","10","11","12",...se.isMalvernCollege?["12/13"]:[],...se.isSaisSchool?["PCS"]:[]],Re=["Student"],We=E.object({firstName:E.string().required("First name is required"),lastName:E.string().required("Last name is required"),email:E.string().email("Email is invalid").required("Email is required"),appTypes:E.array().of(E.string()).min(1,"School tier is required"),msRoles:E.array().of(E.string()).test("ms-role-required","Role is required",(t,o)=>{const m=pe(o.parent.preferredAppType,o.parent.appTypes,o.parent.gradeLevel);return m==="ms"?!!t&&t.length>0:m==="both"?(t?.length||0)+(o.parent.hsRoles?.length||0)+(o.parent.esRoles?.length||0)>0:!0}),hsRoles:E.array().of(E.string()).test("hs-role-required","HS role is required",(t,o)=>pe(o.parent.preferredAppType,o.parent.appTypes,o.parent.gradeLevel)==="hs"?!!t&&t.length>0:!0),esRoles:E.array().of(E.string()).test("es-role-required","ES role is required",(t,o)=>pe(o.parent.preferredAppType,o.parent.appTypes,o.parent.gradeLevel)==="es"?!!t&&t.length>0:!0),gradeLevel:E.string().nullable().test("grade-level-required","Grade level is required",(t,o)=>{const m=o.parent.msRoles||[],_=o.parent.esRoles||[],g=o.parent.hsRoles||[];return m.includes("Student")||_.includes("Student")||g.includes("Student")?!!t:!0})}),Xe={currentPage:1,pageSize:100},Ze=(t,o)=>{const[m,_]=T.useState([]),[g,u]=T.useState(!1),[R,y]=T.useState(Xe),[I,N]=T.useState(),S=ne.useDispatch(),F=T.useCallback(async()=>{u(!0);try{const r=(await be.getRosterUsersApi(R)).data?.items||[];_(M(r))}catch{S(f.setAlert({type:"error",message:"Cannot get roster users"}))}u(!1)},[JSON.stringify(R)]),X=T.useCallback(async()=>{if(!o)return;const i=m.find(r=>r.value===o);if(i){N(i);return}u(!0);try{const H=(await be.getRosterUserBySourcedIdApi(o)).data;N({label:q(H),value:H.sourcedId})}catch(r){console.log("err:",r)}u(!1)},[o]),M=i=>i.map(r=>({label:q(r),value:r.sourcedId})),q=i=>{const r=[],{givenName:H,middleName:b,familyName:j,email:U,role:C}=i,v=[];return H&&v.push(H),b&&v.push(b),j&&v.push(j),v.length&&r.push(v.join(" ")),U&&r.push(U),`${r.join(" - ")}${C?` (${C})`:""}`},z=i=>{y(r=>({...r,searchString:i}))},$=T.useCallback(i=>{y({...R,...i})},[JSON.stringify(R)]);return T.useEffect(()=>{R.roles?.length&&F()},[JSON.stringify(R)]),T.useEffect(()=>{$({roles:t})},[JSON.stringify(t)]),T.useEffect(()=>{X()},[o]),{users:m,isLoading:g,user:I,handleInputChange:z}},Qe=({value:t,roles:o,onChange:m})=>{const{users:_,isLoading:g,user:u,handleInputChange:R}=Ze(o,t);return e.jsx(x.Select,{label:"Select user",value:u?.value||"",onChange:y=>{m(y.target.value)},onOpen:()=>R(""),disabled:g,className:`${Me.styles["profile-value"]}`,variant:"outlined",children:g?e.jsx(x.MenuItem,{disabled:!0,children:e.jsx(x.CircularProgress,{size:20})}):_.length>0?_.map(y=>e.jsx(x.MenuItem,{value:y.value,children:`${y.label}`},y.value)):e.jsx(x.MenuItem,{disabled:!0,children:"No users found"})})},es=({userDetail:t,confirmData:o,goBack:m,teacherOptions:_,getDataTeachers:g,id:u,checkHasTeacher:R,setCheckHasTeacher:y,userHasData:I,currentRoles:N})=>{const{t:S}=f.useTranslation(),F=T.useRef(null),M=ne.useSelector($=>$.common.user)?.hasEsSchool!==!1,{getLabel:q,system:z}=f.useGradeLabel();return e.jsxs("div",{className:n["edit-profile-container"],children:[e.jsx("div",{className:n["edit-profile-container__title"],children:`${u?"Edit User Profile":"Create User"}`}),e.jsx(je.Formik,{initialValues:t,enableReinitialize:!0,onSubmit:$=>{o($)},validationSchema:We,children:$=>{const{values:i,setFieldValue:r,handleSubmit:H,errors:b,touched:j}=$,U=Object.keys(b);U.length&&document.querySelector(`input[name=${U[0]}]`)?.scrollIntoView({behavior:"smooth",block:"center"});const C=i?.appTypes||[],v=C.includes("MS"),me=C.includes("ES"),Z=C.includes("HS"),Q=i?.msRoles||[],K=i?.esRoles||[],oe=i?.hsRoles||[],A=Q.includes(h.STUDENT)||K.includes(h.STUDENT)||oe.includes(h.STUDENT),ee=A&&(i?.preferredAppType==="HS"||i?.preferredAppType==="MS")?i.preferredAppType.toLowerCase():pe(i?.preferredAppType,C,i?.gradeLevel),L=!M&&ee==="es"?"ms":ee,ae=L==="ms"||L==="both",fe=L==="hs"||L==="both",re=M&&(L==="es"||L==="both"),ie=A?L==="es"?ue.filter(a=>B.includes(a)):L==="hs"?ue.filter(a=>G.includes(a)):ue.filter(a=>V.includes(a)):ue,he=a=>{const p=a.target.value;r("gradeLevel",p),A&&(G.includes(p)?(r("preferredAppType","HS"),r("hsRoles",[h.STUDENT]),r("msRoles",[]),r("esRoles",[]),u||r("appTypes",["HS"])):V.includes(p)?(r("preferredAppType","MS"),r("msRoles",[h.STUDENT]),r("hsRoles",[]),r("esRoles",[]),u||r("appTypes",["MS"])):B.includes(p)&&(r("preferredAppType","ES"),r("esRoles",[h.STUDENT]),r("msRoles",[]),r("hsRoles",[]),u||r("appTypes",["ES"])))},le=(a,p)=>{if(!p)return;const s=Ye(p).filter(d=>M||d!=="ES"),l=M?Je(p):s.join(", "),w=d=>{const c=t?.gradeLevel;return d==="hs"?c&&G.includes(c)?c:G[0]:d==="ms"?c&&V.includes(c)?c:V[0]??"6":d==="es"?c&&B.includes(c)?c:B[0]:i?.gradeLevel};if(!u)r("appTypes",s),r("preferredAppType",l),A&&(p==="es"?(r("esRoles",[h.STUDENT]),r("msRoles",[]),r("hsRoles",[])):p==="hs"?(r("hsRoles",[h.STUDENT]),r("msRoles",[]),r("esRoles",[])):p==="ms"&&(r("msRoles",[h.STUDENT]),r("hsRoles",[]),r("esRoles",[])),g(p==="es"?"ES":"MS"),p==="hs"&&i?.gradeLevel&&G.includes(i.gradeLevel)||p==="ms"&&i?.gradeLevel&&V.includes(i.gradeLevel)||p==="es"&&i?.gradeLevel&&B.includes(i.gradeLevel)||r("gradeLevel",w(p)));else{const d=Array.from(new Set([...i?.appTypes||[],...s]));r("appTypes",d),r("preferredAppType",l),A&&(p==="es"?(r("esRoles",[h.STUDENT]),r("msRoles",[]),r("hsRoles",[])):p==="hs"?(r("hsRoles",[h.STUDENT]),r("msRoles",[]),r("esRoles",[])):p==="ms"&&(r("msRoles",[h.STUDENT]),r("hsRoles",[]),r("esRoles",[])),p==="hs"&&i?.gradeLevel&&G.includes(i.gradeLevel)||p==="ms"&&i?.gradeLevel&&V.includes(i.gradeLevel)||p==="es"&&i?.gradeLevel&&B.includes(i.gradeLevel)||r("gradeLevel",w(p)))}},ce=N?.MS?.includes(h.STUDENT)||N?.ES?.includes(h.STUDENT)||N?.HS?.includes(h.STUDENT),ge=a=>p=>{const s=p.target.value,l=a==="MS"?"msRoles":a==="ES"?"esRoles":"hsRoles",w=a==="MS"?["esRoles","hsRoles"]:a==="ES"?["msRoles","hsRoles"]:["msRoles","esRoles"],d=F.current,c=I?.[a]??{};if(u&&(c.isHasTeacherData&&d==="Teacher"||c.isHasAssistantData&&d==="Assistant"||c.isHasCounselorData&&d==="Counselor"||c.isHasSecondaryTeacherData&&d==="SecondaryTeacher"||d==="Student"&&(c.isHasAssistantData||c.isHasCounselorData||c.isHasSecondaryTeacherData||c.isHasTeacherData))){alert("Please switch data before removing the role");return}if(ce&&!s.includes(h.STUDENT)){alert("Student account cannot be changed to another role");return}const k=i?.[l]||[],_e=s.some(J=>Re.includes(J))?d&&!k.includes(d)?[d]:[s.find(J=>Re.includes(J))].filter(Boolean):s,Ae=k.includes(h.STUDENT),Te=_e.includes(h.STUDENT);if(r(l,_e),F.current=null,Te){const J=a;r("preferredAppType",J),w.forEach(Ue=>r(Ue,[])),u||(r("appTypes",[J]),g(a==="ES"?"ES":"MS"))}else Ae&&!Te&&w.forEach(J=>r(J,[]))},te=a=>{const p=a==="MS"?"msRoles":a==="ES"?"esRoles":"hsRoles",s=a==="MS"?Q:a==="ES"?K:i?.hsRoles||[],l=a==="MS"?Ve:a==="ES"?ze:Ge,w=N?.[a]||[];return e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${ae&&re?n["edit-profile-container__form--width-50"]:""}`,children:[e.jsxs("p",{children:[M&&e.jsx("span",{style:{display:"inline-block",fontSize:11,fontWeight:700,color:"#3b4ba8",backgroundColor:"#e9ecfb",borderRadius:4,padding:"1px 6px",marginRight:6,verticalAlign:"middle"},children:a}),M?a==="HS"?"High school roles":a==="MS"?"Middle school roles":"Elementary school roles":a==="HS"?"High school roles":a==="MS"?"Middle school roles":"Roles"," ",L!=="both"?e.jsx("sup",{children:"*"}):null]}),e.jsx(x.Select,{variant:"outlined",multiple:!0,name:p,value:s,renderValue:d=>d.map(c=>c==="SecondaryTeacher"?"Support Teacher":c).join(", "),onChange:ge(a),className:`${n["profile-value"]}`,children:l.map(d=>{const c=u?ce?d!==h.STUDENT:d===h.STUDENT||["Parent"].includes(d)||w.some(k=>["Student","Parent","General ED teacher"].includes(k)):["Parent"].includes(d)||A&&d!==h.STUDENT;return e.jsxs(x.MenuItem,{value:d,disabled:c,onClick:()=>{F.current=d},children:[e.jsx(x.Checkbox,{checked:s.includes(d)}),e.jsx(x.ListItemText,{primary:d==="SecondaryTeacher"?"Support Teacher":d})]},d)})}),b[p]&&j[p]?e.jsx("div",{className:`${n["input-error"]}`,children:b[p]}):null]})};return e.jsxs("div",{className:n["edit-profile-container__form"],children:[e.jsxs("div",{className:n["edit-profile-container__form--row"],children:[e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${n["edit-profile-container__form--width-50"]}`,children:[e.jsxs("p",{children:[S("first_name")," ",e.jsx("sup",{children:"*"})]}),e.jsx(x.TextField,{name:"firstName",variant:"outlined",value:i?.firstName||"",onChange:a=>r("firstName",a.target.value)}),b.firstName&&j.firstName?e.jsx("div",{className:`${n["input-error"]}`,children:b.firstName}):null]}),e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${n["edit-profile-container__form--width-50"]}`,children:[e.jsxs("p",{children:[S("last_name")," ",e.jsx("sup",{children:"*"})]}),e.jsx(x.TextField,{name:"lastName",variant:"outlined",className:`${n["profile-value"]}`,value:i?.lastName||"",onChange:a=>r("lastName",a.target.value)}),b.lastName&&j.lastName?e.jsx("div",{className:`${n["input-error"]}`,children:b.lastName}):null]})]}),e.jsxs("div",{className:n["edit-profile-container__form--row"],children:[e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${n["edit-profile-container__form--width-30"]}`,children:[e.jsxs("p",{children:[" ",S("date_of_birth")]}),e.jsx(xe.LocalizationProvider,{dateAdapter:Le.AdapterMoment,children:e.jsx(xe.DatePicker,{format:"Do MMM YYYY",value:i?.dateOfBirth&&!Ee.DATE_MIN_VALUE.includes(i?.dateOfBirth)?Pe(i?.dateOfBirth):null,onChange:a=>{if(a){const p=a.format("YYYY-MM-DD");r("dateOfBirth",p)}else r("dateOfBirth",null)},slotProps:{textField:{variant:"outlined",id:"time-picker",className:`${n["profile-value"]}`},openPickerButton:{"aria-label":"change date"}}})})]}),e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${n["edit-profile-container__form--width-70"]}`,children:[e.jsxs("p",{children:[S("email")," ",e.jsx("sup",{children:"*"})]}),e.jsx(x.TextField,{name:"email",variant:"outlined",className:`${n["profile-value"]}`,value:i?.email||"",onChange:a=>r("email",a.target.value)}),b.email&&j.email?e.jsx("div",{className:`${n["input-error"]}`,children:b.email}):null]})]}),e.jsxs("div",{style:{border:"1px solid #e0e0e0",borderRadius:"12px",marginBottom:"24px",overflow:"hidden"},children:[e.jsx("div",{style:{backgroundColor:"#f8f9fa",padding:"16px 24px",borderBottom:"1px solid #e0e0e0"},children:e.jsxs("div",{className:`${n["edit-profile-container__form--field"]}`,style:{marginBottom:0,width:"100%"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsxs("p",{style:{marginBottom:4,fontWeight:600,fontSize:16},children:["School tier ",e.jsx("sup",{children:"*"})]}),e.jsx("p",{style:{fontSize:13,color:"#6c757d",marginTop:0,marginBottom:0},children:L==="both"?"Roles can be assigned across tiers (at least one tier required).":"Pick a tier. Roles are assigned per tier."})]}),e.jsxs(x.ToggleButtonGroup,{exclusive:!0,value:L,onChange:le,size:"small",sx:{border:"1px solid #e0e0e0",borderRadius:"30px",padding:"4px",backgroundColor:"#fff","& .MuiToggleButton-root":{border:"none",borderRadius:"30px !important",textTransform:"none",padding:"6px 20px",margin:"0",color:"#6c757d",fontWeight:500,fontSize:14,"&.Mui-selected":{backgroundColor:"#2b65d9",color:"#fff","&:hover":{backgroundColor:"#1d4ed8"}}}},children:[e.jsx(x.ToggleButton,{value:"ms",disabled:!!u&&!v&&!Z&&A,children:"Middle school"}),e.jsx(x.ToggleButton,{value:"hs",disabled:!!u&&!v&&!Z&&A,children:"High school"}),M&&e.jsx(x.ToggleButton,{value:"es",disabled:!!u&&!me&&A,children:"Elementary"}),!A&&e.jsx(x.ToggleButton,{value:"both",disabled:!1,children:"All"})]})]}),b.appTypes&&j.appTypes?e.jsx("div",{className:`${n["input-error"]}`,children:b.appTypes}):null]})}),e.jsxs("div",{style:{backgroundColor:"#fff",padding:"24px",display:"flex",flexDirection:"column",gap:"24px"},children:[e.jsxs("div",{className:n["edit-profile-container__form--row"],style:{margin:0},children:[re&&te("ES"),ae&&te("MS")]}),fe&&e.jsx("div",{className:n["edit-profile-container__form--row"],style:{margin:0},children:te("HS")})]})]}),e.jsx("div",{className:n["edit-profile-container__form--row"],children:e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${n["edit-profile-container__form--width-50"]}`,children:[e.jsx("p",{children:S("status")}),e.jsx("div",{className:`${n.gender}`,children:Ke.map(a=>e.jsxs("div",{className:`${n.gender__item}`,children:[e.jsx(x.Radio,{color:"primary",value:a.value,checked:i?.isActive===a.value,onChange:()=>r("isActive",a.value),disabled:!!u&&!!i?.isImportedFromIntegration}),a.label]},a.label))})]})}),A&&!u&&!!_&&e.jsx("div",{className:n["edit-profile-container__form--row"],children:e.jsxs("div",{className:`${n["edit-profile-container__form--field"]}`,children:[e.jsxs("p",{children:["Assign Teacher ",e.jsx("sup",{children:"*"})]}),e.jsx(x.Select,{multiple:!0,variant:"outlined",name:"teacherUserId",value:i?.teacherUserId||[],renderValue:a=>_.filter(p=>a.includes(p.value)).map(p=>p.label).join(", "),onChange:a=>{const p=a.target.value;r("teacherUserId",p),y(!!p.length)},className:`${n["profile-value"]}`,children:_?.map(a=>e.jsx(x.MenuItem,{value:a.value,children:a.label},a.value))}),!R&&e.jsx("div",{className:`${n["input-error"]}`,children:"Teacher is required"})]})}),A&&e.jsx("div",{className:n["edit-profile-container__form--row"],children:e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${n["edit-profile-container__form--width-50"]}`,children:[e.jsxs("p",{children:[" ",z==="UK"?"Year":S("grade_level")," ",e.jsx("sup",{children:"*"})]}),e.jsxs(x.Select,{variant:"outlined",value:i?.gradeLevel??"",renderValue:a=>q(a),onChange:he,className:`${n["profile-value"]}`,children:[i?.gradeLevel&&!ie.includes(i.gradeLevel)&&e.jsx(x.MenuItem,{value:i.gradeLevel,sx:{display:"none"},children:q(i.gradeLevel)},"__current__"),ie.map(a=>e.jsx(x.MenuItem,{value:a,children:q(a)},a))]}),b.gradeLevel&&j.gradeLevel?e.jsx("div",{className:`${n["input-error"]}`,children:b.gradeLevel}):null]})}),!A&&(!!Q.length||!!K.length)&&!!u&&e.jsx("div",{className:n["edit-profile-container__form--row"],children:e.jsxs("div",{className:`${n["edit-profile-container__form--field"]} ${n["edit-profile-container__form--width-50"]}`,children:[e.jsx("p",{children:S("Map from Roster")}),e.jsx(Qe,{roles:[...Q,...K],value:i.sourcedId,onChange:a=>r("sourcedId",a)})]})}),e.jsxs("div",{className:n["edit-profile-container__form--btn-group"],children:[e.jsx("button",{type:"button",className:n["btn-cancel"],onClick:()=>m(),children:S("cancel")}),e.jsxs("button",{type:"button",className:n["btn-save"],onClick:()=>H(),children:[e.jsx(Ce.DoneCheckInIcon,{color:"#fff"}),S("save_changes")]})]})]})}})]})},D={"input-error":"_input-error_gmvmh_1","change-password-container":"_change-password-container_gmvmh_6","change-password-container__title":"_change-password-container__title_gmvmh_11","change-password-container__form":"_change-password-container__form_gmvmh_19","change-password-container__form--field":"_change-password-container__form--field_gmvmh_24","change-password-container__form--description":"_change-password-container__form--description_gmvmh_38","change-password-container__form--btn-group":"_change-password-container__form--btn-group_gmvmh_54","btn-save":"_btn-save_gmvmh_60","btn-cancel":"_btn-cancel_gmvmh_82"},ss=E.object({oldPassword:E.string().required("Old password is required"),newPassword:E.string().required("New password is required"),confirmedNewPassword:E.string().oneOf([E.ref("newPassword"),void 0],"New password must match").required("Confirm your new password")}),rs=({confirmChangePassword:t,goBack:o})=>{const{t:m}=f.useTranslation();return e.jsxs("div",{className:D["change-password-container"],children:[e.jsx("div",{className:D["change-password-container__title"],children:m("change_password")}),e.jsx(je.Formik,{initialValues:{oldPassword:"",newPassword:"",confirmedNewPassword:"",showOldPassword:!1,showNewPassword:!1,showConfirmNewPassword:!1},enableReinitialize:!0,onSubmit:_=>{t(_)},validateOnChange:!1,validateOnBlur:!1,validationSchema:ss,children:_=>{const{values:g,setFieldValue:u,handleSubmit:R,errors:y,touched:I}=_,N=Object.keys(y);return N.length&&document.querySelector(`input[name=${N[0]}]`)?.scrollIntoView({behavior:"smooth",block:"center"}),e.jsxs("div",{className:D["change-password-container__form"],children:[e.jsxs("div",{className:`${D["change-password-container__form--field"]}`,children:[e.jsx("p",{children:m("old_password")}),e.jsx(O.FormControl,{variant:"outlined",className:`${D["input-field"]}`,children:e.jsx(O.OutlinedInput,{type:g.showOldPassword?"text":"password",value:g?.oldPassword,onChange:S=>u("oldPassword",S.target.value.trim()),endAdornment:e.jsx(O.InputAdornment,{position:"end",children:e.jsx(ve.IconButton,{"aria-label":"toggle password visibility",onClick:()=>u("showOldPassword",!g.showOldPassword),onMouseDown:S=>S.preventDefault(),children:g.showOldPassword?e.jsx(Se.Visibility,{color:"primary"}):e.jsx(P.VisibilityOff,{color:"primary"})})})})}),y.oldPassword&&I.oldPassword&&e.jsx("div",{className:`${D["input-error"]}`,children:y.oldPassword})]}),e.jsxs("div",{className:`${D["change-password-container__form--field"]}`,children:[e.jsx("p",{children:m("new_password")}),e.jsx(O.FormControl,{variant:"outlined",className:`${D["input-field"]}`,children:e.jsx(O.OutlinedInput,{type:g.showNewPassword?"text":"password",value:g?.newPassword,onChange:S=>u("newPassword",S.target.value.trim()),endAdornment:e.jsx(O.InputAdornment,{position:"end",children:e.jsx(ve.IconButton,{"aria-label":"toggle password visibility",onClick:()=>u("showNewPassword",!g.showNewPassword),onMouseDown:S=>S.preventDefault(),children:g.showNewPassword?e.jsx(Se.Visibility,{color:"primary"}):e.jsx(P.VisibilityOff,{color:"primary"})})})})}),y.newPassword&&I.newPassword&&e.jsx("div",{className:`${D["input-error"]}`,children:y.newPassword}),e.jsxs("div",{className:`${D["change-password-container__form--description"]}`,children:["Password must contain at least: 1 uppercase letter, 1 lowercase letter,",e.jsx("br",{})," 1 number, and 1 special character"]})]}),e.jsxs("div",{className:`${D["change-password-container__form--field"]}`,children:[e.jsx("p",{children:m("confirm_new_password")}),e.jsx(O.FormControl,{variant:"outlined",className:`${D["input-field"]}`,children:e.jsx(O.OutlinedInput,{type:g.showConfirmNewPassword?"text":"password",value:g?.confirmedNewPassword,onChange:S=>u("confirmedNewPassword",S.target.value.trim()),endAdornment:e.jsx(O.InputAdornment,{position:"end",children:e.jsx(ve.IconButton,{"aria-label":"toggle password visibility",onClick:()=>u("showConfirmNewPassword",!g.showConfirmNewPassword),onMouseDown:S=>S.preventDefault(),children:g.showConfirmNewPassword?e.jsx(Se.Visibility,{color:"primary"}):e.jsx(P.VisibilityOff,{color:"primary"})})})})}),y.confirmedNewPassword&&I.confirmedNewPassword&&e.jsx("div",{className:`${D["input-error"]}`,children:y.confirmedNewPassword})]}),e.jsxs("div",{className:D["change-password-container__form--btn-group"],children:[e.jsx("button",{type:"button",className:D["btn-cancel"],onClick:()=>{o()},children:m("cancel")}),e.jsxs("button",{type:"button",className:D["btn-save"],onClick:()=>R(),children:[e.jsx(Ce.DoneCheckInIcon,{color:"#fff"}),m("save_new_password")]})]})]})}})]})},ts={id:"",firstName:"",lastName:"",email:"",dateOfBirth:Ee.DATE_MIN_VALUE,msRoles:[],esRoles:[],hsRoles:[],isActive:!0,profileImageFileName:"",teacherUserId:[],gradeLevel:"",currentGradeLevel:"",isImportedFromIntegration:!1,appTypes:["MS"],preferredAppType:"MS"},Ne="/admin/users/user-list",ns="User detail",os=12,as=20,is=t=>{const o=ne.useDispatch(),m=De.useNavigate(),_=ne.useSelector(s=>s.common.user),g=ne.useSelector(s=>s.common?.defaultFontSize),[u,R]=T.useState(ts),[y,I]=T.useState(null),[N,S]=T.useState(!1),[F,X]=T.useState({MS:[],ES:[],HS:[]}),[M,q]=T.useState([]),[z,$]=T.useState(!1),[i,r]=T.useState(W.Info),[H,b]=T.useState(!0),[j,U]=T.useState({}),C=async()=>{localStorage.setItem(window.location.href,"true"),S(!0)},v=()=>{$(!z)},me=T.useMemo(()=>g==as?"font-large":g==os?"font-small":"",[g]);T.useEffect(()=>{document.title=ns,S(!1),localStorage.getItem(window.location.href)&&localStorage.removeItem(window.location.href)},[]),T.useEffect(()=>{t&&Q(),!t&&re()},[t]);const Z=(s=[])=>s.includes("EduTeacher")?[...s.filter(l=>l!=="EduTeacher"),h.EDUTEACHER]:s,Q=T.useCallback(async()=>{o(f.setLoading(!0));try{const s=await P.getByIdUser(t),l=(s.data.appTypeRaw||s.data.appType||"MS").toUpperCase(),w=l.includes("MS"),d=l.includes("ES"),c=l.includes("HS"),k=[];d&&k.push("ES"),w&&k.push("MS"),c&&k.push("HS"),k.length===0&&k.push("MS");let Y=s.data.preferredAppType||l;((s.data.roles||[]).includes("Student")||(s.data.msRoles||[]).includes("Student")||(s.data.esRoles||[]).includes("Student"))&&s.data.gradeLevel&&(G.includes(s.data.gradeLevel)?Y="HS":V.includes(s.data.gradeLevel)?Y="MS":B.includes(s.data.gradeLevel)&&(Y="ES")),R({...s.data,dateOfBirth:Ie.format(new Date(s.data.dateOfBirth),f.DATE_FORMAT),msRoles:Z(s.data.msRoles),esRoles:Z(s.data.esRoles),hsRoles:Z(s.data.hsRoles),currentGradeLevel:s.data.gradeLevel,appTypes:k,preferredAppType:Y}),X({MS:s.data.msRoles??[],ES:s.data.esRoles??[],HS:s.data.hsRoles??[]}),document.title=s.data?.fullName,(w||c)&&K("MS"),d&&K("ES")}catch(s){o(f.setAlert({type:"danger",message:s.response?.data?.title||s.message}))}o(f.setLoading(!1))},[t]),K=T.useCallback(async s=>{o(f.setLoading(!0));try{const l=await P.userRoleHasDataApi(t,s);U(w=>({...w,[s]:l.data}))}catch(l){o(f.setAlert({type:"danger",message:l.response?.data?.title||l.message}))}o(f.setLoading(!1))},[t]),oe=T.useCallback(s=>{m(s&&typeof s=="string"?Ne+`?query=${s}`:Ne)},[]),A=s=>["Student","Parent","EduTeacher"].includes(s),ee=(s=[])=>s.includes(h.EDUTEACHER)?[...s.filter(l=>l!==h.EDUTEACHER),"EduTeacher"]:s,L=T.useCallback(async s=>{const l=s.msRoles?.includes(h.STUDENT)||s.esRoles?.includes(h.STUDENT)||s.hsRoles?.includes(h.STUDENT);if(l&&!t&&!s.teacherUserId){b(!1);return}l&&s.gradeLevel&&(G.includes(s.gradeLevel)?(s.preferredAppType="HS",s.hsRoles=[h.STUDENT],s.msRoles=[],s.esRoles=[]):V.includes(s.gradeLevel)?(s.preferredAppType="MS",s.msRoles=[h.STUDENT],s.hsRoles=[],s.esRoles=[]):B.includes(s.gradeLevel)&&(s.preferredAppType="ES",s.esRoles=[h.STUDENT],s.msRoles=[],s.hsRoles=[])),o(f.setLoading(!0));try{if(_?.hasEsSchool===!1)if(s.esRoles=[],l)s.preferredAppType!=="HS"?(s.appTypes=["MS"],s.preferredAppType="MS"):s.appTypes=["HS"];else{const c=(s.appTypes||[]).filter(k=>k!=="ES");s.appTypes=c.length>0?c:["MS"]}const w=t?P.update:P.create;if(!t&&delete s.id,s.teacherUserId=l?s.teacherUserId:[],s.msRoles=ee(s.msRoles),s.esRoles=ee(s.esRoles),s.hsRoles=ee(s.hsRoles),!t&&!l){const c=(s.preferredAppType||"MS").toUpperCase();c.includes("MS")||(s.msRoles=[]),c.includes("HS")||(s.hsRoles=[]),c.includes("ES")||(s.esRoles=[])}if(!l){const c=[];s.esRoles&&s.esRoles.length>0&&c.push("ES"),s.msRoles&&s.msRoles.length>0&&c.push("MS"),s.hsRoles&&s.hsRoles.length>0&&c.push("HS"),c.length>0&&(s.preferredAppType=c.join(", "),t||(s.appTypes=c))}l&&(s.preferredAppType==="HS"?(s.hsRoles=[h.STUDENT],s.msRoles=[],s.esRoles=[]):s.preferredAppType==="ES"?(s.esRoles=[h.STUDENT],s.msRoles=[],s.hsRoles=[]):(s.msRoles=[h.STUDENT],s.hsRoles=[],s.esRoles=[])),t||(s.profileImageFileName=y||"");const d=await w(s);d&&P.getByIdUser(d.data.id).then(c=>{oe(c.data.fullName)}),t||alert("Password of "+d.data.email+` is "${d.data.password}"`),o(f.setAlert({type:"success",message:`${t?"Update":"Create"} user successfully`}))}catch(w){o(f.setAlert({type:"danger",message:w.response?.data?.title||w.message}))}o(f.setLoading(!1))},[t,y]),ae=async s=>{o(f.setLoading(!0));try{await P.changePassword(s),o(f.setAlert({type:"success",message:"Change password successfully"}))}catch(l){o(f.setAlert({type:"danger",message:l.response?.data?.title||l.message}))}o(f.setLoading(!1))},fe=T.useCallback(async s=>{o(f.setLoading(!0));try{await P.forgotChangePassword(s),o(f.setAlert({type:"success",message:"Send forgot password link successfully"}))}catch(l){o(f.setAlert({type:"danger",message:l.response?.data?.title||l.message||"Error occured"}))}o(f.setLoading(!1))},[]),re=async s=>{try{const l=await P.getTeachers({sortBy:"Email"},s);l.data&&q((l.data.map?.(w=>({label:w.email,value:w.id}))||[]).sort((w,d)=>w.label.localeCompare(d.label)))}catch(l){o(f.setAlert({type:"danger",message:l.response?.data?.title||l.message}))}},ie=20097152,[he,le]=T.useState(""),ce=s=>{s.preventDefault();let l=new FileReader,w=s.target.files[0];if(w.size>ie){o(f.setAlert({type:"danger",message:"File can't be larger than 2MB"}));return}l.onloadend=async()=>{if(le(l.result),w){const d=new FormData,{name:c}=w;d.append("file",w,c);const Y=(await P.systemProfileUpload(d))?.data?.key;t?await P.updateAvatarByAdminApi(u.id||"",Y):I(Y)}},w&&l.readAsDataURL(w)},ge=async()=>{await P.updateAvatarByAdminApi(u.id||"",""),le("")},te=he||f.getFileUrl(u?.profileImageFileName),a=u?.profileImageFileName||"";return{userDetail:u,getDataTeachers:re,backToList:oe,confirmData:L,file:y,setFile:I,edited:N,currentRoles:F,setEdited:S,setEditedTrue:C,confirmChangePassword:ae,forgotPasswordRequest:fe,handleDisableRoles:A,classFontSize:me,teacherOptions:M,handleToggleModel:v,openModel:z,user:_,activeTab:i,setActiveTab:r,imageSrc:te,imageUse:a,handleImageChange:ce,handleDeleteAvatar:ge,getFile:()=>{var s=window.location.origin+"/api/ExportDataUser/"+t;window.open(s)},checkHasTeacher:H,setCheckHasTeacher:b,userHasData:j}},ls="/images/image-default.png",cs=()=>{const{id:t}=De.useParams(),{userDetail:o,getDataTeachers:m,backToList:_,confirmData:g,confirmChangePassword:u,forgotPasswordRequest:R,teacherOptions:y,user:I,activeTab:N,setActiveTab:S,imageSrc:F,handleImageChange:X,handleDeleteAvatar:M,getFile:q,currentRoles:z,handleDisableRoles:$,checkHasTeacher:i,setCheckHasTeacher:r,userHasData:H}=is(t),b=[{value:W.Info,component:e.jsx(es,{id:t,goBack:_,userDetail:o,confirmData:g,teacherOptions:y,getDataTeachers:m,currentRoles:z,handleDisableRoles:$,checkHasTeacher:i,setCheckHasTeacher:r,userHasData:H})},{value:W.ChangePassword,component:e.jsx(rs,{confirmChangePassword:u,goBack:_})}],j=de.find(v=>v.value===W.ForgotPassword),U=de.find(v=>v.value===W.DownloadUserData),C=de.find(v=>v.value===W.ChangePassword);return e.jsxs("div",{className:n["user-profile-container-admin"],children:[e.jsxs("div",{className:n["user-profile-container-admin__left"],children:[e.jsxs("div",{className:n["user-profile-container-admin__left--information"],children:[e.jsxs("div",{className:n["image-user-container"],children:[e.jsx(ye.Input,{className:"d-none",type:"file",id:"uploadFile",onChange:X,accept:"image/*"}),e.jsx("img",{src:F||f.getStaticFileUrl(ls),alt:"avatar",className:`${n["image-user-container__image"]}`}),e.jsx(ye.Label,{htmlFor:"uploadFile",role:"button",tabIndex:0,children:e.jsx("div",{className:n["image-user-container__edit-btn"],children:e.jsx("img",{src:f.getStaticFileUrl("/images/user/Edit.svg"),alt:"edit-avatar"})})}),t&&e.jsx("button",{type:"button",onClick:()=>M(),className:n["image-user-container__delete-btn"],children:e.jsx("img",{src:f.getStaticFileUrl("/images/user/DeleteAvatar.svg"),alt:"delete-avatar"})})]}),e.jsxs("div",{className:n["name-role-container"],children:[e.jsx("div",{className:n.name,children:`${o?.firstName||""} ${o?.lastName||""}`}),e.jsx("div",{className:n.role,children:Array.from(new Set([...o?.msRoles||[],...o?.esRoles||[],...o?.hsRoles||[]])).map(v=>v==="SecondaryTeacher"?"Support Teacher":v).join(", ")})]})]}),e.jsxs("div",{className:n["user-profile-container-admin__left--btn-control"],children:[de.filter(v=>v.isControl).map(v=>e.jsxs("button",{type:"button",className:`${n.item} ${N===v.value?n["item-active"]:""}`,onClick:()=>S(v.value),children:[e.jsx("img",{src:f.getStaticFileUrl(v.icon),alt:v.icon}),v.label]},v.value)),!!t&&!!C&&I?.id===t&&e.jsxs("button",{type:"button",className:`${n.item} ${N===C.value?n["item-active"]:""}`,onClick:()=>S(C.value),children:[e.jsx("img",{src:f.getStaticFileUrl(C.icon),alt:C.icon}),C.label]},C.value),t&&j&&e.jsxs("button",{type:"button",className:`${n.item} ${N===j.value?n["item-active"]:""}`,onClick:()=>R({email:o?.email||""}),children:[e.jsx("img",{src:f.getStaticFileUrl(j.icon),alt:j.icon}),j.label]},j.value),t&&U&&e.jsxs("button",{type:"button",className:`${n.item} ${N===U.value?n["item-active"]:""}`,onClick:()=>q(),children:[e.jsx("img",{src:f.getStaticFileUrl(U.icon),alt:U.icon}),U.label]},U.value)]})]}),e.jsx("div",{className:n["user-profile-container-admin__right"],children:b.find(v=>v.value===N)?.component})]})};exports.default=cs;
|