1 line
5.5 KiB
JavaScript
1 line
5.5 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8895,5602],{8464:function(e,r,a){Promise.resolve().then(a.bind(a,8782)),Promise.resolve().then(a.bind(a,8001))},7176:function(e,r,a){"use strict";var t=a(7437);a(2265),r.Z=e=>{let{column:r}=e,{filterValue:a,setFilter:s}=r;return(0,t.jsx)("div",{className:"w-full mt-2.5 ",children:(0,t.jsx)("input",{type:"text",value:a||"",onChange:e=>s(e.target.value),onClick:e=>e.stopPropagation(),className:"w-full px-3 py-1 border border-stroke focus:border-primary outline-none rounded-md "})})}},8782:function(e,r,a){"use strict";a.d(r,{default:function(){return x}});var t=a(7437),s=a(2265),o=a(3708),n=a(7176),l=a(9376),c=a(3464),i=a(3330),u=a(5740);let d=async(e,r,a,t,s,o,n,l)=>{let d=(0,u.B)();try{return(await c.Z.post("".concat(i.Q,"/api/v1/legacy304"),{tipo:e,legajo:r,encuesta:a,especialidad:t,plan:s,materia:o,comision:n,facultad:l},{headers:{Authorization:"".concat(d)}})).data.registros}catch(e){throw Error(e.response.data.statussalida)}},p=async e=>{try{return(await c.Z.post("".concat(i.Q,"/api/v1/legacy305"),{vector:e},{headers:{Authorization:"".concat((0,u.B)())}})).data}catch(e){throw console.error("Error al enviar la encuesta:",e),e}};var m=a(9317),h=a(3014);let b=[{Header:"Pregunta",accessor:"pregunta"},{Header:"Respuesta",accessor:"respuesta"},{Header:"Observaci\xf3n",accessor:"observacion"}];var x=()=>{let{user:e}=(0,h.a)(),[r,a]=(0,s.useState)([]),[c,i]=(0,s.useState)(!1),[u,x]=(0,s.useState)(!1),g=(0,l.useSearchParams)(),f=Number(g.get("encuesta")),v=Number(g.get("especialidad")),y=Number(g.get("plan")),j=Number(g.get("materia")),N=Number(g.get("comision")),k=(null==e?void 0:e.currentUser.role)==="Docente"?2:1,[w,S]=(0,s.useState)({}),[E,P]=(0,s.useState)(!1),C=(0,l.useRouter)(),F=(0,s.useMemo)(()=>b,[]),H=(0,s.useMemo)(()=>Array.isArray(r)?r:[],[r]),_=(0,s.useMemo)(()=>({Filter:n.Z}),[]),{getTableProps:A,getTableBodyProps:U,headerGroups:Z,page:B,prepareRow:M}=(0,o.useTable)({data:H,columns:F,defaultColumn:_},o.useFilters,o.useGlobalFilter,o.useSortBy,o.usePagination),O=async e=>{i(!0),a(await d(k,e.currentUser.legajo,f,v,y,j,N,e.currentUser.facultad)||[]),i(!1)};if((0,s.useMemo)(()=>r.map(e=>{if("S"===e.titulo&&e.valores){let r=e.valores.split(";").filter(e=>""!==e.trim());return{...e,valoresArray:r}}return e}),[r]),(0,s.useEffect)(()=>{c||!e||u||(O(e),x(!0))},[e,c,u]),c)return(0,t.jsx)(m.Z,{mensaje:"Cargando informaci\xf3n"});let G=async a=>{if(a.preventDefault(),E)return;P(!0);let t={};if(r.forEach((e,r)=>{"S"!=e.obligatoria||e.respuesta||(t[r]="Este campo es obligatorio")}),Object.keys(t).length>0){S(t),alert("Por favor, completa todos los campos obligatorios antes de enviar."),P(!1);return}S({});let s=r.filter(e=>"S"!==e.titulo).map((r,a)=>({encuesta:f,tipo:k,legajo:e.currentUser.legajo,especialidad:e.currentUser.especialidad,plan:y,materia:j,comision:N,orden:r.orden,respuesta:r.respuesta||"",observacion:r.comentario||""}));try{await p(s),alert("Encuesta enviada correctamente."),C.push("/estudiante/encuesta-enviada")}catch(e){alert("Error al enviar la encuesta.")}finally{P(!1)}};return(0,t.jsx)("div",{className:"rounded-sm border border-stroke bg-white px-5 pt-6 pb-2.5 shadow-default dark:border-strokedark dark:bg-boxdark sm:px-7.5 xl:pb-1",children:(0,t.jsx)("div",{className:"max-w-full overflow-x-auto",children:(0,t.jsxs)("form",{onSubmit:G,children:[(0,t.jsxs)("table",{className:"w-full table-auto",...A(),children:[(0,t.jsx)("thead",{children:Z.map((e,r)=>(0,s.createElement)("tr",{...e.getHeaderGroupProps(),key:"headerGroup-".concat(r)},e.headers.map((e,r)=>(0,s.createElement)("th",{...e.getHeaderProps(e.getSortByToggleProps()),key:"column-".concat(r),className:"py-4 px-4 font-medium text-black dark:text-white"},e.render("Header")))))}),(0,t.jsx)("tbody",{...U(),children:r.map((e,s)=>{e.valorinicial;let o=e.valores?e.valores.split(";").filter(e=>""!==e.trim()):[];return(0,t.jsx)("tr",{children:"S"===e.titulo?(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("td",{className:"border px-4 py-2 text-center font-bold",colSpan:3,children:e.pregunta})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("td",{className:"border px-4 py-2",children:e.pregunta}),o.length>0?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("td",{className:"border px-4 py-2",children:(0,t.jsxs)("select",{className:"w-full border px-2 py-1 rounded ".concat(w[s]?"border-red-500":""),value:e.respuesta||"",onChange:e=>{let t=[...r];t[s].respuesta=e.target.value,a(t),S(e=>({...e,[s]:""}))},children:[(0,t.jsx)("option",{value:"",children:"Selecciona una opci\xf3n"}),o.map((e,r)=>(0,t.jsx)("option",{value:e,children:e},r))]})}),(0,t.jsx)("td",{className:"border px-4 py-2",children:(0,t.jsx)("input",{type:"text",className:"w-full border px-2 py-1 rounded",placeholder:"Escribe un comentario",value:e.comentario||"",onChange:e=>{let t=[...r];t[s].comentario=e.target.value,a(t)}})})]}):(0,t.jsx)("td",{className:"border px-4 py-2",colSpan:2,children:(0,t.jsx)("input",{type:"text",className:"w-full border px-2 py-1 rounded",placeholder:"",value:e.respuesta||"",onChange:e=>{let t=[...r];t[s].respuesta=e.target.value,a(t)}})})]})},s)})})]}),(0,t.jsx)("div",{className:"flex justify-end mt-4",children:(0,t.jsx)("button",{type:"submit",className:"text-white bg-black hover:bg-primary focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800",children:(0,t.jsx)("span",{className:"text-xs px-2",children:"ENVIAR"})})})]})})})}}},function(e){e.O(0,[3587,9070,4609,5947,8316,798,5640,1320,8001,2971,2117,1744],function(){return e(e.s=8464)}),_N_E=e.O()}]); |