felicity-lims/felicity/templates/static/assets/VoucherCodes-812e2c8c.js
2024-04-21 12:22:39 +02:00

1 line
4.9 KiB
JavaScript

import{d as P,bg as z,s as H,D as G,N as J,V as W,r as K,z as Q,o as u,c as m,b as e,f as i,g as w,F as U,p as X,t as y,q as Y,G as A,e as x,y as L,i as _,v as D,ad as Z,w as ee,x as oe,j as S,_ as E,O as se,I as te,J as ie,k as de}from"./index-2a6c9271.js";import{g as ae,h as le}from"./billing.mutations-ad702213.js";import{c as ne,a as p,d as re,g as ue,u as ce,b as c}from"./array-52a0b0d0.js";const l=h=>(te("data-v-8e7b96f9"),h=h(),ie(),h),he={class:"mt-4"},me={key:0},_e={key:1},pe=l(()=>e("h4",{class:"text-gray-800 text-l font-semibold"},"Voucher Codes",-1)),ve=l(()=>e("hr",null,null,-1)),fe={class:"grid grid-cols-5 gap-2 mt-2"},ge={class:"font-semibold text-gray-800 flex justify-between items-center"},be={class:"text-sm text-gray-500 flex-grow text-right"},ye=["onClick"],xe=l(()=>e("h3",null,"Voucher Code Form",-1)),Ce={class:"grid grid-cols-2 gap-x-4 mb-4"},Ve={class:"block col-span-1 mb-2"},ke=l(()=>e("span",{class:"text-gray-700"},"Voucher Code",-1)),we={class:"block col-span-1 mb-2"},Ue=l(()=>e("span",{class:"text-gray-700"},"Usage Limit",-1)),Ae={class:"grid grid-cols-2 gap-x-4 mb-4"},Le={class:"block col-span-1 mb-2"},De=l(()=>e("span",{class:"text-gray-700"},"Is Active",-1)),Se=l(()=>e("hr",null,null,-1)),Ee=P({__name:"VoucherCodes",props:{voucherUid:String},setup(h){const I=S(()=>E(()=>import("./LoadingMessage-72d34fcf.js"),["assets/LoadingMessage-72d34fcf.js","assets/index-2a6c9271.js","assets/index-88806377.css"])),F=S(()=>E(()=>import("./SimpleModal-0c0664c5.js"),["assets/SimpleModal-0c0664c5.js","assets/index-2a6c9271.js","assets/index-88806377.css","assets/SimpleModal-f645a074.css"])),n=h,{withClientMutation:C}=se();let r=z();const{fetchingVoucherCodes:R}=H(r),M=G(()=>{const o=r.getVouchers,s=o?.findIndex(b=>b.uid===n.voucherUid);return s>-1?o[s]?.codes:[]});J(()=>r.fetchVoucherCodes(n.voucherUid)),W(()=>n.voucherUid,o=>{r.fetchVoucherCodes(n.voucherUid)});let a=K(!1);const O=ne({uid:p().nullable(),voucherUid:p().required(),code:p().required("Code is Required"),usageLimit:re().required("Usage Limit is Required"),used:p().nullable(),isActive:ue().default(!0)}),{handleSubmit:q,errors:V,setFieldValue:d}=ce({validationSchema:O,initialValues:{isActive:!0,voucherUid:n.voucherUid}}),{value:B}=c("uid");c("voucherUid");const{value:v}=c("code"),{value:f}=c("usageLimit");c("used");const{value:g}=c("isActive"),k=q(o=>{o.uid||N(o),o.uid&&j(o)});let T=o=>{d("uid",o.uid),d("code",o.code),d("usageLimit",o.usageLimit),d("used",o.used),d("isActive",o.isActive),a.value=!0};const $=()=>{d("uid",void 0),d("voucherUid",n.voucherUid),d("code",void 0),d("usageLimit",void 0),d("used",void 0),d("isActive",!0),a.value=!0},N=o=>{delete o.uid,C(ae,{payload:o},"createVoucherCode").then(s=>r.addVoucherCode(s)).finally(()=>a.value=!1)},j=o=>{delete o.uid,delete o.used,C(le,{uid:B?.value,payload:o},"updateVoucherCode").then(s=>r.updateVoucherCode(s)).finally(()=>a.value=!1)};return(o,s)=>{const b=Q("font-awesome-icon");return u(),m(U,null,[e("div",he,[i(R)?(u(),m("div",me,[w(i(I),{message:"Fetching voucher codes ..."})])):(u(),m("section",_e,[e("div",{class:"flex justify-between"},[pe,e("button",{class:"px-4 my-2 p-1 text-sm border-sky-800 border text-dark-700 transition-colors duration-150 rounded-sm focus:outline-none hover:bg-sky-800 hover:text-gray-100",onClick:$}," Add Voucher Code ")]),ve,e("div",fe,[(u(!0),m(U,null,X(M.value,t=>(u(),m("div",{key:t.uid,class:"col-span-1 bg-white rounded-sm shadow-sm hover:shadow-md duration-500 px-2 py-2"},[e("div",ge,[e("h5",null,y(t.code),1),e("div",be,y(t.used)+" of "+y(t.usageLimit),1),e("a",{class:"ml-2 pl-2 text-gray-400 border-l-2 border-l-gray-400",onClick:Ie=>i(T)(t)},[w(b,{class:"text-xs hover:text-gray-800",icon:"pen"})],8,ye)])]))),128))])]))]),i(a)?(u(),Y(i(F),{key:0,onClose:s[4]||(s[4]=t=>_(a)?a.value=!1:a=!1),contentWidth:"w-3/6"},{header:A(()=>[xe]),body:A(()=>[e("form",null,[e("div",Ce,[e("label",Ve,[ke,x(e("input",{class:L(["form-input mt-1 block w-full",{"border-red-500 animate-pulse":i(V).code}]),type:"text","onUpdate:modelValue":s[0]||(s[0]=t=>_(v)?v.value=t:null),placeholder:"Code ..."},null,2),[[D,i(v)]])]),e("label",we,[Ue,x(e("input",{class:L(["form-input mt-1 block w-full",{"border-red-500 animate-pulse":i(V).usageLimit}]),type:"number",min:"1","onUpdate:modelValue":s[1]||(s[1]=t=>_(f)?f.value=t:null)},null,2),[[D,i(f)]])])]),e("div",Ae,[e("label",Le,[De,x(e("input",{class:"form-checkbox ml-4",type:"checkbox","onUpdate:modelValue":s[2]||(s[2]=t=>_(g)?g.value=t:null),checked:""},null,512),[[Z,i(g)]])])]),Se,e("button",{type:"submit",class:"-mb-4 border border-sky-800 bg-sky-800 text-white rounded-sm px-2 py-1 mt-2 transition-colors duration-500 ease select-none hover:bg-sky-800 focus:outline-none focus:shadow-outline",onClick:s[3]||(s[3]=ee((...t)=>i(k)&&i(k)(...t),["prevent"]))}," Save Voucher ")])]),_:1})):oe("",!0)],64)}}});const Oe=de(Ee,[["__scopeId","data-v-8e7b96f9"],["__file","/home/aurthur/Documents/Development/felicity-lims/webapp/views/admin/billing/VoucherCodes.vue"]]);export{Oe as default};