Current Path : /home/ncdcgo/admin.ncdc.go.ug/static/js/ |
Current File : /home/ncdcgo/admin.ncdc.go.ug/static/js/6.4b2e7bef.chunk.js |
(this["webpackJsonpncdc-admin"]=this["webpackJsonpncdc-admin"]||[]).push([[6],{731:function(t,e,n){"use strict";n.d(e,"a",(function(){return c}));var r=n(732),s=n.n(r),a=n(6),i=n.n(a),c=function(t){return s()(t).format("MMMM D, YYYY h:mm A")};c.propTypes={date:i.a.string.isRequired}},732:function(t,e,n){t.exports=function(){"use strict";var t=1e3,e=6e4,n=36e5,r="millisecond",s="second",a="minute",i="hour",c="day",o="week",u="month",d="quarter",l="year",f="date",p="Invalid Date",j=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,h=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},b=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:b,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),s=n%60;return(e<=0?"+":"-")+b(r,2,"0")+":"+b(s,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),s=e.clone().add(r,u),a=n-s<0,i=e.clone().add(r+(a?-1:1),u);return+(-(r+(n-s)/(a?s-i:i-s))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:u,y:l,w:o,d:c,D:f,h:i,m:a,s:s,ms:r,Q:d}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},O="en",x={};x[O]=m;var g=function(t){return t instanceof D},y=function(t,e,n){var r;if(!t)return O;if("string"==typeof t)x[t]&&(r=t),e&&(x[t]=e,r=t);else{var s=t.name;x[s]=t,r=s}return!n&&r&&(O=r),r||!n&&O},w=function(t,e){if(g(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new D(n)},$=v;$.l=y,$.i=g,$.w=function(t,e){return w(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var D=function(){function m(t){this.$L=y(t.locale,null,!0),this.parse(t)}var b=m.prototype;return b.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if($.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(j);if(r){var s=r[2]-1||0,a=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],s,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)):new Date(r[1],s,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},b.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},b.$utils=function(){return $},b.isValid=function(){return!(this.$d.toString()===p)},b.isSame=function(t,e){var n=w(t);return this.startOf(e)<=n&&n<=this.endOf(e)},b.isAfter=function(t,e){return w(t)<this.startOf(e)},b.isBefore=function(t,e){return this.endOf(e)<w(t)},b.$g=function(t,e,n){return $.u(t)?this[e]:this.set(n,t)},b.unix=function(){return Math.floor(this.valueOf()/1e3)},b.valueOf=function(){return this.$d.getTime()},b.startOf=function(t,e){var n=this,r=!!$.u(e)||e,d=$.p(t),p=function(t,e){var s=$.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?s:s.endOf(c)},j=function(t,e){return $.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},h=this.$W,m=this.$M,b=this.$D,v="set"+(this.$u?"UTC":"");switch(d){case l:return r?p(1,0):p(31,11);case u:return r?p(1,m):p(0,m+1);case o:var O=this.$locale().weekStart||0,x=(h<O?h+7:h)-O;return p(r?b-x:b+(6-x),m);case c:case f:return j(v+"Hours",0);case i:return j(v+"Minutes",1);case a:return j(v+"Seconds",2);case s:return j(v+"Milliseconds",3);default:return this.clone()}},b.endOf=function(t){return this.startOf(t,!1)},b.$set=function(t,e){var n,o=$.p(t),d="set"+(this.$u?"UTC":""),p=(n={},n[c]=d+"Date",n[f]=d+"Date",n[u]=d+"Month",n[l]=d+"FullYear",n[i]=d+"Hours",n[a]=d+"Minutes",n[s]=d+"Seconds",n[r]=d+"Milliseconds",n)[o],j=o===c?this.$D+(e-this.$W):e;if(o===u||o===l){var h=this.clone().set(f,1);h.$d[p](j),h.init(),this.$d=h.set(f,Math.min(this.$D,h.daysInMonth())).$d}else p&&this.$d[p](j);return this.init(),this},b.set=function(t,e){return this.clone().$set(t,e)},b.get=function(t){return this[$.p(t)]()},b.add=function(r,d){var f,p=this;r=Number(r);var j=$.p(d),h=function(t){var e=w(p);return $.w(e.date(e.date()+Math.round(t*r)),p)};if(j===u)return this.set(u,this.$M+r);if(j===l)return this.set(l,this.$y+r);if(j===c)return h(1);if(j===o)return h(7);var m=(f={},f[a]=e,f[i]=n,f[s]=t,f)[j]||1,b=this.$d.getTime()+r*m;return $.w(b,this)},b.subtract=function(t,e){return this.add(-1*t,e)},b.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||p;var r=t||"YYYY-MM-DDTHH:mm:ssZ",s=$.z(this),a=this.$H,i=this.$m,c=this.$M,o=n.weekdays,u=n.months,d=function(t,n,s,a){return t&&(t[n]||t(e,r))||s[n].substr(0,a)},l=function(t){return $.s(a%12||12,t,"0")},f=n.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},j={YY:String(this.$y).slice(-2),YYYY:this.$y,M:c+1,MM:$.s(c+1,2,"0"),MMM:d(n.monthsShort,c,u,3),MMMM:d(u,c),D:this.$D,DD:$.s(this.$D,2,"0"),d:String(this.$W),dd:d(n.weekdaysMin,this.$W,o,2),ddd:d(n.weekdaysShort,this.$W,o,3),dddd:o[this.$W],H:String(a),HH:$.s(a,2,"0"),h:l(1),hh:l(2),a:f(a,i,!0),A:f(a,i,!1),m:String(i),mm:$.s(i,2,"0"),s:String(this.$s),ss:$.s(this.$s,2,"0"),SSS:$.s(this.$ms,3,"0"),Z:s};return r.replace(h,(function(t,e){return e||j[t]||s.replace(":","")}))},b.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},b.diff=function(r,f,p){var j,h=$.p(f),m=w(r),b=(m.utcOffset()-this.utcOffset())*e,v=this-m,O=$.m(this,m);return O=(j={},j[l]=O/12,j[u]=O,j[d]=O/3,j[o]=(v-b)/6048e5,j[c]=(v-b)/864e5,j[i]=v/n,j[a]=v/e,j[s]=v/t,j)[h]||v,p?O:$.a(O)},b.daysInMonth=function(){return this.endOf(u).$D},b.$locale=function(){return x[this.$L]},b.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=y(t,e,!0);return r&&(n.$L=r),n},b.clone=function(){return $.w(this.$d,this)},b.toDate=function(){return new Date(this.valueOf())},b.toJSON=function(){return this.isValid()?this.toISOString():null},b.toISOString=function(){return this.$d.toISOString()},b.toString=function(){return this.$d.toUTCString()},m}(),I=D.prototype;return w.prototype=I,[["$ms",r],["$s",s],["$m",a],["$H",i],["$W",c],["$M",u],["$y",l],["$D",f]].forEach((function(t){I[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),w.extend=function(t,e){return t.$i||(t(e,D,w),t.$i=!0),w},w.locale=y,w.isDayjs=g,w.unix=function(t){return w(1e3*t)},w.en=x[O],w.Ls=x,w.p={},w}()},735:function(t,e,n){"use strict";n.r(e),n.d(e,"PostsRoutes",(function(){return G}));var r=n(15),s=n(29),a=n(61),i=n(96),c=n(172),o=n(33),u=n(48),d=n(731),l=n(21),f=n(18),p=n(47),j=n(6),h=n.n(j),m=n(721),b=function(t){var e=t.postId;return p.a.get("/posts/".concat(e,"/comments"))};b.propTypes={postId:h.a.string.isRequired};var v=n(13),O=n.n(v),x=n(23),g=n(171),y=n(95),w=n(170),$=function(t){var e=t.postId,n=t.id;return p.a.delete("/posts/".concat(e,"/comments/").concat(n))};$.propTypes={postId:h.a.string.isRequired,id:h.a.string.isRequired};var D=n(2),I=function(t){var e=t.postId,n=t.id,r=function(t){var e=t.config,n=t.postId,r=Object(y.a)().addNotification;return Object(w.a)(Object(f.a)(Object(f.a)({onMutate:function(){var t=Object(x.a)(O.a.mark((function t(e){var r;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,g.a.cancelQueries(["comments",n]);case 2:return r=g.a.getQueryData(["comments",n]),g.a.setQueryData(["comments",n],null===r||void 0===r?void 0:r.filter((function(t){return t.id!==e.commentId}))),t.abrupt("return",{previousComments:r});case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),onError:function(t,e,r){(null===r||void 0===r?void 0:r.previousComments)&&g.a.setQueryData(["comments",n],r.previousComments)},onSuccess:function(){g.a.invalidateQueries(["comments",n]),r({type:"success",title:"Comment Deleted"})}},e),{},{mutationFn:$}))}({postId:e});return Object(D.jsx)(s.b,{isDone:r.isSuccess,icon:"danger",title:"Delete Comment",body:"Are you sure you want to delete this comment?",triggerButton:Object(D.jsx)(s.a,{variant:"danger",children:Object(D.jsx)(l.j,{className:"h-4 w-4"})}),confirmButton:Object(D.jsx)(s.a,{isLoading:r.isLoading,type:"button",className:"bg-red-600",onClick:Object(x.a)(O.a.mark((function t(){return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.mutateAsync({postId:e,id:n});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),children:"Delete Comment"})})},M=function(t){var e,n=t.postId,r=Object(o.b)().user,a=function(t){var e=t.postId,n=t.config;return Object(m.a)(Object(f.a)(Object(f.a)({},n),{},{queryKey:["comments",e],queryFn:function(){return b({postId:e})}}))}({postId:n});return a.isLoading?Object(D.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:Object(D.jsx)(s.e,{size:"lg"})}):(null===a||void 0===a||null===(e=a.data)||void 0===e?void 0:e.length)?Object(D.jsx)("ul",{"aria-label":"comments",className:"flex flex-col space-y-3",children:a.data.map((function(t,e){return Object(D.jsxs)("li",{"aria-label":"comment-".concat(t.text,"-").concat(e),className:"w-full bg-white shadow-sm p-4",children:[Object(D.jsx)(u.a,{policyCheck:u.b["comment:delete"](r,t),children:Object(D.jsxs)("div",{className:"flex justify-between",children:[Object(D.jsx)("span",{className:"text-xs font-semibold",children:Object(d.a)(t.createdAt)}),Object(D.jsx)(I,{postId:n,id:t._id})]})}),Object(D.jsx)(s.d,{value:t.text})]},t._id||e)}))}):Object(D.jsxs)("div",{role:"list","aria-label":"comments",className:"bg-white text-gray-500 h-40 flex justify-center items-center flex-col",children:[Object(D.jsx)(l.a,{className:"h-10 w-10"}),Object(D.jsx)("h4",{children:"No Comments Found"})]})},S=n(98),C=n(97),N=n(22),T=function(t){var e=t.postId,n=t.data;return p.a.post("/posts/".concat(e,"/comments"),n)};T.propTypes={data:h.a.shape({text:h.a.string.isRequired}).isRequired,postId:h.a.string.isRequired};var R=C.a({text:C.b().min(1,"Required")}),q=function(t){var e=t.postId,n=function(t){var e=t.config,n=t.postId,r=Object(y.a)().addNotification;return Object(w.a)(Object(f.a)(Object(f.a)({onMutate:function(){var t=Object(x.a)(O.a.mark((function t(e){var r;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,g.a.cancelQueries(["comments",n]);case 2:return r=g.a.getQueryData(["comments",n]),g.a.setQueryData(["comments",n],[].concat(Object(N.a)(r||[]),[e.data])),t.abrupt("return",{previousComments:r});case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),onError:function(t,e,r){(null===r||void 0===r?void 0:r.previousComments)&&g.a.setQueryData(["comments",n],r.previousComments)},onSuccess:function(){g.a.invalidateQueries(["comments",n]),r({type:"success",title:"Comment Created"})}},e),{},{mutationFn:T}))}({postId:e});return Object(D.jsx)(D.Fragment,{children:Object(D.jsx)(S.c,{size:"sm",isDone:n.isSuccess,triggerButton:Object(D.jsx)(s.a,{size:"sm",startIcon:Object(D.jsx)(l.i,{className:"h-4 w-4"}),children:"Create Comment"}),title:"Create Comment",submitButton:Object(D.jsx)(s.a,{isLoading:n.isLoading,form:"create-comment",type:"submit",size:"sm",disabled:n.isLoading,children:"Submit"}),children:Object(D.jsx)(S.b,{id:"create-comment",onSubmit:function(){var t=Object(x.a)(O.a.mark((function t(r){return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.mutateAsync({data:{text:r.text},postId:e});case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),schema:R,children:function(t){var e=t.formState,n=t.watch,r=t.setValue;return Object(D.jsx)(S.f,{label:"Body",error:e.errors.text,editorContent:n("text"),setValue:r,value:"text"})}})})})},L=function(t){var e=t.postId;return Object(D.jsxs)("div",{children:[Object(D.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[Object(D.jsx)("h3",{className:"text-1xl font-bold",children:"Comments:"}),Object(D.jsx)(q,{postId:e})]}),Object(D.jsx)(M,{postId:e})]})},Q=function(){var t=Object(x.a)(O.a.mark((function t(e){var n;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.postId,t.next=3,p.a.get("/posts/".concat(n));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),P=function(t){var e=t.postId,n=t.config;return Object(m.a)(Object(f.a)(Object(f.a)({},n),{},{queryKey:["post",e],queryFn:function(){return Q({postId:e})}}))},_=n(28),k=n(99),A=n(0),F=function(t){var e=t.data,n=t.postId;return p.a.patch("/posts/".concat(n),e,{headers:{"Content-Type":"multipart/form-data"}})};F.propTypes={data:h.a.shape({title:h.a.string.isRequired,desc:h.a.string.isRequired,category:h.a.string.isRequired}).isRequired,postId:h.a.string.isRequired};var Y=C.a({title:C.b().min(1,"Required"),desc:C.b().min(1,"Required")}),z=function(t){var e,n,r,a=t.postId,i=Object(A.useState)(null),c=Object(_.a)(i,2),o=c[0],d=c[1],l=Object(A.useState)(null),p=Object(_.a)(l,2),j=p[0],h=p[1],m=P({postId:a}),b=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,e=Object(y.a)().addNotification;return Object(w.a)(Object(f.a)(Object(f.a)({onMutate:function(){var t=Object(x.a)(O.a.mark((function t(e){var n;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,g.a.cancelQueries(["post",null===e||void 0===e?void 0:e.postId]);case 2:return n=g.a.getQueryData[null===e||void 0===e?void 0:e.postId],g.a.setQueryData(["post",null===e||void 0===e?void 0:e.postId],Object(f.a)(Object(f.a)(Object(f.a)({},n),e.data),{},{id:e.postId})),t.abrupt("return",{previousPost:n});case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),onError:function(t,e,n){(null===n||void 0===n?void 0:n.previousPost)&&g.a.setQueryData(["post",n.previousPost.id],n.previousPost)},onSuccess:function(t){g.a.refetchQueries(["post",t.id]),e({type:"success",title:"Post Updated"})}},t),{},{mutationFn:F}))}();return Object(D.jsx)(u.a,{allowedRoles:[u.c.ADMIN],children:Object(D.jsx)(S.c,{size:"sm",isDone:b.isSuccess,triggerButton:Object(D.jsx)(s.a,{startIcon:Object(D.jsx)(k.a,{className:"h-4 w-4"}),size:"sm",children:"Update Post"}),title:"Update Post",submitButton:Object(D.jsx)(s.a,{form:"update-post",type:"submit",size:"sm",isLoading:b.isLoading,children:"Submit"}),children:Object(D.jsx)(S.b,{id:"update-post",encType:"multipart/form-data",onSubmit:function(){var t=Object(x.a)(O.a.mark((function t(e){var n,r,s,i,c;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.title,r=e.desc,s=e.category,i=void 0===s?"News":s,(c=new FormData).append("image",o),c.append("title",n),c.append("desc",r),c.append("category",i),t.next=8,b.mutateAsync({data:c,postId:a});case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),options:{defaultValues:{title:null===(e=m.data)||void 0===e?void 0:e.title,desc:null===(n=m.data)||void 0===n?void 0:n.desc,category:null===(r=m.data)||void 0===r?void 0:r.category}},schema:Y,children:function(t){var e=t.register,n=t.formState,r=t.watch,s=t.setValue;return Object(D.jsxs)(D.Fragment,{children:[Object(D.jsx)(S.d,{label:"Title",error:n.errors.title,registration:e("title")}),Object(D.jsx)(S.f,{label:"Content",error:n.errors.desc,editorContent:r("desc"),setValue:s,value:"desc"}),Object(D.jsx)(S.d,{label:"Category",disabled:!0,error:n.errors.category,registration:e("category")}),Object(D.jsx)("span",{className:"text-gray-500 text-sm",children:"Default category is set to news and can not be updated."}),Object(D.jsx)(S.g,{title:"Update Cover Photo",subTitle:"This will also be used as the thumbnail in feeds",error:n.errors.image,x:1024,y:768,onChange:function(t){d(t.target.files[0]),h(URL.createObjectURL(t.target.files[0]))},preview:j})]})}})})})},U=function(){var t=Object(r.j)().postId,e=P({postId:t});return e.isLoading?Object(D.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:Object(D.jsx)(s.e,{size:"lg"})}):e.data?Object(D.jsxs)(D.Fragment,{children:[Object(D.jsx)(a.a,{title:e.data.title}),Object(D.jsxs)(i.a,{title:e.data.title,button:Object(D.jsx)(z,{postId:t}),children:[Object(D.jsx)("span",{className:"text-xs font-bold",children:Object(d.a)(e.data.createdAt)}),Object(D.jsxs)("div",{className:"mt-6 flex flex-col space-y-16",children:[Object(D.jsx)("div",{children:Object(D.jsxs)("div",{className:"bg-white shadow overflow-hidden sm:rounded-lg",children:[Object(D.jsx)("div",{children:Object(D.jsx)("img",{src:"".concat(c.b,"/posts/resized/").concat(e.data.image),alt:"background for post",className:"h-48 object-cover hover:opacity-75 transition-opacity duration-200"})}),Object(D.jsx)("div",{className:"px-4 py-5 sm:px-6",children:Object(D.jsx)("div",{className:"mt-1 max-w-2xl text-sm text-gray-500",children:Object(D.jsx)(s.d,{value:e.data.desc})})})]})}),Object(D.jsx)("div",{children:Object(D.jsx)(L,{postId:t})})]})]})]}):null},B=function(t){var e=t.data;return p.a.post("/posts",e,{headers:{"Content-Type":"multipart/form-data"}})};B.propTypes={data:h.a.shape({title:h.a.string.isRequired,category:h.a.string.isRequired}).isRequired};var H=C.a({title:C.b().min(1,"Required"),desc:C.b()}),V=function(){var t=Object(A.useState)(null),e=Object(_.a)(t,2),n=e[0],r=e[1],a=Object(A.useState)(null),i=Object(_.a)(a,2),c=i[0],o=i[1],d=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,e=Object(y.a)().addNotification;return Object(w.a)(Object(f.a)(Object(f.a)({onMutate:function(){var t=Object(x.a)(O.a.mark((function t(e){var n;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,g.a.cancelQueries("posts");case 2:return n=g.a.getQueryData("posts"),g.a.setQueryData("posts",[].concat(Object(N.a)(n||[]),[e.data])),t.abrupt("return",{previousPosts:n});case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),onError:function(t,e,n){(null===n||void 0===n?void 0:n.previousPosts)&&g.a.setQueryData("posts",n.previousPosts)},onSuccess:function(){g.a.invalidateQueries("posts"),e({type:"success",title:"Post Created"})}},t),{},{mutationFn:B}))}();return Object(D.jsx)(u.a,{allowedRoles:[u.c.ADMIN],children:Object(D.jsx)(S.c,{size:"sm",isDone:d.isSuccess,triggerButton:Object(D.jsx)(s.a,{size:"sm",startIcon:Object(D.jsx)(l.i,{className:"h-4 w-4"}),children:"Create Post"}),title:"Create Post",submitButton:Object(D.jsx)(s.a,{form:"create-post",type:"submit",size:"sm",isLoading:d.isLoading,children:"Submit"}),children:Object(D.jsx)(S.b,{id:"create-post",encType:"multipart/form-data",onSubmit:function(){var t=Object(x.a)(O.a.mark((function t(e){var r,s,a,i,c;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.title,s=e.desc,a=e.category,i=void 0===a?"News":a,(c=new FormData).append("image",n),c.append("title",r),c.append("desc",s),c.append("category",i),t.next=8,d.mutateAsync({data:c});case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),schema:H,children:function(t){var e=t.register,n=t.formState,s=t.watch,a=t.setValue;return Object(D.jsxs)(D.Fragment,{children:[Object(D.jsx)(S.d,{label:"Title",error:n.errors.title,registration:e("title")}),Object(D.jsx)(S.f,{label:"Content",error:n.errors.desc,editorContent:s("desc"),setValue:a,value:"desc"}),Object(D.jsx)(S.d,{label:"Category",value:"News",disabled:!0,error:n.errors.category,registration:e("category")}),Object(D.jsx)("span",{className:"text-gray-500 text-sm",children:"Default category is set to news."}),Object(D.jsx)(S.g,{title:"Upload a Cover Photo",subTitle:"This will also be used as the thumbnail in feeds",error:n.errors.image,x:1024,y:768,onChange:function(t){r(t.target.files[0]),o(URL.createObjectURL(t.target.files[0]))},preview:c})]})}})})})},W=function(){return p.a.get("/posts")},E=function(t){var e=t.postId;return p.a.delete("/posts/".concat(e))};E.propTypes={postId:h.a.string.isRequired};var J=function(t){var e=t.id,n=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,e=Object(y.a)().addNotification;return Object(w.a)(Object(f.a)(Object(f.a)({onMutate:function(){var t=Object(x.a)(O.a.mark((function t(e){var n;return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,g.a.cancelQueries("posts");case 2:return n=g.a.getQueryData("posts"),g.a.setQueryData("posts",null===n||void 0===n?void 0:n.filter((function(t){return t.id!==e.postId}))),t.abrupt("return",{previousPosts:n});case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),onError:function(t,e,n){(null===n||void 0===n?void 0:n.previousPosts)&&g.a.setQueryData("posts",n.previousPosts)},onSuccess:function(){g.a.invalidateQueries("posts"),e({type:"success",title:"Post Deleted"})}},t),{},{mutationFn:E}))}();return Object(D.jsx)(u.a,{allowedRoles:[u.c.ADMIN],children:Object(D.jsx)(s.b,{icon:"danger",title:"Delete Post",body:"Are you sure you want to delete this Post?",triggerButton:Object(D.jsx)(s.a,{variant:"danger",children:Object(D.jsx)(l.j,{className:"h-4 w-4"})}),confirmButton:Object(D.jsx)(s.a,{isLoading:n.isLoading,type:"button",className:"bg-red-600",onClick:Object(x.a)(O.a.mark((function t(){return O.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.mutateAsync({postId:e});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),children:"Delete Post"})})})},Z=function(){var t=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config;return Object(m.a)(Object(f.a)(Object(f.a)({},t),{},{queryKey:["posts"],queryFn:function(){return W()}}))}();return t.isLoading?Object(D.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:Object(D.jsx)(s.e,{size:"lg"})}):t.data?Object(D.jsx)(s.f,{data:t.data,columns:[{title:"Title",field:"title"},{title:"Created At",field:"createdAt",Cell:function(t){var e=t.entry.createdAt;return Object(D.jsx)("span",{children:Object(d.a)(e)})}},{title:"",field:"_id",Cell:function(t){var e=t.entry._id;return Object(D.jsx)(s.c,{to:"./".concat(e),children:"View"})}},{title:"",field:"_id",Cell:function(t){var e=t.entry._id;return Object(D.jsx)(J,{id:e})}}]}):null},K=function(){return Object(D.jsx)(i.a,{title:"Posts",button:Object(D.jsx)(V,{}),children:Object(D.jsx)("div",{className:"mt-4",children:Object(D.jsx)(Z,{})})})},G=function(){return Object(D.jsxs)(r.e,{children:[Object(D.jsx)(r.c,{path:"",element:Object(D.jsx)(K,{})}),Object(D.jsx)(r.c,{path:":postId",element:Object(D.jsx)(U,{})}),Object(D.jsx)(r.c,{path:"*",element:Object(D.jsx)(r.a,{to:"."})})]})}}}]); //# sourceMappingURL=6.4b2e7bef.chunk.js.map