Files
Rasadyar_FrontEnd/build/assets/SendMassage-BbhK7Cvl.js

2 lines
47 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{j as u,T as b,ak as N,d as Y,B as T,bf as te,ai as O,aX as M,bg as re,a3 as F,ag as Q,av as Z,aw as uu,ax as m,ah as ne,aj as Su,I as K,b0 as Au,b5 as Wu,am as se,an as ae,b4 as Ru,ap as bu,aq as Fu,b as vu,s as $u,ar as oe,a9 as le}from"./mui-vendor-CkIVaoQP.js";import{L as S,j as E,h as v,A as U,V as mu,c as tu,M as q,cs as ie,u as ru,G as h,S as P,ct as ce,C as eu,b as au,O as J,X as _,N as Xu,p as Ce,cu as de,cv as he,cw as pe,cx as Tu,cy as Pu,cz as cu,cA as Ou,cB as Nu,cC as Cu,cD as xe,cE as ge,cF as Iu,cG as wu,cH as ku,cI as du,cJ as Mu,cK as Du,cL as hu,cM as pu,cN as Bu,cO as xu,cP as Uu,cQ as gu,cR as zu,cS as Vu}from"./index-Cr86_nOs.js";import{L as X}from"./LinkItem-Tk56BMy7.js";import{r as C,f as ve,k as H}from"./react-vendor-CmFgShSM.js";import{S as Lu}from"./SelectCheck-CAe89SYT.js";import{a as R,u as z,f as Ae}from"./redux-vendor-B7uoacJt.js";import{d as me}from"./Add-CdBsyA2e.js";import{d as je}from"./Refresh-Ct5Xwsd3.js";import{a as Ee,R as Hu}from"./index.esm-Bu7XMDZU.js";import{A as fe}from"./AdvancedTable-BvRVoK6m.js";import{e as Gu,f as lu,g as _e,h as ye}from"./index.esm-BY9chGNa.js";import{B as Se}from"./BackButton-7Uc4b2uz.js";import{a as Re}from"./get-announcement-B1eH8Kwj.js";import{g as be}from"./getRoleList-CIBz1jD_.js";import{P as Yu}from"./PageTable-whKVbv5q.js";import{d as ju}from"./Tune-m0V6JHJm.js";import{d as Fe}from"./PublishedWithChanges-wX45M9wC.js";import{d as Ku}from"./Edit-DVocKJob.js";import{d as Ju}from"./Delete-CTUmuli-.js";import{R as Te}from"./ResponsiveTable-Dua7tTwQ.js";import"./iconBase-BEJYyZsk.js";import"./index-IuzvFnSU.js";import"./Close-C8iZ2Qr6.js";import"./Search-DLgMQCPC.js";import"./styled-components.browser.esm-gS9mh05b.js";import"./FilterAlt-RwhTl5ac.js";const Pe=["Admin","CityOperator","Poultry","ProvinceOperator","ProvinceFinancial","KillHouse","KillHouseVet","VetFarm","Driver","ProvinceInspector","VetSupervisor","Jahad","ProvincialGovernment"],Oe=R("PROVINCE_GET_USERS_BY_ROLES_SERVICE",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.get("diageram",{params:e});return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data}}}),Ne=R("PROVINCE_SEND_SMS_SERVICE",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.post("sms/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data}}});function Ie(){const e=z(),[t]=C.useContext(U),[r,s]=C.useState([]),[i,n]=C.useState([]),[a,x]=C.useState([]);C.useEffect(()=>{if(r.length){const g=r.map(k=>({label:k.fullname,value:k.key}));n(g)}},[r]);const[d]=C.useState(Pe.map((g,k)=>({label:mu(g),value:g}))),l=tu().shape({selectedRoles:ie().required("لطفا نقش را انتخاب کنید"),inputText:q().required("لطفا متن پیامک را وارد کنید")}),o=ru({initialValues:{selectedRoles:[],inputText:""},validationSchema:l,onSubmit:()=>{e(Ne({user:a,message:o.values.inputText,role:o.values.selectedRoles})).then(g=>{g.payload.status===200&&t({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})})}});C.useEffect(()=>{o.validateForm()},[]);const y=g=>{const k=/[آ-ی]/.test(g);let I=0;return k?I=A(g)*980:I=A(g)*1320,o.values.selectedRoles.length?a.length>0?I*a.length+" ریال":I*i.length+" ریال":"نامشخص (پیامک برای کل کاربران ارسال میشود) "},A=g=>{const k=[160,146,153,153],I=[70,64,67,67],L=/[آ-ی]/.test(g)?I:k;let W=g.length,G=0;for(;W>0;){const j=L[G]||L[L.length-1];if(W>=j)W-=j,G++;else{G++;break}}return G};return C.useEffect(()=>{o.values.selectedRoles.length&&e(Oe({role:o.values.selectedRoles.join(",")})).then(g=>s(g.payload.data))},[o.values.selectedRoles]),u.jsxs(h,{container:!0,mx:P.SMALL,justifyContent:"space-between",children:[u.jsx(h,{item:!0,xs:12,sm:12,md:4,lg:3,direction:"column",alignItems:"start",gap:P.SMALL,children:u.jsx(h,{children:u.jsxs("form",{style:{display:"flex",alignItems:"start",flexDirection:"column",gap:P.LARGE},onSubmit:o.handleSubmit,children:[u.jsxs(h,{children:[u.jsx(Lu,{name:"selectedOption",label:"انتخاب نقش",onChange:g=>o.setFieldValue("selectedRoles",g),options:d}),o.errors.selectedOption&&u.jsx(b,{variant:"caption",color:g=>g.palette.grey.A700,children:o.errors.selectedOption})]}),!!i.length&&u.jsxs(h,{container:!0,direction:"column",alignItems:"start",children:[u.jsx(h,{children:u.jsx(Lu,{name:"slaughterHousesListForSelect",label:"انتخاب کاربر",onChange:g=>x(g),options:i})}),u.jsxs(h,{container:!0,gap:P.TINY,mt:P.SMALL,children:[u.jsx(h,{item:!0,children:u.jsx(b,{variant:"button",color:"red",children:"تعداد کاربر انتخابی:"})}),u.jsx(h,{item:!0,mb:P.SMALL,children:u.jsx(b,{variant:"caption",color:g=>g.palette.grey.A700,children:a.length>0?a.length:"همه"})})]})]}),u.jsx(h,{container:!0,children:u.jsxs(h,{container:!0,direction:"column",alignItems:"start",children:[u.jsx(h,{children:u.jsx(N,{style:{width:"280px"},id:"inputText",name:"inputText",label:"متن پیامک را وارد کنید",multiline:!0,rows:10,value:o.values.inputText,onChange:o.handleChange})}),o.errors.inputText&&u.jsx(b,{mt:P.TINY,variant:"caption",color:g=>g.palette.grey.A700,children:o.errors.inputText}),u.jsxs(h,{container:!0,direction:"row",alignItems:"start",gap:P.LARGE,children:[u.jsxs(h,{container:!0,gap:P.TINY,children:[u.jsx(h,{item:!0,children:u.jsx(b,{variant:"button",color:"red",children:"تعداد کاراکتر:"})}),u.jsx(h,{item:!0,mb:P.SMALL,children:u.jsx(b,{variant:"caption",color:g=>g.palette.grey.A700,children:o.values.inputText.length})})]}),u.jsxs(h,{container:!0,gap:P.TINY,children:[u.jsx(h,{item:!0,children:u.jsx(b,{variant:"button",color:"red",children:"تعداد پیامک:"})}),u.jsx(h,{item:!0,mb:P.SMALL,children:u.jsx(b,{variant:"caption",color:g=>g.palette.grey.A700,children:A(o.values.inputText)})})]})]}),u.jsx(h,{children:u.jsx(Y,{title:"در صورتی که کاربری انتخاب نکنید پیغام برای همه کاربران نقش ارسال میشود",placement:"left",children:u.jsx(T,{disabled:!o.isValid,variant:"contained",type:"submit",children:"ارسال پیامک"})})})]})})]})})}),u.jsxs(h,{item:!0,container:!0,direction:"column",alignItems:"start",gap:P.SMALL,xs:12,sm:12,md:7,lg:8,children:[u.jsxs(h,{container:!0,xs:12,sm:12,md:12,lg:12,gap:"20px",alignItems:"center",justifyContent:"start",children:[u.jsxs(h,{children:[u.jsx(b,{sx:{marginRight:"5px"},variant:"v2",color:"green",children:"مانده حساب:"}),u.jsx(b,{variant:"caption",color:g=>g.palette.grey.A700,children:"230,000 ریال"})]}),u.jsxs(h,{children:[u.jsx(b,{sx:{marginRight:"5px"},variant:"v2",color:"red",children:"محاسبه تقریبی هزینه پیام:"}),u.jsxs(b,{variant:"caption",color:g=>g.palette.grey.A700,children:[y(o.values.inputText).toLocaleString()," "]})]}),u.jsxs(h,{xs:12,sm:12,md:12,container:!0,justifyContent:"space-between",children:[u.jsxs(h,{container:!0,justifyContent:"start",gap:P.TINY,children:[u.jsx(T,{component:"a",href:"http://sahandsms.com/OnlineCharge/OnlineCharge.aspx",target:"_blank",startIcon:u.jsx(me,{}),variant:"contained",size:"small",type:"submit",children:"شارژ کیف پول"}),u.jsx(T,{component:"a",href:"http://sahandsms.com/OnlineCharge/OnlineCharge.aspx",startIcon:u.jsx(Ee,{}),variant:"contained",size:"small",type:"submit",color:"success",children:"خروجی اکسل"})]}),u.jsx(h,{children:u.jsx(T,{startIcon:u.jsx(je,{}),variant:"contained",size:"small",type:"submit",color:"success",children:"بروزرسانی پیام ها"})})]})]}),u.jsx(fe,{name:"پیام های ارسال شده",columns:["نقش","نام و نام خانوادگی","تلفن","متن پیام","تاریخ ارسال","وضعیت"]})]})]})}const we=R("PROVINCE_SMS_LINCENSE_SERVICE",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.post("sms_license/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data}}});function ke(){const[e]=C.useContext(U),[t,r]=C.useState({hatching:!1,poultry_request:!1,city_approval:!1,province_approval:!1,kill_request:!1,province_kill_request:!1,farm_veterinarian_approval:!1,kill_house_house_veterinarian_approval:!1,assingment_information:!1,confirmation_of_assingment_information:!1,invoice_payment:!1,invoice_payment_confirmation:!1,inspector_approval:!1,kill_house_request:!1}),s=z(),i=x=>{r({...t,[x.target.name]:x.target.checked})},{provinceGetSmsLincense:n}=Ae(x=>x.provinceSlice);C.useEffect(()=>{s(ce())},[]),C.useEffect(()=>{var x,d,l,c,o,y,A,g,k,I,$,L,W,G;n!=null&&n.length&&r({hatching:(x=n[0])==null?void 0:x.hatching,poultry_request:(d=n[0])==null?void 0:d.poultryRequest,city_approval:(l=n[0])==null?void 0:l.cityApproval,province_approval:(c=n[0])==null?void 0:c.provinceApproval,kill_request:(o=n[0])==null?void 0:o.killRequest,province_kill_request:(y=n[0])==null?void 0:y.provinceKillRequest,farm_veterinarian_approval:(A=n[0])==null?void 0:A.farmVeterinarianApproval,kill_house_house_veterinarian_approval:(g=n[0])==null?void 0:g.killHouseHouseVeterinarianApproval,assingment_information:(k=n[0])==null?void 0:k.assingmentInformation,confirmation_of_assingment_information:(I=n[0])==null?void 0:I.confirmationOfAssingmentInformation,invoice_payment:($=n[0])==null?void 0:$.invoicePayment,invoice_payment_confirmation:(L=n[0])==null?void 0:L.invoicePaymentConfirmation,inspector_approval:(W=n[0])==null?void 0:W.inspectorApproval,kill_house_request:(G=n[0])==null?void 0:G.killHouseRequest})},[n]);const a=x=>{x.preventDefault(),s(we(t)).then(d=>{e({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})})};return u.jsxs(h,{container:!0,direction:"column",alignItems:"start",gap:P.SMALL,children:[u.jsx(h,{children:u.jsx(b,{children:"با تغییر دادن این سطوح، می‌توانید تنظیم کنید که کاربران شما پیامک‌های خودکار را در چه زمان‌هایی دریافت کنند."})}),u.jsx(h,{children:u.jsx("form",{onSubmit:a,children:u.jsxs(te,{children:[u.jsx(O,{control:u.jsx(M,{checked:t.hatching,onChange:i,name:"hatching"}),label:"جوجه ریزی مرغدار"}),u.jsx(O,{control:u.jsx(M,{checked:t.poultry_request,onChange:i,name:"poultry_request"}),label:"درخواست کشتار مرغدار"}),u.jsx(O,{control:u.jsx(M,{checked:t.city_approval,onChange:i,name:"city_approval"}),label:"تاییدیه شهرستان"}),u.jsx(O,{control:u.jsx(M,{checked:t.province_approval,onChange:i,name:"province_approval"}),label:"تاییدیه استان"}),u.jsx(O,{control:u.jsx(M,{checked:t.kill_request,onChange:i,name:"kill_request"}),label:"درخواست کشتار کشتارگاه"}),u.jsx(O,{control:u.jsx(M,{checked:t.province_kill_request,onChange:i,name:"province_kill_request"}),label:"تخصیص استان"}),u.jsx(O,{control:u.jsx(M,{checked:t.farm_veterinarian_approval,onChange:i,name:"farm_veterinarian_approval"}),label:"تاییدیه دامپزشک فارم"}),u.jsx(O,{control:u.jsx(M,{checked:t.kill_house_request,onChange:i,name:"kill_house_request"}),label:"تخصیص کشتارگاه"}),u.jsx(O,{control:u.jsx(M,{checked:t.kill_house_house_veterinarian_approval,onChange:i,name:"kill_house_house_veterinarian_approval"}),label:"تاییدیه دامپزشک"}),u.jsx(O,{control:u.jsx(M,{checked:t.assingment_information,onChange:i,name:"assingment_information"}),label:"ورود اطلاعات بار"}),u.jsx(O,{control:u.jsx(M,{checked:t.confirmation_of_assingment_information,onChange:i,name:"confirmation_of_assingment_information"}),label:"تاییدیه اطلاعات بار/صدور فاکتور"}),u.jsx(O,{control:u.jsx(M,{checked:t.invoice_payment,onChange:i,name:"invoice_payment"}),label:"پرداخت فاکتور"}),u.jsx(O,{control:u.jsx(M,{checked:t.invoice_payment_confirmation,onChange:i,name:"invoice_payment_confirmation"}),label:"تاییدیه پرداخت فاکتور"}),u.jsx(O,{control:u.jsx(M,{checked:t.inspector_approval,onChange:i,name:"inspector_approval"}),label:"تاییدیه بازرس"}),u.jsx(h,{children:u.jsx(T,{type:"submit",variant:"contained",children:"ثبت"})})]})})})]})}const Me=R("PROVINCE_SMS_ANNOUNCEMENT",async(e,{dispatch:t})=>{t(S());const{data:r,status:s}=await E.put("announcements/0/",e);return t(v()),{data:r,status:s}}),De=()=>{const[e]=C.useContext(U),[t,r]=C.useState(0),[s,i]=C.useState([]),n=o=>{r(o.target.value)},a=z();C.useEffect(()=>{a(Re()).then(o=>{var y,A;i(o.payload.data),c.setFieldValue("status",((y=o.payload.data[0])==null?void 0:y.active)===!0?"true":"false"),c.setFieldValue("announcement",(A=o.payload.data[0])==null?void 0:A.description)})},[]);const x={status:"",announcement:""},d=tu().shape({status:q().required("لطفا وضعیت را انتخاب کنید"),announcement:q().when("status",{is:"true",then:q().required("لطفا متن اعلان را وارد کنید!")})});C.useEffect(()=>{s.length&&(c.setFieldValue("status",s[t].active===!0?"true":"false"),s[t].description?c.setFieldValue("announcement",s[t].description):c.setFieldValue("announcement",""))},[t]);const c=ru({initialValues:x,validationSchema:d,onSubmit:o=>{a(Me({active:o.status==="true",description:o.announcement,key:s[t].key})).then(y=>{y.error?e({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):e({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})})}});return u.jsx(re,{maxWidth:"md",children:u.jsx("div",{style:{backgroundColor:"#ffffff",padding:"20px",borderRadius:"4px",boxShadow:"0px 4px 10px rgba(0, 0, 0, 0.1)",transition:"box-shadow 0.3s ease",":hover":{boxShadow:"0px 8px 20px rgba(0, 0, 0, 0.2)"}},children:u.jsx("form",{onSubmit:c.handleSubmit,children:u.jsxs(F,{container:!0,spacing:3,children:[u.jsx(F,{container:!0,item:!0,xs:12,alignItems:"center",children:u.jsx(F,{item:!0,xs:12,sm:6,children:u.jsxs(Q,{children:[u.jsx(Z,{id:"demo-simple-select-label",children:"مقصد"}),u.jsxs(uu,{labelId:"demo-simple-select-label",id:"demo-simple-select",value:t,label:"مقصد",onChange:n,size:"small",children:[u.jsx(m,{value:0,children:"کشتارگاه"}),u.jsx(m,{value:1,children:"شهرستان"})]})]})})}),u.jsx(F,{item:!0,xs:12,children:u.jsxs(ne,{row:!0,"aria-label":"status",name:"status",value:c.values.status,onChange:c.handleChange,children:[u.jsx(O,{value:"true",control:u.jsx(Su,{}),label:"فعال"}),u.jsx(O,{value:"false",control:u.jsx(Su,{}),label:"غیر فعال"})]})}),c.values.status==="true"&&u.jsx(F,{item:!0,xs:12,children:u.jsx(N,{id:"announcement",name:"announcement",label:"متن اعلان",multiline:!0,rows:4,fullWidth:!0,variant:"outlined",value:c.values.announcement,onChange:c.handleChange,error:c.touched.announcement&&!!c.errors.announcement,helperText:c.touched.announcement&&c.errors.announcement})}),u.jsx(F,{item:!0,xs:12,children:u.jsx(T,{type:"submit",variant:"contained",color:"primary",style:{marginTop:"16px"},children:"ثبت"})})]})})})})},Be=R("PROVINCE_SEND_REPORT_GET_TIMES",async(e,{dispatch:t})=>{t(S());const{data:r,status:s}=await E.get("report-submission/");return t(v()),{data:r,status:s}});R("PROVINCE_SEND_REPORT_GET_POSITIONS",async(e,{dispatch:t})=>{t(S());const{data:r,status:s}=await E.get("user-position/");return t(v()),{data:r,status:s}});const Ue=R("PROVINCE_UPDATE_SEND_TIME",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.put("report-submission/0/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),qu=R("PROVINCE_UPDATE_REPORT_STATUS",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.put("user-reports/0/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),ze=R("PROVINCE_UPDATE_SUBMIT_REPORT",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.post("user-reports/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),Ve=R("PROVINCE_SEND_REPORT_GET_REPORTS",async(e,{dispatch:t})=>{t(S());const{data:r,status:s}=await E.get("reports/");return t(v()),{data:r,status:s}}),Le=({fetchApiData:e})=>{const[t]=C.useContext(U),r=z(),[s,i]=C.useState(12),[n,a]=C.useState("روزانه");C.useEffect(()=>{r(Be()).then(l=>{var c,o,y,A;i((o=(c=l.payload)==null?void 0:c.data)==null?void 0:o.hour),a((A=(y=l==null?void 0:l.payload)==null?void 0:y.data)==null?void 0:A.type)})},[]);const x=l=>{i(l.target.value)},d=l=>{a(l.target.value)};return u.jsxs(h,{xs:12,container:!0,gap:2,children:[u.jsxs(Q,{fullWidth:!0,children:[u.jsx(Z,{id:"demo-simple-select-label",children:"ارسال"}),u.jsxs(uu,{labelId:"demo-simple-select-label",label:"ارسال",value:n,onChange:d,children:[u.jsx(m,{value:"روزانه",children:"روزانه"}),u.jsx(m,{value:"یک روز در میان",children:"یک روز در میان"})]})]}),u.jsxs(Q,{fullWidth:!0,children:[u.jsx(Z,{id:"demo-simple-select-label",children:"ساعت"}),u.jsxs(uu,{labelId:"demo-simple-select-label",label:"ساعت",value:s,onChange:x,children:[u.jsx(m,{value:1,children:"1"}),u.jsx(m,{value:2,children:"2"}),u.jsx(m,{value:3,children:"3"}),u.jsx(m,{value:4,children:"4"}),u.jsx(m,{value:5,children:"5"}),u.jsx(m,{value:6,children:"6"}),u.jsx(m,{value:7,children:"7"}),u.jsx(m,{value:8,children:"8"}),u.jsx(m,{value:9,children:"9"}),u.jsx(m,{value:10,children:"10"}),u.jsx(m,{value:11,children:"11"}),u.jsx(m,{value:12,children:"12"}),u.jsx(m,{value:13,children:"13"}),u.jsx(m,{value:14,children:"14"}),u.jsx(m,{value:15,children:"15"}),u.jsx(m,{value:16,children:"16"}),u.jsx(m,{value:17,children:"17"}),u.jsx(m,{value:18,children:"18"}),u.jsx(m,{value:19,children:"19"}),u.jsx(m,{value:20,children:"20"}),u.jsx(m,{value:21,children:"21"}),u.jsx(m,{value:22,children:"22"}),u.jsx(m,{value:23,children:"23"}),u.jsx(m,{value:24,children:"24"})]})]}),u.jsx(T,{variant:"contained",fullWidth:!0,onClick:()=>{r(Ue({type:n,hour:s})).then(l=>{l.payload.error?t({vertical:"top",horizontal:"center",msg:l.payload.error,severity:"error"}):(t({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),e(1),r(eu()))})},children:"ثبت"})]})},Ge=({fetchApiData:e})=>{const[t,r]=C.useState([]),[s,i]=C.useState(),[n]=C.useContext(U),a=z(),x=d=>{const{target:{value:l}}=d;r(typeof l=="string"?l.split(","):l)};return C.useEffect(()=>{a(Ve()).then(d=>{i(d.payload.data)})},[a]),u.jsxs(h,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(Q,{fullWidth:!0,children:[u.jsx(Z,{id:"demo-simple-select-label",children:"گزارش"}),u.jsx(uu,{labelId:"demo-simple-select-label",label:"گزارش",value:t,onChange:x,multiple:!0,children:s==null?void 0:s.map((d,l)=>u.jsx(m,{value:d==null?void 0:d.key,children:d==null?void 0:d.title},l))})]}),u.jsx(T,{variant:"contained",fullWidth:!0,disabled:!(t!=null&&t.length),onClick:()=>{a(ze({reports_list:t})).then(d=>{d.payload.error?n({vertical:"top",horizontal:"center",msg:d.payload.error,severity:"error"}):(n({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),e(1),a(eu()))})},children:"ثبت"})]})},qe=R("PROVINCE_SEND_REPORT_NEW_USER",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.post("reports-users/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),Qu=R("PROVINCE_SEND_REPORT_EDIT_USER",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.put("reports-users/0/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),We=R("PROVINCE_DELETE_USER_REPORT",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.delete("reports-users/"+e+"/");return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),Zu=({fetchApiData:e,isEdit:t,item:r})=>{var d;const s=z(),[i]=C.useContext(U),n=tu({firstname:q().required("این فیلد اجباری است"),lastname:q().required("این فیلد اجباری است"),mobile:au().required("این فیلد اجباری است!").typeError("لطفا اعداد انگلیسی وارد کنید!").test("len","شماره تلفن باید 11 رقم باشد!",(l,c)=>c.originalValue&&c.originalValue.length===11),post:q().required("این فیلد اجباری است"),city:q().required("این فیلد اجباری است")}),a=ru({initialValues:{firstname:r!=null&&r.firstname?r==null?void 0:r.firstname:"",lastname:r!=null&&r.lastname?r==null?void 0:r.lastname:"",mobile:r!=null&&r.mobile?r==null?void 0:r.mobile:"",post:r!=null&&r.position?r==null?void 0:r.position:"",city:r!=null&&r.city?r==null?void 0:r.city:""},validationSchema:n,onSubmit:l=>{t?s(Qu({user_key:r==null?void 0:r.key,firstname:l.firstname,lastname:l.lastname,mobile:l.mobile,position:l.post,city:l.city})).then(c=>{c.payload.error?i({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(i({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),s(eu()),e(1))}):s(qe({firstname:l.firstname,lastname:l.lastname,mobile:l.mobile,position:l.post,city:l.city})).then(c=>{c.payload.error?i({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(i({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),s(eu()),e(1))})}}),x=l=>{a.setFieldValue("post",l.target.value)};return u.jsxs(F,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:1,children:[u.jsx(N,{fullWidth:!0,id:"firstname",name:"firstname",label:"نام",value:a.values.firstname,onChange:a.handleChange,error:a.touched.firstname&&!!a.errors.firstname,helperText:a.touched.firstname&&a.errors.firstname,onBlur:a.handleBlur}),u.jsx(N,{fullWidth:!0,id:"lastname",name:"lastname",label:"نام خانوادگی",value:a.values.lastname,onChange:a.handleChange,error:a.touched.lastname&&!!a.errors.lastname,helperText:a.touched.lastname&&a.errors.lastname,onBlur:a.handleBlur}),u.jsx(N,{id:"mobile",label:"شماره تلفن",variant:"outlined",sx:{width:"100%"},value:a.values.mobile,error:a.touched.mobile?!!a.errors.mobile:null,onChange:a.handleChange,onBlur:a.handleBlur,helperText:a.touched.mobile&&a.errors.mobile?a.errors.mobile:null}),u.jsx(N,{id:"city",label:"شهر",variant:"outlined",sx:{width:"100%"},value:a.values.city,error:a.touched.city?!!a.errors.city:null,onChange:a.handleChange,onBlur:a.handleBlur,helperText:a.touched.city&&a.errors.city?a.errors.city:null}),u.jsxs(Q,{fullWidth:!0,children:[u.jsx(Z,{id:"demo-simple-select-label",children:"سمت"}),u.jsx(uu,{labelId:"demo-simple-select-label",label:"سمت",value:a.values.post,onChange:x,children:(d=be())==null?void 0:d.map((l,c)=>u.jsx(m,{value:l==null?void 0:l.role,children:l==null?void 0:l.translation},c))})]}),u.jsx(T,{color:"primary",variant:"contained",fullWidth:!0,type:"submit",onClick:a.handleSubmit,children:"ثبت"})]})},$e=({item:e,fetchApiData:t})=>{const[r,s]=C.useState(null),[i]=C.useContext(U),n=z(),a=c=>{s(c.currentTarget)},x=()=>{s(null)},d=!!r,l=d?"popover":void 0;return u.jsxs(h,{container:!0,children:[u.jsx(K,{"aria-describedby":l,variant:"contained",color:"primary",onClick:a,children:u.jsx(ju,{})}),u.jsx(Au,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:l,open:d,anchorEl:r,onClose:x,children:u.jsxs(h,{gap:1,style:{padding:"20px",display:"flex",flexDirection:"column"},children:[u.jsx(T,{size:"small",color:"primary",variant:"contained",onClick:()=>n(J({title:"ویرایش عضو",content:u.jsx(Zu,{fetchApiData:t,item:e,isEdit:!0})})),children:"ویرایش"}),u.jsx(T,{size:"small",color:"error",variant:"contained",onClick:()=>{n(We(e==null?void 0:e.id)).then(c=>{c.payload.error?i({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(i({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),t(1))})},children:"حذف"}),u.jsx(O,{control:u.jsx(Wu,{defaultChecked:e==null?void 0:e.active,onClick:()=>{n(Qu({user_key:e==null?void 0:e.key,active:!(e!=null&&e.active)})).then(c=>{c.payload.error?i({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(i({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),t(1))})}}),label:e!=null&&e.active?"فعال":"غیر فعال"})]})})]})},Xe=()=>{const e=z(),[t,r]=C.useState([]),[s,i]=C.useState(!1),[n,a]=C.useState(0),[x,d]=C.useState(10),[l,c]=C.useState(""),[o]=C.useContext(U),y=p=>{c(p.target.value)},A=async(p,f)=>{i(!0);const B=await E.get(`reports-users/?search=filter&value=${f}&page=${p}&role=${_()}&page_size=${x}`);r(B.data.results),a(B.data.count),i(!1)},g=p=>{A(p,l)},k=async(p,f)=>{i(!0);const B=await E.get(`reports-users/?search=filter&value=${l}&page=${f}&role=${_()}&page_size=${p}`);r(B.data.results),a(B.data.count),d(p),i(!1)};C.useEffect(()=>{A(1)},[]);const I=async p=>{p.preventDefault(),i(!0);try{const f=await E.get(`reports-users/?search=filter&value=${l}&role=${_()}`);r(f.data.results),a(f.data.count)}catch(f){console.error("Error fetching data:",f)}finally{i(!1)}};let $=[{name:"عملیات",selector:(p,f)=>u.jsx($e,{item:p,fetchApiData:A}),sortable:!1,wrap:!0,allowOverflow:!0,center:!0},{name:"ردیف",selector:(p,f)=>f+1,sortable:!1,wrap:!0,allowOverflow:!0,center:!0},{name:"وضعیت",selector:(p,f)=>p!=null&&p.active?"فعال":"غیر فعال",sortable:!1,wrap:!0,allowOverflow:!0,center:!0},{name:"نام و نام خانوادگی",selector:(p,f)=>(p==null?void 0:p.firstname)+" "+(p==null?void 0:p.lastname),sortable:!1,wrap:!0,allowOverflow:!0,center:!0},{name:"موبایل",selector:(p,f)=>p==null?void 0:p.mobile,sortable:!1,wrap:!0,allowOverflow:!0,center:!0},{name:"شهر",selector:(p,f)=>p==null?void 0:p.city,sortable:!1,wrap:!0,allowOverflow:!0,center:!0},{name:"سمت",selector:(p,f)=>mu(p==null?void 0:p.position),sortable:!1,wrap:!0,allowOverflow:!0,center:!0}];const[L,W]=C.useState(!1),G=p=>{var f;e(qu({report_key:(f=p==null?void 0:p.report)==null?void 0:f.key,active:L})).then(B=>{B.payload.error?o({vertical:"top",horizontal:"center",msg:B.payload.error,severity:"error"}):(o({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),A(1))})},[j,D]=C.useState([]);return C.useEffect(()=>{var p,f;if(t!=null&&t.length){const B=(f=(p=t[0])==null?void 0:p.userReports)==null?void 0:f.map((w,ou)=>{var nu,su;return{name:u.jsxs(h,{container:!0,direction:"column",alignItems:"center",children:[u.jsx(Y,{placement:"top",title:(nu=w==null?void 0:w.report)==null?void 0:nu.description,children:u.jsx(b,{variant:"body2",children:(su=w==null?void 0:w.report)==null?void 0:su.title})}),u.jsx(Y,{placement:"right",title:"فعال / غیر فعال برای همه",children:u.jsx(K,{color:"primary",onClick:()=>{W(!L,G(w))},children:u.jsx(Fe,{})})})]}),selector:(V,iu)=>{var Eu;return u.jsx(M,{checked:(Eu=V==null?void 0:V.userReports[ou])==null?void 0:Eu.active,name:"item1",onClick:()=>{var fu,_u;e(qu({user_report_key:(fu=V==null?void 0:V.userReports[ou])==null?void 0:fu.key,active:!((_u=V==null?void 0:V.userReports[ou])!=null&&_u.active)})).then(yu=>{yu.payload.error?o({vertical:"top",horizontal:"center",msg:yu.payload.error,severity:"error"}):(o({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),A(1))})}})},sortable:!1,wrap:!0,allowOverflow:!0,center:!0}});D(B)}},[t]),u.jsxs(h,{container:!0,xs:12,justifyContent:"center",alignItems:"center",mt:2,mb:2,children:[u.jsxs(h,{container:!0,justifyContent:"space-between",xs:12,alignItems:"center",style:{width:"100%"},children:[u.jsxs(h,{container:!0,gap:2,alignItems:"center",children:[u.jsx(T,{variant:"contained",onClick:()=>e(J({title:"گزارش جدید",content:u.jsx(Ge,{fetchApiData:A})})),children:"گزارش جدید"}),u.jsx(T,{variant:"contained",onClick:()=>e(J({title:"ثبت عضو جدید",content:u.jsx(Zu,{fetchApiData:A})})),children:"ثبت عضو"})]}),u.jsx(T,{variant:"contained",onClick:()=>e(J({title:"زمان ارسال",content:u.jsx(Le,{fetchApiData:A})})),children:"زمان ارسال"})]}),u.jsx(se,{style:{width:"100%",margin:"30px"}}),u.jsx(h,{xs:12,children:u.jsx(Yu,{title:u.jsxs(h,{container:!0,gap:2,alignItems:"center",mb:2,children:[u.jsx(b,{variant:"body1",children:"لیست گزارشات"}),u.jsxs("form",{onSubmit:I,children:[u.jsx(N,{id:"outlined-basic",size:"small",autoComplete:"off",label:"جستجو",variant:"outlined",style:{width:250},onChange:y}),u.jsx(T,{type:"submit",onClick:I,endIcon:u.jsx(Hu,{}),children:"جستجو"})]})]}),columns:[...$,...j],data:t,progressPending:s,pagination:!0,paginationServer:!0,paginationTotalRows:n,onChangeRowsPerPage:k,onChangePage:g})})]})},He=R("PROVINCE_UPDATE_MOBILE_MESSAGES_ACTIVE_SERVICE",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.put("moving-text-with-role/0/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),ue=R("PROVINCE_UPDATE_MOBILE_MESSAGES_ACTIVE_TEXT_SERVICE",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.put("moving-text/0/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),Ye=R("PROVINCE_UPDATE_SUBMIT_MOVING_TEXT",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.post("moving-text/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),Ke=R("PROVINCE_DELETE_MOVING_TEXT",async(e,{dispatch:t})=>{t(S());const{data:r,status:s}=await E.delete("moving-text/"+e+"/");return t(v()),{data:r,status:s}}),ee=({fetchApiData:e,item:t,isEdit:r})=>{const[s]=C.useContext(U),i=z(),n=ru({initialValues:{movingText:t!=null&&t.movingText?t==null?void 0:t.movingText:""},validationSchema:tu({movingText:q().required("این فیلد اجباری است!").typeError("لطفا فیلد را پر کنید!")})});return C.useEffect(()=>{n.validateForm()},[]),u.jsxs(h,{xs:12,container:!0,direction:"column",gap:2,children:[u.jsx(N,{id:"movingText",label:"متن متحرک",multiline:!0,rows:5,variant:"outlined",sx:{width:"100%",height:"100%"},value:n.values.movingText,error:n.touched.movingText?!!n.errors.movingText:null,onChange:n.handleChange,onBlur:n.handleBlur,helperText:n.touched.movingText&&n.errors.movingText?n.errors.movingText:null}),u.jsx(h,{children:u.jsx(T,{fullWidth:!0,variant:"contained",disabled:!n.isValid,onClick:()=>{r?i(ue({moving_text:n.values.movingText,moving_text_key:t==null?void 0:t.key})).then(a=>{a.payload.error?s({vertical:"top",horizontal:"center",msg:a.payload.error,severity:"error"}):(s({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),i(eu()),e(1))}):i(Ye({moving_text:n.values.movingText})).then(a=>{a.payload.error?s({vertical:"top",horizontal:"center",msg:a.payload.error,severity:"error"}):(s({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),i(eu()),e(1))})},children:"ویرایش توضیحات"})})]})},Je=({item:e,fetchApiData:t})=>{var c;const r=z(),[s]=C.useContext(U),[i,n]=C.useState(null),a=o=>{n(o.currentTarget)},x=()=>{n(null)},d=!!i,l=d?"popover":void 0;return u.jsxs("div",{children:[u.jsx(K,{"aria-describedby":l,variant:"contained",color:"primary",onClick:a,children:u.jsx(ju,{})}),u.jsx(Au,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:l,open:d,anchorEl:i,onClose:x,children:u.jsx("div",{style:{padding:"20px"},children:u.jsxs(h,{container:!0,direction:"column",children:[u.jsx(Y,{title:((c=e.ProvinceInspector)==null?void 0:c.trash)===!0?"فعالسازی متن":"غیر فعال کردن متن",placement:"right",children:u.jsx(O,{size:"small",label:e.active===!0?"فعال":" غیر فعال",control:u.jsx(Wu,{size:"small",checked:e==null?void 0:e.active,onClick:()=>{r(ue({moving_text_key:e==null?void 0:e.key,active:!(e!=null&&e.active)})).then(o=>{o.payload.error?s({vertical:"top",horizontal:"center",msg:o.payload.error,severity:"error"}):(s({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),t(1))})}})})}),u.jsx(Y,{title:"ویرایش",placement:"right",children:u.jsx(K,{color:"primary",onClick:()=>{x(),r(J({title:"ویرایش متن متحرک",content:u.jsx(ee,{fetchApiData:t,item:e,isEdit:!0})}))},children:u.jsx(Ku,{})})}),u.jsx(Y,{title:"حذف متن",placement:"right",children:u.jsx(K,{"aria-label":"delete",color:"error",onClick:()=>{r(Ke(e==null?void 0:e.id)).then(o=>{o.payload.error?s({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است",severity:"error"}):(t(1),s({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:u.jsx(Ju,{})})})]})})})]})},Qe=()=>{const[e]=C.useContext(U),[t,r]=C.useState([]),[s,i]=C.useState(!1),[n,a]=C.useState(0),[x,d]=C.useState(10),[l,c]=C.useState(""),o=j=>{c(j.target.value)},y=z(),A=async(j,D)=>{i(!0);const p=await E.get(`moving-text/?search=filter&value=${D}&page=${j}&page_size=${x}`);r(p.data.results),a(p.data.count),i(!1)},g=j=>{A(j,l)},k=async(j,D)=>{i(!0);const p=await E.get(`moving-text/?search=filter&value=${l}&page=${D}&page_size=${j}`);r(p.data.results),a(p.data.count),d(j),i(!1)};C.useEffect(()=>{A(1)},[]);const I=async j=>{j.preventDefault(),i(!0);try{const D=await E.get(`moving-text/?search=filter&value=${l}`);r(D.data.results),a(D.data.count)}catch(D){console.error("Error fetching data:",D)}finally{i(!1)}};C.useEffect(()=>{A(1)},[]);const $=[{name:"ردیف",selector:(j,D)=>D+1,sortable:!0,wrap:!0,allowOverflow:!0,center:!0,width:"60px"},{name:"عملیات",selector:j=>u.jsx(Je,{fetchApiData:A,item:j}),sortable:!0,wrap:!0,allowOverflow:!0,center:!0},{name:"وضعیت",selector:j=>j!=null&&j.active?"فعال":"غیر فعال",sortable:!0,wrap:!0,allowOverflow:!0,center:!0},{name:"متن",selector:j=>j==null?void 0:j.movingText,sortable:!0,wrap:!0,allowOverflow:!0,center:!0}],[L,W]=C.useState([]);C.useEffect(()=>{var j,D;if(t!=null&&t.length){const p=(D=(j=t[0])==null?void 0:j.roles)==null?void 0:D.map((f,B)=>({name:u.jsx(b,{variant:"body2",children:mu(f==null?void 0:f.role)}),selector:(w,ou)=>{var nu;return u.jsx(M,{checked:(nu=w==null?void 0:w.roles[B])==null?void 0:nu.active,name:"item1",onClick:()=>{var su,V;y(He({moving_text_role_key:(su=w==null?void 0:w.roles[B])==null?void 0:su.key,active:!((V=w==null?void 0:w.roles[B])!=null&&V.active)})).then(iu=>{iu.payload.error?e({vertical:"top",horizontal:"center",msg:iu.payload.error,severity:"error"}):(e({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),A(1))})}})},sortable:!1,wrap:!0,allowOverflow:!0,center:!0}));W(p)}},[t]);const G=u.jsx(h,{container:!0,alignItems:"center",justifyContent:"space-between",gap:2,paddingTop:2,mb:1,children:u.jsxs(h,{container:!0,alignItems:"center",gap:P.SMALL,children:[u.jsx(b,{children:"متن متحرک "}),u.jsxs("form",{onSubmit:I,children:[u.jsx(N,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:o}),u.jsx(T,{type:"submit",onClick:I,endIcon:u.jsx(Hu,{}),children:"جستجو"})]})]})});return u.jsxs(h,{alignItems:"center",justifyContent:"center",mt:4,children:[u.jsx(h,{container:!0,children:u.jsx(T,{variant:"contained",onClick:()=>{y(J({title:"ثبت متن متحرک",content:u.jsx(ee,{fetchApiData:A})}))},children:"متن جدید"})}),u.jsx(Yu,{title:G,columns:[...$,...L],data:t,progressPending:s,pagination:!0,paginationServer:!0,paginationTotalRows:n,onChangeRowsPerPage:k,onChangePage:g})]})},Ze=R("GET_AGE_MESSAGES",async(e,{dispatch:t})=>{t(S());const{data:r,status:s}=await E.get("age-notification-poultry/");return t(v()),{data:r,status:s}}),u6=R("EDIT_AGE_MESSAGES",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.put("age-notification-poultry/0/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),e6=R("SUBMIT_AGE_MESSAGES",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.post("age-notification-poultry/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),t6=R("DELETE_AGE_MESSAGES",async(e,{dispatch:t})=>{t(S());try{const{data:r,status:s}=await E.delete("age-notification-poultry/0/?notif_key="+e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),r6=({item:e,fetchData:t})=>{const[r]=C.useContext(U),s=z(),i=tu({ageRange:au().required("بازه سنی ضروری است").max(99,"عدد دورقمی وارد کنید!"),lossPercent:au().required("درصد افت ضروری است").max(99,"عدد دورقمی وارد کنید!"),message:q().required("پیغام ضروری است").max(500,"حداکثر 500 کاراکتر")}),n=ru({initialValues:{ageRange:e==null?void 0:e.poultryAge,message:e==null?void 0:e.message,lossPercent:e==null?void 0:e.lossesPercent},validationSchema:i,onSubmit:a=>{s(u6({message:a.message,poultry_age:a.ageRange,losses_percent:a.lossPercent,notif_key:e==null?void 0:e.key})).then(x=>{x.payload.error?r({vertical:"top",horizontal:"center",msg:x.payload.error,severity:"error"}):(t(),s(Xu({right:!1,bottom:!1,content:null})),r({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})}});return u.jsx("form",{onSubmit:n.handleSubmit,children:u.jsxs(F,{container:!0,justifyContent:"center",alignItems:"center",xs:12,gap:2,children:[u.jsx(F,{item:!0,xs:12,children:u.jsx(N,{fullWidth:!0,id:"ageRange",name:"ageRange",label:"بازه سنی",variant:"outlined",value:n.values.ageRange,onChange:n.handleChange,onBlur:n.handleBlur,error:n.touched.ageRange&&!!n.errors.ageRange,helperText:n.touched.ageRange&&n.errors.ageRange})}),u.jsx(F,{item:!0,xs:12,children:u.jsx(N,{fullWidth:!0,id:"lossPercent",name:"lossPercent",label:"درصد افت",variant:"outlined",value:n.values.lossPercent,onChange:n.handleChange,onBlur:n.handleBlur,error:n.touched.lossPercent&&!!n.errors.lossPercent,helperText:n.touched.lossPercent&&n.errors.lossPercent})}),u.jsx(F,{item:!0,xs:12,children:u.jsx(N,{fullWidth:!0,multiline:!0,rows:5,id:"message",name:"message",label:"پیغام",variant:"outlined",value:n.values.message,onChange:n.handleChange,onBlur:n.handleBlur,error:n.touched.message&&!!n.errors.message,helperText:n.touched.message&&n.errors.message})}),u.jsx(F,{item:!0,xs:12,children:u.jsx(T,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,children:"ثبت"})})]})})},n6=()=>{const[e,t]=C.useState([]),[r]=C.useContext(U),s=z(),i=tu({ageRange:au().required("بازه سنی ضروری است").max(99,"عدد دورقمی وارد کنید!"),lossPercent:au().required("درصد افت ضروری است").max(99,"عدد دورقمی وارد کنید!"),message:q().required("پیغام ضروری است").max(500,"حداکثر 500 کاراکتر")}),n=ru({initialValues:{ageRange:"",message:"",lossPercent:""},validationSchema:i,onSubmit:(d,{resetForm:l})=>{s(e6({message:d.message,poultry_age:d.ageRange,losses_percent:d.lossPercent})).then(c=>{c.payload.error?r({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(a(),l(),r({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})}}),a=()=>{s(Ze()).then(d=>{var c;const l=(c=d.payload.data)==null?void 0:c.map((o,y)=>[y+1,Ce(o==null?void 0:o.createDate),o==null?void 0:o.lossesPercent,o==null?void 0:o.poultryAge,o==null?void 0:o.message,u.jsx(F,{justifyContent:"center",alignItems:"center",children:u.jsx(x,{item:o,onDelete:()=>{s(t6(o==null?void 0:o.key)).then(A=>{A.payload.error?r({vertical:"top",horizontal:"center",msg:A.payload.error,severity:"error"}):(a(),r({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},onEdit:()=>{s(Xu({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ویرایش خریدار",content:u.jsx(r6,{isEdit:!0,item:o,fetchData:a})}))}})},y)]);t(l)})},x=({onDelete:d,onEdit:l})=>{const[c,o]=C.useState(null),y=!!c,A=$=>{o($.currentTarget)},g=()=>{o(null)},k=()=>{d(),g()},I=()=>{l(),g()};return u.jsxs(F,{children:[u.jsx(Y,{title:"تنظیمات",children:u.jsx(K,{color:"primary",className:"avicultureActiveRequestsBtn",onClick:A,children:u.jsx(ju,{})})}),u.jsx(Au,{open:y,anchorEl:c,onClose:g,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},children:u.jsxs(ae,{sx:{minWidth:140,p:1},children:[u.jsxs(Ru,{onClick:I,sx:{py:1},children:[u.jsx(bu,{children:u.jsx(Ku,{color:"primary"})}),u.jsx(Fu,{primary:u.jsx(b,{variant:"body2",color:"textPrimary",children:"ویرایش"})})]}),u.jsxs(Ru,{onClick:k,sx:{py:1},children:[u.jsx(bu,{children:u.jsx(Ju,{color:"error"})}),u.jsx(Fu,{primary:u.jsx(b,{variant:"body2",color:"textPrimary",children:"حذف"})})]})]})})]})};return C.useEffect(()=>{a()},[s]),u.jsx("form",{onSubmit:n.handleSubmit,children:u.jsxs(F,{container:!0,justifyContent:"space-between",xs:12,spacing:2,children:[u.jsxs(F,{container:!0,spacing:2,xs:12,sm:6,children:[u.jsx(F,{item:!0,xs:6,children:u.jsx(N,{fullWidth:!0,id:"ageRange",name:"ageRange",label:"بازه سنی",variant:"outlined",value:n.values.ageRange,onChange:n.handleChange,onBlur:n.handleBlur,error:n.touched.ageRange&&!!n.errors.ageRange,helperText:n.touched.ageRange&&n.errors.ageRange})}),u.jsx(F,{item:!0,xs:6,children:u.jsx(N,{fullWidth:!0,id:"lossPercent",name:"lossPercent",label:"درصد افت",variant:"outlined",value:n.values.lossPercent,onChange:n.handleChange,onBlur:n.handleBlur,error:n.touched.lossPercent&&!!n.errors.lossPercent,helperText:n.touched.lossPercent&&n.errors.lossPercent})}),u.jsx(F,{item:!0,xs:12,children:u.jsx(N,{fullWidth:!0,multiline:!0,rows:5,id:"message",name:"message",label:"پیغام",variant:"outlined",value:n.values.message,onChange:n.handleChange,onBlur:n.handleBlur,error:n.touched.message&&!!n.errors.message,helperText:n.touched.message&&n.errors.message})}),u.jsx(F,{item:!0,xs:12,children:u.jsx(T,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,children:"ثبت"})})]}),u.jsx(F,{container:!0,spacing:2,xs:12,sm:6,children:u.jsx(Te,{title:"پیغام بازه سنی",paginated:!0,columns:["ردیف","تاریخ ثبت","درصد افت","بازه سنی","متن پیام","عملیات"],data:e})})]})})},s6=R("PROVINCE_SUBMIT_DASHBOARD_NEWS_SERVICE",async(e,{dispatch:t})=>{try{t(S());const{data:r,status:s}=await E.post("dashboard_notification/",e);return t(v()),{data:r,status:s}}catch(r){return t(v()),{error:r.response.data.result}}}),a6=[{id:1,role:"AdminX",name:"ادمین ایکس"},{id:2,role:"SuperAdmin",name:"ادمین کل"},{id:3,role:"ProvinceOperator",name:"مدیر اجرایی"}],o6=$u(le)(({theme:e})=>({padding:e.spacing(4),borderRadius:e.shape.borderRadius*2,boxShadow:e.shadows[4],maxWidth:800,margin:"0 auto"})),l6=$u(T)(({theme:e})=>({marginTop:e.spacing(3),padding:e.spacing(1.5),fontSize:"1rem"})),i6=()=>{const[e,t]=C.useState({title:"",text:"",status:"",selectedRoles:[]}),r=z(),[s]=C.useContext(U),i=x=>{const{name:d,value:l}=x.target;t(c=>({...c,[d]:l}))},n=x=>{const d=x.target.value;t(l=>({...l,selectedRoles:Array.isArray(d)?d:[d]}))},a=()=>{const x={role:e.selectedRoles.map(d=>d.role),title:e.title,text:e.text,status:e.status};r(s6(x)).then(d=>{d.error?s({vertical:"top",horizontal:"center",msg:d.error,severity:"error"}):(s({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),t({title:"",text:"",status:"",selectedRoles:[]}))})};return u.jsx(vu,{sx:{padding:3},children:u.jsxs(o6,{children:[u.jsx(b,{variant:"h5",gutterBottom:!0,sx:{mb:3,fontWeight:600},children:"ایجاد اطلاعیه جدید"}),u.jsxs(h,{container:!0,spacing:3,children:[u.jsx(h,{item:!0,xs:12,children:u.jsx(N,{fullWidth:!0,label:"عنوان",name:"title",value:e.title,onChange:i,variant:"outlined",size:"small"})}),u.jsx(h,{item:!0,xs:12,children:u.jsx(N,{fullWidth:!0,label:"متن توضیحات خبر",name:"text",value:e.text,onChange:i,variant:"outlined",multiline:!0,rows:6,size:"small"})}),u.jsx(h,{item:!0,xs:12,sm:6,children:u.jsx(N,{fullWidth:!0,label:"وضعیت",name:"status",value:e.status,onChange:i,variant:"outlined",size:"small",placeholder:"مثلاً: فوری، عادی، اطلاعیه"})}),u.jsx(h,{item:!0,xs:12,sm:6,children:u.jsxs(Q,{fullWidth:!0,size:"small",children:[u.jsx(Z,{id:"roles-label",children:"نقش ها"}),u.jsx(uu,{labelId:"roles-label",id:"roles-select",multiple:!0,value:e.selectedRoles,onChange:n,renderValue:x=>u.jsx(vu,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:x.map(d=>u.jsx(oe,{label:d.name,size:"small"},d.id))}),children:a6.map(x=>u.jsx(m,{value:x,children:x.name},x.id))})]})}),u.jsx(h,{item:!0,xs:12,sx:{textAlign:"left"},children:u.jsx(l6,{onClick:a,color:"primary",variant:"contained",disabled:!e.title||!e.text||!e.status||e.selectedRoles.length===0,children:"ثبت اطلاعیه"})})]})]})})},M6=()=>{const{pathname:e}=ve();return u.jsx(u.Fragment,{children:u.jsx(vu,{display:"flex",justifyContent:"center",children:u.jsxs(h,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[e===de||e===he||e===pe?u.jsxs(h,{container:!0,direction:"column",justifyContent:"center",alignItems:"center",my:P.MEDIUM,children:[u.jsx(h,{mb:P.SMALL,children:u.jsx(b,{variant:"h5",color:"textSecondary",children:"پیامک ها"})}),u.jsxs(h,{container:!0,gap:P.SMALL,xs:12,justifyContent:"center",children:[u.jsx(H,{to:_()==="SuperAdmin"?Tu:_()==="AdminX"?Pu:cu,active:e===cu?"true":null,children:u.jsx(X,{icon:u.jsx(Gu,{size:30,color:"#244CCC"}),title:"ارسال پیامک",description:"ارسال پیامک برای نقش ها و کاربران مختلف"})}),u.jsx(H,{to:_()==="SuperAdmin"?Ou:_()==="AdminX"?Nu:Cu,active:e===Cu?"true":null,children:u.jsx(X,{icon:u.jsx(lu,{size:30,color:"#244CCC"}),title:"مدیریت پیامک اطلاع رسانی",description:"تعیین گزینه های اطلاع رسانی برای نقش ها و مراحل مختلف"})}),u.jsx(H,{to:_()==="SuperAdmin"?xe:_()==="AdminX"?ge:Iu,active:e===Iu?"true":null,children:u.jsx(X,{icon:u.jsx(lu,{size:30,color:"#244CCC"}),title:"مدیریت پیام های سیستمی",description:"تعیین گزینه های اطلاع رسانی برای نقش ها و مراحل مختلف"})}),u.jsx(H,{to:_()==="SuperAdmin"?wu:_()==="AdminX"?ku:du,active:e===du?"true":null,children:u.jsx(X,{icon:u.jsx(lu,{size:30,color:"#244CCC"}),title:"اعلانات",description:"تعیین گزینه های اطلاع رسانی برای نقش ها و مراحل مختلف"})}),_()==="SuperAdmin"&&u.jsx(H,{to:_()==="SuperAdmin"?Mu:_()==="AdminX"?Du:hu,active:e===hu?"true":null,children:u.jsx(X,{icon:u.jsx(lu,{size:30,color:"#244CCC"}),title:"گزارش دهی",description:"تعیین گزینه های اطلاع رسانی برای نقش ها و مراحل مختلف"})}),(_()==="SuperAdmin"||_()==="AdminX")&&u.jsx(H,{to:_()==="SuperAdmin"?pu:Bu,active:e===pu?"true":null,children:u.jsx(X,{icon:u.jsx(_e,{size:30,color:"#244CCC"}),title:"پیغام متحرک"})}),(_()==="SuperAdmin"||_()==="AdminX")&&u.jsx(H,{to:_()==="SuperAdmin"?xu:Uu,active:e===xu?"true":null,children:u.jsx(X,{icon:u.jsx(Gu,{size:30,color:"#244CCC"}),title:"پیغام بازه سنی"})}),(_()==="SuperAdmin"||_()==="AdminX")&&u.jsx(H,{to:_()==="SuperAdmin"?gu:_()==="AdminX"?zu:Vu,active:e===gu?"true":null,children:u.jsx(X,{icon:u.jsx(ye,{size:30,color:"#244CCC"}),title:"اطلاعیه داشبورد"})})]})]}):u.jsx(Se,{}),(e===cu||e===Tu||e===Pu)&&u.jsx(Ie,{}),(e===Cu||e===Ou||e===Nu)&&u.jsx(ke,{}),(e===du||e===wu||e===ku)&&u.jsx(De,{}),(e===hu||e===Mu||e===Du)&&u.jsx(Xe,{}),(e===pu||e===Bu)&&u.jsx(Qe,{}),(e===xu||e===Uu)&&u.jsx(n6,{}),(e===gu||e===zu||e===Vu)&&u.jsx(i6,{})]})})})};export{M6 as default};