PageSourceSearch

https://crppr.org.br/assets/TarefasPessoais-bc5aQBM1.js

js crppr.org.br collected 2026-10-02 15:03:58 UTC 16,355 bytes, 1 lines download raw bytes

1import{a as W,A as Y,Y as P,a9 as Z,j as e,c as H,F as J}from"./index-BzhlEb2N.js";import{r as c}from"./vendor-react-CpRvMXaC.js";import{F as ee}from"./PlusIcon-DEsYe4eY.js";import{F as ae}from"./PencilIcon-B3CbNM63.js";import{F as se}from"./TrashIcon-Dwynpqlu.js";import"./vendor-pdf-De61ZhIs.js";import"./vendor-ui-5rZvml82.js";import"./vendor-editor-DoAMYjM7.js";function re({title:s,titleId:i,...n},u){return c.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:u,"aria-labelledby":i},n),s?c.createElement("title",{id:i},s):null,c.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.347a1.125 1.125 0 0 1 0 1.972l-11.54 6.347a1.125 1.125 0 0 1-1.667-.986V5.653Z"}))}const te=c.forwardRef(re),p=W.create({baseURL:Y.BASE_URL,timeout:15e3,headers:{"Content-Type":"application/json",Accept:"application/json"},withCredentials:!0});function ie(s){const n=`; ${document.cookie}`.split(`; ${s}=`);return n.length===2?n.pop().split(";").shift():null}p.interceptors.request.use(s=>{const i=P.getToken();i&&(s.headers.Authorization=`Bearer ${i}`);const n=ie("XSRF-TOKEN");return n&&(s.headers["X-XSRF-TOKEN"]=decodeURIComponent(n)),s});p.interceptors.response.use(s=>s,s=>{var i;return((i=s.response)==null?void 0:i.status)===401&&(P.removeToken(),window.location.href="/login"),Promise.reject(s)});const v={async listar(s={}){const i=new URLSearchParams;return Object.entries(s).forEach(([u,d])=>{d!=null&&d!==""&&i.append(u,d)}),(await p.get(`/api/v1/tarefas-pessoais?${i.toString()}`)).data},async criar(s){return(await p.post("/api/v1/tarefas-pessoais",s)).data},async atualizar(s,i){return(await p.put(`/api/v1/tarefas-pessoais/${s}`,i)).data},async gerarAgora(s){return(await p.post(`/api/v1/tarefas-pessoais/${s}/gerar-agora`)).data},async excluir(s){return(await p.delete(`/api/v1/tarefas-pessoais/${s}`)).data}},$=[{value:"diaria",label:"Diária"},{value:"semanal",label:"Semanal"},{value:"mensal",label:"Mensal"},{value:"anual",label:"Anual"},{value:"a_cada_x_dias",label:"A cada X dias"},{value:"dias_semana",label:"Dias da semana"},{value:"dia_mes",label:"Dia do mês"}],D=[{value:"baixa",label:"Baixa"},{value:"media",label:"Média"},{value:"alta",label:"Alta"},{value:"urgente",label:"Urgente"}],oe=[{value:"system",label:"Sistema"},{value:"email",label:"E-mail"},{value:"whatsapp",label:"WhatsApp"}],F=[{value:0,label:"Dom"},{value:1,label:"Seg"},{value:2,label:"Ter"},{value:3,label:"Qua"},{value:4,label:"Qui"},{value:5,label:"Sex"},{value:6,label:"Sáb"}],I={titulo:"",descricao:"",prioridade:"media",recorrencia_tipo:"diaria",intervalo_dias:"",dias_semana:[],dia_mes:"",canais_notificacao:["system","email","whatsapp"],proxima_ocorrencia_em:new Date().toISOString().slice(0,10)};function le(s){if(!s)return"-";const i=String(s).slice(0,10),[n,u,d]=i.split("-").map(Number);if(!n||!u||!d)return"-";const x=new Date(n,u-1,d);return Number.isNaN(x.getTime())?"-":x.toLocaleDateString("pt-BR")}function ne(s){var i;if(s.recorrencia_tipo==="a_cada_x_dias")return`A cada ${s.intervalo_dias} dias`;if(s.recorrencia_tipo==="dias_semana"){const n=(s.dias_semana||[]).map(u=>{var d;return(d=F.find(x=>x.value===Number(u)))==null?void 0:d.label}).filter(Boolean).join(", ");return n?`Dias: ${n}`:"Dias da semana"}return s.recorrencia_tipo==="dia_mes"?`Dia ${s.dia_mes} do mês`:((i=$.find(n=>n.value===s.recorrencia_tipo))==null?void 0:i.label)||s.recorrencia_tipo}function fe(){const{toast:s}=Z(),[i,n]=c.useState([]),[u,d]=c.useState(!0),[x,S]=c.useState(""),[h,O]=c.useState("visiveis"),[j,L]=c.useState(""),[g,b]=c.useState(1),[N,A]=c.useState(1),[z,f]=c.useState(!1),[w,E]=c.useState(null),[t,m]=c.useState(I),[k,R]=c.useState(!1),[T,_]=c.useState(null),C=c.useRef(""),y=c.useCallback(async()=>{var a,r;try{d(!0),S("");const o=await v.listar({escopo:h,search:j,page:g,per_page:20}),l=Array.isArray(o==null?void 0:o.data)?o.data:[];n(l),b(Number.isInteger(o==null?void 0:o.current_page)?o.current_page:1),A(Number.isInteger(o==null?void 0:o.last_page)?o.last_page:1)}catch(o){const l=((r=(a=o.response)==null?void 0:a.data)==null?void 0:r.message)||"Erro ao carregar tarefas pessoais.";S(l),n([]),b(1),A(1),C.current!==l&&(C.current=l,s.error(l))}finally{d(!1)}},[h,j,g,s]);c.useEffect(()=>{y()},[y]),c.useEffect(()=>{C.current=""},[h,j,g]);const B=()=>{E(null),m(I),f(!0)},M=a=>{E(a),m({titulo:a.titulo||"",descricao:a.descricao||"",prioridade:a.prioridade||"media",recorrencia_tipo:a.recorrencia_tipo||"diaria",intervalo_dias:a.intervalo_dias||"",dias_semana:a.dias_semana||[],dia_mes:a.dia_mes||"",canais_notificacao:Array.isArray(a.canais_notificacao)&&a.canais_notificacao.length?a.canais_notificacao:["system","email","whatsapp"],proxima_ocorrencia_em:(a.proxima_ocorrencia_em||"").slice(0,10)}),f(!0)},q=a=>{m(r=>{const o=r.dias_semana.includes(a);return{...r,dias_semana:o?r.dias_semana.filter(l=>l!==a):[...r.dias_semana,a].sort()}})},U=a=>{m(r=>{const l=r.canais_notificacao.includes(a)?r.canais_notificacao.filter(V=>V!==a):[...r.canais_notificacao,a];return{...r,canais_notificacao:l.length?l:r.canais_notificacao}})},X=()=>({titulo:t.titulo.trim(),descricao:t.descricao.trim()||null,prioridade:t.prioridade,recorrencia_tipo:t.recorrencia_tipo,intervalo_dias:t.recorrencia_tipo==="a_cada_x_dias"?Number(t.intervalo_dias):null,dias_semana:t.recorrencia_tipo==="dias_semana"?t.dias_semana:null,dia_mes:["dia_mes","mensal"].includes(t.recorrencia_tipo)&&t.dia_mes?Number(t.dia_mes):null,canais_notificacao:t.canais_notificacao,proxima_ocorrencia_em:t.proxima_ocorrencia_em}),G=async a=>{var r,o;a.preventDefault();try{R(!0);const l=X();w?(await v.atualizar(w.id,l),s.success("Tarefa atualizada.")):(await v.criar(l),s.success("Tarefa criada.")),f(!1),await y()}catch(l){s.error(((o=(r=l.response)==null?void 0:r.data)==null?void 0:o.message)||"Erro ao salvar tarefa.")}finally{R(!1)}},K=async a=>{var r,o;try{_(a.id);const l=await v.gerarAgora(a.id);s.success((l==null?void 0:l.message)||"Demanda pessoal gerada. Verifique em /admin/demandas."),await y()}catch(l){s.error(((o=(r=l.response)==null?void 0:r.data)==null?void 0:o.message)||"Não foi possível gerar a demanda pessoal agora.")}finally{_(null)}},Q=async a=>{if(window.confirm(`Excluir a tarefa "${a.titulo}"?`))try{_(a.id),await v.excluir(a.id),s.success("Tarefa excluída."),await y()}catch{s.error("Erro ao excluir tarefa.")}finally{_(null)}};return e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-8",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Tarefas Pessoais"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Tarefas recorrentes particulares, separadas das demandas institucionais."})]}),e.jsxs("button",{onClick:B,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(ee,{className:"h-4 w-4"}),"Nova tarefa"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-4",children:[e.jsx("div",{className:"inline-flex rounded-lg border border-gray-200 bg-gray-50 p-1",children:[{key:"visiveis",label:"Disponíveis"},{key:"todas",label:"Todas"}].map(a=>e.jsx("button",{type:"button",onClick:()=>{b(1),O(a.key)},className:`rounded-md px-4 py-2 text-sm font-semibold transition-colors ${h===a.key?"bg-white text-teal-700 shadow-sm":"text-gray-600 hover:text-gray-900"}`,children:a.label},a.key))}),e.jsxs("div",{className:"relative flex-1 min-w-[220px]",children:[e.jsx(H,{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 tarefa...",value:j,onChange:a=>{b(1),L(a.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("div",{className:"bg-white rounded-xl border border-gray-200 overflow-hidden",children:[x&&e.jsx("div",{className:"border-b border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:x}),u?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"})}):i.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:"Nenhuma tarefa encontrada"}),e.jsx("p",{className:"text-sm",children:h==="visiveis"?"Tarefas futuras aparecem aqui apenas na data programada.":"Crie uma tarefa recorrente para começar."})]}):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:"Tarefa"}),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:"Recorrência"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Próxima ocorrência"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium text-gray-600",children:"Ações"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:i.map(a=>{var r;return e.jsxs("tr",{className:"hover:bg-gray-50 transition-colors",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("p",{className:"font-medium text-gray-900",children:a.titulo}),a.descricao&&e.jsx("p",{className:"text-xs text-gray-500 mt-0.5 line-clamp-2",children:a.descricao})]}),e.jsx("td",{className:"px-4 py-3 text-gray-600",children:((r=D.find(o=>o.value===a.prioridade))==null?void 0:r.label)||"Média"}),e.jsx("td",{className:"px-4 py-3 text-gray-600",children:ne(a)}),e.jsx("td",{className:"px-4 py-3 text-gray-600",children:le(a.proxima_ocorrencia_em)}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs("button",{onClick:()=>K(a),disabled:T===a.id,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:[e.jsx(te,{className:"h-4 w-4"}),"Gerar demanda agora"]}),e.jsx("button",{onClick:()=>M(a),className:"p-2 rounded-lg text-gray-500 hover:text-teal-700 hover:bg-teal-50",children:e.jsx(ae,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>Q(a),disabled:T===a.id,className:"p-2 rounded-lg text-gray-500 hover:text-red-700 hover:bg-red-50 disabled:opacity-50",children:e.jsx(se,{className:"h-4 w-4"})})]})})]},a.id)})})]})]}),N>1&&e.jsxs("div",{className:"flex justify-center gap-2 mt-4",children:[e.jsx("button",{disabled:g===1,onClick:()=>b(a=>a-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:[g," / ",N]}),e.jsx("button",{disabled:g===N,onClick:()=>b(a=>a+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"})]}),z&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{backgroundColor:"rgba(0,0,0,0.6)"},onClick:()=>f(!1),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-xl overflow-hidden",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-gray-100",children:[e.jsx("h2",{className:"text-base font-semibold text-gray-800",children:w?"Editar tarefa":"Nova tarefa pessoal"}),e.jsx("button",{onClick:()=>f(!1),className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-700 hover:bg-gray-100",children:e.jsx(J,{className:"h-5 w-5"})})]}),e.jsxs("form",{onSubmit:G,className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Título"}),e.jsx("input",{value:t.titulo,onChange:a=>m(r=>({...r,titulo:a.target.value})),required:!0,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-teal-400"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Descrição"}),e.jsx("textarea",{value:t.descricao,onChange:a=>m(r=>({...r,descricao:a.target.value})),rows:3,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-teal-400 resize-none"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Prioridade"}),e.jsx("select",{value:t.prioridade,onChange:a=>m(r=>({...r,prioridade:a.target.value})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-xl bg-white focus:outline-none focus:ring-2 focus:ring-teal-400",children:D.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Recorrência"}),e.jsx("select",{value:t.recorrencia_tipo,onChange:a=>m(r=>({...r,recorrencia_tipo:a.target.value})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-xl bg-white focus:outline-none focus:ring-2 focus:ring-teal-400",children:$.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Próxima ocorrência"}),e.jsx("input",{type:"date",value:t.proxima_ocorrencia_em,onChange:a=>m(r=>({...r,proxima_ocorrencia_em:a.target.value})),required:!0,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-teal-400"})]})]}),t.recorrencia_tipo==="a_cada_x_dias"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Intervalo em dias"}),e.jsx("input",{type:"number",min:"1",max:"365",value:t.intervalo_dias,onChange:a=>m(r=>({...r,intervalo_dias:a.target.value})),required:!0,className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-teal-400"})]}),t.recorrencia_tipo==="dias_semana"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-2",children:"Dias da semana"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:F.map(a=>e.jsx("button",{type:"button",onClick:()=>
1q(a.value),className:`px-3 py-1.5 rounded-lg border text-sm font-medium ${t.dias_semana.includes(a.value)?"bg-teal-600 border-teal-600 text-white":"bg-white border-gray-200 text-gray-600 hover:bg-gray-50"}`,children:a.label},a.value))})]}),["dia_mes","mensal"].includes(t.recorrencia_tipo)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Dia do mês"}),e.jsx("input",{type:"number",min:"1",max:"31",value:t.dia_mes,onChange:a=>m(r=>({...r,dia_mes:a.target.value})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-teal-400"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-2",children:"Canais de notificação"}),e.jsx("div",{className:"flex flex-wrap gap-3",children:oe.map(a=>e.jsxs("label",{className:"inline-flex items-center gap-2 rounded-xl border border-gray-200 px-3 py-2 text-sm text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:t.canais_notificacao.includes(a.value),onChange:()=>U(a.value),className:"h-4 w-4 rounded border-gray-300 text-teal-600 focus:ring-teal-500"}),a.label]},a.value))})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>f(!1),disabled:k,className:"px-4 py-2 text-sm text-gray-600 hover:text-gray-800 hover:bg-gray-100 rounded-xl",children:"Cancelar"}),e.jsx("button",{type:"submit",disabled:k||!t.titulo.trim(),className:"px-4 py-2 bg-teal-600 hover:bg-teal-700 disabled:opacity-40 text-white text-sm font-medium rounded-xl",children:k?"Salvando...":"Salvar"})]})]})]})})]})}export{fe 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.