PageSourceSearch

https://evenimente-hey.lovable.app/assets/DisponibilitateaMea-V50gT-7c.js

js evenimente-hey.lovable.app collected 2026-10-03 03:30:56 UTC 13,803 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-query-B4OkWwCn.js";import{f as ye,r as i}from"./vendor-react-B3Mucgts.js";import{t as be,af as k,s as g,o,ag as I,c0 as te,u as p,ad as Ne,ae as _e,aL as E,ak as we,B as h,a2 as Me,aJ as q,C as y,aO as ze,aP as Ce,L as ae,c1 as De,c2 as Se,c3 as ne,a6 as T,P as ke,A as Ee,E as Te,b4 as Ae,az as Oe,D as Le,h as Pe,i as Be,j as Fe,k as Ie,l as b,a1 as qe,I as $,v as $e,w as Re,x as Ue,y as Ve,z as N,m as We,r as A}from"./index-DNteAA61.js";import{s as ie,i as Ke}from"./subMonths-OVzWW2lw.js";import{C as Je}from"./calendar-x-SEZyqhqu.js";import"./vendor-supabase-BspNZ9qP.js";const He={neasignat:"bg-muted text-muted-foreground",trimis_operator:"bg-warning text-warning-foreground",in_asteptare:"bg-warning text-warning-foreground",acceptat:"bg-success text-success-foreground",in_desfasurare:"bg-accent text-accent-foreground",refuzat:"bg-destructive text-destructive-foreground",finalizat:"bg-primary text-primary-foreground",anulat:"bg-muted text-muted-foreground"},Xe={neasignat:"Neasignat",trimis_operator:"Trimis",in_asteptare:"În așteptare",acceptat:"Acceptat",in_desfasurare:"În desfășurare",refuzat:"Refuzat",finalizat:"Finalizat",anulat:"Anulat"},Ze={personal:"Personal",boala:"Boală",concediu:"Concediu",alt_eveniment:"Alt eveniment",altul:"Altul"},re=(r,m)=>!r&&!m?"Interval necompletat":`${(r==null?void 0:r.slice(0,5))??"--:--"} - ${(m==null?void 0:m.slice(0,5))??"--:--"}`;function as(){const{user:r,companyId:m}=be(),le=ye(),[c,R]=i.useState(()=>k(new Date)),[u,ce]=i.useState(new Date),[oe,U]=i.useState(!0),[_,de]=i.useState([]),[w,me]=i.useState([]),[ue,M]=i.useState(!1),[z,xe]=i.useState(null),[v,V]=i.useState(!0),[O,W]=i.useState("09:00"),[L,K]=i.useState("18:00"),[J,H]=i.useState("personal"),[X,Z]=i.useState(""),[G,Q]=i.useState(!1);i.useEffect(()=>{if(!r)return;j();const s=g.channel("my-availability").on("postgres_changes",{event:"*",schema:"public",table:"events",filter:`assigned_operator_id=eq.${r.id}`},()=>j()).on("postgres_changes",{event:"*",schema:"public",table:"operator_availability",filter:`operator_id=eq.${r.id}`},()=>j()).subscribe();return()=>{g.removeChannel(s)}},[r,c]);const j=async()=>{if(!r)return;U(!0);const s=o(ie(k(c),1),"yyyy-MM-dd"),t=o(I(te(c,1)),"yyyy-MM-dd");try{const[{data:a,error:n},{data:f,error:d}]=await Promise.all([g.from("events").select("id, client_name, event_date, start_time, end_time, location, status, event_type").eq("assigned_operator_id",r.id).gte("event_date",s).lte("event_date",t).order("start_time",{nullsFirst:!1}),g.from("operator_availability").select("id, date, full_day, start_time, end_time, reason, notes").eq("operator_id",r.id).gte("date",s).lte("date",t)]);(n||d)&&p.error((n==null?void 0:n.message)??(d==null?void 0:d.message)??"Nu am putut încărca datele"),de(a??[]),me(f??[])}finally{U(!1)}},Y=i.useMemo(()=>{const s={};return _.forEach(t=>{var a;(s[a=t.event_date]||(s[a]=[])).push(t)}),Object.values(s).forEach(t=>t.sort((a,n)=>(a.start_time??"").localeCompare(n.start_time??""))),s},[_]),ee=i.useMemo(()=>{const s={};return w.forEach(t=>{var a;(s[a=t.date]||(s[a]=[])).push(t)}),s},[w]),P=s=>o(s,"yyyy-MM-dd"),B=Y[P(u)]||[],F=ee[P(u)]||[],C=i.useMemo(()=>{const s=o(k(c),"yyyy-MM-dd"),t=o(I(c),"yyyy-MM-dd"),a=_.filter(l=>l.event_date>=s&&l.event_date<=t),n=a.filter(l=>["in_asteptare","trimis_operator","acceptat","in_desfasurare"].includes(l.status)),f=a.filter(l=>l.status==="finalizat"),d=w.filter(l=>l.date>=s&&l.date<=t).length;return{total:a.length,upcoming:n.length,done:f.length,offDays:d}},[_,w,c]),pe=i.useMemo(()=>{const s=Ne(k(c),{weekStartsOn:1}),t=_e(I(c),{weekStartsOn:1}),a=[];let n=s;for(;n<=t;)a.push(n),n=E(n,1);return a},[c]),se=s=>{xe(s),V(!0),W("09:00"),K("18:00"),H("personal"),Z(""),M(!0)},he=async()=>{if(!z||!r||!m)return;if(!v&&L<=O){p.error("Ora de sfârșit trebuie să fie după ora de început");return}Q(!0);const{error:s}=await g.from("operator_availability").insert({operator_id:r.id,company_id:m,date:o(z,"yyyy-MM-dd"),full_day:v,start_time:v?null:O,end_time:v?null:L,reason:J,notes:X||null});if(Q(!1),s){p.error("Eroare: "+s.message);return}p.success("Indisponibilitate salvată"),M(!1),j()},fe=async s=>{if(!confirm("Sigur ștergi această indisponibilitate?"))return;const{error:t}=await g.from("operator_availability").delete().eq("id",s);if(t){p.error(t.message);return}p.success("Șters"),j()},ge=async()=>
1{if(!r||!m||!confirm("Marchez indisponibil următorul weekend (vineri-duminică)?"))return;const s=new Date,a=(5-s.getDay()+7)%7||7,n=E(s,a),f=E(n,1),d=E(n,2),l=[n,f,d].map(S=>({operator_id:r.id,company_id:m,date:o(S,"yyyy-MM-dd"),full_day:!0,reason:"personal"})),{error:D}=await g.from("operator_availability").insert(l);D?p.error(D.message):(p.success("Weekend blocat"),j())},ve=["L","M","M","J","V","S","D"];return e.jsxs("div",{className:"p-4 md:p-8 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-display font-bold flex items-center gap-2",children:[e.jsx(we,{className:"h-7 w-7 text-primary"}),"Calendarul meu"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Vezi-ți evenimentele și marchează zilele când nu ești disponibil."})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(h,{variant:"warm",onClick:ge,children:[e.jsx(Me,{className:"h-4 w-4 mr-2"})," Blochează weekendul următor"]}),e.jsxs(h,{variant:"hero",onClick:()=>se(u),children:[e.jsx(q,{className:"h-4 w-4 mr-2"})," Marchează indisponibil"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs(y,{className:"p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Evenimente lună"}),e.jsx("div",{className:"text-2xl font-display font-bold",children:C.total})]}),e.jsxs(y,{className:"p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Viitoare"}),e.jsx("div",{className:"text-2xl font-display font-bold text-warning",children:C.upcoming})]}),e.jsxs(y,{className:"p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Finalizate"}),e.jsx("div",{className:"text-2xl font-display font-bold text-success",children:C.done})]}),e.jsxs(y,{className:"p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Zile blocate"}),e.jsx("div",{className:"text-2xl font-display font-bold text-destructive",children:C.offDays})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-[1.4fr_1fr] gap-4",children:[e.jsxs(y,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx(h,{variant:"outline",size:"icon",onClick:()=>R(ie(c,1)),children:e.jsx(ze,{className:"h-4 w-4"})}),e.jsx("div",{className:"font-display font-bold text-lg capitalize",children:o(c,"MMMM yyyy",{locale:A})}),e.jsx(h,{variant:"outline",size:"icon",onClick:()=>R(te(c,1)),children:e.jsx(Ce,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:ve.map((s,t)=>e.jsx("div",{className:"text-center text-[10px] font-semibold text-muted-foreground uppercase py-1",children:s},t))}),oe?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ae,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx("div",{className:"grid grid-cols-7 gap-1",children:pe.map(s=>{const t=P(s),a=Y[t]||[],n=ee[t]||[],f=De(s,c),d=Se(s,u),l=ne(s),D=Ke(s)&&!l,S=n.length>0;return e.jsxs("button",{onClick:()=>ce(s),className:T("aspect-square rounded-lg p-1 text-left transition-all relative flex flex-col","border",d?"ring-2 ring-primary border-primary bg-primary/5":"border-transparent hover:border-border hover:bg-muted/40",!f&&"opacity-40",D&&"text-muted-foreground",S&&"bg-destructive/10"),children:[e.jsx("div",{className:T("text-xs font-semibold",l&&"h-5 w-5 rounded-full bg-primary text-primary-foreground flex items-center justify-center"),children:o(s,"d")}),e.jsxs("div",{className:"flex-1 flex items-end justify-center gap-0.5 pb-0.5",children:[S&&e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-destructive"}),a.slice(0,3).map((x,je)=>e.jsx("div",{className:T("h-1.5 w-1.5 rounded-full",x.status==="finalizat"&&"bg-success",x.status==="acceptat"&&"bg-success",(x.status==="in_asteptare"||x.status==="trimis_operator")&&"bg-warning",x.status==="in_desfasurare"&&"bg-accent",x.status==="refuzat"&&"bg-destructive",x.status==="anulat"&&"bg-muted-foreground",x.status==="neasignat"&&"bg-muted-foreground")},je)),a.length>3&&e.jsxs("div",{className:"text-[8px] text-muted-foreground",children:["+",a.length-3]})]})]},t)})}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-3 pt-3 border-t text-[10px] text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-warning"})," Pending"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-success"})," Acceptat/Finalizat"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-accent"})," În desfășurare"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-destructive"})," Indisponibil"]})]})]}),e.jsxs(y,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:ne(u)?"Astăzi":o(u,"EEEE",{locale:A})}),e.jsx("div",{className:"text-xl font-display font-bold capitalize",children:o(u,"d MMMM yyyy",{locale:A})})]}),e.jsxs(h,{size:"sm",variant:"outline",onClick:()=>se(u),children:[e.jsx(ke,{className:"h-3 w-3 mr-1"})," Indisp."]})]}),F.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-xs font-semibold text-destructive flex items-center gap-1",children:[e.jsx(q,{className:"h-3 w-3"})," Indisponibil"]}),F.map(s=>e.jsxs("div",{className:"flex items-center justify-between bg-destructive/10 border border-destructive/30 rounded-lg p-2",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:s.full_day?"Toată ziua":re(s.start_time,s.end_time)}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[Ze[s.reason]??s.reason,s.notes&&` · ${s.notes}`]})]}),e.jsx(h,{size:"icon",variant:"ghost",onClick:()=>fe(s.id),children:e.jsx(Ee,{className:"h-3 w-3 text-destructive"})})]},s.id))]}),B.length>0?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-xs font-semibold text-primary",children:["Evenimente (",B.length,")"]}),B.map(s=>e.jsxs("button",{onClick:()=>le(`/eveniment/${s.id}`),className:"w-full text-left p-3 rounded-lg border hover:border-primary hover:bg-primary/5 transition-all",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-semibold truncate",children:s.client_name}),e.jsx("div",{className:"text-xs text-muted-foreground capitalize mt-0.5",children:(s.event_type??"altul").replace("_"," ")})]}),e.jsx(Te,{className:T("text-[10px] shrink-0",He[s.status]),children:Xe[s.status]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ae,{className:"h-3 w-3"}),re(s.start_time,s.end_time)]}),e.jsxs("span",{className:"flex items-center gap-1 truncate",children:[e.jsx(Oe,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:s.location??"Locație necompletată"})]})]})]},s.id))]}):F.length===0&&e.jsxs("div",{className:"text-center py-8 text-muted-foreground space-y-2",children:[e.jsx(Je,{className:"h-10 w-10 mx-auto text-muted-foreground
1/40"}),e.jsx("p",{className:"text-sm",children:"Nimic programat pentru această zi."}),e.jsx("p",{className:"text-xs",children:"Ești liber. 🎉"})]})]})]}),e.jsx(Le,{open:ue,onOpenChange:M,children:e.jsxs(Pe,{children:[e.jsxs(Be,{children:[e.jsxs(Fe,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5 text-destructive"})," Marchează indisponibil"]}),e.jsx(Ie,{children:z&&o(z,"EEEE, d MMMM yyyy",{locale:A})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/40 rounded-lg",children:[e.jsx(b,{htmlFor:"fullday",className:"cursor-pointer",children:"Toată ziua"}),e.jsx(qe,{id:"fullday",checked:v,onCheckedChange:V})]}),!v&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(b,{children:"De la"}),e.jsx($,{type:"time",value:O,onChange:s=>W(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(b,{children:"Până la"}),e.jsx($,{type:"time",value:L,onChange:s=>K(s.target.value)})]})]}),e.jsxs("div",{children:[e.jsx(b,{children:"Motiv"}),e.jsxs($e,{value:J,onValueChange:H,children:[e.jsx(Re,{children:e.jsx(Ue,{})}),e.jsxs(Ve,{children:[e.jsx(N,{value:"personal",children:"Personal"}),e.jsx(N,{value:"boala",children:"Boală"}),e.jsx(N,{value:"concediu",children:"Concediu"}),e.jsx(N,{value:"alt_eveniment",children:"Alt eveniment"}),e.jsx(N,{value:"altul",children:"Altul"})]})]})]}),e.jsxs("div",{children:[e.jsx(b,{children:"Detalii (opțional)"}),e.jsx($,{value:X,onChange:s=>Z(s.target.value),placeholder:"Ex: nuntă în familie, programare medic..."})]})]}),e.jsxs(We,{children:[e.jsx(h,{variant:"outline",onClick:()=>M(!1),children:"Anulează"}),e.jsx(h,{variant:"hero",onClick:he,disabled:G,children:G?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-4 w-4 mr-2 animate-spin"})," Se salvează..."]}):"Salvează"})]})]})})]})}export{as 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.