PageSourceSearch

https://crppr.org.br/assets/MinhasDemandas-CZo3OrUN.js

js crppr.org.br collected 2026-09-25 02:54:42 UTC 15,437 bytes, 1 lines download raw bytes

1import{a8 as $,j as e,F,a5 as z,ah as q,c as B}from"./index-BCp-6lKF.js";import{r as s,f as L}from"./vendor-react-CpRvMXaC.js";import{r as U}from"./responsavelAreaService-qHelZozx.js";import{F as G}from"./PaperClipIcon-BupCwwnF.js";import{F as W}from"./PlusIcon-DEsYe4eY.js";import{F as H}from"./UserIcon-BY8Y9OID.js";import{F as Q}from"./BuildingOffice2Icon-DRJ0NxeE.js";import"./vendor-pdf-CLXYJc0c.js";import"./vendor-ui-5rZvml82.js";import"./vendor-editor-DoAMYjM7.js";const Z=[{value:"baixa",label:"Baixa"},{value:"media",label:"Media"},{value:"alta",label:"Alta"},{value:"urgente",label:"Urgente"}],J="image/jpeg,image/png,image/gif,image/webp,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/plain,application/zip";function T(l,d=0){return Array.isArray(l)?l.flatMap(c=>[{...c,depth:d},...T(c.children,d+1)]):[]}function K({isOpen:l,onClose:d,onCriado:c}){const{toast:p}=$(),v=s.useRef(null),[g,x]=s.useState([]),[_,b]=s.useState(!1),[S,h]=s.useState(""),[n,f]=s.useState({titulo:"",responsavel_area_id:"",prioridade:"media",descricao:""}),[j,N]=s.useState([]),[E,w]=s.useState([]),[D,A]=s.useState(!1),[C,t]=s.useState(!1);if(s.useEffect(()=>{l?(b(!0),h(""),U.listarAtivasHierarquicas().then(a=>{x(T(a))}).catch(()=>{x([]),h("Não foi possível carregar os setores. Tente novamente em instantes.")}).finally(()=>b(!1))):(f({titulo:"",responsavel_area_id:"",prioridade:"media",descricao:""}),N([]),w([]),t(!1),h(""),b(!1))},[l]),!l)return null;const i=a=>{const{name:r,value:m}=a.target;f(o=>({...o,[r]:m}))},y=a=>{const r=Array.from(a),m=r.filter(o=>o.size<=10*1024*1024);m.length<r.length&&p.error("Arquivos maiores que 10MB foram ignorados."),N(o=>[...o,...m]),m.forEach(o=>{if(o.type.startsWith("image/")){const u=new FileReader;u.onloadend=()=>w(O=>[...O,{name:o.name,src:u.result}]),u.readAsDataURL(o)}else w(u=>[...u,{name:o.name,src:null}])})},I=a=>{N(r=>r.filter((m,o)=>o!==a)),w(r=>r.filter((m,o)=>o!==a))},M=async a=>{var m,o;if(a.preventDefault(),!n.titulo.trim()||!n.descricao.trim()){p.error("Titulo e descricao sao obrigatorios.");return}if(!n.responsavel_area_id){p.error("Selecione o setor responsável pela demanda.");return}const r=new FormData;r.append("titulo",n.titulo),r.append("descricao",n.descricao),r.append("prioridade",n.prioridade),n.responsavel_area_id&&r.append("responsavel_area_id",n.responsavel_area_id),j.forEach(u=>r.append("anexos[]",u));try{A(!0);const u=await q.criar(r);p.success("Demanda aberta com sucesso!"),c==null||c(u),d()}catch(u){p.error(((o=(m=u.response)==null?void 0:m.data)==null?void 0:o.message)||"Erro ao abrir demanda.")}finally{A(!1)}};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black bg-opacity-50 transition-opacity",onClick:d}),e.jsxs("div",{className:"relative bg-white rounded-xl shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Abrir demanda"}),e.jsx("button",{type:"button",onClick:d,className:"text-gray-400 hover:text-gray-600 transition-colors",children:e.jsx(F,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"overflow-y-auto flex-1 px-6 py-5",children:e.jsxs("form",{id:"criar-demanda-u
1suario-form",onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Titulo ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",name:"titulo",value:n.titulo,onChange:i,placeholder:"Descreva brevemente o problema",maxLength:255,className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-teal-500"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Setor"}),e.jsxs("select",{name:"responsavel_area_id",value:n.responsavel_area_id,onChange:i,className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-teal-500 bg-white",children:[e.jsx("option",{value:"",children:_?"Carregando setores...":"Selecionar..."}),g.map(a=>e.jsx("option",{value:a.id,children:`${"-- ".repeat(a.depth||0)}${a.nome}`},a.id))]}),S&&e.jsx("p",{className:"mt-1 text-xs text-red-600",children:S}),!_&&!S&&g.length===0&&e.jsx("p",{className:"mt-1 text-xs text-amber-700",children:"Nenhum setor ativo cadastrado."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Prioridade"}),e.jsx("select",{name:"prioridade",value:n.prioridade,onChange:i,className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-teal-500 bg-white",children:Z.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Descricao ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("textarea",{name:"descricao",value:n.descricao,onChange:i,rows:5,placeholder:"Descreva detalhadamente o problema ou solicitacao...",className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-teal-500 resize-y"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Anexos ",e.jsx("span",{className:"text-gray-400 font-normal",children:"(opcional, max. 10MB por arquivo)"})]}),e.jsxs("div",{onDragOver:a=>{a.preventDefault(),t(!0)},onDragLeave:()=>t(!1),onDrop:a=>{a.preventDefault(),t(!1),y(a.dataTransfer.files)},onClick:()=>{var a;return(a=v.current)==null?void 0:a.click()},className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors ${C?"border-teal-400 bg-teal-50":"border-gray-300 hover:border-gray-400"}`,children:[e.jsx(G,{className:"h-6 w-6 text-gray-400 mx-auto mb-1"}),e.jsxs("p",{className:"text-sm text-gray-600",children:["Arraste arquivos ou ",e.jsx("span",{className:"text-teal-600 font-medium",children:"clique para selecionar"})]}),e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:"Imagens, PDF, Word, Excel, ZIP"}),e.jsx("input",{ref:v,type:"file",multiple:!0,accept:J,className:"hidden",onChange:a=>y(a.target.files)})]}),E.length>0&&e.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:E.map((a,r)=>e.jsxs("div",{className:"relative flex items-center gap-2 bg-gray-50 border border-gray-200 rounded-lg p-2",children:[a.src?e.jsx("img",{src:a.src,alt:a.name,className:"h-8 w-8 object-cover rounded"}):e.jsx("div",{className:"h-8 w-8 flex items-center justify-center bg-gray-200 rounded",children:e.jsx(z,{className:"h-4 w-4 text-gray-400"})}),e.jsx("span",{className:"text-xs text-gray-700 truncate flex-1",children:a.name}),e.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),I(r)},className:"text-gray-400 hover:text-red-500 flex-shrink-0",children:e.jsx(F,{className:"h-4 w-4"})})]},r))})]})]})}),e.jsxs("div",{className:"flex gap-3 px-6 py-4 border-t border-gray-200",children:[e.jsx("button",{type:"button",onClick:d,className:"flex-1 px-4 py-2 border border-gray-300 text-gray-700 text-sm font-medium rounded-lg hover:bg-gray-50 transition-colors",children:"Cancelar"}
1),e.jsx("button",{type:"submit",form:"criar-demanda-usuario-form",disabled:D||_||g.length===0,className:"flex-1 px-4 py-2 bg-teal-600 hover:bg-teal-700 disabled:opacity-60 text-white text-sm font-medium rounded-lg transition-colors",children:D?"Enviando...":"Abrir demanda"})]})]})]})}const k={aguardando_triagem:{label:"Aguardando triagem",bg:"bg-sky-100",text:"text-sky-800"},encaminhada:{label:"Encaminhada",bg:"bg-blue-100",text:"text-blue-800"},reprovada:{label:"Reprovada",bg:"bg-rose-100",text:"text-rose-800"},capturada:{label:"Capturada",bg:"bg-indigo-100",text:"text-indigo-800"},em_atendimento:{label:"Em atendimento",bg:"bg-purple-100",text:"text-purple-800"},aguardando_validacao:{label:"Aguardando validação",bg:"bg-amber-100",text:"text-amber-800"},retornada_ajustes:{label:"Retornada para ajustes",bg:"bg-rose-100",text:"text-rose-800"},pendente:{label:"Pendente",bg:"bg-blue-100",text:"text-blue-800"},em_andamento:{label:"Em andamento",bg:"bg-purple-100",text:"text-purple-800"},concluido:{label:"Finalizada",bg:"bg-green-100",text:"text-green-800"}},R={baixa:{label:"Baixa",bg:"bg-green-100",text:"text-green-800"},media:{label:"Média",bg:"bg-yellow-100",text:"text-yellow-800"},alta:{label:"Alta",bg:"bg-orange-100",text:"text-orange-800"},urgente:{label:"Urgente",bg:"bg-red-100",text:"text-red-800"}},V={minhas:{title:"Minhas Demandas",description:"Criadas por mim, atribuídas a mim ou aguardando minha validação",empty:"Nenhuma demanda pessoal encontrada"},setor:{title:"Demandas do Setor",description:"Demandas do meu setor e dos subsetores permitidos",empty:"Nenhuma demanda do setor encontrada"}};function P(l){return l?new Date(l).toLocaleDateString("pt-BR"):"—"}function X(l){var d,c,p,v,g;return((d=l.responsavel_area)==null?void 0:d.nome)||((p=(c=l.responsavel)==null?void 0:c.responsavel_area)==null?void 0:p.nome)||((g=(v=l.usuario)==null?void 0:v.responsavel_area)==null?void 0:g.nome)||l.categoria||"—"}function de(){const l=L(),{toast:d}=$(),[c,p]=s.useState([]),[v,g]=s.useState(!0),[x,_]=s.useState("minhas"),[b,S]=s.useState(""),[h,n]=s.useState(""),[f,j]=s.useState(1),[N,E]=s.useState(1),[w,D]=s.useState(!1),A=s.useCallback(async()=>{try{g(!0);const t={per_page:15,page:f,escopo:x};b&&(t.search=b),h&&(t.status=h);const i=await q.listar(t);p(i.data||[]),j(i.current_page||1),E(i.last_page||1)}catch{d.error("Erro ao carregar demandas.")}finally{g(!1)}},[x,b,h,f,d]);s.useEffect(()=>{A()},[A]),s.useEffect(()=>{j(1)},[x,b,h]);const C=V[x];return e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:C.title}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:C.description})]}),e.jsxs("button",{onClick:()=>D(!0),className:"flex items-center gap-2 bg-teal-600 hover:bg-teal-700 text-white text-sm font-medium px-4 py-2 rounded-lg transition-colors",children:[e.jsx(W,{className:"h-4 w-4"}),"Abrir demanda"]})]}),e.jsx("div",{className:"mb-4 inline-flex rounded-lg border border-gray-200 bg-gray-50 p-1",children:[{key:"minhas",label:"Minhas Demandas",icon:H},{key:"setor",label:"Demandas do Setor",icon:Q}].map(({key:t,label:i,icon:y})=>e.jsxs("button",{type:"button",onClick:()=>_(t),className:`flex items-center gap-2 rounded-md px-4 py-2 text-sm font-semibold transition-colors ${x===t?"bg-white text-teal-700 shadow-sm":"text-gray-600 hover:text-gray-900"}`,children:[e.jsx(y,{className:"h-4 w-4"}),i]},t))}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-4",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(B,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Buscar por título ou número...",value:b,onChange:t=>S(t.target.value),className:"w-full pl-9 pr-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-teal-500"})]}),e.jsxs("select",{value:h,onChange:t=>n(t.target.value),className:"px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-teal-500 bg-white",children:[e.jsx("option",{value:"",children:"Todos os status"}),e.jsx("option",{value:"aguardando_triagem",children:"Aguardando triagem"}),e.jsx("option",{value:"encaminhada",children:"Encaminhada"}),e.jsx("option",{value:"reprovada",children:"Reprovada"}),e.jsx("option",{value:"capturada",children:"Capturada"}),e.jsx("option",{value:"em_atendimento",children:"Em atendimento"}),e.jsx("option",{value:"aguardando_validacao",children:"Aguardando validação"}),e.jsx("option",{value:"retornada_ajustes",children:"Retornada para ajustes"}),e.jsx("option",{value:"concluido",children:"Finalizada"})]})]}),e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 overflow-hidden",children:v?e.jsx("div",{className:"flex justify-center items-center py-16",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-teal-600"})}):c.length===0?e.jsxs("div",{className:"text-center py-16 text-gray-500",children:[e.jsx("p",{className:"text-lg font-medium mb-1",children:C.empty}),e.jsx("p",{className:"text-sm",children:x==="minhas"?'Clique em "Abrir demanda" para criar a primeira.':"Quando houver demandas vinculadas ao seu setor, elas aparecerão aqui."})]}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 border-b border-gray-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Número"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Título"}),x==="setor"&&e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Setor"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Prioridade"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Status"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Aberto em"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Última resposta"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:c.map(t=>{const i=k[t.status]||k.pendente,y=R[t.prioridade]||R.media;return e.jsxs("tr",{onClick:()=>l(`/minhas-demandas/${t.numero}`),className:"hover:bg-gray-50 cursor-pointer transition-colors",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-gray-500",children:t.numero}),e.jsx("td",{className:"px-4 py-3 text-gray-900 font-medium max-w-xs truncate",children:t.titulo}),x==="setor"&&e.jsx("td",{className:"px-4 py-3 text-gray-600 max-w-[180px] truncate",children:X(t)}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-semibold ${y.bg} ${y.text}`,children:y.label})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-semibold ${i.bg} ${i.text}`,children:i.label})}),e.jsx("td",{className:"px-4 py-3 text-gray-500",children:P(t.data_abertura)}),e.jsx("td",{className:"px-4 py-3 text-gray-500",children:P(t.data_ultima_resposta)})]},t.id)})})]})}),N>1&&e.jsxs("div",{className:"flex justify-center gap-2 mt-4",children:[e.jsx("button",{disabled:f===1,onClick:()=>j(t=>t-1),className:"px-3 py-1.5 text-sm border border-gray-300 rounded-lg disabled:opacity-50 hover:bg-gray-50",children:"Anterior"}),e.jsxs("span",{className:"px-3 py-1.5 text-sm text-gray-600",children:[f," / ",N]}),e.jsx("button",{disabled:f===N,onClick:()=>j(t=>t+1),className:"px-3 py-1.5 text-sm border border-gray-300 rounded-lg disabled:opacity-50 hover:bg-gray-50",children:"Próxima"})]}),e.jsx(K,{isOpen:w,onClose:()=>D(!1),onCriado:()=>{j(1),A()}})]})}export{de as default};

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.