| Current Path : /home/users/unlimited/www/admin.medimeet.codeskitter.site/assets/ |
| Current File : /home/users/unlimited/www/admin.medimeet.codeskitter.site/assets/Files-_jZYhJi_.js |
import{r,w as le,j as e,B as u,T as R,N as ce,O as de,x as v,P as ue,y as U,C as B,R as me,F as $,J as xe}from"./index-f5FVPPWf.js";import{e as he,f as pe}from"./index-D-rZ_zLU.js";import{u as fe}from"./SettingData-HUsgVeqA.js";import{F as je}from"./index-NjlW3JBs.js";import{u as q}from"./HasPermission-D75jcuOi.js";import{V as ge,u as De,N as Fe,S as M,i as Ce,D as ye,P as be}from"./Dashboard-QYea_GjR.js";import{U as _e,D as Se}from"./DeletePatientFile-DQM2O37z.js";import{i as Pe}from"./image-DDwLQVjO.js";import{a as Ee,u as O,I as N}from"./index-B8iLT9XL.js";import{h as Ae,u as Ie,M as ke,b as Me,a as Oe,c as ve,g as ze,d as Le,F as T,e as we,f as p,L as Re}from"./index.esm-CxKpqEdJ.js";import{u as Be}from"./UsePatientsData-2jGB5q0K.js";import{U as $e}from"./UsersComboBox-BR1MkjhI.js";import{D as Y}from"./use-clickable-DJbYv-Vn.js";import{d as Q,I as z,F}from"./input-aKY8cD2r.js";import"./tr-SHTCPR9-.js";import"./visually-hidden.style-BrEqndXz.js";import"./popover-BeKqgCqh.js";function Ne({isOpen:i,onClose:s}){const[o,l]=r.useState(),[c,m]=r.useState(null),f=r.useRef(),{register:S,handleSubmit:P,reset:C}=Ae(),y=le(),d=Ie(),x=5*1024*1024,{patientsData:E}=Be(),[j,A]=r.useState(),b=t=>{t.preventDefault();const a=t.dataTransfer.files[0];a&&a.size>x?p(d,"error","Please select a file smaller than 5 MB."):m(a)},h=t=>{t.preventDefault()},I=t=>{const a=t.target.files[0];a&&a.size>x?p(d,"error","Please select a file smaller than 5 MB."):m(a)},_=async t=>{if(!j)return p(d,"error","Please Select Patient");if(!c)return p(d,"error","Please Select File");let a={...t,patient_id:j.id,file:c};try{l(!0);const g=await ue(U.token,"add_patient_file",a);l(!1),g.response===200?(p(d,"success","File Added!"),y.invalidateQueries(["patient-files",j.id]),y.invalidateQueries(["all-files"]),m(null),C(),s()):p(d,"error",g.message)}catch(g){l(!1),p(d,"error",JSON.stringify(g))}};return e.jsxs(ke,{isOpen:i,onClose:s,isCentered:!0,size:"lg",children:[e.jsx(Me,{}),e.jsxs(Oe,{as:"form",onSubmit:P(_),children:[e.jsx(ve,{fontSize:18,py:2,children:"Add Patient Files"}),e.jsx(ze,{}),e.jsx(Y,{}),e.jsx(Le,{children:e.jsxs(u,{pb:3,children:[e.jsxs(Q,{isRequired:!0,children:[e.jsx(T,{children:"Patient"}),e.jsx($e,{data:E,name:"Patient",setState:A,addNew:!1})]}),e.jsxs(Q,{isRequired:!0,mt:5,children:[e.jsx(T,{children:"File Name"}),e.jsx(z,{placeholder:"Name",...S("file_name",{required:!0})})]}),e.jsx(u,{mt:5,p:4,border:"2px dashed",borderColor:"gray.300",borderRadius:"md",onDrop:b,onDragOver:h,onClick:()=>{f.current&&f.current.click()},cursor:"pointer",children:c?e.jsxs(u,{position:"relative",children:[e.jsxs(R,{children:["Selected File: ",c.name]}),e.jsx(ce,{position:"absolute",right:-2,top:-2,size:"sm",onClick:()=>{m(null)}})]}):e.jsxs(u,{children:[e.jsxs(ge,{children:[" ",e.jsx(z,{ref:f,type:"file",onChange:I,accept:"*",mb:4})]}),e.jsxs(de,{children:[" ",e.jsx(Ee,{fontSize:32})]}),e.jsxs(R,{textAlign:"center",mt:3,children:[e.jsx("b",{children:"Choose a file"})," or Drag it here.",e.jsx("br",{}),"Max 5 MB"]})]})})]})}),e.jsx(Y,{}),e.jsxs(we,{py:3,children:[e.jsx(v,{colorScheme:"gray",mr:3,onClick:s,size:"sm",children:"Close"}),e.jsx(v,{variant:"solid",size:"sm",colorScheme:"blue",type:"submit",isLoading:o,children:"Add File"})]})]})]})}const Te=(i,s)=>{const o=(i-1)*s;let l=o+s-1;return{startIndex:o,endIndex:l}};function is(){const[i,s]=r.useState(),{isOpen:o,onOpen:l,onClose:c}=O(),{hasPermission:m}=q(),{isOpen:f,onOpen:S,onClose:P}=O(),{isOpen:C,onOpen:y,onClose:d}=O(),[x,E]=r.useState(1),[j,A]=r.useState(""),b=De(j,1e3),[h,I]=r.useState({startDate:null,endDate:null}),_=h.startDate?B(h.startDate).format("YYYY-MM-DD"):"",t=h.endDate?B(h.endDate).format("YYYY-MM-DD"):"",{startIndex:a,endIndex:g}=Te(x,50),k=r.useRef(null),V=n=>{s(n)},H=async()=>{const n=await xe(U.token,`get_patient_file_page?start=${a}&end=${g}&search=${b}&start_date=${_}&end_date=${t}`);return{data:n==null?void 0:n.data.map(K=>{const{id:X,patient_id:Z,file_name:ee,file:se,f_name:te,l_name:ae,phone:ne,isd_code:re,updated_at:ie,created_at:oe}=K;return{id:X,patient_id:Z,"file name":e.jsxs(Re,{isExternal:!0,href:`${Pe}/${se}`,display:"flex",alignItems:"center",gap:3,children:[ee," ",e.jsx(pe,{})]}),patient_Name:`${te} ${ae}`,phone:`${re}${ne}`,created_at:oe,updated_at:ie}}),total_record:n.total_record}},{data:D,isLoading:J,error:L}=fe({queryKey:["all-files",b,x,_,t],queryFn:H}),W=n=>{E(n)},G=Math.ceil((D==null?void 0:D.total_record)/50);return r.useEffect(()=>{k.current&&k.current.scrollIntoView({behavior:"smooth",block:"start"})},[x]),L?e.jsx(me,{errorCode:L.name}):m("FILE_VIEW")?e.jsxs(u,{ref:k,children:[J||!D?e.jsxs(u,{children:[e.jsxs(F,{mb:5,justify:"space-between",children:[e.jsx(M,{w:400,h:8}),e.jsx(M,{w:200,h:8})]}),[...Array(10)].map((n,w)=>e.jsx(M,{h:10,w:"100%",mt:2},w))]}):e.jsxs(u,{children:[e.jsxs(F,{mb:5,justify:"space-between",align:"center",children:[e.jsxs(F,{align:"center",gap:4,children:[e.jsx(z,{size:"md",placeholder:"Search",w:400,maxW:"50vw",onChange:n=>A(n.target.value),value:j}),e.jsx(Ce,{dateRange:h,setDateRange:I,size:"md"})]}),e.jsx(u,{children:e.jsx(v,{isDisabled:!m("FILE_ADD"),size:"sm",colorScheme:"blue",onClick:l,children:"Add New"})})]}),e.jsx(ye,{minPad:"8px 8px",data:D.data,onActionClick:e.jsx(Ye,{onClick:V,DeleteonOpen:y,EditonOpen:S})}),e.jsx(F,{justify:"center",mt:4,children:e.jsx(be,{currentPage:x,onPageChange:W,totalPages:G})})]}),o&&e.jsx(Ne,{isOpen:o,onClose:c}),f&&e.jsx(_e,{isOpen:f,onClose:P,data:i}),C&&e.jsx(Se,{isOpen:C,onClose:d,data:i})]}):e.jsx(Fe,{})}const Ye=({onClick:i,rowData:s,DeleteonOpen:o,EditonOpen:l})=>{const{hasPermission:c}=q();return e.jsxs(F,{justify:"center",children:[c("FILE_UPDATE")&&e.jsx(N,{size:"sm",variant:"ghost",_hover:{background:"none"},onClick:()=>{i(s),l()},icon:e.jsx(he,{fontSize:18,color:$.colors.blue[500]})}),c("FILE_DELETE")&&e.jsx(N,{size:"sm",variant:"ghost",_hover:{background:"none"},onClick:()=>{i(s),o()},icon:e.jsx(je,{fontSize:18,color:$.colors.red[500]})})]})};export{is as default};