"use strict";(self.webpackChunkclient=self.webpackChunkclient||[]).push([[1641],{81641:(e,t,s)=>{s.r(t),s.d(t,{default:()=>u});var i=s(89379),n=s(65043),a=s(75206),l=s(86319),c=s(60184),r=s(89698),d=s(9435),o=s(66580),h=s(1880),m=s(70579);const u=e=>{let{mode:t}=e;const s=(0,d.A)(),[u,x]=(0,n.useState)({title:"",details:""}),{id:p}=(0,o.g)(),j=(0,o.Zp)();(0,n.useEffect)((()=>{if(t){(async()=>{const e=h.A.get("token"),t=await fetch("https://ezybill.ureshiiweightloss.com/api/v1/unit/get",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:e,id:p})}),s=await t.json();x((0,i.A)((0,i.A)({},u),s.data))})()}}),[t]);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(a.A,{title:t?"Update Unit":"Add Unit"}),(0,m.jsxs)("main",{id:"main",children:[(0,m.jsx)(l.A,{}),(0,m.jsx)("div",{className:"content__body",children:(0,m.jsxs)("div",{className:"content__body__main bg-white ",children:[(0,m.jsx)("div",{className:" flex-col lg:flex-row",children:(0,m.jsx)("div",{className:"w-full",children:(0,m.jsxs)("div",{className:"p-2",children:[(0,m.jsxs)("p",{className:"pb-1",children:["Title ",(0,m.jsx)("span",{className:"required__text",children:"*"})]}),(0,m.jsx)("input",{type:"text",onChange:e=>x((0,i.A)((0,i.A)({},u),{},{title:e.target.value})),value:u.title})]})})}),(0,m.jsxs)("div",{className:"flex justify-center pt-9 mb-6",children:[(0,m.jsxs)("div",{className:"flex rounded-sm bg-green-500 text-white",children:[(0,m.jsx)(c.yjt,{className:"mt-3 ml-2"}),(0,m.jsx)("button",{className:"p-2",onClick:async e=>{if(""===u.title)return s("fill the blank","error");try{const e="https://ezybill.ureshiiweightloss.com/api/v1/unit/add",n=h.A.get("token"),a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?(0,i.A)((0,i.A)({},u),{},{token:n,update:!0,id:p}):(0,i.A)((0,i.A)({},u),{},{token:n}))}),l=await a.json();return 200!==a.status||l.err?s(l.err,"error"):(t||x({title:"",details:""}),s(t?"Unit update success":"Unit create success","success"),void j("/admin/unit"))}catch(n){return s("Something went wrong","error")}},children:t?"Update":"Save"})]}),(0,m.jsxs)("div",{className:"flex rounded-sm ml-4 bg-blue-500 text-white",children:[(0,m.jsx)(r.A1o,{className:"mt-3 ml-2"}),(0,m.jsx)("button",{className:"p-2",onClick:e=>{x({title:""})},children:"Reset"})]})]})]})})]})]})}}}]);
//# sourceMappingURL=1641.17fd76cc.chunk.js.map