1import{c as E,r as v,e as I,ac as x,f as j,n as b,d as S,z as N,q as U,t as y,C as L,x as C,j as e,D as l,L as q,i as F,F as T,E as $,I as h,g as A}from"./index-Az_DQIbU.js";import{u as k,b as O,c as P}from"./event.api-Bzg_TdGc.js";import{w as R}from"./withRole-Dp1BazmZ.js";const z=u=>{const m=E(),[f,o]=v.useState(!1),t=new Date;t.setHours(0,0,0,0);const p=a=>new Date(a).toISOString(),g=I({eventName:j().required("Event name is required"),assignUserId:j().required("Event Director is required"),startDate:x().nullable().transform((a,i)=>i===""||i===void 0?null:a).typeError("Invalid start date").min(t,"Start date must be in the future").required("Start date is required"),endDate:x().nullable().transform((a,i)=>i===""||i===void 0?null:a).typeError("Invalid end date").when("startDateTime",{is:a=>a!=null,then:a=>a.min(b("startDateTime"),"End date must be after start date"),otherwise:a=>a}).required("End date is required")});return{addEventFormik:S({initialValues:{eventLogo:null,eventName:"",assignUserId:"",startDate:"",endDate:""},validationSchema:g,onSubmit:async(a,{resetForm:i})=>{o(!0);const c=new FormData;c.append("eventName",a.eventName),c.append("assignUserId",a.assignUserId),c.append("startDate",p(a.startDate)),c.append("endDate",p(a.endDate)),a.eventLogo&&c.append("eventLogo",a.eventLogo);try{if(u){const d=await k(c,u);d.status===200&&(N.success(d.message),m("/events"))}else{const d=await O(c);d.status===200&&(N.success(d.message),i(),m("/events"))}}catch(d){console.error("An error occurred while saving the event.",d)}finally{o(!1)}}}),loading:f}},M=U(async()=>await y.get("/admin/user-management/eventdirector/all")),H=()=>{const u=L(),m=C(),f=E(),{id:o}=u,{addEventFormik:t,loading:p}=z(o),[g,D]=v.useState([]),[a,i]=v.useState(null);v.useEffect(()=>{if(m.pathname.includes("/update")&&!o){f("/events",{replace:!0});return}},[o,m.pathname,f]);const c=r=>{const s=new Date(r),n=s.getTimezoneOffset();return new Date(s.getTime()-n*60*1e3).toISOString().slice(0,10)},d=r=>r?c(r):"";v.useEffect(()=>{o&&(async()=>{try{const s=await P(o);if(s.event){const n=s.event;t.setValues({eventLogo:null,eventName:n?.eventName||"",assignUserId:n?.assignUserId?.id||"",startDate:d(n?.startDate),endDate:d(n?.endDate)}),i(n?.eventLogo||"")}}catch(s){console.error("Error fetching event data:",s)}})()},[o]),v.useEffect(()=>{(async()=>{try{const s=await M();s.eventDirectors&&D(s.eventDirectors)}catch(s){console.error("Error fetching dropdown data:",s)}})()},[]);const w=r=>{const s=r.target.files[0];if(s){t.setFieldValue("eventLogo",s);const n=new FileReader;n.onloadend=()=>{typeof n.result=="string"&&i(n.result)},n.readAsDataURL(s)}};return e.jsx("div",{id:"editevent",className:`${l.myprofilewrapper} dashboard-card-global`,children:e.jsxs("div",{className:"profile-card",children:[e.jsxs("div",{className:l.profile_flex,children:[e.jsx("h2",{children:o?"Update Event":"Add Event"}),e.jsx(q,{to:"/events",state:{fromPage:m.state?.fromPage},children:e.jsx("button",{className:"custom-button",children:"Back"})})]}),e.jsxs("form",{onSubmit:t.handleSubmit,autoComplete:"off",className:"formaddevent from-fix-global-wrap",children:[e.jsx("div",{className:"profile-picture-upload",children:e.jsx("div",{className:"uploadimage center",children:e.jsxs("div",{className:"upimg",children:[e.jsx("img",{src:a||F.homeNoImage,alt:"Home Logo"}),e.jsx("input",{className:"choosefile",id:"eventLogo",name:"eventLogo",type:"file",accept:"image/*",onChange:r=>w(r)}),e.jsx("div",{className:"overlay",children:e.jsx("span",{className:"icon",children:e.jsx(T,{icon:$})})})]})})}),e.jsxs("div",{className:`${l.profileform} from-fix-global`,children:[e.jsx("div",{className:l.profileformcol,children:e.jsx("div",{className:"formgrp",children:e.jsx(h,{type:"text",title:"Event Name",id:"eventName",placeholder:"Enter Event name",name:"eventName",onChange:t.handleChange,value:t.values.eventName,required:!0,errorMsg:t.touched.eventName&&t.errors.eventName?t.errors.eventName:""})})}),e.jsx("div",{className:l.profileformcol,children:e.jsxs("div",{className:"formgrp",children:[e.jsxs("label",{htmlFor:"assignUserId",children:["Event Director",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsxs("select",{id:"assignUserId",name:"assignUserId",value:t.values.assignUserId,onChange:t.handleChange,children:[e.jsx("option",{value:"",children:"-- Select Event Director --"}),g.map(r=>
1e.jsx("option",{value:r.id,children:r.fullName},r.id))]}),t.touched.assignUserId&&t.errors.assignUserId&&e.jsx("div",{className:"error",children:t.errors.assignUserId})]})}),e.jsx("div",{className:l.profileformcol,children:e.jsx("div",{className:"formgrp",children:e.jsx(h,{type:"date",title:"Start Date",id:"startDate",name:"startDate",min:new Date().toISOString().split("T")[0],onChange:t.handleChange,value:t.values.startDate,required:!0,errorMsg:t.touched.startDate&&t.errors.startDate?t.errors.startDate:""})})}),e.jsx("div",{className:l.profileformcol,children:e.jsx("div",{className:"formgrp",children:e.jsx(h,{type:"date",title:"End Date",id:"endDate",name:"endDate",min:t.values.startDate||new Date().toISOString().split("T")[0],onChange:t.handleChange,value:t.values.endDate,required:!0,errorMsg:t.touched.endDate&&t.errors.endDate?t.errors.endDate:""})})})]}),p?e.jsx(A,{}):e.jsx("div",{className:`${l.profileformcol} submit-btn-wrap`,children:e.jsx("button",{className:"custom-button submit-btn",children:o?"Update Event":"Add Event"})})]})]})})};function B(){return e.jsx("section",{children:e.jsx(H,{})})}const K=R(B,["admin"]);export{K 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.