PageSourceSearch

https://nadort-elektro.nl/assets/Verlof-7k1o8xXX.js

js nadort-elektro.nl collected 2026-10-09 22:03:32 UTC 10,923 bytes, 1 lines download raw bytes

1import{u as ae,r as l,b as h,at as se,j as e,am as j,an as v,ao as _,ap as N,aq as g,B as p,L as re,a5 as te,a6 as ne,a7 as le,a8 as de,a as o,I as b,T as oe,c}from"./index-DZ2JdFDg.js";import{notifyUsers as ie}from"./pushNotifications-BojXWary.js";import{e as ce,i as O,L as k,S as F,b as ue,t as $,a as w,h as A,D as me,f as xe}from"./hr-C96k9XLj.js";import{P as Y}from"./plane-DY28mkTY.js";import{C as he}from"./calendar-BBfYG9fL.js";import{P as ge}from"./plus-DWaCrKyQ.js";import{T as pe}from"./trash-2-DeU-Lotm.js";const ye=k.map(r=>({value:r.value,label:r.label})),I=()=>new Date().toISOString().slice(0,10);function U(r){return new Date(r).toLocaleDateString("nl-NL",{day:"numeric",month:"long",year:"numeric"})}function Se(){const{user:r}=ae(),[R,H]=l.useState([]),[z,q]=l.useState(!0),[G,u]=l.useState(!1),[t,M]=l.useState(null),[y,J]=l.useState(new Date().getFullYear()),[S,K]=l.useState("all"),[f,Q]=l.useState("all"),[B,W]=l.useState(!1),[s,d]=l.useState({start_date:I(),end_date:I(),leave_type:"vakantie",day_part:"hele_dag",custom_hours:0,signature_name:"",note:""}),D=async()=>{if(!r)return;q(!0);const[{data:a},n,{data:x}]=await Promise.all([h.from("leave_requests").select("*").eq("user_id",r.id).order("start_date",{ascending:!1}),xe(r.id,y),h.from("hr_settings").select("allow_negative_balance").maybeSingle()]);H(a??[]),M(n),W(!!(x!=null&&x.allow_negative_balance)),q(!1)};l.useEffect(()=>{D(),r&&!s.signature_name&&h.from("profiles").select("full_name").eq("id",r.id).maybeSingle().then(({data:a})=>{a!=null&&a.full_name&&d(n=>({...n,signature_name:n.signature_name||a.full_name}))})},[r==null?void 0:r.id,y]);const[L,E]=se();l.useEffect(()=>{if(L.get("new")==="1"){u(!0);const a=new URLSearchParams(L);a.delete("new"),E(a,{replace:!0})}},[L,E]);const m=(t==null?void 0:t.uren_per_werkdag)??8,C=l.useMemo(()=>ce(s.start_date,s.end_date,s.day_part,s.custom_hours,m),[s.start_date,s.end_date,s.day_part,s.custom_hours,m]),T=t&&O(s.leave_type)?C>t.resterend_uren:!1,X=async a=>{if(a.preventDefault(),!r)return;if(!s.signature_name.trim())return c.error("Naam voor ondertekenen is verplicht");if(s.end_date<s.start_date)return c.error("Einddatum mag niet vóór startdatum liggen");if(T&&!B)return c.error("Onvoldoende verlofsaldo. Neem contact op met de administratie.");const{error:n}=await h.from("leave_requests").insert({user_id:r.id,start_date:s.start_date,end_date:s.end_date,reason:s.leave_type,leave_type:s.leave_type,day_part:s.day_part,custom_hours:s.day_part==="uren"?s.custom_hours:null,signature_name:s.signature_name.trim().slice(0,200),note:s.note.trim().slice(0,2e3)||null});if(n)return c.error(n.message);c.success("Verlofaanvraag verstuurd"),ie({title:"Nieuwe verlofaanvraag",body:`${s.signature_name.trim()}: ${$(s.leave_type)} ${U(s.start_date)} t/m ${U(s.end_date)}`,url:"/portaal/verlof-beheer",roles:["admin"],type:"leave_request"}),d({...s,note:"",custom_hours:0}),u(!1),D()},Z=async a=>{if(!confirm("Aanvraag verwijderen?"))return;const{error:n}=await h.from("leave_requests").delete().eq("id",a);if(n)return c.error(n.message);D()},P=R.filter(a=>S!=="all"&&(a.leave_type??a.reason)!==S?!1:f==="open"?a.status==="pending":!(f!=="all"&&a.status!==f)),ee=Array.from({length:3},(a,n)=>new Date().getFullYear()-1+n),V=a=>a>0?-a:a,i=({label:a,hours:n,tone:x})=>e.jsxs("div",{className:`p-4 rounded-xl border border-border ${x??"bg-card"}`,children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:a}),e.jsxs("div",{className:"text-2xl font-semibold mt-1",children:[w(n)," ",e.jsx("span",{className:"text-sm text-muted-foreground font-normal",children:"uur"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[A(n,m)," dagen"]})]});return e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-start sm:items-center justify-between mb-6 gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h1",{className:"text-xl sm:text-2xl md:text-3xl font-semibold flex items-center gap-2",children:[e.jsx(Y,{className:"w-6 h-6 sm:w-7 sm:h-7 text-accent shrink-0"}),e.jsx("span",{className:"truncate",children:"Mijn verlof"})]}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground",children:"Bekijk je verlofsaldo en dien nieuwe aanvragen in."})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap w-full sm:w-auto",children:[e.jsxs(j,{value:String(y),onValueChange:a=>J(Number(a)),children:[e.jsx(v,{className:"w-full sm:w-28",children:e.jsx(_,{})}),e.jsx(N,{children:ee.map(a=>e.jsx(g,{value:String(a),children:a},a))})]}),e.jsx(p,{asChild:!0,variant:"outline",className:"w-full sm:w-auto gap-2",children:e.jsxs(re,{to:"/portaal/verlof/kalender",children:[e.jsx(he,{className:"w-4 h-4"})," Teamkalender"]})}),e.jsxs(p,{onClick:()=>u(!0),className:"gap-2 bg-accent text-accent-foreground hover:bg-accent/90 w-full sm:w-auto",children:[e.jsx(ge,{className:"w-4 h-4"})," Nieuwe aanvraag"]})]})]}),t&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-3 mb-6",children:[e.jsx(i,{label:"Beginsaldo",hours:t.beginsaldo_uren}),e.jsx(i,{label:"Correctie",hours:t.correctie_uren}),e.jsx(i,{label:"Overuren-registratie",hours:t.overuren_uren,tone:"bg-sky-500/10"}),e.jsx(i,{label:"Opgenomen",hours:V(t.opgenomen_uren)}),e.jsx(i,{label:"Gepland",hours:V(t.gepland_uren)}),e.jsx(i,{label:"Beschikbaar",hours:t.resterend_uren,tone:t.resterend_uren<0?"bg-rose-500/10":"bg-emerald-500/10"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[e.jsxs(j,{value:S,onValueChange:a=>K(a),children:[e.jsx(v,{className:"w-40",children:e.jsx(_,{})}),e.jsxs(N,{children:[e.jsx(g,{value:"all",children:"Alle typen"}),k.map(a=>e.jsx(g,{value:a.value,children:a.label},a.value))]})]}),e.jsx("div",{className:"flex flex-wrap rounded-lg border border-border p-1 bg-card",children:["all","open","approved","rejected"].map(a=>e.jsx("button",{onClick:()=>Q(a),className:`px-2.5 py-1.5 text-xs rounded-md whitespace-nowrap ${f===a?"bg-accent text-accent-foreground":"text-muted-foreground hover:text-foreground"}`,children:a==="open"?"Open":a==="all"?"Alles":F[a]},a))})]}),z?e.jsx("p",{className:"text-muted-foreground",children:"Laden…"}):P.length===0?e.jsx("p",{className:"text-muted-foreground",children:"Geen verlofaanvragen."}):e.jsx("ul",{className:"space-y-3",children:P.map(a=>e.jsx("li",{className:"p-4 sm:p-5 bg-card border border-border rounded-xl",children:e.jsxs("div",{className:"flex items-start justify-between gap-2 sm:gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsxs("h3",{className:"font-semibold text-base sm:text-lg",children:[new Date(a.start_date).toLocaleDateString("nl-NL")," t/m ",new Date(a.end_date).toLocaleDateString("nl-NL")]}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${ue[a.status]}`,children:F[a.status]}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-secondary text-secondary-foreground",children:$(a.leave_type??a.reason)}),a.hours!=null&&e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-secondary text-secondary-foreground",children:[w(a.hours)," u · ",A(a.hours,m)," d"]})]}),a.note&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2 whitespace-pre-wrap",children:a.note}),a.reject_reason&&e.jsxs("p",{className:"text-sm mt-2 p-2 rounded-md bg-rose-500/10",children:[e.jsx("span",{className:"font-medium",children:"Afwijsreden:"})," ",a.reject_reason]}),a.admin_note&&e.jsxs("p",{className:"text-sm mt-2 p-2 rounded-md bg-secondary/60",children:[e.jsx("span",{className:"font-medium",children:"Notitie:"})," ",a.admin_note]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["Aangevraagd op ",new Date(a.created_at).toLocaleDateString("nl-NL",{day:"numeric",month:"long",year:"numeric"})]})]}),a.status==="pending"&&e.jsx(p,{size:"icon",variant:"ghost",onClick:()=>Z(a.id),title:"Verwijderen",children:e.jsx(pe,{className:"w-4 h-4"})})]})},a.id))}),e.jsx(te,{open:G,onOpenChange:u,children:e.jsxs(ne,{className:"max-w-[calc(100vw-2rem)] sm:max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(le,{children:e.jsxs(de,{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-5 h-5 text-accent"})," Nieuwe verlofaanvraag"]})}),e.jsxs("form",{onSubmit:X,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(o,{children:"Type verlof *"}),e.jsxs(j,{value:s.leave_type,onValueChange:a=>d({...s,leave_type:a}),children:[e.jsx(v,{children:e.jsx(_,{})}),e.jsx(N,{children:k.map(a=>e.jsx(g,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(o,{children:"Van *"}),e.jsx(b,{type:"date",value:s.start_date,onChange:a=>d({...s,start_date:a.target.value,end_date:s.end_date<a.target.value?a.target.value:s.end_date}),required:!0})]}),e.jsxs("div",{children:[e.jsx(o,{children:"T/m *"}),e.jsx(b,{type:"date",value:s.end_date,onChange:a=>d({...s,end_date:a.target.value}),required:!0})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(o,{children:"Dagdeel *"}),e.jsxs(j,{value:s.day_part,onValueChange:a=>d({...s,day_part:a}),children:[e.jsx(v,{children:e.jsx(_,{})}),e.jsx(N,{children:me.map(a=>e.jsx(g,{value:a.value,children:a.label},a.value))})]})]}),s.day_part==="uren"&&e.jsxs("div",{children:[e.jsx(o,{children:"Aantal uren *"}),e.jsx(b,{type:"number",min:0,step:.25,value:s.custom_hours,onChange:a=>d({...s,custom_hours:Number(a.target.value)}),required:!0})]})]}),e.jsxs("div",{className:"p-3 rounded-md bg-secondary/60 text-sm flex items-center justify-between",children:[e.jsxs("span",{children:["Berekend: ",e.jsxs("strong",{children:[w(C)," uur"]})," · ",A(C,m)," dagen"]}),O(s.leave_type)&&t&&e.jsxs("span",{className:T?"text-rose-600 font-medium":"text-muted-foreground",children:["Beschikbaar: ",w(t.resterend_uren)," u"]})]}),T&&e.jsxs("p",{className:"text-xs text-rose-600",children:["Deze aanvraag overschrijdt je verlofsaldo. ",B?"Beheerder heeft negatief saldo toegestaan.":"Neem contact op met de administratie."]}),e.jsxs("div",{children:[e.jsx(o,{children:"Naam voor ondertekenen *"}),e.jsx(b,{value:s.signature_name,onChange:a=>d({...s,signature_name:a.target.value}),maxLength:200,required:!0,placeholder:"Uw volledige naam"})]}),e.jsxs("div",{children:[e.jsx(o,{children:"Opmerking (optioneel)"}),e.jsx(oe,{value:s.note,onChange:a=>d({...s,note:a.target.value}),maxLength:2e3,rows:3})]}),e.jsxs("div",{className:"flex flex-col-reverse sm:flex-row gap-2",children:[e.jsx(p,{type:"button",variant:"outline",onClick:()=>u(!1),className:"sm:w-auto",children:"Annuleren"}),e.jsx(p,{type:"submit",className:"bg-accent text-accent-foreground hover:bg-accent/90 sm:w-auto",children:"Versturen"})]})]})]})})]})}export{ye as REASONS,F as STATUS_LABEL,ue as STATUS_STYLE,Se 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.