https://www.imagic.co.nz/_next/static/chunks/pages/components/AdminSickLeaveForm-bfc90dfa9372681b.js
1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3313],{35458:function(e,a,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/components/AdminSickLeaveForm",function(){return t(31088)}])},31088:function(e,a,t){"use strict";t.r(a),t.d(a,{default:function(){return o}});var l=t(85893),s=t(67294),r=t(11988),n=t(26),i=t(62380);function c(e){return e?(0,n.WU)(e,"yyyy-MM-dd"):""}function o(e){let{onCreated:a}=e,[t,n]=(0,s.useState)([]),[o,d]=(0,s.useState)(""),[u,m]=(0,s.useState)(null),[f,h]=(0,s.useState)(null),[p,v]=(0,s.useState)(""),[x,j]=(0,s.useState)([]),[y,b]=(0,s.useState)(!1),[N,k]=(0,s.useState)(null),[S,g]=(0,s.useState)(null);async function D(e){if(e.preventDefault(),!o||!u||!f){k("error"),g("Please select an employee and both dates.");return}b(!0),k(null),g(null);try{let t=new FormData;t.append("email",o),t.append("startDate",c(u)),t.append("lastDate",c(f)),t.append("reason",p),x.forEach(e=>t.append("attachments",e));let l=await fetch("/api/leave-sick-create",{method:"POST",body:t}),s=await l.json();l.ok&&s.success?(null==a||a(s.entry),d(""),m(null),h(null),v(""),j([]),e.target.reset(),k("success"),g("Sick leave recorded and notifications sent."),setTimeout(()=>{k(null),g(null)},4e3)):(k("error"),g(s.error||"Failed to record sick leave."))}catch(e){console.error("Error creating sick leave entry:",e),k("error"),g("Failed to record sick leave.")}finally{b(!1)}}return(0,s.useEffect)(()=>{let e=!1;return fetch("/api/leave-admin-users").then(e=>e.json()).then(a=>{!e&&Array.isArray(a.users)&&n([...a.users].sort((e,a)=>e.name.localeCompare(a.name)))}).catch(e=>console.error("Error fetching employees:",e)),()=>{e=!0}},[]),(0,l.jsxs)("div",{className:"leave-form admin-sick-leave-form","data-bg":"white",children:[(0,l.jsx)("h3",{className:"admin-section-title",children:"Add Sick Leave"}),(0,l.jsxs)("form",{className:"form-block",onSubmit:D,children:[(0,l.jsx)("div",{className:"form-row",children:(0,l.jsxs)("div",{className:"form-field form-field-full",children:[(0,l.jsx)("label",{className:"input-label label-text",htmlFor:"sickLeaveEmail",children:"Employee"}),(0,l.jsxs)("select",{id:"sickLeaveEmail",value:o,onChange:e=>d(e.target.value),required:!0,children:[(0,l.jsx)("option",{value:"",disabled:!0,children:"Select employeeâ¦"}),t.map(e=>(0,l.jsx)("option",{value:e.email,children:e.name},e.id))]})]})}),(0,l.jsxs)("div",{className:"form-row",children:[(0,l.jsxs)("div",{className:"form-field",children:[(0,l.jsx)("label",{className:"input-label label-text",htmlFor:"sickLeaveStart",children:"First Day"}),(0,l.jsx)(r.ZP,{id:"sickLeaveStart",selected:u,onChange:m,selectsStart:!0,startDate:u,endDate:f,dateFormat:"dd/MM/yyyy",className:"date-picker-input",placeholderText:"DD / MM / YYYY",autoComplete:"off",calendarStartDay:1,popperContainer:i.default,required:!0})]}),(0,l.jsxs)("div",{className:"form-field",children:[(0,l.jsx)("label",{className:"input-label label-text",htmlFor:"sickLeaveEnd",children:"Last Day"}),(0,l.jsx)(r.ZP,{id:"sickLeaveEnd",selected:f,onChange:h,selectsEnd:!0,startDate:u,endDate:f,minDate:u,dateFormat:"dd/MM/yyyy",className:"date-picker-input",placeholderText:"DD / MM / YYYY",autoComplete:"off",calendarStartDay:1,popperContainer:i.default,required:!0})]})]}),(0,l.jsx)("div",{className:"form-row",children:(0,l.jsxs)("div",{className:"form-field form-field-full",children:[(0,l.jsx)("label",{className:"input-label label-text",htmlFor:"sickLeaveReason",children:"Reason (optional)"}),(0,l.jsx)("input",{id:"sickLeaveReason",type:"text",value:p,onChange:e=>v(e.target.value),placeholder:"e.g. Flu"})]})}),(0,l.jsx)("div",{className:"form-row",children:(0,l.jsxs)("div",{className:"form-field form-field-full",children:[(0,l.jsx)("label",{className:"input-label label-text",htmlFor:"sickLeaveAttachments",children:"Attachments (optional)"}),(0,l.jsx)("input",{id:"sickLeaveAttachments",type:"file",accept:"image/*,application/pdf",multiple:!0,onChange:function(e){j(Array.from(e.target.files||[]))}}),x.length>0&&(0,l.jsxs)("p",{className:"admin-sick-leave-attachments-hint",children:[x.length," file",x.length>1?"s":""," selected"]})]})}),(0,l.jsx)("div",{className:"form-buttons",children:(0,l.jsx)("button",{type:"submit",className:"btn btn-bg-green",disabled:y,children:(0,l.jsx)("span",{children:y?"Savingâ¦":"Add Sick Leave"})})}),"error"===N&&(0,l.jsx)("div",{className:"form-status form-status-error",children:(0,l.jsx)("p",{children:S})}),"success"===N&&(0,l.jsx)("div",{className:"form-status form-status-success",children:(0,l.jsx)("p",{children:S})})]})]})}},62380:function(e,a,t){"use strict";t.r(a),t.d(a,{default:function(){return n}});
1var l=t(85893),s=t(67294),r=t(73935);function n(e){let{children:a}=e,[t,n]=(0,s.useState)(!1);return((0,s.useEffect)(()=>{n(!0)},[]),t)?(0,r.createPortal)((0,l.jsx)("div",{className:"leave-datepicker-portal",children:a}),document.body):null}}},function(e){e.O(0,[2644,6342,26,2598,2888,9774,179],function(){return e(e.s=35458)}),_N_E=e.O()}]);
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.