Current Path : /home/ncdcgo/admin.ncdc.go.ug/static/js/ |
Current File : /home/ncdcgo/admin.ncdc.go.ug/static/js/109.ec1dd1ed.chunk.js |
"use strict";(self.webpackChunkpanel=self.webpackChunkpanel||[]).push([[109],{223:function(e,t,r){r(2791);var n=r(3504),a=r(2506),o=r(184);t.Z=function(e){var t=e.routes;return(0,o.jsx)("nav",{className:"flex bg-white border border-gray-200 p-2 rounded-full px-4 mt-4","aria-label":"Breadcrumb",children:(0,o.jsxs)("ol",{className:"inline-flex items-center space-x-1 md:space-x-3",children:[(0,o.jsx)("li",{className:"inline-flex items-center text-gray-800",children:(0,o.jsxs)(n.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,o.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,o.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,o.jsxs)("li",{className:"inline-flex items-center",children:[(0,o.jsx)(a.Z,{size:10,className:"mr-4"}),(0,o.jsx)(n.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)}))]})})}},5109:function(e,t,r){r.r(t),r.d(t,{GalleryRoutes:function(){return $}});var n=r(6871),a=r(9630),o=r(5528),i=r(2412),s=r(77),c=r(8592),l=r(1413),u=r(6771),d=r(1933),p=function(e){var t=e.photoId,r=e.config;return(0,d.useQuery)((0,l.Z)((0,l.Z)({},r),{},{queryKey:["photo",t],queryFn:function(){return function(e){var t=e.photoId;return u.o.get("/gallery/".concat(t))}({photoId:t})}}))},h=r(4165),x=r(5861),f=r(885),m=r(806),v=r(4430),g=r(8419),j=r(2791),y=r(9879),w=r(3777),b=r(7889),Z=r(2007),N=r.n(Z),k=function(e){var t=e.data,r=e.photoId;return u.o.patch("/gallery/".concat(r),t)};k.propTypes={data:N().shape({caption:N().string,image:N().string}).isRequired,photoId:N().string.isRequired};var I=r(184),E=y.Ry({caption:y.Z_()}),P=function(e){var t,r,n=e.photoId,o=(0,j.useState)(null),i=(0,f.Z)(o,2),s=i[0],c=i[1],u=(0,j.useState)(null),y=(0,f.Z)(u,2),Z=y[0],N=y[1],P=p({photoId:n}),z=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,d.useMutation)((0,l.Z)((0,l.Z)({onMutate:function(){var e=(0,x.Z)((0,h.Z)().mark((function e(t){var r;return(0,h.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.E.cancelQueries(["photo",null===t||void 0===t?void 0:t.photoId]);case 2:return r=w.E.getQueryData[null===t||void 0===t?void 0:t.photoId],w.E.setQueryData(["photo",null===t||void 0===t?void 0:t.photoId],(0,l.Z)((0,l.Z)((0,l.Z)({},r),t.data),{},{id:t.photoId})),e.abrupt("return",{previousPhotot: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.previousPhotot&&w.E.setQueryData(["photo",r.previousPhotot.id],r.previousPhotot)},onSuccess:function(e){w.E.refetchQueries(["photo",e.id]),t({type:"success",title:"Photo Updated"})}},e),{},{mutationFn:k}))}();return z.isLoading?(0,I.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,I.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,I.jsx)(a.$j,{size:"sm"})})}):(0,I.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,I.jsx)(m._8,{size:"sm",isDone:z.isSuccess,triggerButton:(0,I.jsx)(a.zx,{variant:"create",startIcon:(0,I.jsx)(g.Z,{className:"h-4 w-4"}),size:"sm",children:"Edit"}),title:"Update Photo",submitButton:(0,I.jsx)(a.zx,{form:"update-photo",type:"submit",size:"sm",isLoading:z.isLoading,children:"Submit"}),children:(0,I.jsx)(m.l0,{id:"update-photo",encType:"multipart/form-data",onSubmit:function(){var e=(0,x.Z)((0,h.Z)().mark((function e(t){var r,a;return(0,h.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.caption,(a=new FormData).append("caption",r),a.append("image",s||P.data.caption),e.next=6,z.mutateAsync({data:a,photoId:n});case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),options:{defaultValues:{caption:null===(t=P.data)||void 0===t?void 0:t.caption,image:null===(r=P.data)||void 0===r?void 0:r.image}},schema:E,children:function(e){var t=e.register,r=e.formState;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(m.UP,{label:"Caption",error:r.errors.caption,registration:t("caption")}),(0,I.jsx)(m.VA,{title:"Update Photo Image",subTitle:"Upload clear image for better visibility",error:r.errors.image,x:1280,y:340,onChange:function(e){c(e.target.files[0]),N(URL.createObjectURL(e.target.files[0]))},preview:Z})]})}})})})},z=r(803),L=function(e){var t=e.photoId;return u.o.delete("/gallery/".concat(t))};L.propTypes={photoId:N().string.isRequired};var D=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,d.useMutation)((0,l.Z)((0,l.Z)({onMutate:function(){var e=(0,x.Z)((0,h.Z)().mark((function e(t){var r;return(0,h.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.E.cancelQueries("photos");case 2:return r=w.E.getQueryData("photos"),w.E.setQueryData("photos",null===r||void 0===r?void 0:r.filter((function(e){return e.id!==t.photoId}))),e.abrupt("return",{previousPhotos: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.previousPhotos&&w.E.setQueryData("photos",r.previousPhotos)},onSuccess:function(){w.E.invalidateQueries("photos"),t({type:"success",title:"Photo Deleted"})}},e),{},{mutationFn:L}))}();return r.isLoading?(0,I.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,I.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,I.jsx)(a.$j,{size:"sm"})})}):(0,I.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,I.jsx)(a.U6,{icon:"danger",title:"Delete Photo",body:"Are you sure you want to delete this Photo?",triggerButton:(0,I.jsx)("button",{className:"text-gray-800",children:(0,I.jsx)(z.Z,{className:"h-4 w-4"})}),confirmButton:(0,I.jsx)(a.zx,{isLoading:r.isLoading,type:"button",className:"bg-red-600",onClick:(0,x.Z)((0,h.Z)().mark((function e(){return(0,h.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.mutateAsync({photoId:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)}))),children:"Delete Photo"})})})},R=r(223),A=function(){var e,t=(0,n.UO)().photoId,r=p({photoId:t});if(r.isLoading)return(0,I.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:(0,I.jsx)(a.$j,{size:"lg"})});var l=[{name:"Photos",path:"/app/gallery"},{name:null===(e=r.data)||void 0===e?void 0:e.caption,path:""}];return r.data?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(o.F,{title:r.data._id}),(0,I.jsxs)(i.D,{title:r.data.caption,button:(0,I.jsxs)("div",{className:"flex flex-row space-x-2",children:[(0,I.jsx)(P,{photoId:t}),(0,I.jsx)(D,{photoId:t})]}),children:[(0,I.jsxs)("span",{className:"text-xs font-bold text-gray-500",children:["Photo added on ",(0,c.p)(r.data.createdAt)]}),(0,I.jsx)(R.Z,{routes:l}),(0,I.jsx)("div",{className:"mx-auto my-4",children:(0,I.jsx)("img",{src:"".concat(s.tC,"/").concat(r.data.image),alt:r.data.caption,className:"w-full h-80 object-cover"})}),(0,I.jsx)("div",{className:"mt-6 flex flex-col p-4 bg-white dark:bg-gray-700 space-y-16",children:(0,I.jsx)("div",{className:"flex flex-row space-x-4",children:(0,I.jsxs)("div",{className:"w-1/2",children:[(0,I.jsx)("div",{className:"text-sm font-bold text-gray-400",children:"Caption"}),(0,I.jsx)("div",{className:"text-sm text-gray-500",children:r.data.caption})]})})})]})]}):null},Q=r(2076),U=r(2982),S=function(e){var t=e.data;return u.o.post("/gallery",t)};S.propTypes={data:N().shape({caption:N().string.isRequired,image:N().string.isRequired}).isRequired};var M=y.Ry({caption:y.Z_()}),C=function(){var e=(0,j.useState)(null),t=(0,f.Z)(e,2),r=t[0],n=t[1],o=(0,j.useState)(null),i=(0,f.Z)(o,2),s=i[0],c=i[1],u=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,t=(0,b.G)().addNotification;return(0,d.useMutation)((0,l.Z)((0,l.Z)({onMutate:function(){var e=(0,x.Z)((0,h.Z)().mark((function e(t){var r;return(0,h.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.E.cancelQueries("photos");case 2:return r=w.E.getQueryData("photos"),w.E.setQueryData("photos",[].concat((0,U.Z)(r||[]),[t.data])),e.abrupt("return",{previousPhotos: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.previousPhotos&&w.E.setQueryData("photos",r.previousPhotos)},onSuccess:function(){w.E.invalidateQueries("photos"),t({type:"success",title:"Photo Added Successfully"})}},e),{},{mutationFn:S}))}();return u.isLoading?(0,I.jsx)("div",{id:"loading-screen",className:"w-full h-full fixed block top-0 left-0 bg-black opacity-75 z-50",children:(0,I.jsx)("span",{className:"opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0",children:(0,I.jsx)(a.$j,{size:"sm"})})}):(0,I.jsx)(v._n,{allowedRoles:[v.K$.ADMIN],children:(0,I.jsx)(m._8,{size:"sm",isDone:u.isSuccess,triggerButton:(0,I.jsx)(a.zx,{variant:"create",size:"sm",startIcon:(0,I.jsx)(Q.Z,{className:"h-4 w-4"}),children:"Add Photo"}),title:"Add Photo",submitButton:(0,I.jsx)(a.zx,{form:"add-photo",type:"submit",size:"sm",isLoading:u.isLoading,children:"Submit"}),children:(0,I.jsx)(m.l0,{id:"add-photo",encType:"multipart/form-data",onSubmit:function(){var e=(0,x.Z)((0,h.Z)().mark((function e(t){var n,a;return(0,h.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.caption,(a=new FormData).append("caption",n),a.append("image",r),e.next=6,u.mutateAsync({data:a});case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),schema:M,children:function(e){var t=e.register,r=e.formState;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(m.UP,{label:"Caption",error:r.errors.caption,registration:t("caption")}),(0,I.jsx)(m.VA,{title:"Upload New Photo to Gallery",subTitle:"Upload clear image for better visibility",error:r.errors.image,x:1280,y:340,onChange:function(e){n(e.target.files[0]),c(URL.createObjectURL(e.target.files[0]))},preview:s})]})}})})})},F=r(7087),B=function(){return u.o.get("/gallery")},q=function(){var e=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config;return(0,d.useQuery)((0,l.Z)((0,l.Z)({},e),{},{queryKey:["photos"],queryFn:function(){return B()}}))}();return e.isLoading?(0,I.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:(0,I.jsx)(a.$j,{size:"lg"})}):e.data&&0!==e.data.length?(0,I.jsx)(I.Fragment,{children:(0,I.jsx)("div",{className:"",children:(0,I.jsx)("section",{class:"overflow-hidden text-gray-700 ",children:(0,I.jsx)("div",{class:"container mx-auto",children:(0,I.jsx)("div",{class:"flex flex-wrap -m-1 md:-m-2",children:e.data.map((function(e){return(0,I.jsx)("div",{class:"flex flex-wrap w-1/5",children:(0,I.jsx)(a.rU,{to:"./".concat(e._id),class:"w-full p-1 md:p-2",children:(0,I.jsx)(F.LazyLoadImage,{src:s.tC+"/"+e.image,alt:e.caption,className:"block object-cover object-center w-full h-full rounded-lg"})})},e._id)}))})})})})}):(0,I.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:(0,I.jsx)("div",{className:"text-center text-gray-500",children:"No photos in gallery."})})},_=function(){return(0,I.jsxs)(i.D,{title:"Gallery",button:(0,I.jsx)(C,{}),children:[(0,I.jsx)(R.Z,{routes:[{name:"Gallery",path:"."}]}),(0,I.jsx)("div",{className:"mt-4",children:(0,I.jsx)(q,{})})]})},$=function(){return(0,I.jsxs)(n.Z5,{children:[(0,I.jsx)(n.AW,{path:"",element:(0,I.jsx)(_,{})}),(0,I.jsx)(n.AW,{path:":photoId",element:(0,I.jsx)(A,{})}),(0,I.jsx)(n.AW,{path:"*",element:(0,I.jsx)(n.Fg,{to:"."})})]})}},2076:function(e,t,r){var n=r(2791);var a=n.forwardRef((function(e,t){return n.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),n.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 4v16m8-8H4"}))}));t.Z=a},803:function(e,t,r){var n=r(2791);var a=n.forwardRef((function(e,t){return n.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),n.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"}))}));t.Z=a},8419:function(e,t,r){var n=r(2791);var a=n.forwardRef((function(e,t){return n.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",ref:t},e),n.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=a}}]); //# sourceMappingURL=109.ec1dd1ed.chunk.js.map