Your IP : 3.145.92.213


Current Path : /home/ncdcgo/admin.ncdc.go.ug/static/js/
Upload File :
Current File : /home/ncdcgo/admin.ncdc.go.ug/static/js/88.7b6d52b1.chunk.js

"use strict";(self.webpackChunkpanel=self.webpackChunkpanel||[]).push([[88],{223:function(e,t,r){r(2791);var a=r(3504),n=r(2506),i=r(184);t.Z=function(e){var t=e.routes;return(0,i.jsx)("nav",{className:"flex bg-white border border-gray-200 p-2 rounded-full px-4 mt-4","aria-label":"Breadcrumb",children:(0,i.jsxs)("ol",{className:"inline-flex items-center space-x-1 md:space-x-3",children:[(0,i.jsx)("li",{className:"inline-flex items-center text-gray-800",children:(0,i.jsxs)(a.rU,{to:"/app",className:"inline-flex items-center text-sm  text-gray-800 hover:text-gray-900 dark:text-gray-800 dark:hover:text-gray-200",children:[(0,i.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"currentColor",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsx)("path",{d:"M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z"})}),"Home"]})}),null===t||void 0===t?void 0:t.map((function(e,t){return(0,i.jsxs)("li",{className:"inline-flex items-center",children:[(0,i.jsx)(n.Z,{size:10,className:"mr-4"}),(0,i.jsx)(a.rU,{to:e.path,className:"inline-flex items-center text-sm font-extrabold text-gray-700 hover:text-gray-900 dark:text-gray-800 dark:hover:text-gray-200",children:e.name})]},t)}))]})})}},2088:function(e,t,r){r.r(t),r.d(t,{DirectorateRoutes:function(){return re}});var a=r(6871),n=r(9630),i=r(5528),s=r(2412),o=r(223),c=r(77),u=r(7087),d=r(1413),l=r(6771),f=r(1933),m=function(e){var t=e.directorateId,r=e.config;return(0,f.useQuery)((0,d.Z)((0,d.Z)({},r),{},{queryKey:["directorate",t],queryFn:function(){return function(e){var t=e.directorateId;return l.o.get("/directorates/".concat(t))}({directorateId:t})}}))},x=r(4165),p=r(5861),g=r(806),v=r(4430),h=r(2076),j=r(2982),y=r(3777),b=r(7889),w=r(2007),D=r.n(w),Z=function(e){var t=e.data,r=e.directorateId;return l.o.post("/directorates/".concat(r,"/managers"),t)};Z.propTypes={directorateId:D().string.isRequired,data:D().shape({managerId:D().string.isRequired}).isRequired};var I=function(){return l.o.get("/managers")},N=r(184),k=function(e){var t=e.directorateId,r=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,f.useMutation)((0,d.Z)((0,d.Z)({onMutate:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.E.cancelQueries("managers");case 2:return r=y.E.getQueryData("managers"),y.E.setQueryData("managers",[].concat((0,j.Z)(r||[]),[t.data])),e.abrupt("return",{previousManagers:r});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onError:function(e,t,r){null!==r&&void 0!==r&&r.previousManagers&&y.E.setQueryData("managers",r.previousManagers)},onSuccess:function(){y.E.invalidateQueries("managers"),t({type:"success",title:"Manager has been added"})}},e),{},{mutationFn:Z}))}(),a=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config;return(0,f.useQuery)((0,d.Z)((0,d.Z)({},e),{},{queryKey:["allManagers"],queryFn:function(){return I()}}))}();return console.log(a.data),r.isLoading?(0,N.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,N.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,N.jsx)(n.$j,{size:"sm"})})}):(0,N.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,N.jsx)(g._8,{size:"sm",isDone:r.isSuccess,triggerButton:(0,N.jsx)(n.zx,{variant:"create",size:"sm",startIcon:(0,N.jsx)(h.Z,{className:"h-4 w-4"}),children:"Add Manager"}),title:"Add Manager",submitButton:(0,N.jsx)(n.zx,{form:"add-manager",type:"submit",size:"sm",isLoading:r.isLoading,children:"Submit"}),children:(0,N.jsx)(g.l0,{id:"add-manager",onSubmit:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(a){return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.mutateAsync({data:a,directorateId:t});case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),children:function(e){var t,r=e.register,n=e.formState;e.watch,e.setValue;return(0,N.jsx)(N.Fragment,{children:(0,N.jsx)(g.mg,{label:"Manager",error:n.errors.managerId,registration:r("managerId"),options:null===(t=a.data)||void 0===t?void 0:t.map((function(e){return{label:e.firstName+" "+e.lastName,value:e.id}}))})})}})})})},z=r(9879),E=function(e){var t=e.data,r=e.directorateId;return l.o.post("/directorates/".concat(r,"/sub_directorates"),t)};E.propTypes={directorateId:D().string.isRequired,data:D().shape({title:D().string.isRequired,desc:D().string.isRequired}).isRequired};var Q=z.Ry({title:z.Z_().min(1,"Required"),desc:z.Z_()}),M=function(e){var t=e.directorateId,r=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,f.useMutation)((0,d.Z)((0,d.Z)({onMutate:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.E.cancelQueries("subDirectorates");case 2:return r=y.E.getQueryData("subDirectorates"),y.E.setQueryData("subDirectorates",[].concat((0,j.Z)(r||[]),[t.data])),e.abrupt("return",{previousDirectorates:r});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onError:function(e,t,r){null!==r&&void 0!==r&&r.previousDirectorates&&y.E.setQueryData("subDirectorates",r.previousDirectorates)},onSuccess:function(){y.E.invalidateQueries("subDirectorates"),t({type:"success",title:"Sub Directorate has been added"})}},e),{},{mutationFn:E}))}();return r.isLoading?(0,N.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,N.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,N.jsx)(n.$j,{size:"sm"})})}):(0,N.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,N.jsx)(g._8,{size:"sm",isDone:r.isSuccess,triggerButton:(0,N.jsx)(n.zx,{variant:"create",size:"sm",startIcon:(0,N.jsx)(h.Z,{className:"h-4 w-4"}),children:"Add Sub Directorate"}),title:"Add Sub Directorate",submitButton:(0,N.jsx)(n.zx,{form:"create-directorate",type:"submit",size:"sm",isLoading:r.isLoading,children:"Submit"}),children:(0,N.jsx)(g.l0,{id:"create-directorate",onSubmit:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(a){return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.mutateAsync({data:a,directorateId:t});case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),schema:Q,children:function(e){var t=e.register,r=e.formState,a=e.watch,n=e.setValue;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(g.UP,{label:"Title",error:r.errors.title,registration:t("title")}),(0,N.jsx)(g.N7,{label:"Description",error:r.errors.desc,editorContent:a("desc"),setValue:n,value:"desc"})]})}})})})},R=function(e){var t=e.directorateId,r=e.config;return(0,f.useQuery)((0,d.Z)((0,d.Z)({},r),{},{queryKey:["managers",t],queryFn:function(){return function(e){var t=e.directorateId;return l.o.get("/directorates/".concat(t,"/managers"))}({directorateId:t})}}))},S=function(e){var t=e.managerId,r=e.config;return(0,f.useQuery)((0,d.Z)((0,d.Z)({},r),{},{queryKey:["manager",t],queryFn:function(){return function(e){var t=e.managerId;return l.o.get("/managers/".concat(t))}({managerId:t})}}))},q=function(e){var t=e.directorateId,r=e.managerId;return l.o.delete("/directorates/".concat(t,"/managers/").concat(r))};q.propTypes={directorateId:D().string.isRequired,managerId:D().string.isRequired};var L=function(e){var t=e.directorateId,r=e.managerId,a=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,f.useMutation)((0,d.Z)((0,d.Z)({onMutate:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.E.cancelQueries("managers");case 2:return r=y.E.getQueryData("managers"),y.E.setQueryData("managers",null===r||void 0===r?void 0:r.filter((function(e){return e.id!==t.directorateId}))),e.abrupt("return",{previousManagers:r});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onError:function(e,t,r){null!==r&&void 0!==r&&r.previousManagers&&y.E.setQueryData("managers",r.previousManagers)},onSuccess:function(){y.E.invalidateQueries("managers"),t({type:"success",title:"Manager Deleted"})}},e),{},{mutationFn:q}))}();return a.isLoading?(0,N.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,N.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,N.jsx)(n.$j,{size:"sm"})})}):(0,N.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,N.jsx)(n.U6,{icon:"danger",title:"Delete Manager",body:"Are you sure you want to delete this manager from directorate?",triggerButton:(0,N.jsx)("button",{children:"Remove"}),confirmButton:(0,N.jsx)(n.zx,{isLoading:a.isLoading,type:"button",className:"bg-red-600",onClick:(0,p.Z)((0,x.Z)().mark((function e(){return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.mutateAsync({directorateId:t,managerId:r});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),children:"Delete Manager"})})})},A=function(e){var t=e.directorateId,r=R({directorateId:t});return r.isLoading?(0,N.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:(0,N.jsx)(n.$j,{size:"lg"})}):r.data?(0,N.jsx)(n.iA,{data:r.data,columns:[{title:"Managers",field:"_id",Cell:function(e){var t=e.entry._id,r=S({managerId:t});return r.isLoading?(0,N.jsx)("div",{className:"flex justify-center items-center",children:(0,N.jsx)(n.$j,{size:"xs"})}):(0,N.jsx)("span",{className:"uppercase",children:r.data.firstName+""+r.data.lastName})}},{title:"",field:"id",Cell:function(e){var r=e.entry._id;return(0,N.jsxs)(N.Fragment,{children:[" ",(0,N.jsx)(n.rU,{to:"./".concat(r),className:"mr-2 text-black dark:text-gray-200 hover:text-green-400",children:"View"})," ",(0,N.jsx)(L,{directorateId:t,managerId:r})]})}}]}):null},C=function(e){var t=e.directorateId,r=e.config;return(0,f.useQuery)((0,d.Z)((0,d.Z)({},r),{},{queryKey:["subDirectorates",t],queryFn:function(){return function(e){var t=e.directorateId;return l.o.get("/directorates/".concat(t,"/sub_directorates"))}({directorateId:t})}}))},_=function(e){var t=e.directorateId,r=e.subDirectoratesId;return l.o.delete("/directorates/".concat(t,"/sub_directorates/").concat(r))};_.propTypes={directorateId:D().string.isRequired};var F=function(e){var t=e.directorateId,r=e.subDirectoratesId,a=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,f.useMutation)((0,d.Z)((0,d.Z)({onMutate:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.E.cancelQueries("subDirectorates");case 2:return r=y.E.getQueryData("subDirectorates"),y.E.setQueryData("subDirectorates",null===r||void 0===r?void 0:r.filter((function(e){return e.id!==t.directoratesId}))),e.abrupt("return",{previousSubDirectorates:r});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onError:function(e,t,r){null!==r&&void 0!==r&&r.previousSubDirectorates&&y.E.setQueryData("subDirectorates",r.previousSubDirectorates)},onSuccess:function(){y.E.invalidateQueries("subDirectorates"),t({type:"success",title:"Sub-Directorate Deleted"})}},e),{},{mutationFn:_}))}();return a.isLoading?(0,N.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,N.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,N.jsx)(n.$j,{size:"sm"})})}):(0,N.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,N.jsx)(n.U6,{icon:"danger",title:"Delete Sub Directorate",body:"Are you sure you want to delete this sub directorate?",triggerButton:(0,N.jsx)("button",{children:"Remove"}),confirmButton:(0,N.jsx)(n.zx,{isLoading:a.isLoading,type:"button",className:"bg-red-600",onClick:(0,p.Z)((0,x.Z)().mark((function e(){return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.mutateAsync({directorateId:t,subDirectoratesId:r});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),children:"Delete Sub Directorate"})})})},B=function(e){var t=e.directorateId,r=C({directorateId:t});return r.isLoading?(0,N.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:(0,N.jsx)(n.$j,{size:"lg"})}):r.data?(0,N.jsx)(n.iA,{data:r.data,columns:[{title:"Sub Directorates",field:"firstName",Cell:function(e){var t=e.entry,r=t.firstName,a=t.lastName;return(0,N.jsx)("span",{className:"uppercase",children:r+""+a})}},{title:"",field:"id",Cell:function(e){var r=e.entry._id;return(0,N.jsxs)(N.Fragment,{children:[" ",(0,N.jsx)(n.rU,{to:"./".concat(r),className:"mr-2 text-black dark:text-gray-200 hover:text-green-400",children:"View"})," ",(0,N.jsx)(F,{directorateId:t,subDirectoratesId:r})]})}}]}):null},U=r(885),$=r(8419),V=r(2791),K=function(e){var t=e.data,r=e.directorateId;return l.o.patch("/directorates/".concat(r),t)};K.propTypes={data:D().shape({title:D().string.isRequired,desc:D().string.isRequired}).isRequired,directorateId:D().string.isRequired};var T=z.Ry({title:z.Z_().min(1,"Required"),desc:z.Z_().min(1,"Required")}),G=function(e){var t,r,a,i=e.directorateId,s=(0,V.useState)(null),o=(0,U.Z)(s,2),c=o[0],u=o[1],l=(0,V.useState)(null),h=(0,U.Z)(l,2),j=h[0],w=h[1],D=(0,V.useState)(!1),Z=(0,U.Z)(D,2),I=Z[0],k=Z[1],z=m({directorateId:i}),E=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,f.useMutation)((0,d.Z)((0,d.Z)({onMutate:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.E.cancelQueries(["directorate",null===t||void 0===t?void 0:t.directorateId]);case 2:return r=y.E.getQueryData[null===t||void 0===t?void 0:t.directorateId],y.E.setQueryData(["directorate",null===t||void 0===t?void 0:t.directorateId],(0,d.Z)((0,d.Z)((0,d.Z)({},r),t.data),{},{id:t.directorateId})),e.abrupt("return",{previousDirectorate:r});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onError:function(e,t,r){null!==r&&void 0!==r&&r.previousDirectorate&&y.E.setQueryData(["directorate",r.previousDirectorate.id],r.previousDirectorate)},onSuccess:function(e){y.E.refetchQueries(["directorate",e.id]),t({type:"success",title:"Directorate Updated"})}},e),{},{mutationFn:K}))}();return E.isLoading?(0,N.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,N.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,N.jsx)(n.$j,{size:"sm"})})}):(0,N.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,N.jsx)(g._8,{size:"sm",isDone:E.isSuccess,triggerButton:(0,N.jsx)(n.zx,{variant:"create",startIcon:(0,N.jsx)($.Z,{className:"h-4 w-4"}),size:"sm",children:"Update"}),title:"Update Directorate",submitButton:(0,N.jsx)(n.zx,{form:"update-directorate",type:"submit",size:"sm",isLoading:E.isLoading,children:"Submit"}),children:(0,N.jsx)(g.l0,{id:"update-directorate",encType:"multipart/form-data",onSubmit:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r,a,n;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.title,a=t.desc,(n=new FormData).append("pageHeaderBgImage",c),n.append("title",r),n.append("desc",a),e.next=7,E.mutateAsync({data:n,directorateId:i});case 7:w(null);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),options:{defaultValues:{title:null===(t=z.data)||void 0===t?void 0:t.title,desc:null===(r=z.data)||void 0===r?void 0:r.desc,pageHeaderBgImage:null===(a=z.data)||void 0===a?void 0:a.pageHeaderBgImage}},schema:T,children:function(e){var t=e.register,r=e.formState,a=e.watch,n=e.setValue;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(g.UP,{label:"Title",error:r.errors.title,registration:t("title")}),(0,N.jsx)(g.N7,{label:"Content",error:r.errors.desc,editorContent:a("desc"),setValue:n,value:"desc"}),(0,N.jsx)("div",{className:"flex justify-between items-center",children:I?(0,N.jsx)("a",{href:"#",className:"bg-green-400 text-gray-800 font-bold p-2 rounded text-sm",onClick:function(e){e.preventDefault(),k(!1)},children:"Close"}):(0,N.jsx)("a",{href:"#",className:"bg-green-400 text-gray-800 font-bold p-2 rounded text-sm",onClick:function(e){e.preventDefault(),k(!0)},children:"Update Image"})}),I&&(0,N.jsx)(g.VA,{title:"Update Cover Photo",subTitle:"This will also be used as the thumbnail in feeds",error:r.errors.image,x:1024,y:768,onChange:function(e){u(e.target.files[0]),w(URL.createObjectURL(e.target.files[0]))},preview:j})]})}})})})},H=function(){var e=(0,a.UO)().directorateId,t=m({directorateId:e});if(t.isLoading)return(0,N.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:(0,N.jsx)(n.$j,{size:"lg"})});if(!t.data)return null;var r=[{name:"Directorates",path:"/app/directorates"},{name:t.data.title,path:"."}];return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(i.F,{title:t.data.title}),(0,N.jsxs)(s.D,{title:t.data.title,button:(0,N.jsx)(G,{directorateId:e}),children:[(0,N.jsx)(o.Z,{routes:r}),(0,N.jsx)("div",{className:"mt-6 flex flex-col space-y-16",children:(0,N.jsx)("div",{children:(0,N.jsxs)("div",{className:"bg-white dark:bg-gray-700 shadow overflow-hidden sm:rounded-lg",children:[(0,N.jsx)(u.LazyLoadImage,{src:"".concat(c.tC,"/").concat(t.data.pageHeaderBgImage),alt:"page header for directorate",className:"h-48 w-full object-cover"}),(0,N.jsx)("div",{className:"px-4 py-5 sm:px-6",children:(0,N.jsx)("div",{className:"mt-1 max-w-2xl text-sm text-gray-400 flex flex-wrap",children:(0,N.jsx)(n.Xz,{value:t.data.desc})})})]})})}),(0,N.jsxs)("div",{className:"mt-6",children:[(0,N.jsx)("div",{className:"flex justify-end",children:(0,N.jsx)(M,{directorateId:t.data.id})}),(0,N.jsx)("div",{className:"bg-white mt-4 dark:bg-gray-700 shadow overflow-hidden sm:rounded-lg",children:(0,N.jsx)(B,{directorateId:t.data.id})})]}),(0,N.jsxs)("div",{className:"mt-6",children:[(0,N.jsx)("div",{className:"flex justify-end",children:(0,N.jsx)(k,{directorateId:t.data.id})}),(0,N.jsx)("div",{className:"bg-white mt-4 dark:bg-gray-700 shadow overflow-hidden sm:rounded-lg",children:(0,N.jsx)(A,{directorateId:t.data.id})})]})]})]})},O=function(e){var t=e.data;return l.o.post("/directorates",t)};O.propTypes={data:D().shape({title:D().string.isRequired,desc:D().string.isRequired}).isRequired};var P=z.Ry({title:z.Z_().min(1,"Required"),desc:z.Z_()}),W=function(){var e=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,f.useMutation)((0,d.Z)((0,d.Z)({onMutate:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.E.cancelQueries("directorates");case 2:return r=y.E.getQueryData("directorates"),y.E.setQueryData("directorates",[].concat((0,j.Z)(r||[]),[t.data])),e.abrupt("return",{previousDirectorates:r});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onError:function(e,t,r){null!==r&&void 0!==r&&r.previousDirectorates&&y.E.setQueryData("directorates",r.previousDirectorates)},onSuccess:function(){y.E.invalidateQueries("directorates"),t({type:"success",title:"Directorate has been added"})}},e),{},{mutationFn:O}))}();return e.isLoading?(0,N.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,N.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,N.jsx)(n.$j,{size:"sm"})})}):(0,N.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,N.jsx)(g._8,{size:"sm",isDone:e.isSuccess,triggerButton:(0,N.jsx)(n.zx,{variant:"create",size:"sm",startIcon:(0,N.jsx)(h.Z,{className:"h-4 w-4"}),children:"Create Directorate"}),title:"Create Directorate",submitButton:(0,N.jsx)(n.zx,{form:"create-directorate",type:"submit",size:"sm",isLoading:e.isLoading,children:"Submit"}),children:(0,N.jsx)(g.l0,{id:"create-directorate",onSubmit:function(){var t=(0,p.Z)((0,x.Z)().mark((function t(r){return(0,x.Z)().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.mutateAsync({data:r});case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),schema:P,children:function(e){var t=e.register,r=e.formState,a=e.watch,n=e.setValue;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(g.UP,{label:"Title",error:r.errors.title,registration:t("title")}),(0,N.jsx)(g.N7,{label:"Description",error:r.errors.desc,editorContent:a("desc"),setValue:n,value:"desc"})]})}})})})},X=function(){return l.o.get("/directorates")},J=function(e){var t=e.directorateId;return l.o.delete("/directorates/".concat(t))};J.propTypes={directorateId:D().string.isRequired};var Y=function(e){var t=e.id,r=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,f.useMutation)((0,d.Z)((0,d.Z)({onMutate:function(){var e=(0,p.Z)((0,x.Z)().mark((function e(t){var r;return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.E.cancelQueries("directorates");case 2:return r=y.E.getQueryData("directorates"),y.E.setQueryData("directorates",null===r||void 0===r?void 0:r.filter((function(e){return e.id!==t.directorateId}))),e.abrupt("return",{previousDirectorates:r});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onError:function(e,t,r){null!==r&&void 0!==r&&r.previousDirectorates&&y.E.setQueryData("directorates",r.previousDirectorates)},onSuccess:function(){y.E.invalidateQueries("directorates"),t({type:"success",title:"Directorate Deleted"})}},e),{},{mutationFn:J}))}();return r.isLoading?(0,N.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,N.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,N.jsx)(n.$j,{size:"sm"})})}):(0,N.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,N.jsx)(n.U6,{icon:"danger",title:"Delete Directorate",body:"Are you sure you want to delete this directorate?",triggerButton:(0,N.jsx)("button",{children:"Remove"}),confirmButton:(0,N.jsx)(n.zx,{isLoading:r.isLoading,type:"button",className:"bg-red-600",onClick:(0,p.Z)((0,x.Z)().mark((function e(){return(0,x.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.mutateAsync({directorateId:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),children:"Delete Directorate"})})})},ee=function(){var e=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config;return(0,f.useQuery)((0,d.Z)((0,d.Z)({},e),{},{queryKey:["directorates"],queryFn:function(){return X()}}))}();return e.isLoading?(0,N.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:(0,N.jsx)(n.$j,{size:"lg"})}):e.data?(0,N.jsx)(n.iA,{data:e.data,columns:[{title:"Directorates",field:"title",Cell:function(e){var t=e.entry.title;return(0,N.jsx)("span",{className:"uppercase",children:t})}},{title:"",field:"id",Cell:function(e){var t=e.entry._id;return(0,N.jsxs)(N.Fragment,{children:[" ",(0,N.jsx)(n.rU,{to:"./".concat(t),className:"mr-2 text-black dark:text-gray-200 hover:text-green-400",children:"View"})," ",(0,N.jsx)(Y,{id:t})]})}}]}):null},te=function(){return(0,N.jsxs)(s.D,{title:"Directorates",button:(0,N.jsx)(W,{}),children:[(0,N.jsx)(o.Z,{routes:[{name:"Directorates",path:"."}]}),(0,N.jsx)("div",{className:"mt-4",children:(0,N.jsx)(ee,{})})]})},re=function(){return(0,N.jsxs)(a.Z5,{children:[(0,N.jsx)(a.AW,{path:"",element:(0,N.jsx)(te,{})}),(0,N.jsx)(a.AW,{path:":directorateId",element:(0,N.jsx)(H,{})}),(0,N.jsx)(a.AW,{path:"*",element:(0,N.jsx)(a.Fg,{to:"."})})]})}},2076:function(e,t,r){var a=r(2791);var n=a.forwardRef((function(e,t){return a.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor","aria-hidden":"true",ref:t},e),a.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 4v16m8-8H4"}))}));t.Z=n},8419:function(e,t,r){var a=r(2791);var n=a.forwardRef((function(e,t){return a.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",ref:t},e),a.createElement("path",{d:"M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"}))}));t.Z=n}}]);
//# sourceMappingURL=88.7b6d52b1.chunk.js.map