Your IP : 3.141.47.139


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

(this["webpackJsonpncdc-admin"]=this["webpackJsonpncdc-admin"]||[]).push([[5],{731:function(t,e,n){"use strict";n.d(e,"a",(function(){return c}));var r=n(732),a=n.n(r),i=n(6),s=n.n(i),c=function(t){return a()(t).format("MMMM D, YYYY h:mm A")};c.propTypes={date:s.a.string.isRequired}},732:function(t,e,n){t.exports=function(){"use strict";var t=1e3,e=6e4,n=36e5,r="millisecond",a="second",i="minute",s="hour",c="day",u="week",d="month",o="quarter",l="year",f="date",h="Invalid Date",j=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,b=/\[([^\]]+)]|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,p={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("_")},m=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),a=n%60;return(e<=0?"+":"-")+m(r,2,"0")+":"+m(a,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()),a=e.clone().add(r,d),i=n-a<0,s=e.clone().add(r+(i?-1:1),d);return+(-(r+(n-a)/(i?a-s:s-a))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:d,y:l,w:u,d:c,D:f,h:s,m:i,s:a,ms:r,Q:o}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},O="en",g={};g[O]=p;var x=function(t){return t instanceof D},y=function(t,e,n){var r;if(!t)return O;if("string"==typeof t)g[t]&&(r=t),e&&(g[t]=e,r=t);else{var a=t.name;g[a]=t,r=a}return!n&&r&&(O=r),r||!n&&O},$=function(t,e){if(x(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new D(n)},w=v;w.l=y,w.i=x,w.w=function(t,e){return $(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var D=function(){function p(t){this.$L=y(t.locale,null,!0),this.parse(t)}var m=p.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(w.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 a=r[2]-1||0,i=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],a,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)):new Date(r[1],a,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},m.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()},m.$utils=function(){return w},m.isValid=function(){return!(this.$d.toString()===h)},m.isSame=function(t,e){var n=$(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return $(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<$(t)},m.$g=function(t,e,n){return w.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!w.u(e)||e,o=w.p(t),h=function(t,e){var a=w.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?a:a.endOf(c)},j=function(t,e){return w.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},b=this.$W,p=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(o){case l:return r?h(1,0):h(31,11);case d:return r?h(1,p):h(0,p+1);case u:var O=this.$locale().weekStart||0,g=(b<O?b+7:b)-O;return h(r?m-g:m+(6-g),p);case c:case f:return j(v+"Hours",0);case s:return j(v+"Minutes",1);case i:return j(v+"Seconds",2);case a:return j(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,u=w.p(t),o="set"+(this.$u?"UTC":""),h=(n={},n[c]=o+"Date",n[f]=o+"Date",n[d]=o+"Month",n[l]=o+"FullYear",n[s]=o+"Hours",n[i]=o+"Minutes",n[a]=o+"Seconds",n[r]=o+"Milliseconds",n)[u],j=u===c?this.$D+(e-this.$W):e;if(u===d||u===l){var b=this.clone().set(f,1);b.$d[h](j),b.init(),this.$d=b.set(f,Math.min(this.$D,b.daysInMonth())).$d}else h&&this.$d[h](j);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[w.p(t)]()},m.add=function(r,o){var f,h=this;r=Number(r);var j=w.p(o),b=function(t){var e=$(h);return w.w(e.date(e.date()+Math.round(t*r)),h)};if(j===d)return this.set(d,this.$M+r);if(j===l)return this.set(l,this.$y+r);if(j===c)return b(1);if(j===u)return b(7);var p=(f={},f[i]=e,f[s]=n,f[a]=t,f)[j]||1,m=this.$d.getTime()+r*p;return w.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||h;var r=t||"YYYY-MM-DDTHH:mm:ssZ",a=w.z(this),i=this.$H,s=this.$m,c=this.$M,u=n.weekdays,d=n.months,o=function(t,n,a,i){return t&&(t[n]||t(e,r))||a[n].substr(0,i)},l=function(t){return w.s(i%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:w.s(c+1,2,"0"),MMM:o(n.monthsShort,c,d,3),MMMM:o(d,c),D:this.$D,DD:w.s(this.$D,2,"0"),d:String(this.$W),dd:o(n.weekdaysMin,this.$W,u,2),ddd:o(n.weekdaysShort,this.$W,u,3),dddd:u[this.$W],H:String(i),HH:w.s(i,2,"0"),h:l(1),hh:l(2),a:f(i,s,!0),A:f(i,s,!1),m:String(s),mm:w.s(s,2,"0"),s:String(this.$s),ss:w.s(this.$s,2,"0"),SSS:w.s(this.$ms,3,"0"),Z:a};return r.replace(b,(function(t,e){return e||j[t]||a.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,f,h){var j,b=w.p(f),p=$(r),m=(p.utcOffset()-this.utcOffset())*e,v=this-p,O=w.m(this,p);return O=(j={},j[l]=O/12,j[d]=O,j[o]=O/3,j[u]=(v-m)/6048e5,j[c]=(v-m)/864e5,j[s]=v/n,j[i]=v/e,j[a]=v/t,j)[b]||v,h?O:w.a(O)},m.daysInMonth=function(){return this.endOf(d).$D},m.$locale=function(){return g[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=y(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return w.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},p}(),M=D.prototype;return $.prototype=M,[["$ms",r],["$s",a],["$m",i],["$H",s],["$W",c],["$M",d],["$y",l],["$D",f]].forEach((function(t){M[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),$.extend=function(t,e){return t.$i||(t(e,D,$),t.$i=!0),$},$.locale=y,$.isDayjs=x,$.unix=function(t){return $(1e3*t)},$.en=g[O],$.Ls=g,$.p={},$}()},738:function(t,e,n){"use strict";n.r(e),n.d(e,"AdsRoutes",(function(){return H}));var r=n(15),a=n(29),i=n(61),s=n(96),c=n(172),u=n(731),d=n(18),o=n(47),l=n(721),f=function(t){var e=t.adId,n=t.config;return Object(l.a)(Object(d.a)(Object(d.a)({},n),{},{queryKey:["ad",e],queryFn:function(){return function(t){var e=t.adId;return o.a.get("/adverts/".concat(e))}({adId:e})}}))},h=n(13),j=n.n(h),b=n(23),p=n(28),m=n(98),v=n(48),O=n(99),g=n(0),x=n(97),y=n(171),$=n(95),w=n(6),D=n.n(w),M=n(170),S=function(t){var e=t.data,n=t.adId;return o.a.patch("/adverts/".concat(n),e)};S.propTypes={data:D.a.shape({title:D.a.string,desc:D.a.string,image:D.a.string}).isRequired,adId:D.a.string.isRequired};var A=n(2),I=x.a({}),N=function(t){var e,n,r=t.adId,i=Object(g.useState)(null),s=Object(p.a)(i,2),c=s[0],u=s[1],o=Object(g.useState)(null),l=Object(p.a)(o,2),h=l[0],x=l[1],w=f({adId:r}),D=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,e=Object($.a)().addNotification;return Object(M.a)(Object(d.a)(Object(d.a)({onMutate:function(){var t=Object(b.a)(j.a.mark((function t(e){var n;return j.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y.a.cancelQueries(["ad",null===e||void 0===e?void 0:e.adId]);case 2:return n=y.a.getQueryData[null===e||void 0===e?void 0:e.adId],y.a.setQueryData(["ad",null===e||void 0===e?void 0:e.adId],Object(d.a)(Object(d.a)(Object(d.a)({},n),e.data),{},{id:e.adId})),t.abrupt("return",{previousAd: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.previousAd)&&y.a.setQueryData(["ad",n.previousAd.id],n.previousAd)},onSuccess:function(t){y.a.refetchQueries(["ad",t.id]),e({type:"success",title:"Ad Updated"})}},t),{},{mutationFn:S}))}();return Object(A.jsx)(v.a,{allowedRoles:[v.c.ADMIN],children:Object(A.jsx)(m.c,{size:"sm",isDone:D.isSuccess,triggerButton:Object(A.jsx)(a.a,{startIcon:Object(A.jsx)(O.a,{className:"h-4 w-4"}),size:"sm",children:"Update"}),title:"Update Ad",submitButton:Object(A.jsx)(a.a,{form:"update-ad",type:"submit",size:"sm",isLoading:D.isLoading,children:"Submit"}),children:Object(A.jsx)(m.b,{id:"update-ad",encType:"multipart/form-data",onSubmit:function(){var t=Object(b.a)(j.a.mark((function t(e){var n,a,i;return j.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.title,a=e.desc,(i=new FormData).append("title",n),i.append("desc",a),i.append("image",c),t.next=7,D.mutateAsync({data:i,adId:r});case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),options:{defaultValues:{title:null===(e=w.data)||void 0===e?void 0:e.title,desc:null===(n=w.data)||void 0===n?void 0:n.desc}},schema:I,children:function(t){var e=t.register,n=t.formState;return Object(A.jsxs)(A.Fragment,{children:[Object(A.jsx)(m.d,{label:"Title",error:n.errors.title,registration:e("title")}),Object(A.jsx)(m.d,{label:"Description",error:n.errors.desc,registration:e("desc")}),Object(A.jsx)(m.g,{title:"Update Banner Image",subTitle:"Upload clear image for better visibility",error:n.errors.image,x:1280,y:340,onChange:function(t){u(t.target.files[0]),x(URL.createObjectURL(t.target.files[0]))},preview:h})]})}})})})},_=function(){var t=Object(r.j)().adId,e=f({adId:t});return e.isLoading?Object(A.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:Object(A.jsx)(a.e,{size:"lg"})}):(console.log(e.data),e.data?Object(A.jsxs)(A.Fragment,{children:[Object(A.jsx)(i.a,{title:e.data._id}),Object(A.jsxs)(s.a,{title:e.data.title,button:Object(A.jsx)(N,{adId:t}),children:[Object(A.jsxs)("span",{className:"text-xs font-bold text-gray-500",children:["Ad created on ",Object(u.a)(e.data.createdAt)]}),Object(A.jsxs)("div",{className:"mt-6 flex flex-col space-y-16",children:[Object(A.jsxs)("div",{className:"flex flex-row space-x-4",children:[Object(A.jsxs)("div",{className:"w-1/2",children:[Object(A.jsx)("div",{className:"text-sm font-bold",children:"Title"}),Object(A.jsx)("div",{className:"text-sm",children:e.data.title})]}),Object(A.jsxs)("div",{className:"w-1/2",children:[Object(A.jsx)("div",{className:"text-sm font-bold",children:"Description"}),Object(A.jsx)("div",{className:"text-sm",children:e.data.desc})]})]}),Object(A.jsx)("div",{className:"mx-auto p-2 bg-gray-300 rounded-md",children:Object(A.jsx)("img",{src:"".concat(c.b,"/ads/resized/").concat(e.data.image),alt:"banner",className:"w-full h-full"})})]})]})]}):null)},T=n(20),L=function(){return o.a.get("/adverts")},Y=n(21),C=function(t){var e=t.adId;return o.a.delete("/adverts/".concat(e))};C.propTypes={adId:D.a.string.isRequired};var Q=function(t){var e=t.id,n=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,e=Object($.a)().addNotification;return Object(M.a)(Object(d.a)(Object(d.a)({onMutate:function(){var t=Object(b.a)(j.a.mark((function t(e){var n;return j.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y.a.cancelQueries("ads");case 2:return n=y.a.getQueryData("ads"),y.a.setQueryData("ads",null===n||void 0===n?void 0:n.filter((function(t){return t.id!==e.managerId}))),t.abrupt("return",{previousAds: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.previousAds)&&y.a.setQueryData("ads",n.previousAds)},onSuccess:function(){y.a.invalidateQueries("ads"),e({type:"success",title:"Ad Deleted"})}},t),{},{mutationFn:C}))}();return Object(A.jsx)(v.a,{allowedRoles:[v.c.ADMIN],children:Object(A.jsx)(a.b,{icon:"danger",title:"Delete Ad",body:"Are you sure you want to delete this Ad?",triggerButton:Object(A.jsx)(a.a,{variant:"danger",children:Object(A.jsx)(Y.j,{className:"h-4 w-4"})}),confirmButton:Object(A.jsx)(a.a,{isLoading:n.isLoading,type:"button",className:"bg-red-600",onClick:Object(b.a)(j.a.mark((function t(){return j.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.mutateAsync({adId:e});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),children:"Delete Ad"})})})},R=function(){var t=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config;return Object(l.a)(Object(d.a)(Object(d.a)({},t),{},{queryKey:["ads"],queryFn:function(){return L()}}))}();return t.isLoading?Object(A.jsx)("div",{className:"w-full h-48 flex justify-center items-center",children:Object(A.jsx)(a.e,{size:"lg"})}):t.data?Object(A.jsx)(a.f,{data:t.data,columns:[{title:"Lists",field:"_id",Cell:function(t){var e=t.entry,n=e._id,r=e.title;return Object(A.jsxs)(T.b,{to:"./".concat(n),children:[Object(A.jsx)("span",{className:"text-gray-700 text-md",children:r}),Object(A.jsx)("br",{}),Object(A.jsx)("span",{className:"p-1 rounded bg-gray-200 w-full text-xs",children:n})]})}},{title:"...",field:"_id",Cell:function(t){var e=t.entry._id;return Object(A.jsx)(Q,{id:e})}}]}):null},U=n(22),k=function(t){var e=t.data;return o.a.post("/adverts",e)};k.propTypes={data:D.a.shape({title:D.a.string.isRequired,desc:D.a.string.isRequired,image:D.a.string.isRequired}).isRequired};var F=x.a({title:x.b(),desc:x.b()}),q=function(){var t=Object(g.useState)(null),e=Object(p.a)(t,2),n=e[0],r=e[1],i=Object(g.useState)(null),s=Object(p.a)(i,2),c=s[0],u=s[1],o=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).config,e=Object($.a)().addNotification;return Object(M.a)(Object(d.a)(Object(d.a)({onMutate:function(){var t=Object(b.a)(j.a.mark((function t(e){var n;return j.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y.a.cancelQueries("ads");case 2:return n=y.a.getQueryData("ads"),y.a.setQueryData("ads",[].concat(Object(U.a)(n||[]),[e.data])),t.abrupt("return",{previousAds: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.previousAds)&&y.a.setQueryData("ads",n.previousAds)},onSuccess:function(){y.a.invalidateQueries("ads"),e({type:"success",title:"New ad successfully created"})}},t),{},{mutationFn:k}))}();return Object(A.jsx)(v.a,{allowedRoles:[v.c.ADMIN],children:Object(A.jsx)(m.c,{size:"sm",isDone:o.isSuccess,triggerButton:Object(A.jsx)(a.a,{size:"sm",startIcon:Object(A.jsx)(Y.i,{className:"h-4 w-4"}),children:"Create Ad"}),title:"Create Ad",submitButton:Object(A.jsx)(a.a,{form:"create-ad",type:"submit",size:"sm",isLoading:o.isLoading,children:"Submit"}),children:Object(A.jsx)(m.b,{id:"create-ad",encType:"multipart/form-data",onSubmit:function(){var t=Object(b.a)(j.a.mark((function t(e){var r,a,i;return j.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.title,a=e.desc,(i=new FormData).append("title",r),i.append("desc",a),i.append("image",n),t.next=7,o.mutateAsync({data:i});case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),schema:F,children:function(t){var e=t.register,n=t.formState,a=t.watch,i=t.setValue;return Object(A.jsxs)(A.Fragment,{children:[Object(A.jsx)(m.d,{label:"Title",error:n.errors.title,registration:e("title")}),Object(A.jsx)(m.f,{label:"Content",error:n.errors.desc,editorContent:a("desc"),setValue:i,value:"desc"}),Object(A.jsx)(m.g,{title:"Upload Ad Banner Image",subTitle:"Upload clear image for better visibility",error:n.errors.image,x:1280,y:340,onChange:function(t){r(t.target.files[0]),u(URL.createObjectURL(t.target.files[0]))},preview:c})]})}})})})},z=function(){return Object(A.jsx)(s.a,{title:"Ads",button:Object(A.jsx)(q,{}),children:Object(A.jsx)("div",{className:"mt-4",children:Object(A.jsx)(R,{})})})},H=function(){return Object(A.jsxs)(r.e,{children:[Object(A.jsx)(r.c,{path:"",element:Object(A.jsx)(z,{})}),Object(A.jsx)(r.c,{path:":adId",element:Object(A.jsx)(_,{})}),Object(A.jsx)(r.c,{path:"*",element:Object(A.jsx)(r.a,{to:"."})})]})}}}]);
//# sourceMappingURL=5.ed7e9973.chunk.js.map