"use strict";(self.webpackChunkclient=self.webpackChunkclient||[]).push([[2396],{12396:(e,t,s)=>{s.r(t),s.d(t,{CategoryComponent:()=>x,default:()=>m});var a=s(89379),i=s(65043),l=s(75206),n=s(86319),r=(s(6839),s(9435)),c=s(35543),d=s(66580),o=s(1880),h=s(53435),u=s(70579);const x=e=>{let{mode:t,save:s}=e;const l=(0,r.A)(),[n,x]=((0,i.useRef)(null),(0,i.useState)({title:"",tax:"",hsn:"",type:"",details:""})),[m,p]=(0,i.useState)([]),{id:j}=(0,d.g)(),g=(0,r.A)(),y=(0,d.Zp)();(0,i.useEffect)((()=>{if(t){(async()=>{const e=o.A.get("token"),t=await fetch("https://ezybill.ureshiiweightloss.com/api/v1/category/get",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:e,id:j})}),s=await t.json();x((0,a.A)((0,a.A)({},n),s.data))})()}}),[t]),(0,i.useEffect)((()=>{(async()=>{const e=await fetch("https://ezybill.ureshiiweightloss.com/api/v1/tax/get",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:o.A.get("token")})}),t=(await e.json()).data.map(((e,t)=>{let{_id:s,title:a}=e;return{label:a,value:s}}));p([...t]),console.log(t)})()}),[]);return(0,u.jsx)(u.Fragment,{children:(0,u.jsxs)("div",{className:"content__body__main bg-white ",children:[(0,u.jsxs)("div",{className:"  flex justify-between  gap-5 flex-col lg:flex-row",children:[(0,u.jsxs)("div",{className:"w-full",children:[(0,u.jsxs)("div",{children:[(0,u.jsxs)("p",{className:"mb-2",children:["Title ",(0,u.jsx)("span",{className:"required__text",children:"*"})]}),(0,u.jsx)("input",{type:"text",onChange:e=>x((0,a.A)((0,a.A)({},n),{},{title:e.target.value})),value:n.title})]}),(0,u.jsxs)("div",{children:[(0,u.jsxs)("p",{className:"ml-1 mb-2 mt-2",children:["Select Tax ",(0,u.jsx)("span",{className:"required__text",children:"*"})]}),(0,u.jsx)(c.A,{className:"w-full",data:m,onChange:e=>x((0,a.A)((0,a.A)({},n),{},{tax:e})),value:n.tax})]})]}),(0,u.jsxs)("div",{className:"w-full pt-1",children:[(0,u.jsxs)("div",{children:[(0,u.jsx)("p",{className:"mb-2 ml-1",children:"HSN/SAC"}),(0,u.jsx)("input",{type:"text",onChange:e=>x((0,a.A)((0,a.A)({},n),{},{hsn:e.target.value})),value:n.hsn})]}),(0,u.jsxs)("div",{children:[(0,u.jsxs)("p",{className:"mb-2 mt-2 ml-1",children:["Type ",(0,u.jsx)("span",{className:"required__text",children:"*"})]}),(0,u.jsxs)("select",{onChange:e=>x((0,a.A)((0,a.A)({},n),{},{type:e.target.value})),value:n.type,children:[(0,u.jsx)("option",{value:"",children:"--select--"}),(0,u.jsx)("option",{value:"Product",children:"Goods"}),(0,u.jsx)("option",{value:"Service",children:"Service"})]})]})]})]}),(0,u.jsxs)("div",{className:"flex justify-center pt-9 mb-6",children:[(0,u.jsxs)("div",{className:"flex rounded-sm bg-green-500 text-white",children:[(0,u.jsx)(h.F.CHECK,{className:"mt-3 ml-2"}),(0,u.jsx)("button",{className:"p-2",onClick:async e=>{if(""===n.title)return l("Title is required","error");if(""===n.tax)return l("Tax is required","error");if(""===n.type)return l("Type is required","error");try{const e="https://ezybill.ureshiiweightloss.com/api/v1/category/add",i=o.A.get("token"),l=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?(0,a.A)((0,a.A)({},n),{},{token:i,update:!0,id:j}):(0,a.A)((0,a.A)({},n),{},{token:i}))}),r=await l.json();return 200!==l.status||r.err?g(r.err,"error"):(t||x({title:"",tax:"",hsn:"",type:"",details:""}),g(t?"Category update success":"Category create success","success"),s?void s(!0):y("/admin/item-category"))}catch(i){return g("Something went wrong","error")}},children:t?"Update":"Save"})]}),(0,u.jsxs)("div",{className:"flex rounded-sm ml-4 bg-blue-500 text-white",children:[(0,u.jsx)(h.F.RESET,{className:"mt-3 ml-2"}),(0,u.jsx)("button",{className:"p-2",onClick:e=>{x({title:"",tax:"",hsn:"",type:"",details:""})},children:"Reset"})]})]})]})})},m=e=>{let{mode:t}=e;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(l.A,{title:t?"Update Category":"Add Category"}),(0,u.jsxs)("main",{id:"main",children:[(0,u.jsx)(n.A,{}),(0,u.jsx)("div",{className:"content__body",children:(0,u.jsx)(x,{mode:t})})]})]})}}}]);
//# sourceMappingURL=2396.fe26bcf4.chunk.js.map