Files
aso/public/dashboard/assets/Index.06178ba2.js
2023-02-15 09:07:33 +07:00

2 lines
5.7 KiB
JavaScript

import{H as X}from"./HeaderBreadcrumbs.5be7a6b4.js";import{P as Z}from"./Page.aa656a85.js";import{a as ee,ap as $,aT as z,a0 as te,r as i,j as r,S,f as e,P as ae,au as B,$ as m,bI as ne,aA as k,B as M,g as re,aB as le,T as oe,Y as W,av as ie}from"./index.ef35a7e7.js";import{d as se,a as ce}from"./KeyboardArrowRight.aa71047a.js";import{d as de}from"./Add.f5557507.js";import{d as ue}from"./Upload.02d965c7.js";import{d as pe}from"./Cancel.3c371513.js";import{B as he}from"./BasePagination.b907cc44.js";import{C as A}from"./Card.cc6fb9c1.js";import{T as me}from"./TableContainer.d3d72d8f.js";import{T as fe,a as v,b as f,c as t}from"./TableRow.e3e9b73a.js";import{B as ge}from"./ButtonGroup.4a34b591.js";import"./jsx-runtime_commonjs-proxy.a0db3bf1.js";function be(){const g=ee();$(),z();const[b,w]=te(),[C,O]=i.exports.useState(null);function q(a){const l=i.exports.useRef(null),[n,c]=i.exports.useState(""),o=s=>{var h;const y=(h=s.target.value)!=null?h:"";c(y)},d=s=>{s.preventDefault(),a.onSearch(n)};return i.exports.useEffect(()=>{var s;c((s=b.get("search"))!=null?s:"")},[b]),e("form",{onSubmit:d,style:{width:"100%"},children:e(ie,{id:"search-input",ref:l,label:"Search",variant:"outlined",fullWidth:!0,onChange:o,value:n})})}function H(a){var E,R,F,L;const[l,n]=B.useState(null),c=Boolean(l),o=i.exports.useRef(null),[d,s]=i.exports.useState(null),y=u=>{n(u.currentTarget)},h=()=>{n(null)},D=()=>{o!=null&&o.current?(h(),o.current?o.current.click():console.log("No File selected")):alert("No file selected")},P=()=>{o.current.value="",o.current.dispatchEvent(new Event("change",{bubbles:!0}))},Q=u=>{u.target.files[0]?s(u.target.files[0].name):s(null)},V=()=>{var u,N;if((u=o.current)!=null&&u.files.length){const j=new FormData;j.append("file",(N=o.current)==null?void 0:N.files[0]),W.post("master/formularium/import",j).then(_=>{P(),x(),O(_.data)}).catch(_=>{enqueueSnackbar("Looks like something went wrong. Please check your data and try again. "+_.message,{variant:"error"})})}else enqueueSnackbar("No File Selected",{variant:"warning"})};return r("div",{children:[e("input",{type:"file",id:"file",ref:o,style:{display:"none"},onChange:Q,accept:".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/plain"}),!d&&r(S,{direction:"row",spacing:2,sx:{p:2},children:[e(q,{onSearch:J}),e(m,{id:"import-button",variant:"outlined",startIcon:e(de,{}),sx:{p:1.8},"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:y,children:"Create"}),r(ne,{id:"import-button",anchorEl:l,open:c,onClose:h,MenuListProps:{"aria-labelledby":"basic-button"},children:[e(k,{onClick:()=>{g("/master/formularium/create")},children:"Create"}),e(k,{onClick:D,children:"Import"}),e(k,{onClick:h,children:"Download Template"})]})]}),d&&r(S,{direction:"row",spacing:2,sx:{p:2},children:[r(ge,{variant:"outlined","aria-label":"outlined button group",fullWidth:!0,children:[e(m,{onClick:D,fullWidth:!0,children:d!=null?d:"No File Selected"}),e(m,{onClick:P,size:"small",fullWidth:!1,sx:{p:1.8},children:e(pe,{color:"error"})})]}),e(m,{id:"upload-button",variant:"outlined",startIcon:e(ue,{}),sx:{p:1.8},onClick:V,children:"Upload"})]}),C&&e(S,{direction:"row",sx:{px:2,pb:2},children:r(M,{sx:{color:"text.secondary"},children:["Last Import Result Report : ",e("a",{href:(R=(E=C.result_file)==null?void 0:E.url)!=null?R:"#",children:(L=(F=C.result_file)==null?void 0:F.name)!=null?L:"-"})]})})]})}function U(a){const{row:l}=a,[n,c]=B.useState(!1);return r(B.Fragment,{children:[r(f,{sx:{"& > *":{borderBottom:"unset"}},children:[e(t,{children:e(re,{"aria-label":"expand row",size:"small",onClick:()=>c(!n),children:n?e(se,{}):e(ce,{})})}),e(t,{align:"left",children:l.code}),e(t,{align:"left",children:l.name}),e(t,{align:"left",children:l.items_count}),e(t,{align:"right",children:e(m,{variant:"outlined",color:"success",size:"small",children:"Active"})}),e(t,{align:"right",children:e(m,{variant:"outlined",color:"error",size:"small",children:"Disable"})})]}),e(f,{children:e(t,{style:{paddingBottom:0,paddingTop:0},colSpan:99,children:e(le,{in:n,timeout:"auto",unmountOnExit:!0,children:e(M,{sx:{borderBottom:1},children:r(oe,{variant:"body2",gutterBottom:!0,component:"div",children:["Description : ",l.description]})})})})})]})}const[G,I]=i.exports.useState(!0);i.exports.useState(0),i.exports.useState("idle");const[T,Y]=i.exports.useState({current_page:1,data:[],path:"",first_page_url:"",last_page:1,last_page_url:"",next_page_url:"",prev_page_url:"",per_page:10,from:0,to:0,total:0});i.exports.useState(5);const x=async(a=null)=>{I(!0);const l=a||Object.fromEntries([...b.entries()]),n=await W.get("/master/formulariums",{params:l});I(!1),Y(n.data)},p={fontWeight:"bold"},J=async a=>{await x({search:a}),w({search:a})},K=(a,l)=>{const n=Object.fromEntries([...b.entries(),["page",l]]);x(n),w(n)};return i.exports.useEffect(()=>{x()},[]),r(S,{children:[e(H,{}),r(A,{children:[e(me,{component:ae,children:r(fe,{"aria-label":"collapsible table",children:[e(v,{children:r(f,{children:[e(t,{style:p,align:"left"}),e(t,{style:p,align:"left",children:"Code"}),e(t,{style:p,align:"left",children:"Name"}),e(t,{style:p,align:"left",children:"Total Item"}),e(t,{style:p,align:"right",children:"Status"}),e(t,{style:p,align:"right",children:"Action"})]})}),G?e(v,{children:e(f,{children:e(t,{colSpan:8,align:"center",children:"Loading"})})}):T.data.length==0?e(v,{children:e(f,{children:e(t,{colSpan:8,align:"center",children:"No Data"})})}):e(v,{children:T.data.map(a=>e(U,{row:a},a.id))})]})}),e(he,{paginationData:T,onPageChange:K})]})]})}function Ee(){$(),z();const g="Formularium";return r(Z,{title:g,children:[e(X,{heading:g,links:[{name:"Master",href:"/master"},{name:"Formularium",href:"/master/formulariums"}]}),e(A,{children:e(be,{})})]})}export{Ee as default};