Files
aso/public/dashboard/assets/Index.e2a588af.js
2022-12-13 13:34:27 +07:00

2 lines
5.7 KiB
JavaScript

import{H as Y}from"./HeaderBreadcrumbs.da67f38c.js";import{P as Z}from"./Page.4c1db0aa.js";import{a as ee,al as W,bi as O,aQ as te,r as i,j as r,S,f as e,P as ae,ar as k,aq as m,bn as ne,ax as B,B as z,g as re,ay as le,T as oe,az as M,as as ie}from"./index.8f299a7d.js";import{d as se,a as ce}from"./KeyboardArrowRight.3ee3e2fb.js";import{d as de}from"./Add.06de942b.js";import{d as ue}from"./Upload.e0210d35.js";import{B as he,d as pe}from"./Cancel.e6e714f4.js";import{B as me}from"./BasePagination.56fc59df.js";import{C as $}from"./Card.1ec83a31.js";import{T as fe}from"./TableContainer.b8d5000e.js";import{T as ge,a as C,b as f,c as t}from"./TableRow.d2ef76cd.js";import"./jsx-runtime_commonjs-proxy.e03e6edd.js";function be(){const g=ee();W(),O();const[b,w]=te(),[v,q]=i.exports.useState(null);function A(a){const l=i.exports.useRef(null),[n,c]=i.exports.useState(""),o=s=>{var p;const T=(p=s.target.value)!=null?p:"";c(T)},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]=k.useState(null),c=Boolean(l),o=i.exports.useRef(null),[d,s]=i.exports.useState(null),T=u=>{n(u.currentTarget)},p=()=>{n(null)},I=()=>{o!=null&&o.current?(p(),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}))},V=u=>{u.target.files[0]?s(u.target.files[0].name):s(null)},X=()=>{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]),M.post("master/formularium/import",j).then(_=>{P(),x(),q(_.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:V,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(A,{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:T,children:"Create"}),r(ne,{id:"import-button",anchorEl:l,open:c,onClose:p,MenuListProps:{"aria-labelledby":"basic-button"},children:[e(B,{onClick:()=>{g("/master/formularium/create")},children:"Create"}),e(B,{onClick:I,children:"Import"}),e(B,{onClick:p,children:"Download Template"})]})]}),d&&r(S,{direction:"row",spacing:2,sx:{p:2},children:[r(he,{variant:"outlined","aria-label":"outlined button group",fullWidth:!0,children:[e(m,{onClick:I,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:X,children:"Upload"})]}),v&&e(S,{direction:"row",sx:{px:2,pb:2},children:r(z,{sx:{color:"text.secondary"},children:["Last Import Result Report : ",e("a",{href:(R=(E=v.result_file)==null?void 0:E.url)!=null?R:"#",children:(L=(F=v.result_file)==null?void 0:F.name)!=null?L:"-"})]})})]})}function U(a){const{row:l}=a,[n,c]=k.useState(!1);return r(k.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(z,{sx:{borderBottom:1},children:r(oe,{variant:"body2",gutterBottom:!0,component:"div",children:["Description : ",l.description]})})})})})]})}const[G,D]=i.exports.useState(!0);i.exports.useState(0),i.exports.useState("idle");const[y,Q]=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)=>{D(!0);const l=a||Object.fromEntries([...b.entries()]),n=await M.get("/master/formulariums",{params:l});D(!1),Q(n.data)},h={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($,{children:[e(fe,{component:ae,children:r(ge,{"aria-label":"collapsible table",children:[e(C,{children:r(f,{children:[e(t,{style:h,align:"left"}),e(t,{style:h,align:"left",children:"Code"}),e(t,{style:h,align:"left",children:"Name"}),e(t,{style:h,align:"left",children:"Total Item"}),e(t,{style:h,align:"right",children:"Status"}),e(t,{style:h,align:"right",children:"Action"})]})}),G?e(C,{children:e(f,{children:e(t,{colSpan:8,align:"center",children:"Loading"})})}):y.data.length==0?e(C,{children:e(f,{children:e(t,{colSpan:8,align:"center",children:"No Data"})})}):e(C,{children:y.data.map(a=>e(U,{row:a},a.id))})]})}),e(me,{paginationData:y,onPageChange:K})]})]})}function Pe(){W(),O();const g="Formularium";return r(Z,{title:g,children:[e(Y,{heading:g,links:[{name:"Master",href:"/master"},{name:"Formularium",href:"/master/formulariums"}]}),e($,{children:e(be,{})})]})}export{Pe as default};